using DevExpress.XtraGrid.Columns; using DevExpress.XtraTreeList; using DevExpress.XtraTreeList.Nodes; 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.Windows.Forms; namespace Gs.DevApp.DevFrm.Warehouse { public partial class FrmDepot : DevExpress.XtraEditors.XtraForm { public FrmDepot() { 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; this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; tlMenu.MouseDoubleClick += GcMain_MouseDoubleClick; tlMenu.ColumnFilterChanged += GridView1_ColumnFilterChanged; tlMenu.CustomDrawNodeIndicator += (s, ee) => { if (ee.IsNodeIndicator) { var index = ee.Node.TreeList.GetVisibleIndexByNode(ee.Node); ee.Info.DisplayText = (index + 1).ToString(); } }; pageBar1.PagerEvent += PageBar1_PagerEvent; getPageList(1, UtilityHelper.GetPageSize()); } private void GridView1_ColumnFilterChanged(object sender, EventArgs e) { //// 获取GridView组件 //GridView view = sender as GridView; //// 确保view不为null //if (view == null) return; //// 获取应用的筛选器信息 //string filter = view.ActiveFilterString; //MessageBox.Show(filter); //getPageList(1, UtilityHelper.GetPageSize()); } /// /// 双击事件 /// /// /// private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e) { TreeListHitInfo info = tlMenu.CalcHitInfo(e.Location); if (info.Node != null) { TreeListNode clickedNode = this.tlMenu.FocusedNode; if (clickedNode.FirstNode == null) { string rowGuid = clickedNode.GetValue("guid").ToString(); string depotGuid = clickedNode.GetValue("upGuid").ToString(); if (!string.IsNullOrEmpty(depotGuid)) rowGuid = depotGuid; getModel(rowGuid, false, 999); } } } /// /// 分页事件 /// /// /// private void PageBar1_PagerEvent(int curPage, int pageSize) { getPageList(curPage, pageSize); } /// /// 查询事件 /// /// /// private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e) { //Gs.DevApp.UserControl.ShowFilter frm = new Gs.DevApp.UserControl.ShowFilter(gridView1.Columns); //frm.UpdateParent += Frm_UpdateParent; //frm.ShowDialog(); } /// /// 查询回调 /// /// /// private void Frm_UpdateParent(object sender, UpdateParentEventArgs e) { string strWhere = e.Data; MessageBox.Show(strWhere); } /// /// 取消事件 /// /// /// private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) { UtilityHelper.ChangeTab(xtraTabControl1, 0); } /// /// 删除事件 /// /// /// private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e) { String rowGuid = Convert.ToString(tlMenu.FocusedNode.GetValue("guid")); if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要删除的行!"); return; } if (!MsgHelper.AskQuestion("你选择了【" + tlMenu.FocusedNode.GetValue("name") + "】,确定删除吗?")) { return; } var _obj = new { guidList = rowGuid,//主建 }; string strJson = ""; try { strJson = UtilityHelper.HttpPost("", "Depot/DeleteModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); if (_rtn.rtnCode > 0) { UtilityHelper.ChangeTab(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) { UtilityHelper.ChangeTab(xtraTabControl1, 0); getPageList(1, UtilityHelper.GetPageSize()); } /// /// 修改事件 /// /// /// private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) { String rowGuid = Convert.ToString(tlMenu.FocusedNode.GetValue("guid")); string depotGuid = Convert.ToString(tlMenu.FocusedNode.GetValue("upGuid")); if (!string.IsNullOrEmpty(depotGuid)) rowGuid = depotGuid; if (string.IsNullOrEmpty(rowGuid)) { ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); return; } getModel(rowGuid, true, 1); } /// /// 新增事件 /// /// /// private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) { UtilityHelper.ChangeTab(xtraTabControl1, 1); lbGuid.Text = ""; List gridViews = new List(); gridViews.Add(gvMx1); UtilityHelper.CleanValue(this.panel1.Controls, true, gridViews); DataTable dt = new DataTable(); foreach (GridColumn col in gvMx1.Columns) { dt.Columns.Add(col.FieldName, typeof(string)); } gridControl1.BindingContext = new BindingContext(); gridControl1.DataSource = dt; gridControl1.ForceInitialize(); } /// /// 保存事件 /// /// /// private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e) { toolBarMenu1.isSetBtn = false; if (string.IsNullOrEmpty(txt_itemNo.Text.Trim())) { Gs.DevApp.ToolBox.MsgHelper.Warning("编号号不能为空!"); txt_itemNo.Focus(); return; } if (string.IsNullOrEmpty(txt_name.Text.Trim())) { Gs.DevApp.ToolBox.MsgHelper.Warning("名称不能为空!"); txt_name.Focus(); return; } if (txt_category.SelectedIndex <= 0) { Gs.DevApp.ToolBox.MsgHelper.Warning("类型不能为空!"); txt_category.Focus(); return; } if (txt_isWy.SelectedIndex <= 0) { Gs.DevApp.ToolBox.MsgHelper.Warning("委外不能为空!"); txt_isWy.Focus(); return; } if (txt_isStatus.SelectedIndex <= 0) { Gs.DevApp.ToolBox.MsgHelper.Warning("状态不能为空!"); txt_isStatus.Focus(); return; } var _obj = new { guid = lbGuid.Text.Trim(),//主建 itemNo = txt_itemNo.Text.Trim(), name = txt_name.Text.Trim(), remark = txt_remark.Text.Trim(), category = txt_category.SelectedIndex, isWy = txt_isWy.SelectedIndex, isStatus = txt_isStatus.SelectedIndex, }; try { string strJson = UtilityHelper.HttpPost("", "Depot/EditModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); if (_rtn.rtnCode > 0) { lbGuid.Text = _rtn.rtnData; toolBarMenu1.isSetBtn = true; List gridViews = new List(); gridViews.Add(gvMx1); UtilityHelper.ChangeEnable(this.panel1.Controls, false, gridViews); } } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } /// /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage, int pageSize) { PageQueryModel pgq = new PageQueryModel(curPage, pageSize, "createTime", "asc", "", ""); string json = JsonConvert.SerializeObject(pgq); try { string strReturn = UtilityHelper.HttpPost("", "Depot/GetListPage", json); ReturnModel dd = UtilityHelper.GetTableByJson(strReturn); DataTable dt = dd.rtnData.list; this.tlMenu.DataSource = dt; this.tlMenu.KeyFieldName = "guid"; this.tlMenu.ParentFieldName = "upGuid"; this.tlMenu.Tag = "name"; this.tlMenu.EndUpdate(); this.tlMenu.ExpandAll(); tlMenu.OptionsView.CheckBoxStyle = DevExpress.XtraTreeList.DefaultNodeCheckBoxStyle.Default; int dddd = dd.rtnData.pages;//总页 pageBar1.TotalPages = dddd; pageBar1.RecordCount = dd.rtnData.total;//记录总数 pageBar1.CurrentPage = curPage;//当前页 pageBar1.RowsCount = pageSize;//每页显示 pageBar1.setTxt(); } 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.ChangeTab(xtraTabControl1, tabIdx); var _obj = new { guid = strGuid,//主建 }; try { string strJson = UtilityHelper.HttpPost("", "Depot/GetModel", JsonConvert.SerializeObject(_obj)); ReturnModel _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); if (_rtn.rtnCode > 0) { dynamic dy = _rtn.rtnData; lbGuid.Text = strGuid; List gridViews = new List(); gridViews.Add(gvMx1); UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit, gridViews); JObject _job = JObject.Parse(strJson); JArray array = new JArray(); var d = _job["rtnData"]["list"]; foreach (var a in d) { array.Add(a); } DataTable dt = JsonConvert.DeserializeObject(array.ToString()); gridControl1.BindingContext = new BindingContext(); gridControl1.DataSource = dt; gridControl1.ForceInitialize(); } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } } }