using DevExpress.ClipboardSource.SpreadsheetML; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Repository; using DevExpress.XtraPrinting.Native; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Gs.DevApp.UserControl; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.ComponentModel; using System.Configuration; using System.Data; using System.Drawing; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Media.Animation; namespace Gs.DevApp.DevFrm.FQC { public partial class Frm_FQCItem : DevExpress.XtraEditors.XtraForm { string _webServiceName = "FqcItemsManager/"; List _filterList = new List(); public Frm_FQCItem() { InitializeComponent(); // 绑定事件 gridView2.CellValueChanged += gridView2_CellValueChanged; gridView3.CellValueChanged += gridView3_CellValueChanged; toolBarMenu1.btnOutClick += ToolBarMenu1_btnOutClick; this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick; this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick; this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick; this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1; this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick; this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; // 添加抽样方法下拉框事件 this.txt_SampleMethod.SelectedIndexChanged += Txt_SampleMethod_SelectedIndexChanged; //this.toolBarMenu1.getXmlConfig(); // 设置GridView参数 Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gridView2); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gridView3); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, picCheckBox, this, "checkStatus", "", (value) => { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); }, tips); Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) => { getModel(value); }, (value) => { getPageList(this.pageBar1.CurrentPage); }, lbGuid); // 初始化数据 getPageList(1); pageBar1.PagerEvent += PageBar1_PagerEvent; } /// /// 抽样方法选择变化事件 /// /// /// private void Txt_SampleMethod_SelectedIndexChanged(object sender, EventArgs e) { ComboBoxEdit comboBox = sender as ComboBoxEdit; if (comboBox != null) { string selectedValue = comboBox.Text.Trim(); if (selectedValue == "匀速") { // 选择匀速时:启用匀速抽样数,禁用随机抽样数 txt_SampleSize1.Properties.ReadOnly = false; txt_SampleSize1.Properties.Appearance.BackColor = Color.White; txt_SampleSize2.Properties.ReadOnly = true; txt_SampleSize2.Properties.Appearance.BackColor = Color.WhiteSmoke; txt_SampleSize2.Text = ""; // 清空随机抽样数 } else if (selectedValue == "随机") { // 选择随机时:启用随机抽样数,禁用匀速抽样数 txt_SampleSize2.Properties.ReadOnly = false; txt_SampleSize2.Properties.Appearance.BackColor = Color.White; txt_SampleSize1.Properties.ReadOnly = true; txt_SampleSize1.Properties.Appearance.BackColor = Color.WhiteSmoke; txt_SampleSize1.Text = ""; // 清空匀速抽样数 } else { // 未选择或其他情况:两个输入框都禁用 txt_SampleSize1.Properties.ReadOnly = true; txt_SampleSize1.Properties.Appearance.BackColor = Color.WhiteSmoke; txt_SampleSize1.Text = ""; txt_SampleSize2.Properties.ReadOnly = true; txt_SampleSize2.Properties.Appearance.BackColor = Color.WhiteSmoke; txt_SampleSize2.Text = ""; } } } /// /// 初始化抽样数输入框状态 /// private void InitializeSampleSizeControls() { // 根据当前抽样方法值设置输入框状态 string currentSampleMethod = txt_SampleMethod.Text.Trim(); if (currentSampleMethod == "匀速") { txt_SampleSize1.Properties.ReadOnly = false; txt_SampleSize1.Properties.Appearance.BackColor = Color.White; txt_SampleSize2.Properties.ReadOnly = true; txt_SampleSize2.Properties.Appearance.BackColor = Color.LightGray; } else if (currentSampleMethod == "随机") { txt_SampleSize2.Properties.ReadOnly = false; txt_SampleSize2.Properties.Appearance.BackColor = Color.White; txt_SampleSize1.Properties.ReadOnly = true; txt_SampleSize1.Properties.Appearance.BackColor = Color.LightGray; } else { // 未选择时两个都禁用 txt_SampleSize1.Properties.ReadOnly = true; txt_SampleSize1.Properties.Appearance.BackColor = Color.LightGray; txt_SampleSize2.Properties.ReadOnly = true; txt_SampleSize2.Properties.Appearance.BackColor = Color.LightGray; } } private async void GridView1_ColumnFilterChanged(object sender, EventArgs e) { _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1); await Task.Delay(100); getPageList(1); } /// /// 分页事件 /// /// /// private void PageBar1_PagerEvent(int curPage, int pageSize) { getPageList(curPage); } /// /// 查询事件 /// /// /// private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e) { gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; gridView1.ActiveFilter.Clear(); gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; var frm = new ShowFilter(gridView1.Columns, _filterList, this.GetType().FullName); frm.UpdateParent += Frm_UpdateParent; frm.ShowDialog(); } /// /// 查询回调 /// /// /// private void Frm_UpdateParent(object sender, UpdateParentEventArgs e) { _filterList = e.FilterList; getPageList(1); } /// /// 取消事件 /// /// /// private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1); } /// /// 删除事件 /// /// /// private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_Guid, gridView1, "FQCNo"); if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?")) return; var _obj = new { guid = rowGuid, }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { if (xtraTabControl1.SelectedTabPageIndex == 0) { } else Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 2); getPageList(this.pageBar1.CurrentPage); } ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 刷新事件 /// /// /// private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) { if (xtraTabControl1.SelectedTabPageIndex == 1) getModel(lbGuid.Text.Trim()); else { getPageList(this.pageBar1.CurrentPage); } } /// /// 新增事件 /// /// /// private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) { lbGuid.Text = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4); List gridViews = new List(); gridViews.Add(gridView1); gridViews.Add(gridView2); gridViews.Add(gridView3); UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true, gridViews); Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMain1, gridView1); Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gridControl1, gridView2); Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gridControl2, gridView3); // 初始化抽样数输入框状态 InitializeSampleSizeControls(); } private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) { string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_Guid, gridView1); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.Warning("请先选择你要操作的行!"); return; } Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3); getModel(rowGuid); } /// /// 保存事件 /// /// /// private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) { toolBarMenu1.isSetBtn = false; var _obj = new { guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), // 主键 fqcNo = txt_FQCNo.Text.Trim(), // 检验单号 workShop = txt_WorkShop.Text.Trim(), // 生产车间 itemName = txt_ItemName.Text.Trim(), // 产品名称 itemModel = txt_ItemModel.Text.Trim(), // 规格型号 brand = txt_Brand.Text.Trim(), // 商标 productionDate = txt_ProductionDate.Text.Trim(), // 生产日期 temperature = txt_Temperature.Text.Trim(), // 室温 voltage = txt_Voltage.Text.Trim(), // 电压 lineNo = txt_LineNo.Text.Trim(), // 线号 batch = txt_Batch.Text.Trim(), // 批量 classes = txt_Classes.Text.Trim(), // 班次 checkResult = txt_CheckResult.Text.Trim(), // 检验结果 acRe_A = txt_AcRe_A.Text.Trim(), // AC/Re A类 acRe_B = txt_AcRe_B.Text.Trim(), // AC/Re B类 acRe_C = txt_AcRe_C.Text.Trim(), // AC/Re C类 processResults = txt_ProcessResults.Text.Trim(), // 处理结果 sampleMethod = txt_SampleMethod.Text.Trim(), // 抽样 sampleSize1 = txt_SampleSize1.Text.Trim(), // 匀速抽样数 sampleSize2 = txt_SampleSize2.Text.Trim(), // 随机抽样数 sampleSize3 = txt_SampleSize3.Text.Trim(), // 样本数 jy_USER = txt_JY_USER.Text.Trim(), // 检验人 jy_DATE = txt_JY_DATE.Text.Trim(), // 检验时间 sp_USER = txt_SP_USER.Text.Trim(), // 审批人 sp_DATE = txt_SP_DATE.Text.Trim(), // 审批日期 remark = txt_Remark.Text.Trim(), // 备注 list1 = new List(), // 项目标准子表 list2 = new List(), // 不合格信息子表 }; // 处理项目标准子表 gridView2.CloseEditor(); gridView2.PostEditor(); gridView2.UpdateCurrentRow(); for (var i = 0; i < gridView2.DataRowCount; i++) { var row = gridView2.GetDataRow(i); if (row != null) { _obj.list1.Add(new { Guid = Gs.DevApp.ToolBox.UtilityHelper.ToGuid(row["Guid"]?.ToString()), PID = UtilityHelper.ToGuid(lbGuid.Text.Trim()), RPB001 = row["RPB001"]?.ToString(), RPB003 = row["RPB003"]?.ToString(), RPB004 = row["RPB004"]?.ToString(), RPB005 = row["RPB005"]?.ToString(), RPB006 = row["RPB006"]?.ToString(), RPB007 = row["RPB007"]?.ToString(), RPB008 = row["RPB008"]?.ToString(), RPB009 = row["RPB009"]?.ToString(), RPB010 = row["RPB010"]?.ToString(), RPB011 = row["RPB011"]?.ToString(), RPB012 = row["RPB012"]?.ToString(), RPB013 = row["RPB013"]?.ToString(), RPB014 = row["RPB014"]?.ToString(), RPB015 = row["RPB015"]?.ToString(), RPB016 = row["RPB016"]?.ToString(), Remark = row["Remark"]?.ToString(), }); } } // 处理不合格信息子表 gridView3.CloseEditor(); gridView3.PostEditor(); gridView3.UpdateCurrentRow(); for (var i = 0; i < gridView3.DataRowCount; i++) { var row = gridView3.GetDataRow(i); if (row != null) { _obj.list2.Add(new { Guid = Gs.DevApp.ToolBox.UtilityHelper.ToGuid(row["Guid"]?.ToString()), PID = UtilityHelper.ToGuid(lbGuid.Text.Trim()), Seq = row["Seq"]?.ToString(), Description = row["Description"]?.ToString(), AClass = row["AClass"]?.ToString(), BClass = row["BClass"]?.ToString(), CClass = row["CClass"]?.ToString(), Point = row["Point"]?.ToString(), Remark = row["Remark"]?.ToString(), }); } } try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { ToolBox.MsgHelper.ShowInformation("提示:" + _rtn.rtnMsg); lbGuid.Text = _rtn.rtnData.outGuid; toolBarMenu1.isSetBtn = true; List gvList = new List(); UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false, gvList); toolBarMenu1.currentAction = ""; Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 6); } else ToolBox.MsgHelper.ShowError("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.ShowError("提示:" + ex.Message); } } /// /// 获取分页列表数据 /// /// 第几页 private void getPageList(int curPage) { gcMain1.DataSource = null; var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList); var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "", "", "", _sbSqlWhere.ToString()); var json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json); var dd = UtilityHelper.ReturnToTablePage(strReturn); if (dd.rtnCode > 0) { DataTable dt = dd.rtnData.list; gcMain1.BindingContext = new BindingContext(); gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; if (dt.Rows.Count > 0) { gcMain1.DataSource = dt; gcMain1.ForceInitialize(); gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1); } else UtilityHelper.SetDefaultTable(gcMain1, gridView1); gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; pageBar1.TotalPages = dd.rtnData.pages;//总页 pageBar1.CurrentPage = curPage;//当前页 pageBar1.RecordCount = dd.rtnData.total;//总记录数 } else { ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg); } } catch (Exception ex) { MsgHelper.ShowError("提示:" + ex.Message); } } /// /// 获取单条记录详细信息 /// /// 主键 private void getModel(string strGuid) { bool isEdit = false; if (toolBarMenu1.currentAction == "add") return; if (toolBarMenu1.currentAction == "edit") isEdit = true; if (string.IsNullOrEmpty(strGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } var _obj = new { guid = strGuid,//主键 }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "GetModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { dynamic dy = _rtn.rtnData; lbGuid.Text = strGuid; UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit); // 控制明细表可编辑状态 List gvList = new List(); gvList.Add(gridView2); // 项目标准子表 gvList.Add(gridView3); // 不合格信息子表 UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit, gvList); JObject _job = JObject.Parse(strJson); // 处理项目标准子表数据 JArray array1 = new JArray(); if (_job["rtnData"]["list"] != null) { foreach (var a in _job["rtnData"]["list"]) { array1.Add(a); } DataTable dt1 = JsonConvert.DeserializeObject(array1.ToString()); if (dt1.Rows.Count > 0) { gridControl1.BindingContext = new BindingContext(); gridControl1.DataSource = dt1; gridControl1.ForceInitialize(); gridView2.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView2); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gridControl1, gridView2); } } // 处理不合格信息子表数据 JArray array2 = new JArray(); if (_job["rtnData"]["list2"] != null) { foreach (var a in _job["rtnData"]["list2"]) { array2.Add(a); } DataTable dt2 = JsonConvert.DeserializeObject(array2.ToString()); if (dt2.Rows.Count > 0) { gridControl2.BindingContext = new BindingContext(); gridControl2.DataSource = dt2; gridControl2.ForceInitialize(); gridView3.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView3); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gridControl2, gridView3); } } } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 项目标准子表值变化事件 /// /// /// private void gridView2_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { // 可以在这里添加项目标准相关的业务逻辑 } /// /// 不合格信息子表值变化事件 /// /// /// private void gridView3_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { // 可以在这里添加不合格信息相关的业务逻辑 } /// /// 导出 /// /// /// /// private void ToolBarMenu1_btnOutClick(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_FQCNo, gridView1, "FQCNo"); if (string.IsNullOrEmpty(rowGuid)) { MsgHelper.ShowError("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定导出吗?")) return; using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()) { folderBrowserDialog.Description = "选择导出文件的保存路径"; DialogResult dialogResult = folderBrowserDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { string _folder = folderBrowserDialog.SelectedPath; var _obj = new { guid = rowGuid, }; try { string strJson = UtilityHelper.HttpPost("", "XlsInOut/XlsOutChengPin", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { string _file = _rtn.rtnData.fileUrl.ToString(); string _folderName = _folder + "\\" + _file.Replace("down/", ""); string _url = ConfigurationManager.AppSettings["WebApiUrl"].ToString() + _file; using (WebClient client = new WebClient()) { client.DownloadFile(_url, _folderName); } var frm = new Gs.DevApp.DevFrm.QC.Xls(_folderName); frm.ShowDialog(); } else { ToolBox.MsgHelper.ShowError("提示:" + _rtn.rtnMsg); } } catch (Exception ex) { ToolBox.MsgHelper.ShowError("提示:" + ex.Message); } } } } } }