using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; using Core.Mes.Client.Comm.Control; using Core.Mes.Client.Comm.Format; using Core.Mes.Client.Comm.Tool; using Core.StlMes.Client.Lims.Data.PipeAndOutdec.封装类.实体类; using CoreFS.CA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinTree; using Core.StlMes.Client.Lims.Data.PipeAndOutdec.数据管理.基础信息管理; namespace Core.StlMes.Client.Lims.Data.PipeAndOutdec { public partial class FrmBaseSynchronizeRelation : FrmBase { private ComBasePhyEntityFull _comBasePhyEntityFull = new ComBasePhyEntityFull(); private bool isAdd = false; public FrmBaseSynchronizeRelation() { InitializeComponent(); } private void FrmBaseSynchronizeRelation_Load(object sender, EventArgs e) { EntityHelper.ShowGridCaption(ugGrid.DisplayLayout.Bands[0]); doQuery2(); } /// /// 重写基类方法 /// /// /// public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": doQuery(); break; case "Add": doAdd(); break; case "Update": doUpdate(); break; case "Delete": doDelete(); break; case "Close": Close(); break; } } private void doUpdate() { if (upEdit.Visible) { btnSave_Click(null, null); } else { if (ugGrid.ActiveRow == null) { MessageBox.Show("请选择需要更新的数据!"); return; } var pipeCheckconsignPhyrelationEntity = ugGrid.ActiveRow.ListObject as PipeCheckconsignPhyrelationEntity; if (pipeCheckconsignPhyrelationEntity == null) return; upEdit.Visible = true; upShow.Visible = false; SetValue(pipeCheckconsignPhyrelationEntity); } } private void doDelete() { if (ugGrid.ActiveRow == null) { MessageBox.Show("请选择需要删除的数据!"); return; } var pipeCheckconsignPhyrelationEntity = ugGrid.ActiveRow.ListObject as PipeCheckconsignPhyrelationEntity; if (pipeCheckconsignPhyrelationEntity == null) return; var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.lims.data.base.FrmBaseSynchronizeRelation"; ccp.MethodName = "doDelete"; ccp.ServerParams = new object[] { pipeCheckconsignPhyrelationEntity.Relationkey }; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) if (ccp.ReturnInfo.Equals("删除成功!")) { doQuery(); MessageUtil.ShowTips(ccp.ReturnInfo); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } private void doAdd() { if (upEdit.Visible) { btnSave_Click(null, null); } else { upEdit.Visible = true; upShow.Visible = false; PipeCheckconsignPhyrelationEntity pipeCheckconsignPhyrelationEntity; if (ugGrid.ActiveRow == null) { pipeCheckconsignPhyrelationEntity = new PipeCheckconsignPhyrelationEntity(); } else { pipeCheckconsignPhyrelationEntity = ugGrid.ActiveRow.ListObject as PipeCheckconsignPhyrelationEntity; } SetValue(pipeCheckconsignPhyrelationEntity, true); } } private void doQuery() { if (tbMain.SelectedTab.Index == 0) doQuery1(); else if (tbMain.SelectedTab.Index == 1) doQuery2(); } private void doQuery1() { var PhyCode = ""; var PhyTypeC = ""; var PhyType = ""; if (chkPhyCode.Checked) PhyCode = cboPhyCodeQuery.Value.ToString(); if (chkPhyTypeC.Checked) PhyTypeC = cboPhyTypeCQuery.Value.ToString(); if (chkPhyType.Checked) PhyType = cboPhyTypeQuery.Value.ToString(); List listSource = EntityHelper.GetData ( "com.steering.lims.data.base.FrmBaseSynchronizeRelation.doQuery", new object[] {PhyCode, PhyTypeC, PhyType}, ob); pipeCheckconsignPhyrelationEntityBindingSource.DataSource = listSource; PublicPipeAndOutdec.RefreshAndAutoSizeColumns(ugGrid, new object[] {}, false); } private void doQuery2() { var wf = new WaitingForm2("正在查询,请稍候...."); try { List listSource = EntityHelper.GetData ( "com.steering.lims.data.base.FrmBaseSynchronizeRelation.doQuery", new object[] {}, ob); treeMain.Nodes.Clear(); UltraTreeNode activeNode = null; treeMain.Nodes.AddRange( listSource.GroupBy(p => new {p.PhyType, p.PhyTypeName}) .Select( p => { var node = new UltraTreeNode { Text = string.Format(@"{0}-({1})", p.Key.PhyTypeName, p.Key.PhyType), Tag = p.Key.PhyType }; if (_comBasePhyEntityFull != null && _comBasePhyEntityFull.PhyCodeC == p.Key.PhyType) { node.Expanded = true; } node.Nodes.AddRange( p.GroupBy(a => new {a.PhyTypeC, a.PhyTypeCName}).ToList().Select(a => { var nodeC = new UltraTreeNode { Text = string.Format(@"{0}-({1})", a.Key.PhyTypeCName, a.Key.PhyTypeC), Tag = a.Key.PhyTypeC }; if (_comBasePhyEntityFull != null && _comBasePhyEntityFull.PhyCodeC == p.Key.PhyType && _comBasePhyEntityFull.PhyCodeB == a.Key.PhyTypeC) { nodeC.Expanded = true; } nodeC.Nodes.AddRange( a.GroupBy(b => new {b.PhyCode, b.PhyName}).Select(b => { var nodeD = new UltraTreeNode { Text = string.Format(@"{0}-({1})", b.Key.PhyName, b.Key.PhyCode), Tag = b.ToList() }; if (_comBasePhyEntityFull != null && _comBasePhyEntityFull.PhyCodeC == p.Key.PhyType && _comBasePhyEntityFull.PhyCodeB == a.Key.PhyTypeC && _comBasePhyEntityFull.PhyCodeA == b.Key.PhyCode) { activeNode = nodeD; } return nodeD; }).ToArray()); return nodeC; }).ToArray()); return node; } ).ToArray()); if (activeNode != null) { activeNode.Selected = true; treeMain.ActiveNode = activeNode; } wf.Close(); Cursor = Cursors.Default; } catch (Exception ex) { wf.Close(); Cursor = Cursors.Default; MessageBox.Show(ex.Message); } } private void treeMain_AfterActivate(object sender, NodeEventArgs e) { if (treeMain.ActiveNode == null) return; upShow.Visible = true; upEdit.Visible = false; if (treeMain.ActiveNode.HasNodes) return; ugGrid.DataSource = treeMain.ActiveNode.Tag as List; ugGrid.Update(); PublicPipeAndOutdec.RefreshAndAutoSizeColumns(ugGrid, new object[] {}, false); } private void btnSave_Click(object sender, EventArgs e) { var data = GetEntity(); if (data.PhyCode == "") { MessageUtil.ShowWarning("检验项不能为空"); return; } if (data.PhyTypeC == "") { MessageUtil.ShowWarning("试样组不能为空"); return; } if (data.PhyType == "") { MessageUtil.ShowWarning("检验大项不能为空"); return; } if (string.IsNullOrWhiteSpace(data.Relationkey)) { var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.lims.data.base.FrmBaseSynchronizeRelation"; ccp.MethodName = "doAdd"; ccp.ServerParams = new object[] {JSONFormat.Format(data)}; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) if (ccp.ReturnInfo.Equals("新增成功!")) { MessageUtil.ShowTips(ccp.ReturnInfo); doQuery(); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } else { var ccp = new CoreClientParam(); ccp.ServerName = "com.steering.lims.data.base.FrmBaseSynchronizeRelation"; ccp.MethodName = "doUpdate"; ccp.ServerParams = new object[] {JSONFormat.Format(data)}; ccp = ob.ExecuteNonQuery(ccp, CoreInvokeType.Internal); if (ccp.ReturnCode != -1) if (ccp.ReturnInfo.Equals("修改成功!")) { MessageUtil.ShowTips(ccp.ReturnInfo); doQuery(); } else { MessageUtil.ShowTips(ccp.ReturnInfo); } } } private void btnCancle_Click(object sender, EventArgs e) { upEdit.Visible = false; upShow.Visible = true; } private void SetValue(PipeCheckconsignPhyrelationEntity pipeCheckconsignPhyrelationEntity,bool isAdd = false) { _comBasePhyEntityFull = new ComBasePhyEntityFull { PhyCodeA = pipeCheckconsignPhyrelationEntity.PhyCode, PhyNameA = pipeCheckconsignPhyrelationEntity.PhyName, PhyCodeB = pipeCheckconsignPhyrelationEntity.PhyTypeC, PhyNameB = pipeCheckconsignPhyrelationEntity.PhyTypeCName, PhyCodeC = pipeCheckconsignPhyrelationEntity.PhyType, PhyNameC = pipeCheckconsignPhyrelationEntity.PhyTypeName }; SetComBasePhyFull(); cboPhyCodeDir.Tag = pipeCheckconsignPhyrelationEntity.PhyCodeDir; cboPhyCodeDir.Text = pipeCheckconsignPhyrelationEntity.PhyNameDir; cboValuename.Text = pipeCheckconsignPhyrelationEntity.Valuename; txtDbColumn1.Text = pipeCheckconsignPhyrelationEntity.DbColumn1; txtDbColumn2.Text = pipeCheckconsignPhyrelationEntity.DbColumn2; txtDbColumn3.Text = pipeCheckconsignPhyrelationEntity.DbColumn3; txtDbColumn4.Text = pipeCheckconsignPhyrelationEntity.DbColumn4; txtDbColumn5.Text = pipeCheckconsignPhyrelationEntity.DbColumn5; txtDbColumn6.Text = pipeCheckconsignPhyrelationEntity.DbColumn6; txtDbPara1.Text = pipeCheckconsignPhyrelationEntity.DbPara1; txtDbPara2.Text = pipeCheckconsignPhyrelationEntity.DbPara2; txtDbPara3.Text = pipeCheckconsignPhyrelationEntity.DbPara3; txtDbParaValue1.Text = pipeCheckconsignPhyrelationEntity.DbParaValue1; txtDbParaValue2.Text = pipeCheckconsignPhyrelationEntity.DbParaValue2; txtDbParaValue3.Text = pipeCheckconsignPhyrelationEntity.DbParaValue3; txtFormula1.Text = pipeCheckconsignPhyrelationEntity.Formula1; txtFormula2.Text = pipeCheckconsignPhyrelationEntity.Formula2; txtFormula3.Text = pipeCheckconsignPhyrelationEntity.Formula3; txtFormula4.Text = pipeCheckconsignPhyrelationEntity.Formula4; txtFormula5.Text = pipeCheckconsignPhyrelationEntity.Formula5; if (!isAdd) txtKey.Text = pipeCheckconsignPhyrelationEntity.Relationkey; } private void SetComBasePhyFull() { cboPhyCode.Tag = _comBasePhyEntityFull.PhyCodeA; cboPhyCode.Text = _comBasePhyEntityFull.PhyNameA; cboPhyTypeC.Tag = _comBasePhyEntityFull.PhyCodeB; cboPhyTypeC.Text = _comBasePhyEntityFull.PhyNameB; cboPhyType.Tag = _comBasePhyEntityFull.PhyCodeC; cboPhyType.Text = _comBasePhyEntityFull.PhyNameC; showButton(); } public void showButton() { cboPhyCode.ButtonsRight["Edit"].Visible = true; cboPhyCode.ButtonsRight["Comm"].Visible = cboPhyCode.Tag.ToString2() != "0000"; cboPhyTypeC.ButtonsRight["Edit"].Visible = cboPhyCode.Tag.ToString2() == "0000"; cboPhyTypeC.ButtonsRight["Comm"].Visible = cboPhyTypeC.ButtonsRight["Edit"].Visible && (cboPhyTypeC.Tag.ToString2() != "0000"); cboPhyType.ButtonsRight["Edit"].Visible = cboPhyTypeC.Tag.ToString2() == "0000"; cboPhyType.ButtonsRight["Comm"].Visible = cboPhyType.ButtonsRight["Edit"].Visible && (cboPhyType.Tag.ToString2() != "0000"); } private PipeCheckconsignPhyrelationEntity GetEntity() { var pipeCheckconsignPhyrelationEntity = new PipeCheckconsignPhyrelationEntity { PhyCode = cboPhyCode.Tag.ToString2(), PhyName = cboPhyCode.Text, PhyCodeDir = cboPhyCodeDir.Tag.ToString2(), PhyNameDir = cboPhyCodeDir.Text, PhyType = cboPhyType.Tag.ToString2(), PhyTypeName = cboPhyType.Text, PhyTypeC = cboPhyTypeC.Tag.ToString2(), PhyTypeCName = cboPhyTypeC.Text, Valuename = cboValuename.Text, DbColumn1 = txtDbColumn1.Text, DbColumn2 = txtDbColumn2.Text, DbColumn3 = txtDbColumn3.Text, DbColumn4 = txtDbColumn4.Text, DbColumn5 = txtDbColumn5.Text, DbColumn6 = txtDbColumn6.Text, DbPara1 = txtDbPara1.Text, DbPara2 = txtDbPara2.Text, DbPara3 = txtDbPara3.Text, DbParaValue1 = txtDbParaValue1.Text, DbParaValue2 = txtDbParaValue2.Text, DbParaValue3 = txtDbParaValue3.Text, Formula1 = " " + txtFormula1.Text, Formula2 = " " + txtFormula2.Text, Formula3 = " " + txtFormula3.Text, Formula4 = " " + txtFormula4.Text, Formula5 = " " + txtFormula5.Text, Relationkey = txtKey.Text }; return pipeCheckconsignPhyrelationEntity; } private void cboPhyCode_EditorButtonClick(object sender, EditorButtonEventArgs e) { var ultraTextEditor = sender as UltraTextEditor; if (ultraTextEditor == null) return; if (e.Button.Key == "Comm") { ultraTextEditor.Tag = "0000"; ultraTextEditor.Text = "通用"; showButton(); } else if (e.Button.Key == "Edit") { using (var PhyCodeSelect = new PhyCodeSelect(ob, _comBasePhyEntityFull, ultraTextEditor == cboPhyCode ? "1" : ultraTextEditor == cboPhyTypeC?"2":ultraTextEditor == cboPhyType?"3":"'")) { if (PhyCodeSelect.ShowDialog() == DialogResult.OK) { _comBasePhyEntityFull = PhyCodeSelect.SelectRow; SetComBasePhyFull(); } } } } private void cboPhyCodeDir_EditorButtonClick(object sender, EditorButtonEventArgs e) { using (var phyCodeSelect = new PhyCodeSelect(ob, new ComBasePhyEntityFull(), "1")) { if (phyCodeSelect.ShowDialog() == DialogResult.OK) { cboPhyCodeDir.Tag = phyCodeSelect.SelectRow.PhyCodeA; cboPhyCodeDir.Text = phyCodeSelect.SelectRow.PhyNameA; } } } } }