using com.steering.pss.sale.order.model; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Server; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.SaleOrder.Dialog; using CoreFS.CA06; using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Core.StlMes.Client.SaleOrder.OrderForm { public partial class FrmOrderAuthentication : FrmBase { public FrmOrderAuthentication() { InitializeComponent(); this.IsLoadUserView = true; } /// /// 可以编辑的列 /// List editList = new List(); private void FrmOrderAuthentication_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(gdOrderInfo.DisplayLayout.Bands[0]); editList.AddRange(new string[] { "CUSTMSIGNDATE", "CUSTMDELVRYDATE", "SCHAPPROVENO", "ORDAPPROVENO", "MEMO", "CUSTMORDERNO" }); dtpEnd.Value = DateTime.Now; dtpStart.Value = DateTime.Now.AddMonths(-2); } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": QueryAuthedOrd(); break; case "ReturnTime": ReturnTime(); break; case "Save": SaveWriteData(); break; case "GetData": getOrdData(); break; case "Update": UpdateDataBase(); break; case "Close": this.Close(); break; case "Export": GridHelper.ulGridToExcel(gdOrderInfo, "认证合同"); break; case "Print": gdOrderInfo.UpdateData(); UltraGridRow row = gdOrderInfo.ActiveRow; if (row == null) return; string strOrderLinePk = row.Cells["ORDLNPK"].Value.ToString(); string url =""; url = "http://172.54.10.42:8080/webroot/decision/view/report?viewlet=RepSalesStockOutOrder.cpt&__bypagesize__=false&ORD_LN_PK=" + strOrderLinePk + ""; FrmRepExcel fre = new FrmRepExcel(this.ob, url); fre.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height); fre.Text = "天津钢管集团股份有限公司产品出库单"; fre.ShowDialog(); break; } } /// /// 获取合同数据至合同认证表 /// private void getOrdData() { WaitingForm2 wf = new WaitingForm2(); wf.Msg = "数据处理中,请稍等。。。"; wf.Show(); wf.Update(); try { CoreClientParam ccp = new CoreClientParam(); ccp.IfShowErrMsg = false; ccp.ServerName = "com.steering.pss.sale.order.CoreOrderAuthentication"; ccp.MethodName = "getOrdData"; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode == -1) { MessageUtil.ShowWarning(ccp.ReturnInfo); wf.Close(); return; } wf.Close(); QueryAuthedOrd(); } } finally { wf.ShowToUser = false; wf.Close(); } } /// /// 查询数据 /// private void QueryAuthedOrd() { WaitingForm2 wf = new WaitingForm2(); wf.Msg = "数据查询中,请稍等。。。"; wf.Show(); wf.Update(); try { string ordNo = ""; string strArea = ""; string timeStart = ""; string timeEnd = ""; if (chkOrderNo.Checked) ordNo = txtOrderNo.Text.Trim(); if (chkArea.Checked) strArea = this.txtArea.Text.Trim(); if (chkTime.Checked) { if (dtpEnd.Value < dtpStart.Value) { MessageUtil.ShowWarning("开始时间不能大于结束时间!"); return; } timeStart = dtpStart.Value.ToString("yyyy-MM-dd") + " 00:00:01"; timeEnd = dtpEnd.Value.ToString("yyyy-MM-dd") + " 23:59:59"; } List list = EntityHelper.GetData( "com.steering.pss.sale.order.CoreOrderAuthentication.queryAuthedOrd", new object[] { ordNo, strArea, timeStart, timeEnd, timeType.Value.ToString() }, this.ob); slmOrderAuthenticationBS1.DataSource = list; wf.Close(); foreach (UltraGridRow urg in gdOrderInfo.Rows) { if (urg.Cells["OrderFile"].Text.Equals("有合同文本")) { urg.Cells["OrderFile"].Appearance.ForeColor = Color.Red; } if (urg.Cells["UserorderFile"].Text.Equals("有合同文本")) { urg.Cells["UserorderFile"].Appearance.ForeColor = Color.Red; } } } finally { wf.ShowToUser = false; wf.Close(); } } /// /// 后台更新数据 (将多个数据表的数据搬到 SLM_ORDER_AUTHENTICATION 表中 ) /// private void UpdateDataBase() { gdOrderInfo.UpdateData(); UltraGridRow[] row = gdOrderInfo.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray(); if (row.Length <= 0) { MessageUtil.ShowWarning("请选择需要更新的合同号!"); return; } List ordArr = new List(); for (int i = 0; i < row.Length; i++) { if (!ordArr.Contains(row[i].Cells["OrderNo"].Value.ToString()) && !string.IsNullOrEmpty(row[i].Cells["OrderNo"].Value.ToString()) && !row[i].IsFilteredOut) { ordArr.Add(row[i].Cells["OrderNo"].Value.ToString()); } } string[] strResult = ordArr.ToArray(); if (strResult.Length > 10000) { MessageUtil.ShowWarning("鉴于系统数据量过大,合同号的个数不能超过300个!"); return; } WaitingForm2 wf = new WaitingForm2(); wf.Msg = "正在更新数据中,请稍等。。。"; wf.Show(); wf.Update(); try { CoreClientParam ccp = new CoreClientParam(); ccp.IfShowErrMsg = false; ccp.ServerName = "com.steering.pss.sale.order.CoreOrderAuthentication"; ccp.MethodName = "updateData"; ccp.ServerParams = new object[] { strResult }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode == -1) { MessageUtil.ShowWarning(ccp.ReturnInfo); wf.Close(); return; } wf.Close(); QueryAuthedOrd(); } } finally { wf.ShowToUser = false; wf.Close(); } } private void gdOrderInfo_AfterRowActivate(object sender, EventArgs e) { UltraGridRow uRow = gdOrderInfo.ActiveRow; if (uRow != null) { if (uRow.Cells["CHK"].Value.ToString().ToUpper() == "TRUE") { for (int i = 0; i < editList.Count; i++) { uRow.Cells[editList[i]].Activation = Activation.AllowEdit; } } else { for (int i = 0; i < editList.Count; i++) { uRow.Cells[editList[i]].Activation = Activation.ActivateOnly; } } } } private void gdOrderInfo_CellChange(object sender, CellEventArgs e) { if (!e.Cell.Column.Key.ToUpper().Equals("CUSTMSIGNDATE") && !e.Cell.Column.Key.ToUpper().Equals("CUSTMDELVRYDATE")) gdOrderInfo.UpdateData(); if (e.Cell.Column.Key.Equals("CHK")) { if (e.Cell.Value.ToString().ToUpper() == "TRUE") { for (int i = 0; i < editList.Count; i++) { e.Cell.Row.Cells[editList[i]].Activation = Activation.AllowEdit; } } else { for (int i = 0; i < editList.Count; i++) { e.Cell.Row.Cells[editList[i]].Activation = Activation.ActivateOnly; } } } } private void gdOrderInfo_AfterSelectChange(object sender, AfterSelectChangeEventArgs e) { foreach (UltraGridRow uRow in gdOrderInfo.Selected.Rows) { if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow)) { uRow.Cells["CHK"].Value = true; } } } private void ReturnTime() { gdOrderInfo.UpdateData(); UltraGridRow[] row = gdOrderInfo.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray(); if (row.Length <= 0) { MessageUtil.ShowWarning("请选择您要确认合同返回的合同!"); return; } List ordArr = new List(); for (int i = 0; i < row.Length; i++) { if (!row[i].IsFilteredOut) { ordArr.Add(row[i].Cells["ORDLNPK"].Value.ToString()); } } string[] parm = ordArr.ToArray(); //int flag = 0; //foreach (var uRow in row) //{ // if (uRow.Cells["ISRETURN"].Value.ToString() == "已返回") // flag += 1; //} //string str = ""; //if (flag > 0) //{ // str = "存在已经确认返回的合同,是否覆盖其返回时间?"; //} //else //{ // str = "是否确认合同返回?"; //} if (MessageUtil.ShowYesNoAndQuestion("是否确认合同返回?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.IfShowErrMsg = false; ccp.ServerName = "com.steering.pss.sale.order.CoreOrderAuthentication"; ccp.MethodName = "returnTime"; ccp.ServerParams = new object[] { parm, UserInfo.GetUserName() }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode == -1) { MessageUtil.ShowWarning(ccp.ReturnInfo); return; } MessageUtil.ShowTips("确认合同返回成功!"); QueryAuthedOrd(); } } /// /// 保存数据 /// private void SaveWriteData() { gdOrderInfo.UpdateData(); UltraGridRow[] row = gdOrderInfo.Rows.AsQueryable().Where(a => a.Cells["CHK"].Value.ToString().ToUpper() == "TRUE").ToArray(); if (row.Length <= 0) { MessageUtil.ShowWarning("请选择需要保存的数据!"); return; } ArrayList parm = new ArrayList(); foreach (var uRow in row) { SlmOrderAuthenticationEntity soa = (SlmOrderAuthenticationEntity)uRow.ListObject; if (soa.CustmSignDate != "") { if (StringUtil.IsNotDateTime(soa.CustmSignDate)) { MessageUtil.ShowWarning("请输入客户合同签订日期!"); return; } soa.CustmSignDate = Convert.ToDateTime(soa.CustmSignDate).ToString("yyyy-MM-dd"); } if (soa.CustmDelvryDate != "") { if (StringUtil.IsNotDateTime(soa.CustmDelvryDate)) { MessageUtil.ShowWarning("请输入客户合同交货日期!"); return; } soa.CustmDelvryDate = Convert.ToDateTime(soa.CustmDelvryDate).ToString("yyyy-MM-dd"); } /*if (soa.SchApproveNo == "") { MessageUtil.ShowWarning("请输入排产审批单号!"); return; } if (soa.OrdApproveNo == "") { MessageUtil.ShowWarning("请输入合同审批单号!"); return; }*/ parm.Add(soa); } if (MessageUtil.ShowYesNoAndQuestion("是否保存数据?") == DialogResult.No) return; CoreClientParam ccp = new CoreClientParam(); ccp.IfShowErrMsg = false; ccp.ServerName = "com.steering.pss.sale.order.CoreOrderAuthentication"; ccp.MethodName = "saveWrite"; ccp.ServerParams = new object[] { parm }; ccp = this.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp != null) { if (ccp.ReturnCode == -1) { MessageUtil.ShowWarning(ccp.ReturnInfo); return; } MessageUtil.ShowTips("保存成功!"); QueryAuthedOrd(); } } private void gdOrderInfo_CellDataError(object sender, CellDataErrorEventArgs e) { e.RaiseErrorEvent = false; e.StayInEditMode = true; } private void chkOrderNo_CheckedChanged(object sender, EventArgs e) { if (chkOrderNo.Checked) { txtOrderNo.ReadOnly = false; } else { txtOrderNo.ReadOnly = true; } } private void txtOrderNo_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) this.QueryAuthedOrd(); } private void chkTime_CheckedChanged(object sender, EventArgs e) { if (!chkTime.Checked) { dtpStart.Enabled = false; dtpEnd.Enabled = false; } else { dtpStart.Enabled = true; dtpEnd.Enabled = true; } } private void txtOrderNo_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { if (e.Button.Key.Equals("select")) { FrmOrdNoSelect fos = new FrmOrdNoSelect(this.ob); fos.ShowDialog(); if (fos.DialogResult != DialogResult.OK) return; txtOrderNo.Tag = fos.OrdArr; } } private void OrdFile_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { if (e.Button.Key.Equals("upload")) // 上传 { UltraGridRow row = gdOrderInfo.ActiveRow; if (row == null) return; string ordPk = row.Cells["ORDPK"].Value.ToString(); string reStr = FlileUpload("ORDFILE/" + ordPk); if (reStr == "F") { MessageUtil.ShowWarning("上传失败,尝试重新上传!"); return; } else if (reStr == "N") { return; } //将合同所在的文件名称存入数据库 if (updateOrderLineOrdFile(ordPk, "ORDFILE/" + ordPk)) { MessageUtil.ShowTips("上传成功!"); updateGridOrdFile(ordPk, "1"); } } else if (e.Button.Key.Equals("view")) //预览 { UltraGridRow row = gdOrderInfo.ActiveRow; if (row == null) return; string ordPk = row.Cells["ORDPK"].Value.ToString(); string filePath = "ORDFILE/" + ordPk; dlgOrderAskDown down = new dlgOrderAskDown(this.ob, filePath); down.ShowDialog(); if (down.CtrlFileDown1.List.Count == 0) { updateOrderLineOrdFile(ordPk, ""); updateGridOrdFile(ordPk, "2"); } } } /// /// 更新界面合同文本字段 /// /// /// private void updateGridOrdFile(string ordPk, string flag) { UltraGridRow[] row = gdOrderInfo.Rows.AsQueryable().Where(a => a.Cells["ORDPK"].Value.ToString() == ordPk).ToArray(); if (flag == "1") { for (int i = 0; i < row.Length; i++) { row[i].Cells["ORDERFILE"].Value = "有合同文本"; } } else if (flag == "2") { for (int i = 0; i < row.Length; i++) { row[i].Cells["ORDERFILE"].Value = "无合同文本"; } } } /// /// 更新界面合同文本字段 /// /// /// private void updateGridUserOrdFile(string ordPk, string flag) { UltraGridRow[] row = gdOrderInfo.Rows.AsQueryable().Where(a => a.Cells["ORDPK"].Value.ToString() == ordPk).ToArray(); if (flag == "1") { for (int i = 0; i < row.Length; i++) { row[i].Cells["USERORDERFILE"].Value = "有合同文本"; } } else if (flag == "2") { for (int i = 0; i < row.Length; i++) { row[i].Cells["USERORDERFILE"].Value = "无合同文本"; } } } /// /// 更新系统合同文本字段 /// /// /// /// true 上传成功 false 上传失败 private bool updateOrderLineOrdFile(string ordPk, string ordFile) { int count = ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderAuthentication.updateOrdFile", new object[] { ordPk, ordFile }, this.ob); if (count > 0) { return true; } else { return false; } } /// /// 更新系统合同文本字段 /// /// /// /// true 上传成功 false 上传失败 private bool updateOrderLineUserOrdFile(string ordPk, string ordFile) { int count = ServerHelper.SetData("com.steering.pss.sale.order.CoreOrderAuthentication.updateUserOrdFile", new object[] { ordPk, ordFile }, this.ob); if (count > 0) { return true; } else { return false; } } /// /// 上传文件 返回文件名称列表 /// /// /// public static string FlileUpload(string sFileName) { List list = new List(); FileBean bean = new FileBean(); OpenFileDialog file = new OpenFileDialog(); file.Multiselect = false; // file.Multiselect = true 改为 file.Multiselect = false DialogResult drStat; drStat = file.ShowDialog(); string fileList = ""; if (drStat == DialogResult.OK) { foreach (string fileName in file.FileNames) { bean = new FileBean(); string filena = System.IO.Path.GetFileName(fileName); bean.setFileName(filena); bean.setPathName(sFileName); bean.setFile(FileHelper.FileToArray(fileName)); list.Add(bean); fileList = filena; } bool isSuccess = false; isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list); if (isSuccess) { return fileList; } else { return "F"; } } else return "N"; //未选择文件 } private void chkArea_CheckedChanged(object sender, EventArgs e) { txtArea.ReadOnly = !this.chkArea.Checked; } private void UserordFile_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e) { if (e.Button.Key.Equals("upload")) // 上传 { UltraGridRow row = gdOrderInfo.ActiveRow; if (row == null) return; string ordPk = row.Cells["ORDPK"].Value.ToString(); string reStr = FlileUpload("USERORDFILE/" + ordPk); if (reStr == "F") { MessageUtil.ShowWarning("上传失败,尝试重新上传!"); return; } else if (reStr == "N") { return; } //将合同所在的文件名称存入数据库 if (updateOrderLineUserOrdFile(ordPk, "USERORDFILE/" + ordPk)) { MessageUtil.ShowTips("上传成功!"); updateGridUserOrdFile(ordPk, "1"); } } else if (e.Button.Key.Equals("view")) //预览 { UltraGridRow row = gdOrderInfo.ActiveRow; if (row == null) return; string ordPk = row.Cells["ORDPK"].Value.ToString(); string filePath = "USERORDFILE/" + ordPk; dlgOrderAskDown down = new dlgOrderAskDown(this.ob, filePath); down.ShowDialog(); if (down.CtrlFileDown1.List.Count == 0) { updateOrderLineUserOrdFile(ordPk, ""); updateGridUserOrdFile(ordPk, "2"); } } } } }