using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Drawing;
|
using System.Text;
|
using System.Windows.Forms;
|
using gregn6Lib;
|
using Pub_Class;
|
using System.Threading;
|
using System.IO.Ports;
|
|
namespace SCM
|
{
|
public partial class Sc_PackUnionBill : Form
|
{
|
public Sc_PackUnionBill()
|
{
|
InitializeComponent();
|
}
|
|
public frmBillQueryCondition_Base frmCondition;
|
public string ModCaption = "包装单";
|
public string ModName = "Sc_PackUnionBill";
|
public Int64 HInterID = 0; //单据ID
|
public string HBillNo = ""; //单据号
|
public string HBillType = "3783"; //单据类型
|
public string HMaker = ""; //制单人
|
public string HSourceBillTypeID = "";
|
public string HSourceBillType = "";
|
public string HSourceBillNo = "";
|
public Int64 HSourceInterID = 0;
|
public Int64 HSourceEntryID = 0;
|
public int HTMCol = 0;
|
public int HMaterIDCol = 1;
|
public string HOrgNumber = "1001";
|
public Int64 HOrgID = 1;
|
public string HBarCode = "";
|
public Model.ClsSc_PackUnionBillMain omodel = new Model.ClsSc_PackUnionBillMain();
|
Pub_Class.ClsGridListSum oSumGrid = new Pub_Class.ClsGridListSum();
|
public Int32 iTopRow = 0;//画横线
|
SCM.WMSWeb.WebService1 oWeb = new SCM.WMSWeb.WebService1();
|
private static string repeatData = string.Empty;
|
//
|
|
#region 固定代码
|
|
//清空界面
|
public void Sub_ClearBill()
|
{
|
//清空界面
|
ClsPub1.Sub_ClearBill(groupBox4);
|
ClsPub1.Sub_ClearBill1(tabPage3);
|
ClsPub1.Sub_ClearBill1(tabPage1);
|
//ClsPub1.Sub_ClearBill1(tabPage4);
|
|
//从服务器 获得单据号ID和单据号
|
string s = "";
|
if (oWeb.get_MaxBillNoAndID(HBillType, ref HBillNo, ref HInterID, ref s))
|
{
|
txtHBillNo.Tag = HInterID.ToString();
|
txtHBillNo.Text = HBillNo;
|
}
|
else
|
{
|
MessageBox.Show("得到单据号失败!" + s);
|
this.Close();
|
}
|
//
|
HMaker = DBUtility.ClsPub.CurUserName;
|
txtHMaker.Text = HMaker;
|
HOrgID = ClsPub1.HOrgID;
|
|
DataSet Ds1 = oWeb.getDataSetBySQL("select * from Xt_ORGANIZATIONS with(nolock) where HItemID=" + HOrgID, "Xt_ORGANIZATIONS", ref DBUtility.ClsPub.sExeReturnInfo);
|
if (Ds1.Tables[0].Rows.Count != 0)
|
{
|
HOrgNumber = DBUtility.ClsPub.isStrNull(Ds1.Tables[0].Rows[0]["HNumber"]);
|
txtHOWNERID.Tag = HOrgID;
|
txtHOWNERID.Text = DBUtility.ClsPub.isStrNull(Ds1.Tables[0].Rows[0]["HName"]);
|
}
|
initGrid();
|
//刷新表体
|
DisBillEntryList_Webs();
|
//
|
txtHMSourceBillNo.Enabled = true;
|
txtHZBarCode.Enabled = true;
|
cmdHSaveBill.Enabled = true;
|
txtHMSourceBillNo.Focus();
|
}
|
|
private void Sc_PackUnionBill_Load(object sender, EventArgs e)
|
{
|
//设置动态URL
|
oWeb.Url = SCM.ClsPub1.WEBSURL;
|
//
|
frmCondition = new frmBillQueryCondition_Base();
|
this.Text = ModCaption;
|
oSumGrid.ogrdMain = grdMain; //初始化 new
|
oSumGrid.oGridsum = grdSum;
|
initGrid();
|
cmbDYMB.Items.Add(this.Text);
|
cmbDYMB.SelectedIndex = 0;
|
}
|
|
//初始化网格
|
private void initGrid()
|
{
|
ClsPub1.initGridList(grdMain, this.Name);
|
grdMain.RowTemplate.Height = 30;
|
grdMain.RowTemplate.MinimumHeight = 30;
|
grdMain.RowsDefaultCellStyle.Font = new Font("宋体", 15);
|
grdMain.ReadOnly = true;
|
//DBUtility.Xt_BaseBillFun.initGridList(grdMain, this.Name);
|
}
|
|
//时间控件
|
private void timer1_Tick(object sender, EventArgs e)
|
{
|
timer1.Enabled=false;
|
Sub_ClearBill();
|
}
|
|
private void timer2_Tick(object sender, EventArgs e)
|
{
|
timer2.Enabled = false;
|
//
|
if (ClsIni.ReadIni("COMINFO", "txtPortName", DBUtility.ClsPub.AppPath + @"/HXERP.ini").Contains("没有找到")==false)
|
{
|
txtPortName.Text = ClsIni.ReadIni("COMINFO", "txtPortName", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
txtBaudRate.Text = ClsIni.ReadIni("COMINFO", "txtBaudRate", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
cmbParity.Text = ClsIni.ReadIni("COMINFO", "cmbParity", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
txtDataBits.Text = ClsIni.ReadIni("COMINFO", "txtDataBits", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
cmbStopBits.Text = ClsIni.ReadIni("COMINFO", "cmbStopBits", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
txtHSend0.Text = ClsIni.ReadIni("COMINFO", "txtHSend0", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
txtHSend.Text = ClsIni.ReadIni("COMINFO", "txtHSend", DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
|
//初始化串口
|
ComDevice = new SerialPort();
|
ComDevice.DataReceived += new SerialDataReceivedEventHandler(Com_DataReceived);//绑定事件
|
string[] PortNames = SerialPort.GetPortNames();
|
//打开串口
|
OpenCom();
|
}
|
|
private void grdMain_Paint(object sender, PaintEventArgs e)
|
{
|
GraphicsGrid();
|
}
|
|
private void GraphicsGrid()
|
{
|
//画底线
|
DBUtility.Xt_BaseBillFun.GraphicsGrid(grdMain);
|
//画横线
|
DBUtility.Xt_BaseBillFun.GraphicsRowGrid(grdMain, iTopRow, iTopRow + 50, Fun_GetCol("hmainid"));
|
}
|
|
private Int32 Fun_GetCol(string sCol)
|
{
|
return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
|
}
|
|
//保存列宽
|
private void bclk_Click(object sender, EventArgs e)
|
{
|
DBUtility.Xt_BaseBillFun.SaveGrid(grdMain, this.Name);
|
}
|
|
//默认列宽
|
private void mrlk_Click(object sender, EventArgs e)
|
{
|
DBUtility.Xt_BaseBillFun.DefaultGridView(grdMain, this.Name);
|
}
|
//是否是空行
|
private bool IsNullRow(int Row)
|
{
|
return DBUtility.Xt_BaseBillFun.IsNullRow(Row, HMaterIDCol, grdMain);
|
}
|
|
#endregion
|
|
|
#region 功能控件
|
|
//退出
|
private void cmdCancel_Click(object sender, EventArgs e)
|
{
|
CloseCom();
|
Thread.Sleep(300);
|
this.Close();
|
}
|
|
//新增
|
private void cmdHAdd_Click(object sender, EventArgs e)
|
{
|
Sub_ClearBill();//清空界面
|
}
|
|
//保存 并生成打印条码
|
private void cmdHSaveBill_Click(object sender, EventArgs e)
|
{
|
//判断是否数据完整
|
if (AllowLoadData() == false)
|
{
|
return;
|
}
|
SaveBill();
|
}
|
|
//上传前判断
|
private bool AllowLoadData()
|
{
|
if (HInterID == 0)
|
{
|
MessageBox.Show("错误的单据内码!");
|
return false;
|
}
|
if (txtHBillNo.Text.Trim() == "")
|
{
|
MessageBox.Show("错误的单据号!");
|
return false;
|
}
|
|
//判断是否存在数量0的明细记录 (至少 扫描一条记录)
|
bool b = false;
|
for (int i = 0; i < grdMain.RowCount; i++)
|
{
|
if (ClsPub.isDoule(grdMain.Rows[i].Cells["数量"].Value) == 0)
|
{
|
b = false;
|
}
|
else
|
{
|
b = true;
|
break;
|
}
|
}
|
if (!b)
|
{
|
MessageBox.Show("没有子件条码扫描记录!");
|
return false;
|
}
|
return true;
|
}
|
|
//写入包装单、条码档案
|
public bool SaveBill()
|
{
|
try
|
{
|
//判断会计期是否合理
|
string s = "";
|
int sYear = 0;
|
int sPeriod = 0;
|
//if (DBUtility.Xt_BaseBillFun.Fun_AllowYearPeriod(dtpHDate.Value, ref sYear, ref sPeriod, ref s) == false)
|
//{
|
// MessageBox.Show(s, "提示");
|
// return false;
|
//}
|
omodel.HYear = sYear;
|
omodel.HPeriod = sPeriod;
|
omodel.HInterID = HInterID;
|
omodel.HDate = dtpHDate.Value;
|
omodel.HBillNo = HBillNo;
|
omodel.HRemark = "";
|
omodel.HICMOInterID = ClsPub.isLong(this.txtHSourceBillNo.Tag);
|
omodel.HICMOBillNo = ClsPub.isStrNull(this.txtHSourceBillNo.Text);
|
omodel.HBarCode_Pack = ClsPub.isStrNull(this.txHBarCode_Pack.Text);
|
omodel.HMaterID = 0;
|
omodel.HUnitID = 0;
|
omodel.HWeight = ClsPub.isSingle(this.txtHWeight.Text);
|
omodel.HPWeight = ClsPub.isSingle(this.txtHPWeight.Text);
|
omodel.HProdOrgID = ClsPub.isLong(this.txtHOWNERID.Tag);
|
omodel.HDeptID = ClsPub.isLong(this.txtHDeptID.Tag);
|
omodel.HEmpID = ClsPub.isLong(this.txtHEmpID.Tag);
|
|
//插入主表
|
oWeb.getRunProc("Insert Into Sc_PackUnionBillMain " +
|
"(HYear,HPeriod,HBillType,HInterID" +
|
",HDate,HBillNo,HBillStatus,HRemark,HICMOInterID" +
|
",HICMOBillNo,HBarCode_Pack,HMaterID,HUnitID" +
|
",HWeight,HPWeight,HProdOrgID,HDeptID,HEmpID" +
|
",HMaker,HMakeDate" +
|
") " +
|
" values(" + omodel.HYear + "," + omodel.HPeriod + ",'" + this.HBillType + "'," + omodel.HInterID +
|
",'" + omodel.HDate + "','" + omodel.HBillNo.ToString() + "'," + omodel.HBillStatus + ",'" + omodel.HRemark + "'," + omodel.HICMOInterID +
|
",'" + omodel.HICMOBillNo.ToString() + "','" + omodel.HBarCode_Pack.ToString() + "'," + omodel.HMaterID + "," + omodel.HUnitID +
|
", " + omodel.HWeight + "," + omodel.HPWeight + "," + omodel.HProdOrgID + "," + omodel.HDeptID + "," + omodel.HEmpID +
|
",'" + DBUtility.ClsPub.CurUserName + "','" + DBUtility.ClsPub.GetServerDate(-1) + "'" +
|
") ", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
//插入子表
|
oWeb.getRunProc("EXEC h_p_Sc_PackUnionBillSub_Insert " + omodel.HInterID + ",'" + omodel.HBillNo.ToString() + "'", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
//将托条码写入条码档案
|
string TM = ""; //条码
|
double HQty = DBUtility.ClsPub.isDoule(txtHWeight.Text); //数量
|
string sDate = ""; //日期
|
//
|
string HWei = ""; //尾数
|
HBarCode = "";
|
string HBarCodeType = "";
|
Int64 HMaterID = 0;
|
Int64 HAuxPropID = 0;
|
Int64 HUnitID = 0;
|
double HQty2 = DBUtility.ClsPub.isDoule(txtHWeight.Text);
|
string HBatchNo2 = "";
|
Int64 HSupID = 0;
|
Int64 HGroupID = 0;
|
int HPrintQty = 0;
|
Int64 HBarcodeNo = 0; //托号
|
Int64 HBarcodeQtys = 0; //总托数
|
Int64 HDeptID = 0;
|
Int64 HWhID = 0;
|
Int64 HSPID = 0;
|
string HRemark = "";
|
string HMaterName = "";
|
string HMaterModel = "";
|
string HPinfan = "";
|
string HMTONo = "";
|
Int64 HCusID = 0;
|
string HCusType = "";
|
DateTime HEndDate;
|
string HWorkLineName = "";
|
DateTime HBeginDate;
|
string HSeOrderBillNo = "";
|
string HJiaYe2 = "";
|
string HPressModel = "";
|
string HCusModel = "";
|
string HMaterialModel = "";
|
string HColor = "";
|
string HLogo = "";
|
string HPackageSize = "";
|
double HMaterialJQty = DBUtility.ClsPub.isDoule(txtHWeight.Text);
|
double HMaterialMQty = DBUtility.ClsPub.isDoule(lblHBWeight.Text);
|
string HCustomBatchNo = "";
|
string HGBBarCode = "";
|
string POOrderBillNo = "";
|
//
|
HBarCode = txHBarCode_Pack.Text;
|
HBarCodeType = "托盘条码";
|
|
HMaterID = 0;
|
HAuxPropID = 0;
|
//HUnitID = DBUtility.ClsPub.isLong(txtHUnitName.Tag);
|
HQty2 = HQty;
|
HBatchNo2 = "";
|
HBarcodeQtys = 0;
|
HBarcodeNo = 1;
|
HSupID = 0;
|
HDeptID = 0;
|
HWhID = 0;
|
HSPID = 0;
|
HRemark = "";
|
HMaterName = "";
|
HMaterModel = "";
|
HPinfan = "";
|
HMTONo = "";
|
HCusID = 0;
|
HCusType = "";
|
HEndDate = dtpHDate.Value;
|
HWorkLineName = "";
|
HBeginDate = dtpHDate.Value;
|
HSeOrderBillNo = "";
|
HGroupID = 0;
|
HJiaYe2 = "";
|
HPressModel = "";
|
HCusModel = "";
|
HMaterialModel = "";
|
HColor = "";
|
HLogo = "";
|
HPackageSize = "";
|
HMaterialJQty = DBUtility.ClsPub.isDoule(txtHWeight.Text);
|
HMaterialMQty = DBUtility.ClsPub.isDoule(lblHBWeight.Text);
|
HCustomBatchNo = "";
|
HGBBarCode = "";
|
POOrderBillNo = "";
|
string sSQLMul = " insert into Gy_BarCodeBill (HBarCode,HBarCodeType,HMaterID,HUnitID,HQty" +
|
",HBatchNo,HSupID,HGroupID,HMaker,HMakeDate,HPrintQty,HinitQty" +
|
",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HEndQty " +
|
",HBarcodeQtys,HBarcodeNo,HDeptID,HWhID,HSPID,HRemark " +
|
",HCusID,HCusType,HEndDate,HWorkLineName,HJiaYe " +
|
",HPressModel,HCusModel,HMaterialModel,HColor,HBarCodeDate " +
|
",HLogo,HPackageSize,HMaterialJQty,HMaterialMQty,HCustomBatchNo " +
|
",HSTOCKORGID,HOWNERID,HBeginDate,HSeOrderBillNo,HGBBarCode " +
|
",POOrderBillNo " +
|
",HMaterName,HMaterModel,HPinfan,HAuxPropID,HMTONo,HInterID " +
|
") values ("
|
+ "'" + HBarCode + "','" + HBarCodeType + "'," + HMaterID.ToString() + "," + HUnitID.ToString() + "," + HQty2.ToString()
|
+ ",'" + HBatchNo2 + "'," + HSupID.ToString() + "," + HGroupID.ToString() + ",'" + ClsPub.CurUserName + "',getdate()," + HPrintQty.ToString() + "," + HQty2.ToString()
|
+ ", " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "','" + HSourceBillTypeID + "','" + HWei + "'"
|
+ ", " + HBarcodeQtys.ToString() + "," + HBarcodeNo.ToString() + "," + HDeptID.ToString() + "," + HWhID.ToString() + "," + HSPID.ToString() + ",'" + HRemark + "'"
|
+ ", " + HCusID.ToString() + ",'" + HCusType + "','" + HEndDate.ToShortDateString() + "','" + HWorkLineName + "','" + HJiaYe2 + "'"
|
+ ",'" + HPressModel + "','" + HCusModel + "','" + HMaterialModel + "','" + HColor + "','" + sDate + "'"
|
+ ",'" + HLogo + "','" + HPackageSize + "'," + HMaterialJQty.ToString() + "," + HMaterialMQty.ToString() + ",'" + HCustomBatchNo + "'"
|
+ ", " + HOrgID.ToString() + "," + HOrgID.ToString() + ",'" + HBeginDate.ToShortDateString() + "','" + HSeOrderBillNo + "','" + HGBBarCode + "'"
|
+ ",'" + POOrderBillNo + "'"
|
+ ",'" + HMaterName + "','" + HMaterModel + "','" + HPinfan + "'," + HAuxPropID.ToString() + ",'" + HMTONo + "',"+ omodel.HInterID + ")";
|
oWeb.getRunProc(sSQLMul, ref DBUtility.ClsPub.sExeReturnInfo);
|
|
//将包装时间反写 销售订单
|
if (HSourceInterID > 100000000 && HSourceInterID < 200000000)
|
{
|
oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToSeOrderPickTime_New " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else if (HSourceInterID > 200000000 && HSourceInterID < 300000000)
|
{
|
oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToOtherOutPickTime_New " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else if (HSourceInterID > 300000000 && HSourceInterID < 400000000)
|
{
|
oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToPICKMTRLPickTime_New " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else if (HSourceInterID > 400000000 && HSourceInterID < 500000000)
|
{
|
oWeb.getRunProc("EXEC h_p_IFCLD_DataBackToMoveStockPickTime_New " + HSourceInterID.ToString() + "," + HSourceEntryID.ToString() + ",'" + HSourceBillNo + "'," + omodel.HInterID.ToString() + ",'" + ClsPub.CurUserName + "'", ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else
|
{
|
//
|
}
|
//刷新界面
|
DisBillEntryList_Webs();
|
//DisplaySub();
|
//根据界面选择打印模板,打印条形码
|
//根据销售订单的客户,找到对应的打印模板;
|
string HLogoName = "";
|
//根据源单号找到客户编号前四位
|
DataSet DS;
|
DS = oWeb.getDataSetBySQL("exec h_p_FindCustTopFour '" + HSourceBillNo + "'", "h_p_FindCustTopFour", ref DBUtility.ClsPub.sExeReturnInfo);
|
if(DS == null || DS.Tables[0].Rows.Count == 0)
|
{
|
MessageBox.Show("获取打印模板失败,请前往包装单列表补打条码!" );
|
cmdHSaveBill.Enabled = false;
|
txtHZBarCode.Enabled = false;
|
cmdHAdd.Enabled = false;
|
return false;
|
}
|
else
|
{
|
string Cust = ClsPub.isStrNull(DS.Tables[0].Rows[0][0]);
|
HLogoName = "-" + Cust;
|
}
|
|
//
|
Sub_SetReport(cmbDYMB.Text + HLogoName);
|
|
if (DBUtility.ClsPub.isStrNull(DBUtility.ClsPub.CurUserName).ToLower() == "admin")
|
{
|
Report.PrintPreview(false);
|
}
|
else
|
{
|
Report.Print(false);
|
}
|
Thread.Sleep(500);
|
cmdHSaveBill.Enabled = false;
|
txtHZBarCode.Enabled = false;
|
return true;
|
}
|
catch (Exception e1)
|
{
|
MessageBox.Show("保存失败!" + e1.Message);
|
cmdHSaveBill.Enabled = true;
|
txtHZBarCode.Enabled = false;
|
return false;
|
}
|
}
|
|
#region //打印设置
|
|
GridppReport Report;
|
string sBarCode = "";
|
|
//预览
|
int CurRows = 0;
|
|
private void Sub_SetReport(string sOpenTmp)
|
{
|
//增加判断:如果子表行 实际数量为0 则不打印出来
|
for (int i = 0; i < grdMain.RowCount; i++)
|
{
|
if (ClsPub.isDoule(grdMain.Rows[i].Cells["数量"].Value) != 0)
|
{
|
grdMain.Rows[i].Cells[0].Value = "*";
|
}
|
}
|
Report = new GridppReport();
|
Report.LoadFromFile(DBUtility.ClsPub.AppPath + @"\" + sOpenTmp + ".grf"); //here .
|
Report.BeforePostRecord += new _IGridppReportEvents_BeforePostRecordEventHandler(ReportBeforePostRecord);
|
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportFetchRecordByDataTable);
|
//Report.PrintEnd += new _IGridppReportEvents_PrintEndEventHandler(ReportPrintEnd);
|
}
|
|
//填入单据表头信息
|
private void ReportBeforePostRecord()//
|
{
|
try
|
{
|
Report.FieldByName("条码编号").AsString = ClsPub.isStrNull(txHBarCode_Pack.Text);
|
Report.FieldByName("总重量").AsString = ClsPub.isStrNull(txtHWeight.Text);
|
Report.FieldByName("客户").AsString = ClsPub.isStrNull(txtHCusName.Text);
|
Report.FieldByName("源单单号").AsString = ClsPub.isStrNull(txtHSourceBillNo.Text);
|
Report.FieldByName("联系方式").AsString = ClsPub.isStrNull(txtHLinkMan.Text)+ "-" + ClsPub.isStrNull(txtHLinkPhone.Text);
|
Report.FieldByName("地址").AsString = ClsPub.isStrNull(txtHAddress.Text);
|
Report.FieldByName("物流方式").AsString = ClsPub.isStrNull(txtHConveyCompName.Text);
|
string HWeight = ClsPub.isStrNull(txtHWeight.Text);
|
if (HWeight==null || HWeight.Equals(""))
|
{
|
HWeight = "0";
|
}
|
Report.FieldByName("总重量").AsString = HWeight;
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("打印失败!表头:" + e.Message);
|
}
|
}
|
|
private void ReportFetchRecordByDataTable()
|
{
|
try
|
{
|
DataTable ds = new DataTable();
|
//BLL.Utility.FillRecordToReport(Report, grdMain, ds, Fun_GetCol("选择"));
|
SCM.Utility.FillRecordToReport(Report, grdMain, ds, Fun_GetCol("选择"));
|
}
|
catch (Exception e)
|
{
|
MessageBox.Show("打印失败!表体:" + e.Message);
|
}
|
}
|
|
#endregion
|
|
//删行
|
private void btnBLSH_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
//清空
|
private void btnBLBD_Click(object sender, EventArgs e)
|
{
|
|
}
|
|
#endregion
|
|
|
#region 扫描源单条码、子件条码
|
|
//扫描源单
|
private void txtHMSourceBillNo_KeyPress(object sender, KeyPressEventArgs e)
|
{
|
if (e.KeyChar == (char)Keys.Return)
|
{
|
//明细表是否为零行
|
bool b = false;
|
for (int i = 0; i < grdMain.RowCount; i++)
|
{
|
if (!IsNullRow(i))
|
{
|
b = true;
|
break;
|
}
|
}
|
if (b == true)
|
{
|
if (MessageBox.Show("已存在源单记录,确定要清空重新扫码?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
|
{
|
SetBillTilte_Webs();
|
txtHMSourceBillNo.Enabled = false;
|
txtHZBarCode.Focus();
|
}
|
}
|
else
|
{
|
SetBillTilte_Webs();
|
txtHMSourceBillNo.Enabled = false;
|
txtHZBarCode.Focus();
|
}
|
}
|
}
|
|
private void SetBillTilte_Webs()
|
{
|
string sTMNumber = ""; //条码自定义前缀
|
int LSH = 0; //流水号
|
|
HSourceBillNo = txtHMSourceBillNo.Text.Trim();
|
HSourceBillType = "3710";
|
//先同步
|
oWeb.getRunProc("exec h_p_IFCLD_ERPSourceBillToLocal_SEOrderToICMO '" + HSourceBillNo + "'", ref DBUtility.ClsPub.sExeReturnInfo);
|
//获取源单信息,并将源单信息存入临时表
|
|
DataSet DS = oWeb.getDataSetBySQL("exec h_p_IF_SourceBill_Check_Add_PackUnion " + HInterID + ",'" + HBillNo + "','" + HBillType + "','" + HSourceBillNo + "','" + HSourceBillType + "','" + HMaker + "'", "h_p_IF_SourceBill_Check_Add_PackUnion", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
if (DBUtility.ClsPub.isLong(DS.Tables[0].Rows[0][0]) == 0)
|
{
|
//加载源单信息
|
txtHSourceBillNo.Text = HSourceBillNo;
|
|
|
|
|
//获取托条码
|
//条码前缀 = 组织代码 + 源单单号
|
sTMNumber = HOrgNumber + DBUtility.ClsPub.isStrNull(txtHSourceBillNo.Text);
|
|
DataSet Ds2 = oWeb.getDataSetBySQL("exec h_p_WMS_GetMaxNo '" + sTMNumber + "'", "h_p_WMS_GetMaxNo", ref DBUtility.ClsPub.sExeReturnInfo);//获取最大流水号
|
LSH = ClsPub.isInt(Ds2.Tables[0].Rows[0][0]);
|
//托条码 = 条码前缀 + 流水号
|
txHBarCode_Pack.Text = sTMNumber + LSH;
|
//
|
string sSQLNoMul = " exec h_p_WMS_SetMaxNo '" + sTMNumber + "' ";
|
oWeb.getRunProc(sSQLNoMul, ref DBUtility.ClsPub.sExeReturnInfo);
|
}
|
else
|
{
|
MessageBox.Show(DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HRemark"]) + "," + DBUtility.ClsPub.sExeReturnInfo);
|
return;
|
}
|
//刷新表体
|
DisBillEntryList_Webs();
|
}
|
|
//扫描子件条码
|
private void txtHZBarCode_KeyPress(object sender, KeyPressEventArgs e)
|
{
|
if (e.KeyChar == (char)Keys.Return)
|
{
|
SetZBarCode_Webs(txtHZBarCode.Text);
|
txtHZBarCode.Text = "";
|
txtHZBarCode.Focus();
|
}
|
}
|
private void SetZBarCode_Webs(string sZCode)
|
{
|
//将子件条码信息存入临时表
|
DataSet DS = oWeb.getDataSetBySQL("exec h_p_KF_PonderationBillMain_Temp_Add_PackUnion " + HInterID + ",'" + HBillNo + "','" + HBillType + "','" + HMaker + "','" + sZCode + "','" + txHBarCode_Pack.Text + "'," + HOrgID, "h_p_KF_PonderationBillMain_Temp_Add_PackUnion", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
if (DBUtility.ClsPub.isLong(DS.Tables[0].Rows[0][0]) == 0)
|
{
|
//刷新表体同步
|
DisBillEntryList_Webs();
|
}
|
else
|
{
|
MessageBox.Show(DBUtility.ClsPub.isStrNull(DS.Tables[0].Rows[0]["HRemark"]) + "," + DBUtility.ClsPub.sExeReturnInfo);
|
return;
|
}
|
}
|
|
//刷新子表
|
private void DisBillEntryList_Webs()
|
{
|
//得到信息
|
DataSet DSet = oWeb.getDataSetBySQL("exec h_p_KF_GetPonderationBillMain_TempList_PackUnion " + HInterID + ",'" + HBillNo + "','" + HBillType + "'", "h_p_KF_GetPonderationBillMain_TempList_PackUnion", ref DBUtility.ClsPub.sExeReturnInfo);
|
|
//生成首行标题
|
if (DSet == null)
|
{
|
return;
|
}
|
if (DSet.Tables[1].Rows.Count > 0)
|
{
|
//写入主表信息
|
txtHCusName.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["客户"]);
|
txtHConveyCompName.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["运输公司"]);
|
txtHLinkMan.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["联系人"]);
|
txtHLinkPhone.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["联系电话"]);
|
txtHAddress.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["收件地址"]);
|
txtHSourceBillNo.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["源单单号"]);
|
txtHPackRemark.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["外包备注"]);
|
txtHBillRemark.Text = DBUtility.ClsPub.isStrNull(DSet.Tables[1].Rows[0]["整单摘要"]);
|
}
|
//
|
grdMain.DataSource = DSet.Tables[0].DefaultView;
|
|
////设置合计列
|
//string sTotalCol = "";
|
//sTotalCol = DBUtility.Gy_BaseFun.GetTotalCols(DSet);
|
//string[] sT;
|
//sT = sTotalCol.Split(Convert.ToChar(","));
|
//oSumGrid.BuildTotalCols(sT);
|
//冻结
|
int FrCol = DBUtility.ClsPub.isInt(frmCondition.txtFrozenCol.Text);
|
string s = frmCondition.cmbHComplete.Text;
|
ClsPub1.DisplayGrid(grdMain, this.Name, s, FrCol);
|
//扫描过的变黄色
|
//int HMustQtyCol = Fun_GetCol("应发数量");
|
int HRelQtyCol = Fun_GetCol("数量");
|
for (int i = 0; i < grdMain.Rows.Count; i++)
|
{
|
if(DBUtility.ClsPub.isDoule(grdMain.Rows[i].Cells[HRelQtyCol].Value)>0)
|
{
|
grdMain.Rows[i].DefaultCellStyle.BackColor = Color.Yellow;
|
}
|
else
|
{
|
grdMain.Rows[i].DefaultCellStyle.BackColor = Color.White;
|
}
|
}
|
//画线
|
//GraphLine();
|
//Total();
|
}
|
|
#endregion
|
|
|
#region 界面基础资料控件处理
|
|
//班组
|
private void cmdHGroupID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsGy_Group_View oGroup = new SCM.ClsGy_Group_View();
|
string sWhere = "";
|
if (oGroup.RefreshView(sWhere))
|
{
|
this.txtHGroupID.Text = oGroup.oModel.HName;
|
this.txtHGroupID.Tag = oGroup.oModel.HItemID.ToString();
|
}
|
else
|
{
|
this.txtHGroupID.Text = "";
|
}
|
}
|
|
private void txtHGroupID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHGroupID);
|
}
|
|
//生产资源
|
private void cmdHSourceID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsIF_Source_View oSource = new SCM.ClsIF_Source_View();
|
string sWhere = "";
|
if (oSource.RefreshView(sWhere))
|
{
|
this.txtHSourceID.Text = oSource.oModel.HName;
|
this.txtHSourceID.Tag = oSource.oModel.HItemID.ToString();
|
}
|
else
|
{
|
this.txtHSourceID.Text = "";
|
}
|
}
|
|
private void txtHSourceID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHSourceID);
|
}
|
|
//工序
|
private void cmdHProcessID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsIF_Process_View oProcess = new SCM.ClsIF_Process_View();
|
string sWhere = "";
|
if (oProcess.RefreshView(sWhere))
|
{
|
this.txtHProcessID.Text = oProcess.oModel.HName;
|
this.txtHProcessID.Tag = oProcess.oModel.HItemID.ToString();
|
}
|
else
|
{
|
this.txtHProcessID.Text = "";
|
}
|
}
|
|
private void txtHProcessID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHProcessID);
|
}
|
|
//车间
|
private void cmdHDeptID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsIF_Department_View oDept = new SCM.ClsIF_Department_View();
|
string sWhere = "";
|
if (oDept.RefreshView(sWhere))
|
{
|
this.txtHDeptID.Text = oDept.oModel.HName;
|
this.txtHDeptID.Tag = oDept.oModel.HItemID.ToString();
|
}
|
else
|
{
|
this.txtHDeptID.Text = "";
|
}
|
}
|
|
private void txtHDeptID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHDeptID);
|
}
|
|
//操作员
|
private void cmdHEmpID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsIF_Employee_View oEmp = new SCM.ClsIF_Employee_View();
|
string sWhere = "";
|
if (oEmp.RefreshView(sWhere))
|
{
|
this.txtHEmpID.Text = oEmp.oModel.HName;
|
this.txtHEmpID.Tag = oEmp.oModel.HItemID.ToString();
|
}
|
else
|
{
|
this.txtHEmpID.Text = "";
|
}
|
}
|
|
private void txtHEmpID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHEmpID);
|
}
|
|
//工作中心
|
private void cmdHWorkCenterID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsIF_WorkCenter_View oWorkCenter = new SCM.ClsIF_WorkCenter_View();
|
string sWhere = "";
|
if (oWorkCenter.RefreshView(sWhere))
|
{
|
this.txtHWorkCenterID.Text = oWorkCenter.oModel.HName;
|
this.txtHWorkCenterID.Tag = oWorkCenter.oModel.HItemID.ToString();
|
}
|
else
|
{
|
this.txtHWorkCenterID.Text = "";
|
}
|
}
|
|
private void txtHWorkCenterID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHWorkCenterID);
|
}
|
|
//组织
|
private void cmdHOWNERID_Click(object sender, EventArgs e)
|
{
|
SCM.ClsXt_ORGANIZATIONS_View oOR = new SCM.ClsXt_ORGANIZATIONS_View();
|
string sWhere = "";
|
if (oOR.RefreshView(sWhere))
|
{
|
this.txtHOWNERID.Text = oOR.oModel.HName;
|
this.txtHOWNERID.Tag = oOR.oModel.HItemID.ToString();
|
HOrgID = oOR.oModel.HItemID;
|
HOrgNumber = oOR.oModel.HNumber;
|
}
|
else
|
{
|
this.txtHOWNERID.Text = "";
|
}
|
}
|
|
private void txtHOWNERID_TextChanged(object sender, EventArgs e)
|
{
|
BLL.ClsPub_BLL.Sub_ClearText(txtHOWNERID);
|
}
|
|
#endregion
|
|
|
private SerialPort ComDevice = null;
|
|
//打开串口
|
private void cmdOpenCom_Click(object sender, EventArgs e)
|
{
|
OpenCom();
|
}
|
|
public void OpenCom()
|
{
|
if (!ComDevice.IsOpen)
|
{
|
|
try
|
{
|
ComDevice.PortName = txtPortName.Text;
|
ComDevice.BaudRate = int.Parse(txtBaudRate.Text);
|
switch (cmbParity.SelectedItem.ToString())
|
{
|
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(txtDataBits.Text);
|
switch (cmbStopBits.SelectedItem.ToString())
|
{
|
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();
|
lblComStatus.Text = "串口状态:开启";
|
timer3.Enabled = true;
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show("打开串口失败!" + ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return;
|
}
|
}
|
else
|
{
|
//try
|
//{
|
// ComDevice.Close();
|
// textBox3.Enabled = true;
|
// textBox4.Enabled = true;
|
// textBox5.Enabled = true;
|
// comboBox1.Enabled = true;
|
// comboBox2.Enabled = true;
|
// AddContent($"串口已关闭");
|
// button1.Enabled = false;
|
// btnPush.Text = "开启串口";
|
//}
|
//catch (Exception ex)
|
//{
|
// MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
// AddContent($"串口关闭失败:{ex.Message}");
|
// return;
|
//}
|
}
|
}
|
|
//关闭串口
|
private void cmdCloseCom_Click(object sender, EventArgs e)
|
{
|
CloseCom();
|
}
|
|
public void CloseCom()
|
{
|
if (!ComDevice.IsOpen)
|
{
|
|
}
|
else
|
{
|
try
|
{
|
timer3.Enabled = false;
|
Thread.Sleep(300);
|
ComDevice.Close();
|
lblComStatus.Text = "串口状态:关闭";
|
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return;
|
}
|
}
|
}
|
|
/// <summary>
|
/// 字符串转换16进制字节数组
|
/// </summary>
|
/// <param name="hexString"></param>
|
/// <returns></returns>
|
private byte[] strToHexByte(string hexString)
|
{
|
hexString = hexString.Replace(" ", "");
|
if ((hexString.Length % 2) != 0)
|
hexString += " ";
|
byte[] returnBytes = new byte[hexString.Length / 2];
|
for (int i = 0; i < returnBytes.Length; i++)
|
returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2).Replace(" ", ""), 16);
|
return returnBytes;
|
}
|
|
/// <summary>
|
/// 发送数据
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="data"></param>
|
public bool SendData(byte[] data)
|
{
|
if (ComDevice.IsOpen)
|
{
|
try
|
{
|
ComDevice.Write(data, 0, data.Length);//发送数据
|
return true;
|
}
|
catch (Exception ex)
|
{
|
MessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}
|
finally
|
{
|
//cmdHSetZero.Enabled = true;
|
}
|
}
|
else
|
{
|
MessageBox.Show("串口未打开", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}
|
return false;
|
}
|
|
private void timer3_Tick(object sender, EventArgs e)
|
{
|
//if (!ComDevice.IsOpen)
|
//{
|
// return;
|
//}
|
//byte[] sendData = strToHexByte(txtHSend.Text);
|
//SendData(sendData);
|
|
}
|
|
/// <summary>
|
/// 接收数据
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void Com_DataReceived(object sender, SerialDataReceivedEventArgs e)
|
{
|
//if (!ComDevice.IsOpen)
|
//{
|
// return;
|
//}
|
//Thread.Sleep(100);
|
byte[] ReDatas = new byte[ComDevice.BytesToRead];
|
ComDevice.Read(ReDatas, 0, ReDatas.Length);//读取数据
|
this.AddData(ReDatas);//输出数据
|
}
|
|
/// <summary>
|
/// 添加数据
|
/// </summary>
|
/// <param name="data">字节数组</param>
|
public void AddData(byte[] data)
|
{
|
//Thread.Sleep(100);
|
StringBuilder sb = new StringBuilder();
|
sb.Append(Encoding.ASCII.GetString(data));
|
var str = sb.ToString().ToUpper();
|
if (str != repeatData)
|
{
|
repeatData = str;
|
var newStr = new StringBuilder();
|
var strArray = str.ToCharArray();
|
for (int i = 0; i < strArray.Length; i++)
|
{
|
var charStr = strArray[i];
|
if (charStr == '+' || charStr == ' ' || charStr == 'K' || charStr == 'G')
|
continue;
|
newStr.Append(strArray[i]);
|
}
|
double ret = 0;
|
if (double.TryParse(newStr.ToString(), out ret))//判断是否是数字
|
{
|
//AddContent($"接收数据-{DateTime.Now}:{newStr.ToString()}");
|
lblHBWeight.Text = newStr.ToString();
|
txtHWeight.Text = DBUtility.ClsPub.isDoule(DBUtility.ClsPub.isDoule(lblHBWeight.Text) - DBUtility.ClsPub.isDoule(txtHPWeight.Text), 2);
|
}
|
}
|
}
|
|
//保存参数
|
private void cmdHSaveInfo_Click(object sender, EventArgs e)
|
{
|
ClsIni.WriteIni("COMINFO", "txtPortName", DBUtility.ClsPub.isStrNull(txtPortName.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("COMINFO", "txtBaudRate", DBUtility.ClsPub.isStrNull(txtBaudRate.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("COMINFO", "cmbParity", DBUtility.ClsPub.isStrNull(cmbParity.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("COMINFO", "txtDataBits", DBUtility.ClsPub.isStrNull(txtDataBits.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("COMINFO", "cmbStopBits", DBUtility.ClsPub.isStrNull(cmbStopBits.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("COMINFO", "txtHSend0", DBUtility.ClsPub.isStrNull(txtHSend0.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
ClsIni.WriteIni("COMINFO", "txtHSend", DBUtility.ClsPub.isStrNull(txtHSend.Text), DBUtility.ClsPub.AppPath + @"/HXERP.ini");
|
}
|
|
|
|
|
|
|
}
|
}
|