using DevExpress.XtraGrid.Views.Grid; using Gs.DevApp.DevFrm.QC.Models; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Windows.Forms; namespace Gs.DevApp.DevFrm.QC { public partial class Frm_MesQmAql1 : DevExpress.XtraEditors.XtraForm { string _webServiceName = "MesQmAql1Manager/"; List _filterList = new List(); public Frm_MesQmAql1() { InitializeComponent(); 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; toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick; toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick; toolBarMenu1.btnPiZhunClick += ToolBarMenu1_btnPiZhunClick; gcMain.MouseDoubleClick += GcMain_MouseDoubleClick; gridView1.FocusedRowChanged += (s, e) => { UtilityHelper.SetCheckIco(s, picCheckBox, this, "foneChecked", ""); }; getPageList(1, UtilityHelper.GetPageSize()); pageBar1.PagerEvent += PageBar1_PagerEvent; gridView1.CustomDrawRowIndicator += (s, e) => { if (e.Info.IsRowIndicator && e.RowHandle >= 0) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } }; gridView1.CustomDrawEmptyForeground += (s, e) => { string str = "暂未查找到匹配的数据!"; Font f = new Font("微软雅黑", 16); Rectangle r = new Rectangle(gridView1.GridControl.Width / 2 - 100, e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5); e.Graphics.DrawString(str, f, Brushes.Gray, r); }; } /// /// 批准 /// /// /// private void ToolBarMenu1_btnPiZhunClick(object sender, EventArgs e) { string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_sampleSizeNo, gridView1); try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "Approval", JsonConvert.SerializeObject(rowGuid)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { UtilityHelper.JumpToTab(xtraTabControl1, 0); getPageList(1, UtilityHelper.GetPageSize()); } ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// 反审核 /// /// /// /// private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e) { toolBarMenu1.guidKey = ""; string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_sampleSizeNo, gridView1); toolBarMenu1.guidKey = rowGuid; } /// /// 审核事件 /// /// /// private void ToolBarMenu1_btnChkClick(object sender, EventArgs e) { toolBarMenu1.guidKey = ""; string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_sampleSizeNo, gridView1); toolBarMenu1.guidKey = rowGuid; } /// /// 双击事件 /// /// /// private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e) { string rowGuid = Gs.DevApp.ToolBox.UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid"); if (!string.IsNullOrEmpty(rowGuid)) getModel(rowGuid, false, 999); } /// /// 分页事件 /// /// /// private void PageBar1_PagerEvent(int curPage, int pageSize) { getPageList(curPage, pageSize); } /// /// 查询回调 /// /// /// private void Frm_UpdateParent(object sender, UpdateParentEventArgs e) { _filterList = e.FilterList; getPageList(1, pageBar1.RowsCount); } /// /// 取消事件 /// /// /// private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) { UtilityHelper.JumpToTab(xtraTabControl1, 0); } /// /// 删除事件 /// /// /// private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_sampleSizeNo, gridView1); if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?")) return; List lst = new List(); lst.Add(rowGuid); var _obj = lst; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) { UtilityHelper.JumpToTab(xtraTabControl1, 0); getPageList(1, UtilityHelper.GetPageSize()); } 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(), false, 999); else getPageList(1, UtilityHelper.GetPageSize()); } /// /// 修改事件 /// /// /// private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) { string rowGuid = "", rowName = ""; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_sampleSizeNo, gridView1); if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } getModel(rowGuid, true, 1); } /// /// 新增事件 /// /// /// private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) { UtilityHelper.JumpToTab(xtraTabControl1, 1); lbGuid.Text = ""; List gridViews = new List(); gridViews.Add(gvMx1); gridViews.Add(gvMx2); UtilityHelper.CleanValueByControl(this.panel1.Controls, true, gridViews); UtilityHelper.SetDefaultTable(gcMx1, gvMx1); UtilityHelper.SetDefaultTable(gcMx2, gvMx2); txt_createDate.Text = DateTime.Now.ToString("G"); txt_fversion.Text = "1"; } /// /// 保存事件 /// /// /// private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) { toolBarMenu1.isSetBtn = false; if (string.IsNullOrEmpty(txt_sampleSizeNo.Text.Trim())) { Gs.DevApp.ToolBox.MsgHelper.Warning("标准编码不能为空!"); txt_sampleSizeNo.Focus(); return; } if (string.IsNullOrEmpty(txt_sampleSizeName.Text.Trim())) { Gs.DevApp.ToolBox.MsgHelper.Warning("标准名称不能为空!"); txt_sampleSizeName.Focus(); return; } gvMx1.CloseEditor(); gvMx1.UpdateCurrentRow(); gvMx2.CloseEditor(); gvMx2.UpdateCurrentRow(); var qmaql2 = new List(); for (var i = 0; i < gvMx1.DataRowCount; i++) { var row = gvMx1.GetDataRow(i); if (row != null) qmaql2.Add(new MesQmAql2 { Guid = UtilityHelper.ToGuid(row["Guid"].ToString()), LotFrom = Convert.ToInt32(row["LotFrom"].ToString()), LotTo = Convert.ToInt32(row["LotTo"].ToString()), FlevelS1 = row["FlevelS1"].ToString(), FlevelS2 = row["FlevelS2"].ToString(), FlevelS3 = row["FlevelS3"].ToString(), FlevelS4 = row["FlevelS4"].ToString(), FlevelI = row["FlevelI"].ToString(), FlevelIi = row["FlevelIi"].ToString(), FlevelIii = row["FlevelIii"].ToString(), Memo = row["Memo"].ToString() }); } var qmaql3 = new List(); for (var i = 0; i < gvMx2.DataRowCount; i++) { var row = gvMx2.GetDataRow(i); if (row != null) qmaql3.Add(new MesQmAql3 { Guid = UtilityHelper.ToGuid(row["Guid"].ToString()), FsampleSizeWord = Convert.ToInt32(row["FsampleSizeWord"].ToString()), SampleSizeWord = row["SampleSizeWord"].ToString(), Aql00010 = Convert.ToInt32(row["Aql00010"].ToString()), Aql00015 = Convert.ToInt32(row["Aql00015"].ToString()), Aql00025 = Convert.ToInt32(row["Aql00025"].ToString()), Aql00040 = Convert.ToInt32(row["Aql00040"].ToString()), Aql00065 = Convert.ToInt32(row["Aql00065"].ToString()), Aql0010 = Convert.ToInt32(row["Aql0010"].ToString()), Aql0015 = Convert.ToInt32(row["Aql0015"].ToString()), Aql0025 = Convert.ToInt32(row["Aql0025"].ToString()), Aql0040 = Convert.ToInt32(row["Aql0040"].ToString()), Aql0065 = Convert.ToInt32(row["Aql0065"].ToString()), Aql0100 = Convert.ToInt32(row["Aql0100"].ToString()), Aql0150 = Convert.ToInt32(row["Aql0150"].ToString()), Aql0250 = Convert.ToInt32(row["Aql0250"].ToString()), Aql0400 = Convert.ToInt32(row["Aql0400"].ToString()), Aql0650 = Convert.ToInt32(row["Aql0650"].ToString()), Aql1000 = Convert.ToInt32(row["Aql1000"].ToString()), Memo = row["Memo"].ToString() }); } if (qmaql2.Count <= 0) { Gs.DevApp.ToolBox.MsgHelper.Warning("样本量子码不能为空!"); return; } if (qmaql3.Count <= 0) { Gs.DevApp.ToolBox.MsgHelper.Warning("抽样方案不能为空!"); return; } var _obj = new MesQmAql1 { Guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), SampleSizeNo = txt_sampleSizeNo.Text.Trim(), SampleSizeName = txt_sampleSizeName.Text.Trim(), Memo = txt_memo.Text.Trim(), CreateDate = DateTime.Now, FtwoChecked = false, Isenabled = false, FoneChecked = false, Fversion = Convert.ToInt32(txt_fversion.Text.Trim()), MesQmAql2s = qmaql2, MesQmAql3s = qmaql3 }; try { string strJson = UtilityHelper.HttpPost("", _webServiceName + "EditModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); if (_rtn.rtnCode > 0) { lbGuid.Text = _rtn.rtnData; toolBarMenu1.isSetBtn = true; List gridViews = new List(); gridViews.Add(gvMx1); gridViews.Add(gvMx2); UtilityHelper.ChangeEnableByControl(this.panel1.Controls, false, gridViews); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage, int pageSize) { System.Text.StringBuilder _sbSqlWhere = new System.Text.StringBuilder(); foreach (FilterEntity itm in _filterList) { _sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" + itm.fileValue + "'"); } PageQueryModel pgq = new PageQueryModel(curPage, pageSize, "create_date", "asc", "", _sbSqlWhere.ToString()); string json = JsonConvert.SerializeObject(pgq); try { string strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json); ReturnModel dd = UtilityHelper.ReturnToTablePage(strReturn); if (dd.rtnCode > 0) { DataTable dt = dd.rtnData.list; gcMain.BindingContext = new BindingContext(); gcMain.DataSource = dt; gcMain.ForceInitialize(); int dddd = dd.rtnData.pages;//总页 pageBar1.TotalPages = dddd; pageBar1.RecordCount = dd.rtnData.total;//记录总数 pageBar1.CurrentPage = curPage;//当前页 pageBar1.setTxt(); } else { ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } private void getModel(string strGuid, bool isEdit, int tabIdx) { if (string.IsNullOrEmpty(strGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } UtilityHelper.JumpToTab(xtraTabControl1, tabIdx); 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; List gvList = new List(); gvList.Add(gvMx1); gvList.Add(gvMx2); UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit, gvList); JObject _job = JObject.Parse(strJson); JArray array = new JArray(); JArray mesQmAql3s = new JArray(); foreach (var a in _job["rtnData"]["mesQmAql2s"]) { array.Add(a); } DataTable dt = JsonConvert.DeserializeObject(array.ToString()); if (dt.Rows.Count > 0) { gcMx1.BindingContext = new BindingContext(); gcMx1.DataSource = dt; gcMx1.ForceInitialize(); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1); } foreach (var a in _job["rtnData"]["mesQmAql3s"]) { mesQmAql3s.Add(a); } DataTable dt1 = JsonConvert.DeserializeObject(mesQmAql3s.ToString()); if (dt1.Rows.Count > 0) { gcMx2.BindingContext = new BindingContext(); gcMx2.DataSource = dt1; gcMx2.ForceInitialize(); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx2, gvMx2); } } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { gvMx1.CloseEditor(); gvMx1.UpdateCurrentRow(); var rowhandle = gvMx1.FocusedRowHandle; if (rowhandle < 0) return; if (e.Button.Index == 0) { var dr = gvMx1.GetDataRow(rowhandle); var mxGuid = dr["guid"].ToString(); if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?")) return; if (string.IsNullOrEmpty(mxGuid)) { gvMx1.DeleteRow(rowhandle); return; } var strJson = ""; var lst = new List(); lst.Add(mxGuid); try { strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModelMx", JsonConvert.SerializeObject(lst)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) getModel(lbGuid.Text, true, 1); MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } } private void repositoryItemButtonEdit2_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { gvMx2.CloseEditor(); gvMx2.UpdateCurrentRow(); var rowhandle = gvMx2.FocusedRowHandle; if (rowhandle < 0) return; if (e.Button.Index == 0) { var dr = gvMx2.GetDataRow(rowhandle); var mxGuid = dr["guid"].ToString(); if (!MsgHelper.AskQuestion("你选择了1条数据,确定删除吗?")) return; if (string.IsNullOrEmpty(mxGuid)) { gvMx1.DeleteRow(rowhandle); return; } var strJson = ""; var lst = new List(); lst.Add(mxGuid); try { strJson = UtilityHelper.HttpPost("", _webServiceName + "DeleteModelMx2", JsonConvert.SerializeObject(lst)); var _rtn = UtilityHelper.ReturnToDynamic(strJson); if (_rtn.rtnCode > 0) getModel(lbGuid.Text, true, 1); MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } } } }