using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Frame.User.BLL; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.UserControl.MessageControl; using System.Data.SqlClient; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Base.Lable.PrintTool; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.APP { public partial class FormICSMaterielCreate : DevExpress.XtraEditors.XtraForm { private FormICSPurchaseLOTUIModelX RecInfo; private string CODE; private string RowNo; private string invStd; private string type; #region 构造函数 public FormICSMaterielCreate(string code,string rowNO,string InvStd,string Type) { InitializeComponent(); chkBtnAll.Checked = false; chkBtnNo.Checked = true; CODE = code; RowNo = rowNO; invStd = InvStd; GetRecInfo(); if (RecInfo == null) { throw new Exception("入库单信息取得失败"); } //if (RecInfo.item.ItemCtrType == null || RecInfo.item.ItemCtrType.ItemCtrTypeCode == "") //{ // throw new Exception("入库单对应料品的控管类型为空,无法生成条码"); //} } #endregion #region 移动窗体 private const int WM_NCHITTEST = 0x84; private const int HTCLIENT = 0x1; private const int HTCAPTION = 0x2; //首先必须了解Windows的消息传递机制,当有鼠标活动消息时, //系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest //假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION , //同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。 //重写窗体,使窗体可以不通过自带标题栏实现移动 protected override void WndProc(ref Message m) { //当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息, //当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体, //这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。 //注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。 switch (m.Msg) { case WM_NCHITTEST: base.WndProc(ref m); if ((int)m.Result == HTCLIENT) m.Result = (IntPtr)HTCAPTION; return; } //拦截双击标题栏、移动窗体的系统消息 if (m.Msg != 0xA3) { base.WndProc(ref m); } } #endregion #region 退出 private void btnClose_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } private void btnExit_Click(object sender, EventArgs e) { AppConfig.CloseFormShow(this.Text); this.Close(); } #endregion private void GetRecInfo() { RecInfo = ICSMaterielLOTBLL.SearchInfo(CODE, RowNo, AppConfig.AppConnectString); init(); } decimal a = 0; private void init() { txtSumNo.Text = ""; txtNowNo.Text = ""; txtNowQty.Text = ""; txtSumQty.Text = ""; txtAllQty.Text = ""; btnLabelCreate.Enabled = true; if (RecInfo == null) { return; } //if (RecInfo.item != null) //{ // if (RecInfo.item.ItemCtrType == null) // { // btnLabelCreate.Enabled = false; // } //if (RecInfo.item.ItemCtrType.ItemCtrTypeCode == ATVControlParam.ItemCtrlEnum.PieceCtrl.Code) //{ // txtNowPackQty.Text = "1"; // txtNowPackQty.Properties.ReadOnly = true; // chkBtnPack.Checked = false; // chkBtnPack.Checked = true; // chkBtnAll.Enabled = false; // chkBtnNo.Enabled = false; // chkBtnPack.Enabled = false; //} //else //{ //txtNowPackQty.Text = "1"; txtNowPackQty.Properties.ReadOnly = false; //chkBtnPack.Checked = false; //chkBtnPack.Checked = true; chkBtnAll.Enabled = true; chkBtnNo.Enabled = true; chkBtnPack.Enabled = true; //} //} txtSumQty.Text = RecInfo.SumQty.ToString(); txtSumNo.Text = RecInfo.SumNo.ToString(); a = RecInfo.Arrive.iQuantity - RecInfo.SumQty; txtNowQty.Text = (RecInfo.Arrive.iQuantity - RecInfo.SumQty > 0 ? RecInfo.Arrive.iQuantity - RecInfo.SumQty : 0).ToString(); //txtNowNo.Text = Math.Ceiling(decimal.Parse(txtNowQty.Text)).ToString(); if (string.IsNullOrWhiteSpace(RecInfo.inventory.INVCARTONQTY.ToString())) { txtNowPackQty.Text = "1"; txtNowNo.Text = Math.Ceiling(decimal.Parse(txtNowQty.Text)).ToString(); } else { if (RecInfo.inventory.INVCARTONQTY == 0) { txtNowPackQty.Text = "1"; txtNowNo.Text = txtNowQty.Text; } else { txtNowPackQty.Text = RecInfo.inventory.INVCARTONQTY.ToString(); txtNowNo.Text = Math.Ceiling(decimal.Parse(txtNowQty.Text) / decimal.Parse(RecInfo.inventory.INVCARTONQTY.ToString())).ToString(); } } txtAllQty.Text = (decimal.Parse(txtSumQty.Text) + decimal.Parse(txtNowQty.Text)).ToString(); txtAllNo.Text = (decimal.Parse(txtSumNo.Text) + decimal.Parse(txtNowNo.Text)).ToString(); } private void btnLabelCreate_Click(object sender, EventArgs e) { string VLotNo = ""; string Lot_NO = ""; if (RecInfo == null) { ICSBaseSimpleCode.AppshowMessageBox("入库单信息取得失败"); return; } if (string.IsNullOrWhiteSpace(RecInfo.Arrive.cCode) || string.IsNullOrWhiteSpace(RecInfo.Arrive.irowno.ToString())) { ICSBaseSimpleCode.AppshowMessageBox("生产订单号或生产订单号行号不能为空!"); return; } DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在生成条码……"); try { _wait.Show(); Decimal totalQty = decimal.Parse(txtNowQty.Text); decimal pieceQty = decimal.Parse(txtNowPackQty.Text); int Num = int.Parse(txtNowNo.Text); if (pieceQty * Num < totalQty || pieceQty * (Num - 1) >= totalQty) { throw new Exception("条码数量计算出错,请重新计算"); } decimal Qty = decimal.Parse(txtNowPackQty.Text); if (Num <= 0) { throw new Exception("条码张数不能为0"); } if (Qty <= 0) { throw new Exception("条码数量不能为0"); } List InfoList = new List(); int m = 0; int count = Convert.ToInt32(RecInfo.MaxNo); DateTime time = AppConfig.GetSeverDateTime("yyyy-MM-dd"); string timeStr=time.ToString("yyMMdd"); string sql = @"SELECT MAX(A.VenderLotNO) AS VenderLotNO FROM ICSITEMLot A WHERE TransNO ='{0}' AND TransLine='{1}'"; sql = string.Format(sql, CODE, RowNo); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; if (dt != null && dt.Rows.Count > 0 && !string.IsNullOrEmpty(dt.Rows[0]["VenderLotNO"].ToString())) { VLotNo = (dt.Rows[0][0].ToString().Substring(0, dt.Rows[0][0].ToString().Length - 3)).ToString() + (Convert.ToInt32(dt.Rows[0][0].ToString().Substring(dt.Rows[0][0].ToString().Length - 3)) + 1).ToString().PadLeft(3, '0'); } else { VLotNo = timeStr.Substring(timeStr.Length - 6) + (RecInfo.TodayMOCount ).ToString().PadLeft(3, '0'); //生产批号,每个批次一个 } string timeLot = time.ToString("yyyyMMdd"); string sql1 = @"SELECT MAX(A.LotNO) AS LotNO FROM ICSITEMLot A WHERE A.LotNO like '%{2}%'"; sql1 = string.Format(sql1, CODE, RowNo, timeLot); DataTable ds = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql1).Tables[0]; if (ds != null && ds.Rows.Count > 0 && !string.IsNullOrEmpty(ds.Rows[0]["LotNO"].ToString())) { Lot_NO = ds.Rows[0]["LOTNO"].ToString(); m = int.Parse(Lot_NO.Substring(Lot_NO.Length - 4)); } for (int i = 0; i < Num; i++) { int b = m + i + 1; _wait.Caption = "正在生成条码……" + " " + i.ToString() + "/" + Num.ToString(); _wait.Refresh(); ICSITEMLot Info = new ICSITEMLot(); Info.ID = ""; if (Qty < totalQty - Qty * i) { Info.LOTQTY = Qty; } else { Info.LOTQTY = totalQty - Qty * i; } Info.LotNO ="7"+ timeLot+b.ToString().PadLeft(4, '0'); Info.ItemCode = RecInfo.Arrive.cInvCode; Info.TransNO = RecInfo.Arrive.cCode; Info.TransLine = Convert.ToString(RecInfo.Arrive.irowno); Info.VENDORITEMCODE = ""; Info.VenderLotNO = VLotNo; //if (!string.IsNullOrWhiteSpace(RecInfo.VenderLotNO)) // Info.VenderLotNO = RecInfo.VenderLotNO; //else // Info.VenderLotNO = timeStr.Substring(timeStr.Length-6) + (RecInfo.TodayMOCount+1).ToString().PadLeft(3,'0'); //生产批号,每个工单一个 Info.PRODUCTDATE = time; Info.ACTIVE = "Y"; Info.Exdate = Convert.ToDateTime("2999-12-31"); //Info.TYPE = RecInfo.Arrive.TYPE; InfoList.Add(Info); } _wait.Caption = "条码生成成功,正在上传数据"; _wait.Refresh(); ICSMaterielLOTBLL.Add(InfoList,AppConfig.AppConnectString); //_wait.Caption = "数据上传完成,正在打开条码打印"; //_wait.Refresh(); //GetRecInfo(); _wait.Close(); this.Close(); } catch (Exception ex) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } private void chkBtnAll_CheckedChanged(object sender, EventArgs e) { if (chkBtnAll.Checked == true) { chkBtnAll.Checked = true; chkBtnNo.Checked = false; chkBtnPack.Checked = false; chkBtnCheckedCharge(); } } private void chkBtnNo_CheckedChanged(object sender, EventArgs e) { if (chkBtnNo.Checked == true) { chkBtnAll.Checked = false; chkBtnNo.Checked = true; chkBtnPack.Checked = false; chkBtnCheckedCharge(); } } private void chkBtnPack_CheckedChanged(object sender, EventArgs e) { if (chkBtnPack.Checked == true) { chkBtnAll.Checked = false; chkBtnNo.Checked = false; chkBtnPack.Checked = true; chkBtnCheckedCharge(); } } private void chkBtnCheckedCharge() { if (chkBtnAll.Checked == true) { chkBtnAll.Checked = true; chkBtnNo.Checked = false; chkBtnPack.Checked = false; this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete; this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit; this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit; txtNowQty.Properties.ReadOnly = false; txtNowNo.Properties.ReadOnly = true; txtNowPackQty.Properties.ReadOnly = false; } else if (chkBtnNo.Checked == true) { chkBtnAll.Checked = false; chkBtnNo.Checked = true; chkBtnPack.Checked = false; this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit; this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete; this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit; txtNowQty.Properties.ReadOnly = false; txtNowNo.Properties.ReadOnly = true; txtNowPackQty.Properties.ReadOnly = false; } else if (chkBtnPack.Checked == true) { chkBtnAll.Checked = false; chkBtnNo.Checked = false; chkBtnPack.Checked = true; this.chkBtnAll.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit; this.chkBtnNo.Image = global::ICSSoft.Frame.APP.Properties.Resources.edit; this.chkBtnPack.Image = global::ICSSoft.Frame.APP.Properties.Resources.header_complete; txtNowQty.Properties.ReadOnly = false; txtNowNo.Properties.ReadOnly = true; txtNowPackQty.Properties.ReadOnly = false; } } private void txtNowPackQty_TextChanged(object sender, EventArgs e) { } private void txtDocOrg_EditValueChanged(object sender, EventArgs e) { } private void txtNowPackQty_EditValueChanged(object sender, EventArgs e)//生成包装箱数量 { bool isOK = false; if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox)) { DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox; if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name) { isOK = true; } } if (!isOK) { return; } decimal No = 0; decimal Qty = 0; decimal Pack = 0; decimal Sqty = 0; decimal.TryParse(txtNowNo.Text, out No); decimal.TryParse(txtNowQty.Text, out Qty); decimal.TryParse(txtNowPackQty.Text, out Pack); if (txtNowNo.Properties.ReadOnly == true) { if (Pack == 0) { ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0"); return; } Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } if (txtNowQty.Properties.ReadOnly == true) { if (Pack != 0) { Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } else { No = 0; } } } private void txtNowNo_EditValueChanged(object sender, EventArgs e) //生成打印数量 { bool isOK = false; if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox)) { DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox; if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name) { isOK = true; } } if (!isOK) { return; } decimal No; decimal Qty; decimal Pack; decimal Sqty = 0; decimal.TryParse(txtNowNo.Text, out No); decimal.TryParse(txtNowQty.Text, out Qty); decimal.TryParse(txtNowPackQty.Text, out Pack); if (txtNowPackQty.Properties.ReadOnly == true) { Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } if (txtNowQty.Properties.ReadOnly == true) { if (No != 0) { Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } else { Pack = 0; } } } private void txtNowQty_EditValueChanged(object sender, EventArgs e) //生成总数 { bool isOK = false; if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox)) { DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox; if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name) { isOK = true; } } if (!isOK) { return; } decimal No = 0; decimal Qty = 0; decimal Pack = 0; decimal Sqty = 0; decimal.TryParse(txtNowNo.Text, out No); decimal.TryParse(txtNowQty.Text, out Qty); decimal.TryParse(txtNowPackQty.Text, out Pack); if (txtNowPackQty.Properties.ReadOnly == true) { if (Pack != 0) { if (Pack == 0) { ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0"); return; } Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } } if (txtNowNo.Properties.ReadOnly == true) { if (Pack == 0) { ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0"); return; } Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } } private void txtNowPackQty_KeyDown(object sender, KeyEventArgs e) { try { if (e.KeyCode == Keys.Enter) { bool isOK = false; if (this.ActiveControl != null && this.ActiveControl.GetType() == typeof(DevExpress.XtraEditors.TextBoxMaskBox)) { DevExpress.XtraEditors.TextBoxMaskBox temp = this.ActiveControl as DevExpress.XtraEditors.TextBoxMaskBox; if (temp.OwnerEdit.Name == ((DevExpress.XtraEditors.TextEdit)sender).Name) { isOK = true; } } if (!isOK) { return; } decimal No = 0; decimal Qty = 0; decimal Pack = 0; decimal Sqty = 0; decimal.TryParse(txtNowNo.Text, out No); decimal.TryParse(txtNowQty.Text, out Qty); decimal.TryParse(txtNowPackQty.Text, out Pack); if (txtNowNo.Properties.ReadOnly == true) { if (Pack == 0) { ICSBaseSimpleCode.AppshowMessageBox("包装量不能为0"); return; } Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } if (txtNowQty.Properties.ReadOnly == true) { if (Pack != 0) { Sqty = Math.Ceiling(Qty / Pack); txtNowNo.Text = Sqty.ToString(); txtNowQty.Text = Qty.ToString(); txtNowPackQty.Text = Pack.ToString(); } else { No = 0; } } } } catch (Exception ex) { throw ex; } } private void txtNowPackQty_EditValueChanged_1(object sender, EventArgs e) { } } }