using DevExpress.XtraTreeList.Nodes; using DevExpress.XtraTreeList; using Gs.DevApp.Entity; using Gs.DevApp.ToolBox; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Gs.DevApp.DevFrm.QC { public partial class DefectCode : DevExpress.XtraEditors.XtraUserControl { string _webServiceName = "MesDefectCodeManager/"; List _filterList = new List(); public string strType = "";//类别(普通信息,认证信息) public DefectCode(string _strType) { InitializeComponent(); strType = _strType; toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; tlMenu.IndicatorWidth = 50; tlMenu.CustomDrawNodeIndicator += (s, ee) => { if (ee.IsNodeIndicator) { var index = ee.Node.TreeList.GetVisibleIndexByNode(ee.Node); ee.Info.DisplayText = (index + 1).ToString(); } }; getPageList(1); this.tlMenu.MouseDown += TlMenu_MouseDown; this.toolStripMenuItemAdd.Click += (s, ee) => { string strGuid = ""; string strUpGuid = ""; if (tlMenu.FocusedNode != null) { strUpGuid = tlMenu.FocusedNode.GetValue("guid").ToString(); } Frm_MesDefectCodeShow frm = new Frm_MesDefectCodeShow(strGuid, strUpGuid,strType); frm.UpdateParent += (s2, ee2) => { getPageList(1); }; frm.ShowDialog(); }; this.toolStripMenuItemRoot.Click += (s, ee) => { string strGuid = ""; string strUpGuid = ""; Frm_MesDefectCodeShow frm = new Frm_MesDefectCodeShow(strGuid, strUpGuid, strType); frm.UpdateParent += (s2, ee2) => { getPageList(1); }; frm.ShowDialog(); }; this.toolStripMenuItemDel.Click += (s, ee) => { if (tlMenu.FocusedNode != null) { string rowGuid = ""; string rowName = ""; rowGuid = tlMenu.FocusedNode.GetValue("guid").ToString(); rowName = tlMenu.FocusedNode.GetValue("defectName").ToString(); 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) { tlMenu.DeleteNode(tlMenu.FocusedNode); } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } }; this.toolStripMenuItemEdt.Click += (s, ee) => { string strGuid = ""; string strUpGuid = ""; if (tlMenu.FocusedNode != null) { strGuid = tlMenu.FocusedNode.GetValue("guid").ToString(); strUpGuid = tlMenu.FocusedNode.GetValue("pid").ToString(); } Frm_MesDefectCodeShow frm = new Frm_MesDefectCodeShow(strGuid, strUpGuid, strType); frm.UpdateParent += (s2, ee2) => { getPageList(1); }; frm.ShowDialog(); }; } /// /// 右键弹出菜单,如果是行,增加子项目,否则增加主项 /// /// /// private void TlMenu_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { TreeListHitInfo hInfo = tlMenu.CalcHitInfo(new Point(e.X, e.Y)); TreeListNode node = hInfo.Node; tlMenu.FocusedNode = node; if (hInfo.HitInfoType == HitInfoType.Cell || hInfo.HitInfoType == HitInfoType.Row || hInfo.HitInfoType == HitInfoType.RowIndent || hInfo.HitInfoType == HitInfoType.RowIndicator ) { if (node != null) { toolStripMenuItemAdd.Visible = true; toolStripMenuItemEdt.Visible = true; toolStripMenuItemDel.Visible = true; toolStripMenuItemRoot.Visible = false; cms1.Show(tlMenu, e.Location); } } else { toolStripMenuItemAdd.Visible = false; toolStripMenuItemEdt.Visible = false; toolStripMenuItemDel.Visible = false; toolStripMenuItemRoot.Visible = true; cms1.Show(tlMenu, e.Location); } } } /// /// 查询事件 /// /// /// private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e) { Gs.DevApp.ToolBox.MsgHelper.ShowInformation("该窗体不支持查询,若想更新页面,请点击 刷新"); } /// /// 刷新事件 /// /// /// private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) { _filterList.Clear(); getPageList(1); } /// /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage) { System.Text.StringBuilder sbWhere = new StringBuilder(); sbWhere.Append(" and a.defect_sort='" + strType + "'"); var pgq = new PageQueryModel(1, 999999, "a.defect_code ", "asc","", sbWhere.ToString()); var json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json); var dd = UtilityHelper.ReturnToTablePage(strReturn); var dt = dd.rtnData.list; tlMenu.DataSource = dt; tlMenu.KeyFieldName = "guid"; tlMenu.ParentFieldName = "pid"; tlMenu.EndUpdate(); //this.tlMenu.CollapseAll(); // this.tlMenu.ExpandAll(); this.tlMenu.ExpandToLevel(0); } catch (Exception ex) { MsgHelper.Warning("提示:" + ex.Message); } } } }