using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Windows.Forms; using DevExpress.XtraEditors; using ICSSoft.Base.Config.AppConfig; using ICSSoft.Base.Config.DBHelper; using ICSSoft.Base.ReferForm.AppReferForm; using ICSSoft.Frame.Data.Entity; using ICSSoft.Frame.Data.BLL; namespace ICSSoft.Frame.APP { public partial class FormICSDeliveryPlanEdit : DevExpress.XtraEditors.XtraForm { String guid = ""; DataSet dataSource = new DataSet(); string Version = ""; string pk_org_ForInvcode = "000110100000000005J9"; DataTable dtSO = new DataTable(); #region 构造函数 public FormICSDeliveryPlanEdit() { InitializeComponent(); this.MaximumSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } public FormICSDeliveryPlanEdit(String id, string version = null) { InitializeComponent(); guid = id; Version = version; this.MaximumSize = new System.Drawing.Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } #endregion #region 关闭 退出 private void btnClose_Click(object sender, EventArgs e) { 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 btnOK_Click(object sender, EventArgs e) { try { if (dataSource == null || dataSource.Tables.Count != 2) { return; } if (txtCustomer.EditValue == null || string.IsNullOrWhiteSpace(txtCustomer.EditValue.ToString())) { throw new Exception("请选择客户!"); } DataTable dt = dataSource.Tables[1]; //DataRow[] drs = dt.Select("InvCode=''"); //if (drs != null && drs.Length > 0) // throw new Exception("物料编码不能为空!"); //var InvCodes = (from DataRow dr in dt.Rows // group dr by (string)dr["InvCode"] into g // select new // { // InvCode = g.Key, // Count = g.Count() // }).Where(a => a.Count > 1).Select(a => a.InvCode); //if (InvCodes != null && InvCodes.Count() > 0) //{ // string invcodes = string.Join(",", InvCodes); // throw new Exception("物料编码不能重复:" + invcodes); //} //var Sequences = (from DataRow dr in dt.Rows // group dr by (int)dr["Sequence"] into g // select new // { // Sequence = g.Key, // Count = g.Count() // }).Where(a => a.Count > 1).Select(a => a.Sequence); //if (Sequences != null && Sequences.Count() > 0) //{ // string invcodes = string.Join(",", Sequences); // throw new Exception("行号不能重复:" + invcodes); //} ICSDeliveryPlan entity = new ICSDeliveryPlan(); entity.ID = guid; entity.DeliveryPlanNO = txtDeliveryPlanNO.Text.Trim(); entity.Version = txtDeliveryPlanNO.Tag.ToString(); entity.Customer = txtCustomer.EditValue.ToString(); entity.Org = txtCustomer.Text.Trim(); entity.Enable = true; entity.MUSER = AppConfig.UserCode; entity.MUSERName = AppConfig.UserName; entity.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"); entity.WorkPoint = AppConfig.WorkPointCode; entity.EATTRIBUTE1 = null; entity.CreateUser = entity.MUSER; entity.CreateDateTime = entity.MTIME; ICSDeliveryPlanBLL.Add(entity, dt, Version, AppConfig.AppConnectString); this.Close(); ICSBaseSimpleCode.AppshowMessageBox("操作成功"); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 取消 private void can_Click(object sender, EventArgs e) { this.Close(); } #endregion #region 页面加载 private void FormICSINVENTORYEditAdd_Load(object sender, EventArgs e) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在加载...请稍等..."); _wait.Show(); try { AppConfig.BindCustomDrawRowIndicator(grdDetail); init(); dataSource = ICSDeliveryPlanBLL.SearchInfoByID(guid, AppConfig.AppConnectString); if (dataSource == null || dataSource.Tables.Count != 2) { throw new Exception("查询数据失败,请重新操作!"); } DataRow dr = dataSource.Tables[0].Rows[0]; txtDeliveryPlanNO.Text = dr["DeliveryPlanNO"].ToString(); txtDeliveryPlanNO.Tag = dr["Version"].ToString(); if (string.IsNullOrWhiteSpace(guid)) { guid = AppConfig.GetGuid(); lblTitle.Text = "拉货计划单新增"; txtDeliveryPlanNO.Properties.ReadOnly = true; txtMUSERName.Text = AppConfig.UserName; txtMTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } else { if (string.IsNullOrWhiteSpace(Version)) lblTitle.Text = "拉货计划单修改"; else lblTitle.Text = "拉货计划单变更"; txtCustomer.Text = dr["Customer"].ToString(); txtDeliveryPlanNO.Properties.ReadOnly = true; txtCustomer.Properties.ReadOnly = true; txtMUSERName.Text = AppConfig.UserName; txtMTIME.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); } grvDetail.DataSource = dataSource.Tables[1]; grdDetail.BestFitColumns(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } finally { _wait.Close(); } } #endregion DataTable dtInvInfo = new DataTable(); #region 初始化查询条件 private void init() { DataSet ds = ICSDeliveryPlanBLL.GetInvInfoAndCust(pk_org_ForInvcode); #region 存货编码 ////string sql = "SELECT DISTINCT INVCODE AS [存货编码] ,INVNAME AS [存货名称] ,INVSTD AS [规格型号] FROM ICSINVENTORY WHERE WorkPoint='{0}' ORDER BY INVCODE "; ////sql = string.Format(sql, AppConfig.WorkPointCode); ////string sql = @"SELECT a.code AS [存货编码] ,a.name AS [存货名称] ,a.materialspec AS [规格型号] //// FROM bd_material a //// -- INNER JOIN org_orgs b ON a.pk_org =b.pk_org //// WHERE a.pk_org='000110100000000005J9' --b.code='Ahwit' //// ORDER BY a.code //// //// SELECT cus.code AS [客户编码],cus.name AS[客户名称] FROM bd_customer cus //// INNER JOIN org_orgs org ON cus.pk_org=org.pk_org //// --WHERE org.code='{0}' //// ORDER BY cus.code"; ////DataSet ds = DBHelper.ExecuteDataset(erp, CommandType.Text, sql); //txtINVCode.ValueMember = "物料编码"; //txtINVCode.DisplayMember = "物料编码"; //txtINVCode.DataSource = dtInvInfo = ds.Tables[0]; //txtINVCode.NullText = "";//空时的值 //txtINVCode.ImmediatePopup = true;//输入值是否马上弹出窗体 //txtINVCode.ValidateOnEnterKey = true;//回车确认 //txtINVCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard //txtINVCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 ////自适应宽度 //txtINVCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion #region 存货编码 dtSO = ds.Tables[1]; txtSOCode.ValueMember = "表体标识"; txtSOCode.DisplayMember = "表体标识"; txtSOCode.DataSource = dtSO; txtSOCode.NullText = "";//空时的值 txtSOCode.ImmediatePopup = true;//输入值是否马上弹出窗体 txtSOCode.ValidateOnEnterKey = true;//回车确认 txtSOCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard txtSOCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度 txtSOCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion #region 客户 // string sql1 = @"SELECT cus.code AS [客户编码],cus.name AS[客户名称] FROM bd_customer cus // INNER JOIN org_orgs org ON cus.pk_org=org.pk_org // --WHERE org.code='{0}' // ORDER BY cus.code"; // sql1 = string.Format(sql1, AppConfig.WorkPointCode); // DataTable dt1 = DBHelper.ExecuteDataset(erp, CommandType.Text, sql1).Tables[0]; txtCustomer.Properties.ValueMember = "客户编码"; txtCustomer.Properties.DisplayMember = "客户名称"; txtCustomer.Properties.DataSource = ds.Tables[2]; txtCustomer.Properties.NullText = "";//空时的值 txtCustomer.Properties.ImmediatePopup = true;//输入值是否马上弹出窗体 txtCustomer.Properties.ValidateOnEnterKey = true;//回车确认 txtCustomer.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard txtCustomer.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 //自适应宽度 txtCustomer.Properties.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; #endregion } #endregion #region 增行 private void btnAdd_Click(object sender, EventArgs e) { try { if (dataSource == null || dataSource.Tables.Count != 2) { return; } DataRow dr = dataSource.Tables[1].NewRow(); dr["Sequence"] = dataSource.Tables[1].Rows.Count+1; dr["InvCode"] = ""; dr["PreDate"] = DateTime.Now; dataSource.Tables[1].Rows.Add(dr); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 删行 private void btnDelete_Click(object sender, EventArgs e) { try { if (dataSource == null || dataSource.Tables.Count != 2) { return; } dataSource.Tables[1].Rows.RemoveAt(grdDetail.FocusedRowHandle); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 复制行 private void btnCopy_Click(object sender, EventArgs e) { try { if (dataSource == null || dataSource.Tables.Count != 2) { return; } DataRow dr = dataSource.Tables[1].Rows[grdDetail.FocusedRowHandle]; dataSource.Tables[1].Rows.Add(dr.ItemArray); int index = dataSource.Tables[1].Rows.Count; //dataSource.Tables[1].Rows[index - 1]["Sequence"] = ""; dataSource.Tables[1].Rows[index - 1]["InvCode"] = ""; dataSource.Tables[1].Rows[index - 1]["materialmnecode"] = ""; } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion private void txtINVCode_EditValueChanged(object sender, EventArgs e) { try { GridLookUpEdit edit = sender as GridLookUpEdit; if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext") { var o = edit.Properties.GetRowByKeyValue(edit.EditValue); if (o is DataRowView) { DataRowView RowView = o as DataRowView; string InvCT = RowView.Row["客户料号"].ToString(); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, InvCT); } else { grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, ""); } } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } //选择销售订单事件 private void txtSOCode_EditValueChanged(object sender, EventArgs e) { try { GridLookUpEdit edit = sender as GridLookUpEdit; if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext") { var o = edit.Properties.GetRowByKeyValue(edit.EditValue); if (o is DataRowView) { DataRowView RowView = o as DataRowView; grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vcooppohcode, RowView.Row["客户订单号"].ToString()); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vbillcode, RowView.Row["销售订单号"].ToString()); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, crowno, RowView.Row["销售订单行号"].ToString()); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, InvCode, RowView.Row["物料编码"].ToString()); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, RowView.Row["客户料号"].ToString()); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, SOQTY, RowView.Row["数量"].ToString()); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, Quantity, RowView.Row["数量"].ToString()); } else { grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vcooppohcode, ""); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, vbillcode, ""); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, crowno, ""); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, InvCode, ""); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, materialmnecode, ""); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, SOQTY, "0"); grdDetail.SetRowCellValue(grdDetail.FocusedRowHandle, Quantity, "0"); } } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } private void txtCustomer_EditValueChanged(object sender, EventArgs e) { try { GridLookUpEdit edit = sender as GridLookUpEdit; if (edit.EditValue != null && edit.EditValue.ToString() != "" && edit.EditValue.ToString() != "nulltext") { var dv = dtSO.DefaultView; dv.RowFilter = "客户编码='" + edit.EditValue + "'"; //txtSOCode.ValueMember = "表体标识"; //txtSOCode.DisplayMember = "表体标识"; txtSOCode.DataSource = dv; //txtSOCode.NullText = "";//空时的值 //txtSOCode.ImmediatePopup = true;//输入值是否马上弹出窗体 //txtSOCode.ValidateOnEnterKey = true;//回车确认 //txtSOCode.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;//要使用户可以输入,这里须设为Standard //txtSOCode.AllowNullInput = DevExpress.Utils.DefaultBoolean.True; //可用Ctrl + Delete清空选择內容 ////自适应宽度 //txtSOCode.BestFitMode = DevExpress.XtraEditors.Controls.BestFitMode.BestFitResizePopup; } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } private void txtCustomer_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e) { try { GridLookUpEdit edit = sender as GridLookUpEdit; if (e.OldValue !=null && e.OldValue.ToString() != e.NewValue.ToString() && grdDetail.RowCount>0) { DialogResult result=MessageBox.Show("原客户已维护对应的销售订单,是否要删除?", "提示", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { dataSource.Tables[1].Clear(); } else { e.NewValue = e.OldValue; } } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } } }