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.Data; using System.Threading.Tasks; using System.Windows.Forms; namespace Gs.DevApp.DevFrm { public partial class Frm_InitialBarcode : DevExpress.XtraEditors.XtraForm { string _webServiceName = "MesInvItemBarcodesManager/"; List _filterList = new List(); public Frm_InitialBarcode() { InitializeComponent(); this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick; this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick; this.toolBarMenu1.getXmlConfig(); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameterMx(gvMx1); Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, "", "", (value) => { Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0); }); Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) => { getModel(value); }, (value) => { getPageList(this.pageBar1.CurrentPage); }); getPageList(1); pageBar1.PagerEvent += PageBar1_PagerEvent; this.txt_suppNo_1.EditChanged += (s, e) => { txt_suppId.Text = this.txt_suppNo_1.GetCode(); }; this.ucBtnPrint1.btnDesignClick += (s, e) => { ucBtnPrint1.rptParameter = "rpt_ItemInv{}"; }; this.ucBtnPrint1.btnReportClick += (s, e) => { string rowGuid, rowName; (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_itemName, gridView1); ucBtnPrint1.guidKey = rowGuid; if (string.IsNullOrEmpty(txt_suppNo_1.GetCode())) { Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择供应商!"); txt_suppNo_1.Focus(); this.ucBtnPrint1.rptParameter = "return false"; return; } if (string.IsNullOrEmpty(txt_iCount_1.Text.Trim())) { Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印条码张数!"); txt_iCount_1.Focus(); this.ucBtnPrint1.rptParameter = "return false"; return; } if (string.IsNullOrEmpty(txt_psnQty_1.Text.Trim())) { Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印条码数量!"); txt_psnQty_1.Focus(); this.ucBtnPrint1.rptParameter = "return false"; return; } this.ucBtnPrint1.rptParameter = "rpt_ItemInv{" + txt_createDate1.Text.Trim() + "," + txt_tc_1.Checked.ToString().ToUpper() + "," + txt_suppNo_1.GetId() + "," + txt_iCount_1.Text.Trim() + "," + txt_psnQty_1.Text.Trim() + "}"; }; } private void GridView1_ColumnFilterChanged(object sender, EventArgs e) { _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1); 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_btnLoadClick(object sender, EventArgs e) { if (xtraTabControl1.SelectedTabPageIndex == 1) getModel(lbGuid.Text.Trim()); else { //_filterList.Clear(); //if (gridView1.ActiveFilter.Count > 0) //{ // gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged; // gridView1.ActiveFilter.Clear(); // gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged; //} //getPageList(1); getPageList(this.pageBar1.CurrentPage); } } /// /// /// /// 第几页 /// 每页几条 private void getPageList(int curPage) { var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList); PageQueryModel pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, " org.FNumber asc ,a.item_no ", "asc", "", _sbSqlWhere.ToString()); string json = JsonConvert.SerializeObject(pgq); try { var strReturn = UtilityHelper.HttpPost("", _webServiceName + "GetListPage", json); ReturnModel 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) { ToolBox.MsgHelper.Warning("提示:" + 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; } txt_iCount_1.Text = ""; txt_psnQty_1.Text = ""; txt_suppNo_1.SetIdOrCode("-1"); 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; txt_suppNo_1.getSuppler(dy["from"]["fSubsidiaryFId"].ToString()); List gvList = new List(); gvList.Add(gvMx1); //主表赋值 UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy["from"], isEdit, gvList); JObject _job = JObject.Parse(strJson); JArray array = new JArray(); //明细表赋值 foreach (var a in _job["rtnData"]["barcodes"]) { array.Add(a); } DataTable dt = JsonConvert.DeserializeObject(array.ToString()); if (dt.Rows.Count > 0) { gcMx1.BindingContext = new BindingContext(); gcMx1.DataSource = dt; gcMx1.ForceInitialize(); gvMx1.BestFitColumns(); } else { Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1); } } else ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); } catch (Exception ex) { ToolBox.MsgHelper.Warning("提示:" + ex.Message); } } } }