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 System.Data.SqlClient; using ICSSoft.Frame.Data.BLL; using ICSSoft.Base.Language.Tool; using ICSSoft.Base.UserControl.MessageControl; 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.Base.Config.AppConfig; using ICSSoft.Base.Report.GridReport; using ICSSoft.Frame.Data.Entity; using ICSSoft.Frame.APP; using System.Net; using System.IO; using ICSSoft.Frame.Data.Entity.NcApiEntity; using Newtonsoft.Json; using System.Linq; namespace ICSSoft.Frame.NC { public partial class FormICSDeliveryPlan : DevExpress.XtraEditors.XtraForm { string pk_org_ForInvcode = "000110100000000005J9"; private string sqltxt = ""; private string sqlconn = ""; String guid = AppConfig.GetGuid(); private DataSet dataSource = null; //Excel模板 List colNameList = new List(); #region 构造函数 public FormICSDeliveryPlan() { InitializeComponent(); this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); this.WindowState = FormWindowState.Maximized; } #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 SystemOptition /// /// 操作权限 /// /// 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); foreach (Control ctr in panelControl3.Controls) { if (ctr.Name == btnFilter.Name || ctr.Name == btnConfig.Name || ctr.Name == btnSelect.Name || ctr.Name == btnCanSelect.Name || ctr.Name == btnImportMould.Name || ctr.Name == btnOutPut.Name || ctr.Name == btnFalsh.Name || ctr.Name == btnExit.Name || ctr.Name == lblTitle.Name || ctr.Name == btnClose.Name) continue; DataRow dr = rData.NewRow(); dr["BtnName"] = ctr.Name; dr["ActionName"] = ctr.Text; rData.Rows.Add(dr); } //List ControlList = new List(); //ControlList.Add(btnConfig); //ControlList.Add(btnAdd); //ControlList.Add(btnEdit); //ControlList.Add(btnDelLable); //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 string tempTableName = ""; private void btnFilter_Click(object sender, EventArgs e) { FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name)); filter.OldTempTableName = tempTableName; if (filter.ShowDialog() == DialogResult.OK) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); tempTableName = filter.NewTempTableName; sqltxt = filter.SqlText; sqlconn = filter.FilterConnectString; dataSource = filter.FilterData; //DataRelation dr = new DataRelation("详情", new DataColumn[] { dataSource.Tables[0].Columns["ID"] }, new DataColumn[] { dataSource.Tables[1].Columns["DeliveryPlanID"] }, false); //dataSource.Relations.Add(dr); grdDetail.DataSource = dataSource.Tables[0]; grvDetail.BestFitColumns(); gridView.BestFitColumns(); rptPage.RecordNum = dataSource.Tables[0].Rows.Count; rptPage.PageSize = 490; rptPage.PageIndex = 1; rptPage.ReLoad(); rptPage.PageIndex = 1; rptPage.PageSize = 500; rptPage.ReLoad(); _wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } } } #endregion #region 全选 private void btnSelect_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, true); } } #endregion #region 全消 private void btnCanSelect_Click(object sender, EventArgs e) { grvDetail.PostEditor(); this.Validate(); for (int i = 0; i < grvDetail.RowCount; i++) { grvDetail.SetRowCellValue(i, colisSelect, false); } } #endregion #region 刷新 private void btnFalsh_Click(object sender, EventArgs e) { if (sqlconn == null || sqlconn == "") { return; } DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在查找...请稍等..."); try { _wait.Show(); FormFilter filter = new FormFilter(AppConfig.GetSourceId(this.Tag.ToString(), btnConfig.Name), false); filter.OldTempTableName = tempTableName; //tempTableName = filter.NewTempTableName; //DataTable data = DBHelper.ExecuteDataset(AppConfig.FrameConnectString, CommandType.Text, "select * from " + tempTableName).Tables[0]; dataSource = DBHelper.ExecuteDataset(sqlconn, CommandType.Text, sqltxt); grdDetail.DataSource = dataSource.Tables[0]; rptPage.RecordNum = dataSource.Tables[0].Rows.Count; rptPage.PageIndex = 1; rptPage.ReLoad(); _wait.Close(); } catch (Exception ex) { MessageBox.Show("异常:" + ex.Message, "异常", MessageBoxButtons.OK, MessageBoxIcon.Error); _wait.Close(); } } #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 btnConfig_Click(object sender, EventArgs e)//绑定数据源 { if (AppConfig.UserCode.ToLower() != "demo") { //ICSBaseSimpleCode.AppshowMessageBox("您没有权限设置数据源,请联系软件提供商!"); return; } FormDataSource fdata = new FormDataSource(AppConfig.GetMenuId(this.Tag.ToString()), btnConfig.Name); fdata.ShowDialog(); } #endregion #region 分页 private void rptPage_PageIndexChanged(object Sender, EventArgs e) { try { if (dataSource == null || dataSource.Tables.Count != 3) { return; } DataSet ds = new DataSet(); DataTable data = AppConfig.GetPageData(dataSource.Tables[0], rptPage.PageIndex, rptPage.PageSize).Copy(); ds.Tables.Add(data); ds.Tables.Add(dataSource.Tables[1].Copy()); DataRelation dr = new DataRelation("详情", new DataColumn[] { ds.Tables[0].Columns["ID"] }, new DataColumn[] { ds.Tables[1].Columns["DeliveryPlanID"] }, false); ds.Relations.Add(dr); grdDetail.DataSource = data; //gridExport.DataSource = dataSource.Tables[2]; } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 加载 private void FormICSFACTORY_Load(object sender, EventArgs e) { //colNameList.Add(new FormReadExcelUIModelColumns("单据号", true)); //colNameList.Add(new FormReadExcelUIModelColumns("行号", true)); colNameList.Add(new FormReadExcelUIModelColumns("客户编码", true)); colNameList.Add(new FormReadExcelUIModelColumns("物料编码", true)); colNameList.Add(new FormReadExcelUIModelColumns("数量", true)); colNameList.Add(new FormReadExcelUIModelColumns("客户订单号", false)); //colNameList.Add(new FormReadExcelUIModelColumns("销售订单行号", false)); colNameList.Add(new FormReadExcelUIModelColumns("要求交期", true)); btnFilter_Click(sender, e); } #endregion #region 增加 private void btnAdd_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } FormICSDeliveryPlanEdit add = new FormICSDeliveryPlanEdit(); add.ShowDialog(); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 修改 private void btnEdit_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; string id = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { count++; id = grvDetail.GetRowCellValue(i, colID).ToString(); if (!string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colChecker).ToString())) throw new Exception("单据已审核,不能修改!"); } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { FormICSDeliveryPlanEdit add = new FormICSDeliveryPlanEdit(id); add.ShowDialog(); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 删除 private void btnDel_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } List IDList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp))) throw new Exception("单据:" + grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString() + " 已上传,不能删除!"); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除吗?删除后无法恢复,确定吗?") != DialogResult.OK) { return; } ICSDeliveryPlanBLL.deleteInfo(IDList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("删除成功"); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 导出 private void btnOutPut_Click(object sender, EventArgs e) { try { DataTable data = dataSource.Tables[2].Copy(); gridExport.DataSource = data; grivExport.OptionsPrint.AutoWidth = false; FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), gridExport); foe.ShowDialog(); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 导入 private void btnImportData_Click(object sender, EventArgs e) { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm(); _wait.Hide(); try { FormReadExcel fre = new FormReadExcel(); if (fre.ShowDialog() != DialogResult.OK) { return; } DataTable dataSource = fre._excelData; if (dataSource == null) { throw new Exception("excel数据取得失败"); } _wait.Show(); _wait.Caption = "模板校验中......"; #region 判断模版是否正确 foreach (FormReadExcelUIModelColumns columnsName in colNameList) { if (!dataSource.Columns.Contains(columnsName.columnsName)) { throw new Exception("模版不正确,缺少列" + columnsName.columnsName); } } #endregion _wait.SetCaption("数据校验中......"); //1获取助记码(客户料号),客户编码 DataSet ds = ICSDeliveryPlanBLL.GetInvInfoAndCust(pk_org_ForInvcode); #region 处理已经生成拉货计划的销售订单 DataTable dt = ds.Tables[1].Copy(); //在GetInvInfoAndCust方法中已生成的已经被排除,此处不需要2022.3.29 ////DataRow[] drso = dataSource.Select("LEN(ISNULL(销售订单号,''))<=0"); ////if (drso != null && drso.Length > 0) ////{ // //var Vourchs = (from DataRow dr in dataSource.Rows // // group dr by (string)dr["单据号"] into g // // select new // // { // // g.Key // // }).Select(a=>a.Key); // string vourchs = ""; // //if (Vourchs != null && Vourchs.Count() > 0) // //{ // // vourchs = string.Join("','", Vourchs); // //} // DataTable dtPlan = ICSDeliveryPlanBLL.GetPlanInfo(vourchs).Tables[0]; // foreach (DataRow dr in dtPlan.Rows) // { // string id = dr["SOCode"].ToString(); // decimal qty = Convert.ToDecimal(dr["Quantity"]); // DataRow[] SOdrs = dt.Select("表体标识='" + id + "'", "要求交期,销售订单号,销售订单行号"); // foreach (DataRow SOdr in SOdrs) // { // decimal SOqty = Convert.ToDecimal(SOdr["数量"]); // //已生成数量大于销售订单行数量 // if (qty >= SOqty) // { // qty -= SOqty; // dt.Rows.Remove(SOdr); // } // else // { // SOdr["数量"] = SOqty - qty; // break; // } // } // } ////} #endregion DataColumn dataColumn = new DataColumn("客户名称", typeof(string)); dataSource.Columns.Add(dataColumn); //2校验 string CT = ""; string SOCode = ""; string inv = ""; for (int i = dataSource.Rows.Count - 1; i >= 0; i--) { DataRow dr=dataSource.Rows[i]; ///判断必输项目是否为空 foreach (FormReadExcelUIModelColumns columnsName in colNameList) { if (string.IsNullOrWhiteSpace(dr[columnsName.columnsName].ToString()) == true && columnsName.NotNull == true) { throw new Exception("列" + columnsName.columnsName + "没有输入值"); } } inv = dr["物料编码"].ToString().Trim(); //string so = dr["销售订单号"].ToString().Trim(); //SOCode = so + "_" + dr["销售订单行号"].ToString().Trim(); SOCode = dr["客户订单号"].ToString().Trim(); CT = dr["客户编码"].ToString().Trim(); if (string.IsNullOrEmpty(inv)) { throw new Exception("行 " + (i + 1).ToString() + " 物料编码为空"); } if (string.IsNullOrEmpty(CT)) { throw new Exception("行 " + (i + 1).ToString() + " 客户编码为空"); } if (ds.Tables[0].Select("物料编码='" + inv + "'").Length == 0) { throw new Exception("物料编码:" + inv + ",不存在"); } var cus = ds.Tables[2].Select("客户编码='" + CT + "'"); if (cus.Length == 0) { throw new Exception("客户编码:" + CT + ",不存在"); } else { dataSource.Rows[i]["客户名称"] = cus[0]["客户名称"]; } //21.11.10销售订单为空时自动根据交期匹配 decimal qty = Convert.ToDecimal(dr["数量"]); if (string.IsNullOrWhiteSpace(SOCode)) { DataRow[] SOdrs = dt.Select("物料编码+客户编码='" + inv + CT + "'", "要求交期,销售订单号,销售订单行号"); SO(dataSource,dt,SOdrs,dr,qty); } else { DataRow[] SOdrs = dt.Select("物料编码+客户编码+客户订单号='" + inv + CT + SOCode + "'", "要求交期,销售订单号,销售订单行号"); SO(dataSource, dt, SOdrs, dr, qty); //DataRow[] drs = dt.Select("销售订单号+'_'+销售订单行号='" + SOCode + "'"); //if (drs == null || drs.Length == 0) //{ // throw new Exception("销售订单:" + SOCode + ",不存在"); //} //else if (CT != drs[0]["客户编码"].ToString()) //{ // throw new Exception("销售订单:" + SOCode + ",对应的客户编码与所填写客户编码:" + CT + " 不符!"); //} //else if (qty > Convert.ToDecimal(drs[0]["数量"])) //{ // throw new Exception("销售订单:" + SOCode + ",剩余数量:" + drs[0]["数量"] + ",不能小于填写数量:" + qty); //} //else //{ // drs[0]["数量"] = Convert.ToDecimal(drs[0]["数量"]) - qty; // dr["销售订单号"] = drs[0]["表体标识"].ToString(); //} } } _wait.SetCaption("数据处理中......"); ICSDeliveryPlanBLL.AddList(dataSource, AppConfig.AppConnectString); _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("数据导入成功!"); btnFalsh_Click(null, null); } catch (Exception ex) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message); } } private void SO(DataTable dataSource,DataTable dt, DataRow[] SOdrs, DataRow dr, decimal qty) { foreach (DataRow SOdr in SOdrs) { decimal SOqty = Convert.ToDecimal(SOdr["数量"]); //已生成数量大于销售订单行数量 if (qty >= SOqty) { qty -= SOqty; string id = SOdr["表体标识"].ToString(); dt.Rows.Remove(SOdr); if (qty == 0) { dr["客户订单号"] = id; break; } else { DataRow drnew = dataSource.NewRow(); drnew.ItemArray = dr.ItemArray; //drnew["行号"] = dataSource.Rows.Count + 1; drnew["数量"] = SOqty; drnew["客户订单号"] = id; dataSource.Rows.Add(drnew); dr["数量"] = qty; } } else { SOdr["数量"] = SOqty - qty; qty = 0; dr["客户订单号"] = SOdr["表体标识"].ToString(); break; } } //if (qty > 0) //{ // throw new Exception("客户编码:" + CT + ",物料编码:" + inv + ",对应的销售订单数量不足!"); //} } #endregion #region 导入模板下载 private void btnImportMould_Click(object sender, EventArgs e) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm(); _wait.Hide(); string anjianExcelFileName = Environment.CommandLine.Substring(1, Environment.CommandLine.LastIndexOf("\\")) + "Output\\"; try { _wait.Show(); _wait.Caption = "模板下载中......"; SaveFileDialog dlgSaveFileDialog = new SaveFileDialog(); //弹框提示保存 dlgSaveFileDialog.InitialDirectory = anjianExcelFileName; //默认打开目录 dlgSaveFileDialog.FilterIndex = 1; dlgSaveFileDialog.RestoreDirectory = true; dlgSaveFileDialog.FileName = "拉货计划单导入模板.xlsx"; //默认保存名称 dlgSaveFileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx"; if (dlgSaveFileDialog.ShowDialog() == DialogResult.OK) { string fileName = dlgSaveFileDialog.FileName; //获取弹出框选择或填写的文件名称 //List colNameList = new List(); //colNameList.Add(new FormReadExcelUIModelColumns("单据号", true)); //colNameList.Add(new FormReadExcelUIModelColumns("客户编码", true)); //colNameList.Add(new FormReadExcelUIModelColumns("客户料号", true)); //DataTable dt = GetMonth(); //foreach (DataRow dr in dt.Rows) //{ // colNameList.Add(new FormReadExcelUIModelColumns(dr[0].ToString(), false)); //} FileUtil.exportToExcelFile(fileName, colNameList); _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("模板下载成功!"); } _wait.Close(); } catch (Exception ex) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("模板下载失败:" + ex.Message); } } #endregion #region 审核 private void btnCheck_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } List IDList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定审核吗?") != DialogResult.OK) { return; } ICSDeliveryPlanBLL.Check(IDList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("审核成功"); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 弃审 private void btBack_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } List IDList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定弃审吗?") != DialogResult.OK) { return; } ICSDeliveryPlanBLL.RefuseCheck(IDList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("弃审成功"); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 复审 private void btnReview_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } List IDList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定复审吗?") != DialogResult.OK) { return; } ICSDeliveryPlanBLL.Review(IDList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("复审成功"); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 取消复审 private void btnReviewBack_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } List IDList = new List(); for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { IDList.Add(grvDetail.GetRowCellValue(i, colID).ToString()); if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp))) throw new Exception("单据:" + grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString() + " 已上传,不能取消复审!"); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定取消复审吗?") != DialogResult.OK) { return; } ICSDeliveryPlanBLL.ReviewBack(IDList, AppConfig.AppConnectString); ICSBaseSimpleCode.AppshowMessageBox("取消复审成功"); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 子表展开 private void grvDetail_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e) { //try //{ // //只展开当前行 // for (int i = 0; i < grvDetail.RowCount; i++) // { // if (i != e.RowHandle) // { // grvDetail.SetMasterRowExpanded(i, false); // } // } // //隐藏由于行列转换出现的null字段 // gridView = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView; // foreach (DevExpress.XtraGrid.Columns.GridColumn col in gridView.Columns) // { // if (!col.FieldName.Contains("-")) // continue; // for (int i = 0; i < gridView.RowCount; i++) // { // if (string.IsNullOrEmpty(gridView.GetRowCellValue(i, col).ToString())) // { // col.Visible = false; // } // else // { // col.Visible = true; // } // } // } // gridView.Columns["DeliveryPlanID"].Visible = false; // gridView.Columns["InvCode"].Caption = "物料编码"; // gridView.Columns["materialmnecode"].Caption = "客户料号"; // gridView.Columns["安全库存数量"].VisibleIndex = 2; // gridView.Columns["之前欠缺数量"].VisibleIndex = 3; // gridView.BestFitColumns(); //} //catch (Exception ex) //{ // ICSBaseSimpleCode.AppshowMessageBox(ex.Message); //} } #endregion #region 变更 private void btnVersion_Click(object sender, EventArgs e) { try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); return; } int count = 0; string id = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { count++; id = grvDetail.GetRowCellValue(i, colID).ToString(); if (string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colChecker).ToString())) throw new Exception("单据未审核,不能变更!"); //if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp))) // throw new Exception("单据:" + grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString() + " 已上传,不能变更!"); } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { FormICSDeliveryPlanEdit add = new FormICSDeliveryPlanEdit(id, "Version"); add.ShowDialog(); btnFalsh_Click(null, null); } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } catch (Exception ex) { ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } #endregion #region 上传ERP private void btnUpload_Click(object sender, EventArgs e) { DevExpress.Utils.WaitDialogForm _wait = new DevExpress.Utils.WaitDialogForm("正在上传...请稍等..."); try { SimpleButton btntemp = (SimpleButton)sender; if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false) { ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!"); _wait.Close(); return; } _wait.Show(); string ids = ""; for (int i = 0; i < grvDetail.RowCount; i++) { if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colisSelect))) { string dcode = grvDetail.GetRowCellValue(i, colDeliveryPlanNO).ToString(); ids = "'" + grvDetail.GetRowCellValue(i, colID).ToString() + "',"; //if (string.IsNullOrWhiteSpace(grvDetail.GetRowCellValue(i, colReviewer).ToString())) // throw new Exception(dcode + "单据未复审,不能上传!"); if (Convert.ToBoolean(grvDetail.GetRowCellValue(i, colUploadErp))) throw new Exception(dcode + "单据已上传,不能重复上传!"); } } ids = ids.TrimEnd(','); if (string.IsNullOrWhiteSpace(ids)) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据!!!"); _wait.Close(); return; } ICSDeliveryPlanBLL.UploadErp(ids, AppConfig.AppConnectString); _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("上传成功"); btnFalsh_Click(null, null); #region old // string sql = @"SELECT InvCode,Period,SUM(Quantity) AS Quantity // FROM ICSDeliveryPlanDetail // WHERE Quantity>0 AND DeliveryPlanID IN ({0}) // GROUP BY InvCode,Period"; // sql = string.Format(sql, ids.TrimEnd(',')); // DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0]; // NcApiInputArguments inputInfo = new NcApiInputArguments(); // inputInfo.datasource = "design"; // inputInfo.usercode = "mestoerp";// AppConfig.UserCode; // inputInfo.password = "sH05R21u1";// AppConfig.FromMd5(AppConfig.UserPwd); // inputInfo.list = new List(); // inputInfo.list.Clear(); // foreach (DataRow dr in dt.Rows) // { // string[] period = dr["Period"].ToString().Split('-'); // if (period == null || period.Length != 2) // continue; // CreateDeliveryPlanEntity DeliveryPlan = new CreateDeliveryPlanEntity(); // DeliveryPlan.pk_org = "01P1";//AppConfig.WorkPointCode; // DateTime time = Convert.ToDateTime(dr["Period"].ToString() + "-01"); // DeliveryPlan.cbegindate = time.ToString("yyyy-MM-dd"); // DeliveryPlan.cenddate = time.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd"); // DeliveryPlan.periodyear = period[0]; // DeliveryPlan.periodcode = Convert.ToInt32(period[1]).ToString(); // DeliveryPlan.vchangerate = "1/1"; // DeliveryPlan.cmaterialid = dr["InvCode"].ToString(); // DeliveryPlan.nnum = dr["Quantity"].ToString(); // inputInfo.list.Add(DeliveryPlan); // } // string inputJson = JsonConvert.SerializeObject(inputInfo); // string resStrCreatDeliveryPlan = HttpPost(urlCreatDeliveryPlan, inputJson); // NcApiOutArguments res = new NcApiOutArguments(); // res = JsonConvert.DeserializeObject(resStrCreatDeliveryPlan); // if (res.flat != "0") // { // throw new Exception("生成预测单失败:" + res.list_info); // } // else // { // ICSBaseSimpleCode.AppshowMessageBox("上传成功"); // //btnFalsh_Click(null, null); // } #endregion } catch (Exception ex) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox(ex.Message); } } public static string HttpPost(string url, string body) { try { Encoding encoding = Encoding.UTF8; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.Accept = "application/json, text/javascript, */*"; //"text/html, application/xhtml+xml, */*"; request.ContentType = "application/json; charset=utf-8"; byte[] buffer = encoding.GetBytes(body); request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), encoding)) { return reader.ReadToEnd(); } } catch (WebException ex) { throw new Exception(ex.Message); } } #endregion } }