From 33253e48c0f67a177cb0e41459b2a2785b49c5aa Mon Sep 17 00:00:00 2001
From: duhe <226547893@qq.com>
Date: 星期四, 31 十月 2024 10:27:48 +0800
Subject: [PATCH] 工艺路线:调用h_p_Gy_RoutingBillCheck存储过程的地方加一个参数
---
WarM/条码打印/Kf_WeighToBarCode.cs | 829 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 800 insertions(+), 29 deletions(-)
diff --git "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs" "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs"
index 9be67cd..8cb2d8a 100644
--- "a/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs"
+++ "b/WarM/\346\235\241\347\240\201\346\211\223\345\215\260/Kf_WeighToBarCode.cs"
@@ -11,6 +11,8 @@
using System.Threading;
using System.IO;
using Pub_Class;
+using System.IO.Ports;
+using System.Linq;
namespace WarM
{
@@ -26,6 +28,8 @@
public Int64 HInterID = 0;
public string HBillNo = "";
public string HBillType = "1202";
+ public Int64 HMaterID = 0;
+ public string HBatchNo = "";
public Int64 HAuxPropID = 0;
public Int64 HUnitID = 0;
public Int64 HWhID = 0;
@@ -35,7 +39,7 @@
public Int64 HSourceEntryID = 0;
public string HSourceBillNo = "";
public string HSourceBillType = "";
- public Int64 ProcessExchangeInterID = 0;
+ public Int64 HProcessExchangeInterID = 0;
public Int64 HSupID = 0;
public double HSourceQty = 0;
public double HMaterWeight = 0; //鐗╂枡鍏嬮噸
@@ -46,6 +50,8 @@
public string PrintQtyCtl = ""; //鏉$爜鎵撳嵃娆℃暟鎺у埗
public string UpdatePrintQtyCtl = ""; //鏉$爜鎵撳嵃娆℃暟鏇存柊
public string sBarCodeItemID = ""; //鏉$爜鑷鍒�
+ public string HBarCode_Pack = ""; //鎵樻潯鐮�
+ public long HSNo = 0; //缁勬墭璁℃暟鐢�
public DAL.ClsGy_BarCodeBill_Ctl oBar = new DAL.ClsGy_BarCodeBill_Ctl();
public DBUtility.ClsPub.Enum_BillStatus BillStatus;
SQLHelper.ClsCN oCn = new SQLHelper.ClsCN();
@@ -62,6 +68,9 @@
grdMain.DataSource = null;
grdSub.DataSource = null;
chkHDYFlag.Checked = true;
+
+ //璇诲彇 鎵撳紑涓插彛鐨勯厤缃俊鎭�
+ readParams();
}
//绐椾綋鍔犺浇
@@ -108,11 +117,15 @@
{
HInterID = DBUtility.ClsPub.CreateBillID_Prod(HBillType, ref DBUtility.ClsPub.sExeReturnInfo); //寰楀埌鏂板崟鎹甀D
HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true); //寰楀埌鏂板崟鎹彿
+ HSNo = 0;
+ this.lblSNo.Text = "";
}
else if (DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0]["HBack"]) == 1)
{
HInterID = DBUtility.ClsPub.CreateBillID_Prod(HBillType, ref DBUtility.ClsPub.sExeReturnInfo); //寰楀埌鏂板崟鎹甀D
HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(HBillType, ref DBUtility.ClsPub.sExeReturnInfo, true); //寰楀埌鏂板崟鎹彿
+ HSNo = 0;
+ this.lblSNo.Text = "";
}
else
{
@@ -124,7 +137,7 @@
if (grdSub.Rows.Count > 0)
{
grdSub.Rows[0].Selected = true;
- SourceBill();
+ SourceBill(1);
txtHQty.Focus();
}
else
@@ -323,6 +336,12 @@
return false;
}
+ if (DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text) != "")
+ {
+ MessageBox.Show("褰撳墠缁勬墭鏈粨鏉燂紝璇风粨鏉熺粍鎵樺悗鍐嶇偣鍑绘崲鐝紒", "鎻愮ず");
+ return false;
+ }
+
//鍒ゆ柇浼氳鏈熸槸鍚﹀悎鐞�
string s = "";
int sYear = 0;
@@ -383,7 +402,13 @@
private void tc_Click(object sender, EventArgs e)
{
- this.Close();
+ //閫�鍑烘椂鍏抽棴涓插彛
+ if (ComDevice != null)
+ {
+ CloseCom();
+ }
+
+ this.Close();
}
#endregion
@@ -402,8 +427,7 @@
}
Source_Display();
grdSub.Rows[0].Selected = true;
- DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
- SourceBill();
+ SourceBill(2);
txtHBarCode.Text = "";
txtHQty.Focus();
}
@@ -419,8 +443,7 @@
}
Source_Display();
grdSub.Rows[0].Selected = true;
- DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
- SourceBill();
+ SourceBill(2);
txtHBarCode.Text = "";
txtHQty.Focus();
}
@@ -451,11 +474,6 @@
private void cmdSourceBillNo_Click(object sender, EventArgs e)
{
- //鍒濆鍖栧彸杈硅〃澶翠俊鎭�
- cmbHBarCodeType.Items.Clear();
- cmbHBarCodeType.Items.Add("鍞竴鏉$爜");
- DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
-
if (grdSub.CurrentRow == null)
{
MessageBox.Show("璇峰湪宸﹁竟鍗曟嵁鍒楄〃涓�夋嫨涓�琛屽崟鎹紒", "鎻愮ず");
@@ -468,7 +486,7 @@
}
else
{
- SourceBill();
+ SourceBill(3);
txtHQty.Focus();
}
}
@@ -485,6 +503,10 @@
}
SaveBarCode();
BarCode_Display();
+ if (DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text) != "")
+ {
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ }
grdMain.Rows[0].Selected = true;
sBarCodeItemID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.SelectedRows[0].Index].Cells[Fun_GetCol("HItemID")].Value).ToString();
@@ -578,6 +600,38 @@
{
if (MessageBox.Show("鐗╂枡缁存姢鍏嬮噸涓猴細"+HMaterWeight.ToString()+ "锛屽疄闄呭厠閲嶄负锛�" + sQty.ToString() + "锛屾墍杈撳叆瀹為檯鍏嬮噸瓒呭嚭鐗╂枡缁存姢鍏嬮噸鐨勭櫨鍒嗕箣浜屽崄鎴栦笉瓒崇墿鏂欑淮鎶ゅ厠閲嶇殑鐧惧垎涔嬪叓鍗侊紝璇锋鏌ヨ緭鍏ョ殑鏁版嵁鏄惁姝g‘锛�", "鎻愮ず", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
+ //return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ //鏉$爜鐢熸垚鍓嶆帶鍒跺垽鏂�
+ double HNowQty = 0; //绫虫暟
+ double HWeightQyt = 0; //閲嶉噺
+ double HKDQty = 0; //鎵g偣鏁�
+ HNowQty = DBUtility.ClsPub.isDoule(txtHQty.Text);
+ HWeightQyt = DBUtility.ClsPub.isDoule(txtHWeightQyt.Text);
+ HKDQty = DBUtility.ClsPub.isDoule(txtHKDQty.Text);
+
+ DataSet oDsCheck = oCn.RunProcReturn("exec h_p_Kf_WeighToBarCode_AddBarCodeCheck " + HInterID.ToString() + "," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + "," + HProcessExchangeInterID.ToString() + "," + HSourceQty.ToString() + "," + HNowQty.ToString() + "," + HWeightQyt.ToString() + "," + HKDQty.ToString(), "h_p_Kf_WeighToBarCode_AddBarCodeCheck");
+ //
+ if (oDsCheck == null && oDsCheck.Tables[0].Rows.Count == 0)
+ {
+ MessageBox.Show("鏉$爜鐢熸垚鍓嶅垽鏂敊璇紒");
+ return false;
+ }
+ else if (DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0][0]) == "1")
+ {
+ MessageBox.Show(DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HRemark"]), "鎻愮ず");
+ return false;
+ }
+ else if (DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0][0]) == "2")
+ {
+ if (MessageBox.Show(DBUtility.ClsPub.isStrNull(oDsCheck.Tables[0].Rows[0]["HRemark"]), "鎻愮ず", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
+ {
return true;
}
else
@@ -585,7 +639,10 @@
return false;
}
}
- return true;
+ else
+ {
+ return true;
+ }
}
//鐢熸垚鏉$爜
@@ -652,7 +709,7 @@
string HRemark = "";
string HMaterName = "";
string HMaterModel = "";
- string ProcessExchangeBillNo = "";
+ string HProcessExchangeBillNo = "";
Int64 HBarcodeNo = 0; //鍖呮暟
Int64 HBadReasonID = 0; //涓嶈壇鍘熷洜ID
string HCusMaterName = ""; //瀹㈡埛鐗╂枡鍚嶇О
@@ -668,11 +725,15 @@
HRemark = DBUtility.ClsPub.isStrNull(txtHRemark.Text);
HMaterName = DBUtility.ClsPub.isStrNull(txtHMaterName.Text);
HMaterModel = DBUtility.ClsPub.isStrNull(txtHMaterModel.Text);
- ProcessExchangeBillNo = DBUtility.ClsPub.isStrNull(txtHBillNo.Text);
+ HProcessExchangeBillNo = DBUtility.ClsPub.isStrNull(txtHBillNo.Text);
HBarcodeNo = DBUtility.ClsPub.isLong(txtHBarcodeNo.Text);
HBadReasonID = DBUtility.ClsPub.isLong(txtHRemark.Tag);
HCusMaterName = DBUtility.ClsPub.isStrNull(txtHCusMaterName.Text);
HCusModel = DBUtility.ClsPub.isStrNull(txtHCusModel.Text);
+ if (HBarCode_Pack != "")
+ {
+ HSNo = HSNo + 1;
+ }
try
{
@@ -684,24 +745,24 @@
",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate,HMaterialJQty,HMaterialMQty,HNowQty " +
- ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HGiveAwayFlag " +
+ ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HGiveAwayFlag,HBarCode_Pack " +
",HOrderInterID,HOrderEntryID,HOrderBillNo,HCustomQty1,HMaterialModel,HCusModel " +
- ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HLogo " +
+ ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HLogo,HPackflag " +
") Values ("
+ "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty.ToString()
+ ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + HMaker + "',getdate(),0," + HQty.ToString()
+ ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "',''"
+ ", 1," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
+ ", 0,'',getdate(),'','" + sDate + "'," + HMaterialJQty.ToString() + "," + HMaterialMQty.ToString() + "," + HNowQty.ToString()
- + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0"
- + ", " + ProcessExchangeInterID.ToString() + ",0,'" + ProcessExchangeBillNo + "'," + HBadReasonID.ToString() + ",'" + HCusMaterName + "','" + HCusModel + "'"
- + ",'" + HMaterName + "','" + HMaterModel + "',''," + HAuxPropID.ToString() + ",'','','1')");
+ + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0,'" + HBarCode_Pack + "'"
+ + ", " + HProcessExchangeInterID.ToString() + ",0,'" + HProcessExchangeBillNo + "'," + HBadReasonID.ToString() + ",'" + HCusMaterName + "','" + HCusModel + "'"
+ + ",'" + HMaterName + "','" + HMaterModel + "',''," + HAuxPropID.ToString() + ",'','','1',0)");
//鍥炲~鏈�澶ф祦姘村彿
oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "',1 ");
//鍥炲~婧愬崟涓存椂琛℉InterID
- oCn.RunProc("update a set a.HInterID=" + HInterID.ToString() + ",a.HBillNo='" + HBillNo +"',a.HRelationInterID= 0 from KF_WeighSource_Temp a where a.HInterID<>" + HInterID.ToString() + " and a.HMaker='" + HMaker + "' and a.HSourceBillNo='" + ProcessExchangeBillNo + "'");
+ oCn.RunProc("update a set a.HInterID=" + HInterID.ToString() + ",a.HBillNo='" + HBillNo +"',a.HRelationInterID= 0 from KF_WeighSource_Temp a where a.HInterID<>" + HInterID.ToString() + " and a.HMaker='" + HMaker + "' and a.HSourceBillNo='" + HProcessExchangeBillNo + "'");
//鍐欏叆鏉$爜鍑哄叆搴撲复鏃惰〃
oCn.RunProc("Insert into KF_PonderationBillMain_Temp " +
@@ -715,8 +776,8 @@
" Values("
+ HInterID.ToString() + ",'" + HBillNo + "','" + HBillType + "'," + HMaterID.ToString() + "," + HAuxPropID.ToString() + ",0"
+ "," + HWhID.ToString() + ",0," + HSPID.ToString() + ",0,0,''"
- +",0," + HQty.ToString() + ",1,'" + HBatchNo + "','" + HBarCode + "',''"
- +",'" + HMaker + "',getdate()," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillType + "','" + HSourceBillNo + "'"
+ +",0," + HQty.ToString() + ",1,'" + HBatchNo + "','" + HBarCode + "','" + HBarCode_Pack + "'"
+ + ",'" + HMaker + "',getdate()," + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillType + "','" + HSourceBillNo + "'"
+",0,0,'',0,'',0"
+"," + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",'','绉伴噸鍏ュ簱鐢熸垚','2'"
+",0,0,'',0)");
@@ -734,9 +795,53 @@
#region //杩斿洖淇℃伅
- //杩斿洖婧愬崟鍒楄〃淇℃伅
- private void SourceBill()
+ //杩斿洖婧愬崟鍒楄〃淇℃伅(num=1锛屾墦寮�妯″潡鏃跺姞杞芥樉绀猴紱num=2锛屾壂娴佽浆鍗℃樉绀猴紱num=3锛岄�夊崟鎸夐挳鏄剧ず)
+ private void SourceBill(int num)
{
+ //鎵撳紑妯″潡鏃跺姞杞芥樉绀�
+ if (num == 1)
+ {
+ txtHBarCode_Pack.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HBarCode_Pack")].Value);
+ HBarCode_Pack = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HBarCode_Pack")].Value);
+ HSNo = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HSNo")].Value);
+ if (HBarCode_Pack == "")
+ {
+ this.lblSNo.Text = "";
+ }
+ else
+ {
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ cmdHBPack.Enabled = false;
+ }
+ }
+ //鎵祦杞崱鏄剧ず
+ if (num == 2)
+ {
+ //鍒濆鍖栧彸杈硅〃澶翠俊鎭�
+ DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
+ if (HBarCode_Pack != "")
+ {
+ txtHBarCode_Pack.Text = HBarCode_Pack;
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ }
+ }
+ //閫夊崟鎸夐挳鏄剧ず
+ if (num == 3)
+ {
+ if (HBarCode_Pack != "" && (HMaterID != DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HMaterID")].Value)
+ || HBatchNo != DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鎵瑰彿")].Value)))
+ {
+ MessageBox.Show("鎵�鎵弿娴佽浆鍗″搴旂墿鏂欍�佹壒鍙蜂笌褰撳墠姝e湪缁勬墭鐗╂枡銆佹壒鍙蜂笉涓�鑷达紝涓嶅悓鐗╂枡銆佹壒鍙蜂笉鍏佽缁勬墭鍦ㄥ悓涓�鎵樹笂锛屽闇�鎹㈢墿鏂欑敓鎴愭潯鐮佽鍏堢粨鏉熷綋鍓嶇粍鎵橈紒", "鎻愮ず");
+ return;
+ }
+ //鍒濆鍖栧彸杈硅〃澶翠俊鎭�
+ DBUtility.Xt_BaseBillFun.Sub_ClearBill(gbUp);
+ if (HBarCode_Pack != "")
+ {
+ txtHBarCode_Pack.Text = HBarCode_Pack;
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ }
+ }
txtHBillNo.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鍗曟嵁鍙�")].Value);
txtHDeptName.Tag = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HDeptID")].Value);
txtHDeptName.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("杞﹂棿")].Value);
@@ -747,6 +852,8 @@
txtHBatchNo.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鎵瑰彿")].Value);
txtHCusMaterName.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HCusMaterName")].Value);
txtHCusModel.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HCusModel")].Value);
+ HMaterID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HMaterID")].Value);
+ HBatchNo = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鎵瑰彿")].Value);
HAuxPropID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HAuxPropID")].Value);
HUnitID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HUnitID")].Value);
HWhID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HWhID")].Value);
@@ -757,9 +864,10 @@
HSourceBillNo = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鐢熶骇璁㈠崟")].Value);
HSourceBillType = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HSourceBillType")].Value);
HSourceQty = DBUtility.ClsPub.isDoule(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("鏁伴噺")].Value);
- ProcessExchangeInterID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("ProcessExchangeInterID")].Value);
+ HProcessExchangeInterID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("ProcessExchangeInterID")].Value);
HSupID = DBUtility.ClsPub.isLong(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HSupID")].Value);
HMaterWeight = DBUtility.ClsPub.isDoule(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("HMaterWeight")].Value);
+ txtHOrderPickRemark.Text = DBUtility.ClsPub.isStrNull(grdSub.SelectedRows[0].Cells[Fun_GetSubCol("璁㈠崟鍖呰澶囨敞")].Value);
}
//杩斿洖婧愬崟鍒楄〃淇℃伅
@@ -825,6 +933,7 @@
string HItemID = "";
string HBarCode = "";
string HBarCode2 = "";
+ long HSNo_Temp = HSNo;
for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
{
HItemID = HItemID + "," + DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("hmainid")].Value.ToString());
@@ -841,9 +950,35 @@
{
HRemark = HRemark + "銆�" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value);
}
+ //鏇存柊褰撳墠宸茬粍鎵樹欢鏁�
+ if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) != ""
+ && DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) == HBarCode_Pack
+ && DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜绫诲瀷")].Value) != "鎵樼洏鏉$爜")
+ {
+ HSNo = HSNo - 1;
+ }
+ if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜绫诲瀷")].Value) == "鎵樼洏鏉$爜")
+ {
+ if (DBUtility.ClsPub.isBool(grdMain.SelectedRows[i].Cells[Fun_GetCol("HPackflag")].Value))
+ {
+ MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value) + " 涓烘墭鐩樻潯鐮侊紝涓斿凡缁勬墭鐢熸垚瀵瑰簲缁勬墭鍗曪紝涓嶅厑璁镐綔搴燂紒", "鎻愮ず");
+ return;
+ }
+ else if (HSNo > 0)
+ {
+ MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value) + " 涓烘墭鐩樻潯鐮侊紝涓斿綋鍓嶆墭鐩樻潯鐮佷笅宸茬敓鎴愬搴旀潯鐮侊紝涓嶅厑璁镐綔搴燂紒", "鎻愮ず");
+ return;
+ }
+ else
+ {
+ HBarCode_Pack = "";
+ }
+ }
}
if (HRemark != "")
{
+ HSNo = HSNo_Temp;
+ HBarCode_Pack = DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text);
MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細"+ HRemark.Remove(0, 1)+" 宸蹭綔搴燂紝涓嶅厑璁搁噸澶嶄綔搴燂紒", "鎻愮ず");
return;
}
@@ -871,11 +1006,23 @@
catch (Exception e2)
{
oCn.RollBack();
+ HSNo = HSNo_Temp;
+ HBarCode_Pack = DBUtility.ClsPub.isStrNull(txtHBarCode_Pack.Text);
MessageBox.Show("浣滃簾鏉$爜澶辫触锛�" + e2.Message, "鎻愮ず");
return;
}
//鍒锋柊绉伴噸璁板綍鍒楄〃淇℃伅
BarCode_Display();
+ if (HBarCode_Pack != "")
+ {
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ }
+ else
+ {
+ txtHBarCode_Pack.Text = "";
+ this.lblSNo.Text = "";
+ cmdHBPack.Enabled = true;
+ }
MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細" + HBarCode.Remove(0, 1) + " 浣滃簾鎴愬姛锛�", "鎻愮ず");
}
}
@@ -903,6 +1050,27 @@
string HItemID = "";
string HBarCode = "";
string HBarCode2 = "";
+ long HSNo_Temp = HSNo;
+ bool HFlag = false;
+
+ //鐣岄潰涓婁负鏈惎鐢ㄧ粍鎵樼姸鎬�
+ if (HBarCode_Pack == "")
+ {
+ for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
+ {
+ //鍒ゆ柇鏉$爜鏄惁涓烘墭鐩樻潯鐮侊紝鏈敓鎴愮粍鎵樺崟锛屽凡浣滃簾鐘舵�侊紝鐣岄潰涓婁负鏈粍鎵樼姸鎬�
+ if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜绫诲瀷")].Value) == "鎵樼洏鏉$爜"
+ && DBUtility.ClsPub.isBool(grdMain.SelectedRows[i].Cells[Fun_GetCol("HPackflag")].Value) == false
+ && DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("浣滃簾鏍囪")].Value) != ""
+ )
+ {
+ HFlag = true;
+ HBarCode_Pack = DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value);
+ break;
+ }
+ }
+ }
+
for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
{
HItemID = HItemID + "," + DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("hmainid")].Value.ToString());
@@ -919,9 +1087,44 @@
{
HRemark = HRemark + "銆�" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value);
}
+
+ //鏉$爜涓虹粍鎵樻潯鐮�
+ if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) != "")
+ {
+ //宸蹭笂浼犵敓鎴愮粍鎵樺崟
+ if (DBUtility.ClsPub.isBool(grdMain.SelectedRows[i].Cells[Fun_GetCol("HPackflag")].Value))
+ {
+
+ }
+ //鏈笂浼犵敓鎴愮粍鎵樺崟
+ else
+ {
+ //鏉$爜瀵瑰簲鎵樻潯鐮佸拰鐣岄潰涓婄殑鎵樻潯鐮佷竴鑷�
+ if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) == HBarCode_Pack)
+ {
+ //鏇存柊褰撳墠宸茬粍鎵樹欢鏁�
+ if (DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜绫诲瀷")].Value) != "鎵樼洏鏉$爜")
+ {
+ HSNo = HSNo + 1;
+ }
+
+ }
+ //鏉$爜瀵瑰簲鎵樻潯鐮佸拰鐣岄潰涓婄殑鎵樻潯鐮佷笉涓�鑷�
+ else
+ {
+ MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value) + " 瀵瑰簲鎵樻潯鐮侊細" + DBUtility.ClsPub.isStrNull(grdMain.SelectedRows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) + " 宸茬敓鎴愮粍鎵樺崟锛屾垨宸蹭綔搴燂紝涓嶅厑璁稿弽浣滃簾锛�", "鎻愮ず");
+ return;
+ }
+ }
+ }
}
if (HRemark != "")
{
+ HSNo = HSNo_Temp;
+ if(HFlag)
+ {
+ HBarCode_Pack = "";
+ }
MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細" + HRemark.Remove(0, 1) + " 鏈綔搴燂紝涓嶅厑璁稿弽浣滃簾锛�", "鎻愮ず");
return;
}
@@ -952,12 +1155,12 @@
",HCusID,HDeptID,HCusBarCode,HMulSourceBill) " +
" select " + HInterID.ToString() + ",'" + HBillNo + "','" + HBillType + "',HMaterID,HAuxPropID,0" +
",HWhID,0,HSPID,0,0,''" +
- ",0,HQty,1,HBatchNo,HBarCode,''" +
+ ",0,HQty,1,HBatchNo,HBarCode,HBarCode_Pack" +
",'" + HMaker + "',getdate(),HSourceInterID,HSourceEntryID,HSourceBillType,HSourceBillNo" +
",0,0,'',0,'',0" +
",HSTOCKORGID,HSTOCKORGID,HSTOCKORGID,'','绉伴噸鍏ュ簱鐢熸垚-鍙嶄綔搴�','2'" +
",0,0,'',0" +
- "from Gy_BarCodeBill with(nolock) where HItemID in (" + HItemID + ")"
+ "from Gy_BarCodeBill with(nolock) where HItemID in (" + HItemID + ") and HBarCodeType='鍞竴鏉$爜' "
);
//鍐欏叆绯荤粺鏃ュ織
@@ -970,11 +1173,28 @@
catch (Exception e2)
{
oCn.RollBack();
+ HSNo = HSNo_Temp;
+ if (HFlag)
+ {
+ HBarCode_Pack = "";
+ }
MessageBox.Show("鍙嶄綔搴熸潯鐮佸け璐ワ紒" + e2.Message, "鎻愮ず");
return;
}
//鍒锋柊绉伴噸璁板綍鍒楄〃淇℃伅
BarCode_Display();
+ if (HBarCode_Pack != "")
+ {
+ txtHBarCode_Pack.Text = HBarCode_Pack;
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ cmdHBPack.Enabled = false;
+ }
+ else
+ {
+ txtHBarCode_Pack.Text = "";
+ this.lblSNo.Text = "";
+ cmdHBPack.Enabled = true;
+ }
MessageBox.Show("鎵�閫夋潯鐮佺紪鍙凤細" + HBarCode.Remove(0, 1) + " 鍙嶄綔搴熸垚鍔燂紒", "鎻愮ず");
}
}
@@ -996,9 +1216,560 @@
#endregion
+ #region //寮�濮嬬粍鎵�
+ private void cmdHBPack_Click(object sender, EventArgs e)
+ {
+ if (!PackSub_AllowSave())
+ {
+ return;
+ }
+ HSNo = 0;
+ SavePackBarCode();
+ BarCode_Display();
+ this.lblSNo.Text = "褰撳墠宸茬粍 " + HSNo + " 浠�";
+ grdMain.Rows[0].Selected = true;
+ txtHBarCode_Pack.Text = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[0].Index].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value);
+ HBarCode_Pack = DBUtility.ClsPub.isStrNull(grdMain.Rows[grdMain.SelectedRows[0].Index].Cells[Fun_GetCol("鏉$爜缂栧彿")].Value);
+ cmdHBPack.Enabled = false;
+
+ sBarCodeItemID = DBUtility.ClsPub.isLong(grdMain.Rows[grdMain.SelectedRows[0].Index].Cells[Fun_GetCol("HItemID")].Value).ToString();
+ //鑷姩鎵撳嵃
+ //if (chkHDYFlag.Checked == true)
+ //{
+ // //鎵撳嵃鏉$爜
+ // Sub_SetReport("鎵樼洏鏉$爜");
+ // Report.Print(false);
+ // Thread.Sleep(1000);
+ //}
+ //else
+ {
+ //閫夋嫨鎵撳嵃妯℃澘
+ BLL.Gy_OpenTmp oFrm = new BLL.Gy_OpenTmp();
+ oFrm.sBillName = ModName;
+ oFrm.sBillModel = ModCaption;
+ oFrm.ShowDialog();
+ if (oFrm.OKTag == Pub_Class.ClsPub.Enum_OKTag.OKTag_OK)
+ {
+ Sub_SetReport(oFrm.sOpenTmp);
+ Report.Print(false);
+ Thread.Sleep(1000);
+ }
+ }
+ }
+
+ //鏉$爜鐢熸垚鍓嶅垽鏂�
+ private bool PackSub_AllowSave()
+ {
+ //鍒ゆ柇褰撳墠鍗曟嵁ID鏄惁宸蹭笂浼犵敓鎴愬崟鎹�
+ DataSet Ds = oCn.RunProcReturn("select top 1 1 from KF_WeighSource_Temp with(nolock) where HInterID=" + HInterID.ToString() + " and HRelationInterID=1 ", "KF_WeighSource_Temp", ref DBUtility.ClsPub.sExeReturnInfo);
+ if (Ds == null || Ds.Tables[0].Rows.Count == 0)
+ {
+ }
+ else
+ {
+ MessageBox.Show("褰撳墠鏉$爜璁板綍宸叉崲鐝笂浼犵敓鎴愬崟鎹紝璇烽��鍑哄悗閲嶆柊杩涘叆璇ユā鍧楄繘琛屾潯鐮佺敓鎴愭搷浣滐紒", "鎻愮ず");
+ return false;
+ }
+
+ if (HInterID == 0 || HBillNo == "")
+ {
+ MessageBox.Show("鑾峰彇鏉$爜瀵瑰簲鍗曟嵁ID鎴栧崟鎹彿澶辫触锛岃閲嶆柊鍒锋柊鐣岄潰锛�", "鎻愮ず");
+ return false;
+ }
+ if (HProcessExchangeInterID == 0)
+ {
+ MessageBox.Show("璇峰厛鎵弿娴佽浆鍗″彿锛�", "鎻愮ず");
+ return false;
+ }
+ return true;
+ }
+
+ //鐢熸垚鎵樼洏鏉$爜
+ private void SavePackBarCode()
+ {
+ int LSHlen = 6; //娴佹按鍙烽暱搴�
+ Int64 LSH = 0; //娴佹按鍙�
+ string LSH2 = ""; //娴佹按鍙疯浆鎹㈡垚瀛楃
+ string sDate = ""; //鏃ユ湡
+ string sYear = ""; //骞�
+ string sPeriod = ""; //鏈�
+ string sDay = ""; //鏃�
+ string sTMNumber = ""; //鏉$爜鑷畾涔夊墠缂�
+ string TM = ""; //鏉$爜缂栧彿
+ DataSet Ds;
+
+ //鏃ユ湡鑾峰彇鏂瑰紡
+ sDate = dtpHDate.Value.ToShortDateString();
+ sYear = DBUtility.ClsPub.isDate(sDate).Year.ToString().Substring(2, 2);
+ sPeriod = "0" + DBUtility.ClsPub.isDate(sDate).Month.ToString();
+ sPeriod = sPeriod.Substring(sPeriod.Length - 2, 2);
+ sDay = "0" + DBUtility.ClsPub.isDate(sDate).Day.ToString();
+ sDay = sDay.Substring(sDay.Length - 2, 2);
+ //==================================
+ //鏉$爜鍓嶇紑 = 'TP' + 缁勭粐浠g爜 + 骞� + 鏈� + 鏃�
+ sTMNumber = "TP" + DBUtility.ClsPub.HOrgNumber + sYear + sPeriod + sDay;
+ Ds = oCn.RunProcReturn("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo"); //鑾峰彇鏈�澶ф祦姘村彿
+ LSH = DBUtility.ClsPub.isLong(Ds.Tables[0].Rows[0][0]);
+ LSH = LSH + 1;
+ LSH2 = LSH.ToString();
+ while (LSH2.Length < LSHlen) //濡傛灉娴佹按鍙峰皬浜�6浣嶆暟鍓嶉潰琛�0
+ {
+ LSH2 = "0" + LSH2;
+ }
+ TM = sTMNumber + LSH2;
+
+ string HBarCode = "";
+ string HBarCodeType = "";
+ string HMaterID = ""; //鐗╂枡鍐呯爜
+ string HBatchNo = ""; //鎵规
+ string HMaterName = "";
+ string HMaterModel = "";
+ string HProcessExchangeBillNo = "";
+ string HCusMaterName = ""; //瀹㈡埛鐗╂枡鍚嶇О
+ string HCusModel = ""; //瀹㈡埛瑙勬牸鍨嬪彿
+
+ HBarCode = TM;
+ HBarCodeType = "鎵樼洏鏉$爜";
+ HMaterID = DBUtility.ClsPub.isStrNull(txtHMaterNumber.Tag);
+ HBatchNo = DBUtility.ClsPub.isStrNull(txtHBatchNo.Text);
+ HMaterName = DBUtility.ClsPub.isStrNull(txtHMaterName.Text);
+ HMaterModel = DBUtility.ClsPub.isStrNull(txtHMaterModel.Text);
+ HProcessExchangeBillNo = DBUtility.ClsPub.isStrNull(txtHBillNo.Text);
+ HCusMaterName = DBUtility.ClsPub.isStrNull(txtHCusMaterName.Text);
+ HCusModel = DBUtility.ClsPub.isStrNull(txtHCusModel.Text);
+
+ try
+ {
+ oCn.BeginTran();
+ //鍐欏叆鏉$爜妗f
+ oCn.RunProc("Insert into Gy_BarCodeBill " +
+ "(HBarCode,HBarCodeType,HMaterID,HUnitID,HQty,HBarCode_Pack" +
+ ",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
+ ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
+ ",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
+ ",HCusID,HCusType,HEndDate,HWorkLineName,HBarCodeDate,HMaterialJQty,HMaterialMQty,HNowQty " +
+ ",HSTOCKORGID,HOWNERID,HSeOrderBillNo,HInterID,HGiveAwayFlag " +
+ ",HOrderInterID,HOrderEntryID,HOrderBillNo,HCustomQty1,HMaterialModel,HCusModel " +
+ ",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInnerBillNo,HLogo,HPackflag " +
+ ") Values ("
+ + "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + ",1,'" + HBarCode + "'"
+ + ",'" + HBatchNo + "'," + HSupID.ToString() + ",0,'" + HMaker + "',getdate(),0,1"
+ + ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillType + "',''"
+ + ",1,0,0,0,0,''"
+ + ", 0,'',getdate(),'','" + sDate + "',0,0,0"
+ + ", " + HStockOrgID.ToString() + "," + HStockOrgID.ToString() + ",''," + HInterID.ToString() + ",0"
+ + ", " + HProcessExchangeInterID.ToString() + ",0,'" + HProcessExchangeBillNo + "',0,'" + HCusMaterName + "','" + HCusModel + "'"
+ + ",'" + HMaterName + "','" + HMaterModel + "',''," + HAuxPropID.ToString() + ",'','','1',0)");
+
+ //鍥炲~鏈�澶ф祦姘村彿
+ oCn.RunProc("exec h_p_WMS_SetMaxNo_QTY '" + sTMNumber + "',1 ");
+ oCn.Commit();
+ }
+ catch (Exception e)
+ {
+ oCn.RollBack();
+ MessageBox.Show("鎵樼洏鏉$爜鐢熸垚澶辫触锛�" + e.Message);
+ }
+ }
+
+
+ #endregion
+
+ #region //缁撴潫缁勬墭
+ private void cmdHEPack_Click(object sender, EventArgs e)
+ {
+ //鐢熸垚缁勬墭鍗曞墠鍒ゆ柇
+ if(HBarCode_Pack=="")
+ {
+ MessageBox.Show("璇峰厛鐐瑰嚮寮�濮嬬粍鎵橈紝杩涜鏉$爜缁勬墭鎿嶄綔锛�", "鎻愮ず");
+ return;
+ }
+ bool b = false;
+ for (int i = 0; i < grdMain.RowCount; i++)
+ {
+ if (DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("鏉$爜绫诲瀷")].Value) == "鍞竴鏉$爜"
+ && DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("HBarCode_Pack")].Value) == HBarCode_Pack
+ && DBUtility.ClsPub.isStrNull(grdMain.Rows[i].Cells[Fun_GetCol("浣滃簾鏍囪")].Value) == "")
+ {
+ b = true;
+ break;
+ }
+ }
+ if (b == false)
+ {
+ MessageBox.Show("褰撳墠鎵樼洏鏉$爜涓嬭繕娌$敓鎴愬搴旀潯鐮侊紝涓嶅厑璁哥敓鎴愮粍鎵樺崟锛�", "鎻愮ず");
+ return;
+ }
+
+ //鍒ゆ柇浼氳鏈熸槸鍚﹀悎鐞�
+ string s = "";
+ int sYear = 0;
+ int sPeriod = 0;
+ if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(HDate, ref sYear, ref sPeriod, ref s) == false)
+ {
+ MessageBox.Show(s, "鎻愮ず");
+ return;
+ }
+
+ try
+ {
+ oCn.BeginTran();
+ //鐢熸垚鐢熶骇缁勬墭鍗�
+ Int64 HPUInterID = DBUtility.ClsPub.CreateBillID_Prod("3783", ref DBUtility.ClsPub.sExeReturnInfo); //寰楀埌鏈�鏂扮敓浜х粍鎵樺崟ID
+ string HPUBillNo = DBUtility.ClsPub.CreateBillCode_Prod("3783", ref DBUtility.ClsPub.sExeReturnInfo, true); //寰楀埌鏈�鏂扮敓浜х粍鎵樺崟鍙�
+
+ //鍐欏叆鐢熶骇缁勬墭鍗曚富琛�
+ oCn.RunProc("Insert Into Sc_PackUnionBillMain " +
+ "(HInterID,HBillNo,HBillType,HBillSubType,HDate,HRemark" +
+ ",HYear,HPeriod,HChecker,HCheckDate,HMaker,HMakeDate" +
+ ",HICMOInterID,HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID,HProdOrgID" +
+ ") Values ("
+ + " " + HPUInterID.ToString() + ",'" + HPUBillNo + "','3783','3783',convert(varchar(10),getdate(),120),''"
+ + "," + sYear.ToString() + "," + sPeriod.ToString() + ",'" + HMaker + "',getdate(),'" + HMaker + "',getdate()"
+ + ",0,'','" + HBarCode_Pack + "',0,0," + HStockOrgID.ToString() + ") ");
+
+ //鍐欏叆鐢熶骇瑁呯鍗曞瓙琛�
+ oCn.RunProc("Insert into Sc_PackUnionBillSub " +
+ "(HInterID,HEntryID,HRelationQty,HRelationMoney,HRemark" +
+ ",HMaterID,HUnitID,HQty,HBarCode,HBarCode_Pack,HScanDate" +
+ ",HAuxPropID,HBatchNo,HMTONo" +
+ ",HSourceID,HEquipID,HGroupID,HWorkerID,HStatus" +
+ ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType) " +
+ " select " + HPUInterID.ToString() + ",HItemID,0,0,''" +
+ ",HMaterID,HUnitID,HQty,HBarCode,HBarCode_Pack,getdate()" +
+ ",HAuxPropID,HBatchNo,HMTONo" +
+ ",0,0,0,0,0" +
+ ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType" +
+ " from Gy_BarCodeBill with(nolock) where HInterID=" + HInterID.ToString() + " and HBarCode_Pack='" + HBarCode_Pack + "' and HStopflag=0 and HBarCodeType='鍞竴鏉$爜' "
+ );
+
+ //鍥炲~鏉$爜妗f缁勬墭鏍囪
+ oCn.RunProc("update Gy_BarCodeBill set HPackflag=1 where HInterID=" + HInterID.ToString() + " and HBarCode_Pack='" + HBarCode_Pack + "' and HStopflag=0", ref DBUtility.ClsPub.sExeReturnInfo);
+
+ MessageBox.Show("鐢熸垚鐢熶骇缁勬墭鍗曪細" + HPUBillNo + " 鎴愬姛锛�", "鎻愮ず");
+
+ txtHBarCode_Pack.Text = "";
+ HBarCode_Pack = "";
+ cmdHBPack.Enabled = true;
+ HSNo = 0;
+ this.lblSNo.Text = "";
+ BarCode_Display();
+ oCn.Commit();
+ return;
+ }
+ catch (Exception e2)
+ {
+ oCn.RollBack();
+ MessageBox.Show("鐢熸垚鐢熶骇缁勬墭鍗曞け璐ワ紒" + e2.Message);
+ return;
+ }
+ }
+
+ #endregion
+ #region 璇诲彇璁惧绉伴噸淇℃伅
+
+
+
+ private static string repeatData = string.Empty;
+ private SerialPort ComDevice = null;
+
+ private int HGetWeight = 0;
+ private string Message = "";
+
+ private int timeIndex = 0;
+
+ private string value_COM = ""; //COM
+ private string value_BaudRate = "9600"; //姣旂壒鐜�
+ private string value_StopBits = "1"; //鍋滄浣�
+ private string value_Parity = "0"; //鏍¢獙浣�
+ private string value_DataBits = "8"; //鏁版嵁浣�
+
+ #region 鎵撳紑涓插彛鎸夐挳瑙﹀彂浜嬩欢
+ private void button_OpenCom_Click(object sender, EventArgs e)
+ {
+ value_COM = textBox_COM.Text;
+ OpenCom();
+ }
+ #endregion
+
+ #region 鎵撳紑涓插彛
+ public void OpenCom()
+ {
+ //鍒濆鍖栦覆鍙�
+ ComDevice = new SerialPort();
+ ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//缁戝畾浜嬩欢
+ string[] PortNames = SerialPort.GetPortNames();
+
+ if (!ComDevice.IsOpen)
+ {
+ try
+ {
+ ComDevice.PortName = value_COM;
+ ComDevice.BaudRate = int.Parse(value_BaudRate);
+ switch (value_Parity)
+ {
+ case "0":
+ ComDevice.Parity = Parity.None;
+ break;
+ case "1":
+ ComDevice.Parity = Parity.Odd;
+ break;
+ case "2":
+ ComDevice.Parity = Parity.Even;
+ break;
+ case "3":
+ ComDevice.Parity = Parity.Mark;
+ break;
+ case "4":
+ ComDevice.Parity = Parity.Space;
+ break;
+ default:
+ break;
+ }
+
+ ComDevice.DataBits = int.Parse(value_DataBits);
+ switch (value_StopBits)
+ {
+ case "0":
+ ComDevice.StopBits = StopBits.None;
+ break;
+ case "1":
+ ComDevice.StopBits = StopBits.One;
+ break;
+ case "2":
+ ComDevice.StopBits = StopBits.Two;
+ break;
+ case "1.5":
+ ComDevice.StopBits = StopBits.OnePointFive;
+ break;
+ default:
+ break;
+ }
+
+ ComDevice.Open();
+
+ MessageBox.Show("涓插彛鎵撳紑鎴愬姛锛�");
+
+ //淇濆瓨涓插彛鐨勯厤缃俊鎭�
+ saveParams();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show("鎵撳紑涓插彛澶辫触锛�" + ex.Message, "閿欒", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ }
+ else
+ {
+
+ }
+ }
+ #endregion
+
+ #region 鍏抽棴涓插彛
+ public void CloseCom()
+ {
+ if (!ComDevice.IsOpen)
+ {
+ MessageBox.Show("涓插彛鍏抽棴澶辫触锛佸綋鍓嶄覆鍙f湭鎵撳紑锛�");
+ }
+ else
+ {
+ try
+ {
+ Thread.Sleep(100);
+ ComDevice.Close();
+
+ MessageBox.Show("涓插彛鍏抽棴鎴愬姛锛�");
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "閿欒", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ }
+ }
+ #endregion
+
+ #region 鎺ユ敹鏁版嵁
+ private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
+ {
+ if (HGetWeight == 1)
+ {
+ byte[] ReDatas = new byte[ComDevice.BytesToRead];
+ ComDevice.Read(ReDatas, 0, ReDatas.Length);//璇诲彇鏁版嵁
+ this.AddData(ReDatas);//杈撳嚭鏁版嵁
+ }
+ }
+ #endregion
+
+ #region 澶勭悊鎺ユ敹鍒扮殑鏁版嵁
+ public void AddData(byte[] data)
+ {
+ StringBuilder sb = new StringBuilder();
+ sb.Append(Encoding.ASCII.GetString(data));
+
+ var str = sb.ToString();
+ str = str.Replace("w", "").Replace("n", "").Replace("kg\r\n", ";");
+
+
+ if (str != repeatData)
+ {
+ repeatData = str;
+ string[] strArray = str.Split(';');
+
+ for (int i = 0; i < strArray.Length; i++)
+ {
+ if (double.TryParse(strArray[i], out double ret))//鍒ゆ柇鏄惁鏄暟瀛�
+ {
+ //淇濈暀涓�浣嶅皬鏁�
+ double temp = double.Parse(strArray[i]);
+ temp = Math.Round(temp,1);
+
+ Message += double.Parse(strArray[i]) + ";";
+ }
+ }
+ }
+ }
+ #endregion
+
+ #region 鑾峰彇鏁扮粍涓嚭鐜伴鐜囨渶楂樼殑鏁版嵁
+ private string getMostStr(string message)
+ {
+ string[] strArray = message.Split(';');
+ // 浣跨敤LINQ鏌ヨ鍑虹幇娆℃暟鏈�澶氱殑鍏冪礌
+ var maxElement = strArray.GroupBy(x => x)
+ .OrderByDescending(g => g.Count())
+ .First()
+ .Key;
+
+
+ return maxElement;
+ }
+ #endregion
+
+ #region 璁℃椂鍣ㄨЕ鍙戜簨浠讹紝鐢ㄤ簬鑾峰彇鏃堕棿闂撮殧鍐呮帴鏀跺埌鐨勬暟鎹�
+ private void timer2_Tick(object sender, EventArgs e)
+ {
+ if (timeIndex == 0)
+ {
+ timeIndex = 1;
+ }
+ else
+ {
+ timer2.Enabled = false;
+
+ string str = getMostStr(Message);
+
+ txtHWeightQyt.Text = str;
+
+
+ Message = "";
+ timeIndex = 0;
+ HGetWeight = 0;
+ }
+ }
+ #endregion
+
+ #region 绉伴噸鎸夐挳瑙﹀彂浜嬩欢
+ private void button_getHWeight_Click(object sender, EventArgs e)
+ {
+ HGetWeight = 1;
+ timer2.Enabled = true;
+ }
+ #endregion
+
+
+ #region 淇濆瓨閰嶇疆淇℃伅
+ //鍐欏叆閰嶇疆鍙傛暟
+ private void saveParams()
+ {
+ //鍒ゆ柇鏂囦欢鏄惁瀛樺湪
+ if (!File.Exists(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt"))
+ {
+ FileStream fs1 = new FileStream(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt", FileMode.Create, FileAccess.Write);//鍒涘缓鍐欏叆鏂囦欢
+ StreamWriter sw = new StreamWriter(fs1);
+ sw.WriteLine(value_COM);//寮�濮嬪啓鍏ュ��
+ sw.WriteLine(value_BaudRate);
+
+ sw.WriteLine(value_StopBits);
+
+ sw.WriteLine(value_Parity);
+ sw.WriteLine(value_DataBits);
+ sw.Close();
+ fs1.Close();
+ }
+ else
+ {
+ FileStream fs1 = new FileStream(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt", FileMode.Create, FileAccess.Write);//鍒涘缓鍐欏叆鏂囦欢
+ StreamWriter sw = new StreamWriter(fs1);
+ sw.WriteLine(value_COM);//寮�濮嬪啓鍏ュ��
+ sw.WriteLine(value_BaudRate);
+
+ sw.WriteLine(value_StopBits);
+
+ sw.WriteLine(value_Parity);
+ sw.WriteLine(value_DataBits);
+ sw.Close();
+ fs1.Close();
+ }
+ }
+ #endregion
+
+ #region 璇诲彇閰嶇疆淇℃伅
+ //璇诲彇閰嶇疆鏂囦欢
+ private void readParams()
+ {
+ //鍏抽棴涓插彛
+ //CloseCom();
+
+ if (File.Exists(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt"))
+ {
+ //璇诲彇鏂囦欢鍊煎苟鏄剧ず鍒扮獥浣�
+ FileStream fs = new FileStream(Application.StartupPath + "//Kf_WeightToBarCodeParams.txt", FileMode.Open, FileAccess.ReadWrite);
+ StreamReader sr = new StreamReader(fs);
+ string line = sr.ReadLine();
+ int curLine = 0;
+ while (line != null)
+ {
+ if (++curLine == 1)
+ {
+ value_COM = line;
+ textBox_COM.Text = value_COM;
+ }
+ else if (curLine == 2)
+ {
+ value_BaudRate = line;
+ }
+ else if (curLine == 3)
+ {
+ value_StopBits = line;
+ }
+ else if (curLine == 4)
+ {
+ value_Parity = line;
+ }
+ else if (curLine == 5)
+ {
+ value_DataBits = line;
+ }
+ else
+ {
+
+ }
+ line = sr.ReadLine();
+ }
+ sr.Close();
+ fs.Close();
+ }
+ }
+
+ #endregion
+
+ #endregion
--
Gitblit v1.9.1