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; namespace ICSSoft.Frame.NC { public partial class FormICSForecast : 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(); private bool VisibleColumn = true;//子表隐藏列 #region 构造函数 public FormICSForecast() { 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["ForecastID"] }, 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["ForecastID"] }, false); ds.Relations.Add(dr); grdDetail.DataSource = data; } 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)); DataTable dt = GetMonth(); foreach (DataRow dr in dt.Rows) { colNameList.Add(new FormReadExcelUIModelColumns(dr[0].ToString(), false)); } 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; } FormICSForecastEdit add = new FormICSForecastEdit(); 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 { FormICSForecastEdit add = new FormICSForecastEdit(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, colForecastNO).ToString() + " 已上传,不能删除!"); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定删除吗?删除后无法恢复,确定吗?") != DialogResult.OK) { return; } ICSForecastBLL.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(); gridControlExport.DataSource = data; gridViewExport.OptionsPrint.AutoWidth = false; gridViewExport.Columns["安全库存数量"].VisibleIndex = 11; gridViewExport.Columns["之前欠缺数量"].VisibleIndex = 12; FormOutExcel foe = new FormOutExcel(this.Tag.ToString(), gridControlExport); 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 = ICSForecastBLL.GetInvInfoAndCust(pk_org_ForInvcode); DataColumn dataColumn = new DataColumn("客户名称", typeof(string)); dataSource.Columns.Add(dataColumn); //2校验 string CT = ""; string inv = ""; for (int i = 0; i < dataSource.Rows.Count; i++) { inv = dataSource.Rows[i]["物料编码"].ToString().Trim(); CT = dataSource.Rows[i]["客户编码"].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[1].Select("客户编码='" + CT + "'"); if (cus.Length == 0) { throw new Exception("客户编码:" + CT + ",不存在"); } else { dataSource.Rows[i]["客户名称"] = cus[0]["客户名称"]; } } _wait.SetCaption("数据处理中......"); ICSForecastBLL.AddList(dataSource, AppConfig.AppConnectString); _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("数据导入成功!"); btnFalsh_Click(null, null); } catch (Exception ex) { _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("数据导入失败:" + ex.Message); } } #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; } ICSForecastBLL.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; } ICSForecastBLL.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; } ICSForecastBLL.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, colForecastNO).ToString() + " 已上传,不能取消复审!"); } } if (IDList == null || IDList.Count == 0) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据"); return; } if (ICSBaseSimpleCode.AppshowMessageBoxRepose("确定取消复审吗?") != DialogResult.OK) { return; } ICSForecastBLL.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); } } gridView.Columns.Clear(); //隐藏由于行列转换出现的null字段 gridView = grvDetail.GetDetailView(e.RowHandle, e.RelationIndex) as DevExpress.XtraGrid.Views.Grid.GridView; if (VisibleColumn) { int index = 0; foreach (DevExpress.XtraGrid.Columns.GridColumn col in gridView.Columns) { index++; if (!col.FieldName.Contains("-")) continue; for (int i = 0; i < gridView.RowCount; i++) { var hcol = gridView.GetRowCellValue(i, col); if (hcol == null || string.IsNullOrEmpty(hcol.ToString().Trim())) { col.Visible = false; } else { col.Visible = true; col.VisibleIndex = index; } } } } gridView.Columns["ForecastID"].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 private DataTable GetMonth() { string sql = @"SELECT Month FROM ICSMonth"; DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString.ToString(), CommandType.Text, sql).Tables[0]; if (dt == null || dt.Rows.Count <= 0) throw new Exception("查询数据失败!"); return dt; } #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, colForecastNO).ToString() + " 已上传,不能变更!"); } } if (count != 1) { ICSBaseSimpleCode.AppshowMessageBox("请选择数据,且只能选择一条进行编辑!!!"); return; } try { FormICSForecastEdit add = new FormICSForecastEdit(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, colForecastNO).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; } ICSForecastBLL.UploadErp(ids, AppConfig.AppConnectString); _wait.Close(); ICSBaseSimpleCode.AppshowMessageBox("上传成功"); btnFalsh_Click(null, null); #region old // string sql = @"SELECT InvCode,Period,SUM(Quantity) AS Quantity // FROM ICSForecastDetail // WHERE Quantity>0 AND ForecastID 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; // CreateForecastEntity forecast = new CreateForecastEntity(); // forecast.pk_org = "01P1";//AppConfig.WorkPointCode; // DateTime time = Convert.ToDateTime(dr["Period"].ToString() + "-01"); // forecast.cbegindate = time.ToString("yyyy-MM-dd"); // forecast.cenddate = time.AddMonths(1).AddDays(-1).ToString("yyyy-MM-dd"); // forecast.periodyear = period[0]; // forecast.periodcode = Convert.ToInt32(period[1]).ToString(); // forecast.vchangerate = "1/1"; // forecast.cmaterialid = dr["InvCode"].ToString(); // forecast.nnum = dr["Quantity"].ToString(); // inputInfo.list.Add(forecast); // } // string inputJson = JsonConvert.SerializeObject(inputInfo); // string resStrCreatForecast = HttpPost(urlCreatForecast, inputJson); // NcApiOutArguments res = new NcApiOutArguments(); // res = JsonConvert.DeserializeObject(resStrCreatForecast); // 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 } }