using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Linq; using System.Linq; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.BandedGrid; using DevExpress.XtraGrid.Columns; using DevExpress.XtraGrid; using System.IO; using System.Threading; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.UserControl.MessageControl; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.Report.Filter; using ICSSoft.Base.UserControl.FormControl; using ICSSoft.Base.Report.GridReport; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Frame.Data.BLL; using ICSSoft.Frame.Data.Entity; using ICSSoft.Base.Lable.PrintTool; namespace ICSSoft.Frame.APP { public partial class FormICSRewarehouse : DevExpress.XtraEditors.XtraForm { private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataTable dataSource = null; private string MoId = ""; private string MoCode = ""; private decimal Qty = 0.00m; DataTable Serialdata = null; private string Type = ""; private string Status = ""; #region 构造函数 public FormICSRewarehouse() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } public FormICSRewarehouse(string moID, string moCode, decimal qty) { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; MoId = moID; MoCode = moCode; Qty = qty; } #endregion #region 操作权限 public DataTable RightOfExute() { DataTable rData = new DataTable(); rData.Columns.Add("BtnName"); rData.Columns.Add("ActionName"); //查看权限(必须有) DataRow seeRow = rData.NewRow(); seeRow["BtnName"] = "see"; seeRow["ActionName"] = "查看"; rData.Rows.Add(seeRow); List ControlList = new List(); ControlList.Add(btnCreate); ControlList.Add(btnDel); ControlList.Add(simpleButton4); foreach (Control ctr in ControlList) { if (ctr.GetType() == typeof(SimpleButton)) { DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } } rData.AcceptChanges(); return rData; } public DataTable RightOfData()// 数据权限 { DataTable rData = new DataTable(); rData.Columns.Add("BodyName"); rData.Columns.Add("ControlName"); rData.Columns.Add("ControlCaption"); rData.AcceptChanges(); return rData; } #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 #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 grvMoDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString(); } #endregion #region 列表 private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString(); } #endregion #region 分页 private void rptPage_PageIndexChanged(object Sender, EventArgs e) { DataTable data = AppConfig.GetPageData(Serialdata, rptPage.PageIndex, rptPage.PageSize).Copy(); grdDetail.DataSource = data; } #endregion private bool check() { int i; if (string.IsNullOrWhiteSpace(txtCode.Text.Trim())) { ICSBaseSimpleCode.AppshowMessageBox("单据号不能为空!"); return false; } if (string.IsNullOrWhiteSpace(cmbSEQ.Text.Trim())) { ICSBaseSimpleCode.AppshowMessageBox("行号不能为空!"); return false; } else if (!int.TryParse(cmbSEQ.Text.Trim(), out i)) { ICSBaseSimpleCode.AppshowMessageBox("行号格式不正确!"); return false; } return true; } #region 新增 private void btnCreate_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } if (Status.Equals("已经完成")) { ICSBaseSimpleCode.AppshowMessageBox("已完成入库,不能生产条码!"); return; } //if (!check()) //{ // return; //} //FormICSRewarehouseCreate form = new FormICSRewarehouseCreate(txtCode.Text.Trim(), cmbSEQ.Text.Trim(), txtStd.Text, Type); //form.ShowDialog(); //cmbSEQ_SelectedIndexChanged(null, null); string moSeq = ""; string moCode = ""; string invStd = ""; for (int i = 0; i < grvMoDetail.RowCount; i++) { if (grvMoDetail.GetRowCellValue(i, colMoIsSelect).ToString() == "Y") { moSeq = grvMoDetail.GetRowCellValue(i, colMOSEQ1).ToString(); moCode = grvMoDetail.GetRowCellValue(i, colMoCode1).ToString(); invStd = grvMoDetail.GetRowCellValue(i, colINVSTD).ToString(); } } if (string.IsNullOrWhiteSpace(moSeq)) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } FormICSRewarehouseCreate form = new FormICSRewarehouseCreate(moCode, moSeq, invStd, Type); form.ShowDialog(); SearchData(moCode, moSeq); if (ICSBaseSimpleCode.AppshowMessageBoxRepose("是否打印?") == DialogResult.OK) { simpleButton4_Click(null, null); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.ToString()); } } /// /// 获取生成的条码 /// /// /// private void SearchData(string moCode, string moSeq) { try { DataSet ds = FormICSRewarehouseBLL.SearchData(moCode, moSeq, AppConfig.AppConnectString); if (ds != null && ds.Tables.Count == 2) { DataTable dt = ds.Tables[0]; Serialdata = ds.Tables[1]; grdDetail.DataSource = Serialdata; grvDetail.BestFitColumns(); rptPage.RecordNum = Serialdata.Rows.Count; rptPage.PageSize = 499; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageSize = 500; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage_PageIndexChanged(null, null); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.ToString()); } } #endregion //加载 private void FormICSRewarehouse_Load(object sender, EventArgs e) { #region //string sql = @"select '' as isSelect,RCARD from ICSMO2RCARD where MOID='{0}' order by RCARD asc"; //sql = string.Format(sql, MoId); ////DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; ////grdDetail.DataSource = dt; //Serialdata = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; //rptPage.RecordNum = Serialdata.Rows.Count; //rptPage.PageIndex = 1; //rptPage.PageSize = 20; //rptPage.ReLoad(); //rptPage_PageIndexChanged(null, null); #endregion init(); } #region 初始化查询条件 private void init() { #region 单据号 #region 原逻辑 //string sql = "SELECT DISTINCT ReceiptNO AS [单据号] FROM ICSINVReceipt WHERE WorkPoint='{0}' ORDER BY ReceiptNO "; #endregion string sql = "SELECT DISTINCT VouchCode AS [单据号] FROM ICSMaterial WHERE WorkPoint='{0}' AND IsPickingOrBack = '3' ORDER BY VouchCode DESC "; sql = string.Format(sql, AppConfig.WorkPointCode); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; txtCode.Properties.ValueMember = "单据号"; txtCode.Properties.DisplayMember = "单据号"; txtCode.Properties.DataSource = dt; txtCode.Properties.NullText = "";//空时的值 txtCode.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体 txtCode.Properties.ValidateOnEnterKey = true;//回车确认 txtCode.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard txtCode.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度 txtCode.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion } #endregion private void txtMOCode_EditValueChanged(object sender, EventArgs e) { try { //this.txtItemCode.Text = ""; //this.txtItemName.Text = ""; //this.txtStd.Text = ""; //this.txtQty.Text = ""; //grdDetail.DataSource = null; //cmbSEQ.Properties.Items.Clear(); //cmbSEQ.Text = ""; //string Code = txtCode.EditValue.ToString(); //#region 原逻辑 ////string sql = "SELECT DISTINCT ReceiptLine FROM ICSINVReceiptDetail WHERE WorkPoint='{0}' AND ReceiptNO='{1}' ORDER BY ReceiptLine"; //#endregion //string sql = "SELECT DISTINCT VouchRow FROM ICSMaterialPick WHERE WorkPoint='{0}' AND VouchCode='{1}' ORDER BY VouchRow"; //sql = string.Format(sql, AppConfig.WorkPointCode, Code); //DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; //#region ////cmbSEQ.Properties.Items.Add(""); ////cmbSEQ.Properties.Items.AddRange(dt.AsEnumerable().Select(a => a["ReceiptLine"]).ToList()); ////cmbSEQ.Properties.Items.AddRange(dt.AsEnumerable().Select(a => a["MOSEQ"]).ToList()); ////if (cmbSEQ.Properties.Items.Count > 0) //// cmbSEQ.SelectedIndex = 0; //#endregion //foreach( DataRow dr in dt.Rows) //{ // cmbSEQ.Properties.Items.Add(dr["VouchRow"].ToString()); //} //if (cmbSEQ.Properties.Items.Count > 0) // cmbSEQ.SelectedIndex = 0; grdDetail.DataSource = null; cmbSEQ.Properties.Items.Clear(); cmbSEQ.Text = ""; string Code = txtCode.EditValue.ToString(); string sql = @"SELECT '' as MoIsSelect, a.VouchCode MOCODE, a.VouchRow MOSEQ, a.Quantity MOPLANQTY, a.SubInvCode ITEMCODE, b.INVNAME, b.INVSTD,a.VoucherNO FROM ICSMaterialPick a LEFT JOIN ICSINVENTORY b ON a.SubInvCode=b.INVCODE WHERE a.VouchCode='{0}' AND a.WorkPoint = '{1}' AND b.WorkPoint = '{1}'"; sql += " order by CAST(a.VouchRow AS INT) asc"; sql = string.Format(sql, Code, AppConfig.WorkPointCode); DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { grdMoDetail.DataSource = dt; grvMoDetail.BestFitColumns(); } else { ICSBaseSimpleCode.AppshowMessageBox("没有找到该单据信息!"); return; } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox("没有找到该单据信息!"); return; } } private void cmbSEQ_SelectedIndexChanged(object sender, EventArgs e) { try { Type = ""; Status = ""; if (cmbSEQ.Properties.Items.Count <= 0 || !check()) { return; } DataSet ds = FormICSRewarehouseBLL.SearchData(txtCode.Text.Trim(), cmbSEQ.Text.Trim(), AppConfig.AppConnectString); if (ds != null && ds.Tables.Count == 2) { DataTable dt = ds.Tables[0]; if (dt != null && dt.Rows.Count > 0) { txtItemCode.Text = dt.Rows[0]["SubInvCode"].ToString(); txtItemName.Text = dt.Rows[0]["INVNAME"].ToString(); txtStd.Text = dt.Rows[0]["INVSTD"].ToString(); txtQty.Text = dt.Rows[0]["Quantity"].ToString(); //Type = dt.Rows[0]["TYPE"].ToString(); //Status = dt.Rows[0]["RECSTATUS"].ToString(); } Serialdata = ds.Tables[1]; grdDetail.DataSource = Serialdata; grvDetail.BestFitColumns(); rptPage.RecordNum = Serialdata.Rows.Count; rptPage.PageSize = 499; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageSize = 500; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage_PageIndexChanged(null, null); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.ToString()); } } private void grvDetail_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (e.RowHandle >= 0 && e.Column.FieldName == "DCTCODE") { e.CellValue = "cccc"; } } #region 全选 private void btnSelectAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, "Y"); } } #endregion #region 全消 private void btnCancelAll_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, ""); } } #endregion private void btnDel_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } List rcardList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y" && grvDetail.GetRowCellValue(i, colisInput).ToString() == "False") { rcardList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); } } if (rcardList.Count == 0 || rcardList == null) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除序列号吗?删除后无法恢复,确定吗?") != DialogResult.OK) { btnCancelAll_Click(sender, e); return; } try { FormICSRewarehouseBLL.deleteInfo(rcardList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("删除成功"); string moSeq = ""; string moCode = ""; for (int i = 0; i < grvMoDetail.RowCount; i++) { if (grvMoDetail.GetRowCellValue(i, colMoIsSelect).ToString() == "Y") { moSeq = grvMoDetail.GetRowCellValue(i, colMOSEQ1).ToString(); moCode = grvMoDetail.GetRowCellValue(i, colMoCode1).ToString(); } } SearchData(moCode, moSeq); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } cmbSEQ_SelectedIndexChanged(null, null); } private void grvDetail_DoubleClick(object sender, EventArgs e) { if (grvDetail.FocusedRowHandle < 0) { return; } if (grvDetail.FocusedColumn == colisSelect) { if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "") { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y"); } else { grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, ""); } } } #region 打印 private void simpleButton4_Click(object sender, EventArgs e) { try { if (sender != null) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } } List parasList = new List(); List InfoList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y") { PrintPara para = new PrintPara(); para.PrintKey = "LOTNO"; para.PrintValues = new object[] { grvDetail.GetRowCellValue(i, colLOTNO).ToString() }; parasList.Add(para); ICSITEMLot Info = new ICSITEMLot(); Info.LotNO = grvDetail.GetRowCellValue(i, colLOTNO).ToString(); Info.lastPrintUSERID = AppConfig.UserId; Info.lastPrintTime = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss"); Info.WorkPoint = AppConfig.WorkPointCode; Info.EATTRIBUTE3 = decimal.Parse(grvDetail.GetRowCellValue(i, colEATTRIBUTE3).ToString()); InfoList.Add(Info); } } if (parasList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据!"); return; } #region 修改打印模板逻辑 #region //if (Type.Equals("半成品")) //{ // FormPrintDialog f = new FormPrintDialog("007", this.Text, parasList, false, null); // f.ShowDialog(); //} //else if (Type.Equals("成品")) //{ // FormPrintDialog f = new FormPrintDialog("008", this.Text, parasList, false, null); // f.ShowDialog(); //} #endregion FormPrintDialog f = new FormPrintDialog("019", this.Text, parasList, false, null); f.ShowDialog(); #endregion //更新打印信息 FormICSRewarehouseBLL.updatePrint(InfoList, AppConfig.AppConnectString); string moSeq = ""; string moCode = ""; for (int i = 0; i < grvMoDetail.RowCount; i++) { if (grvMoDetail.GetRowCellValue(i, colMoIsSelect).ToString() == "Y") { moSeq = grvMoDetail.GetRowCellValue(i, colMOSEQ1).ToString(); moCode = grvMoDetail.GetRowCellValue(i, colMoCode1).ToString(); } } SearchData(moCode, moSeq); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } #endregion private void grdMoDetail_DoubleClick(object sender, EventArgs e) { int x = 0; if (grvMoDetail.FocusedRowHandle < 0) { return; } if (grvMoDetail.FocusedColumn == colMoIsSelect) { if (grvMoDetail.GetRowCellValue(grvMoDetail.FocusedRowHandle, colMoIsSelect).ToString() == "") { grvMoDetail.SetRowCellValue(grvMoDetail.FocusedRowHandle, colMoIsSelect, "Y"); x = grvMoDetail.FocusedRowHandle; } else { grvMoDetail.SetRowCellValue(grvMoDetail.FocusedRowHandle, colMoIsSelect, ""); } } for (int i = 0; i < grvMoDetail.RowCount; i++) { if (x != i) { grvMoDetail.SetRowCellValue(i, colMoIsSelect, ""); } } try { Type = ""; Status = ""; string moSeq = ""; string moCode = ""; for (int i = 0; i < grvMoDetail.RowCount; i++) { if (grvMoDetail.GetRowCellValue(i, colMoIsSelect).ToString() == "Y") { moSeq = grvMoDetail.GetRowCellValue(i, colMOSEQ1).ToString(); moCode = grvMoDetail.GetRowCellValue(i, colMoCode1).ToString(); } } DataSet ds = FormICSRewarehouseBLL.SearchData(moCode, moSeq, AppConfig.AppConnectString); if (ds != null && ds.Tables.Count == 2) { DataTable dt = ds.Tables[0]; Serialdata = ds.Tables[1]; grdDetail.DataSource = Serialdata; grvDetail.BestFitColumns(); rptPage.RecordNum = Serialdata.Rows.Count; rptPage.PageSize = 499; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageSize = 500; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage_PageIndexChanged(null, null); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.ToString()); } } private void grdMoDetail_Click(object sender, EventArgs e) { } } }