lu
2024-11-14 1a8f404f8641d38b5a2746d9d6d14b1e40f3b5bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
using DevExpress.XtraGrid.Views.Grid;
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
{
    public partial class Frm_InitialBarcode : DevExpress.XtraEditors.XtraForm
    {
        string _webServiceName = "MesInvItemBarcodesManager/";
        List<FilterEntity> _filterList = new List<FilterEntity>();
        public Frm_InitialBarcode()
        {
            InitializeComponent();
            this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            toolBarMenu1.btnReportClick += ToolBarMenu1_btnReportClick;
            toolBarMenu1.btnDesignClick += ToolBarMenu1_btnDesignClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            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);
            };
            //设置供应商选择
            this.txt_suppNo_1.KeyFile = "id";
            this.txt_suppNo_1.EditChanged += (s, e) =>
            {
                txt_suppId.Text = this.txt_suppNo_1.GetId();
            };
          
        }
 
      
        /// <summary>
        /// 双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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);
        }
        /// <summary>
        /// 分页事件
        /// </summary>
        /// <param name="curPage"></param>
        /// <param name="pageSize"></param>
        private void PageBar1_PagerEvent(int curPage, int pageSize)
        {
            getPageList(curPage, pageSize);
        }
        /// <summary>
        /// 查询事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e)
        {
            Gs.DevApp.UserControl.ShowFilter frm = new Gs.DevApp.UserControl.ShowFilter(gridView1.Columns, _filterList);
            frm.UpdateParent += Frm_UpdateParent;
            frm.ShowDialog();
        }
        /// <summary>
        /// 查询回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        {
            _filterList = e.FilterList;
            getPageList(1, pageBar1.RowsCount);
        }
 
        /// <summary>
        /// 刷新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        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_btnDesignClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_itemName, gridView1);
            toolBarMenu1.guidKey = rowGuid;
            toolBarMenu1.rptParameter = "rpt_ItemInv{}";
        }
        private void ToolBarMenu1_btnReportClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_itemName, gridView1);
            toolBarMenu1.guidKey = rowGuid;
            if (xtraTabControl1.SelectedTabPageIndex == 0)
            {
                getModel(rowGuid, false, 999);
                this.toolBarMenu1.rptParameter = "return false";
                return;
            }
            if (string.IsNullOrEmpty(txt_suppNo_1.GetCode()))
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择供应商!");
                txt_suppNo_1.Focus();
                this.toolBarMenu1.rptParameter = "return false";
                return;
            }
            if (string.IsNullOrEmpty(txt_iCount_1.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印条码张数!");
                txt_iCount_1.Focus();
                this.toolBarMenu1.rptParameter = "return false";
                return;
            }
            if (string.IsNullOrEmpty(txt_psnQty_1.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.ShowError("请选择打印条码数量!");
                txt_psnQty_1.Focus();
                this.toolBarMenu1.rptParameter = "return false";
                return;
            }
            this.toolBarMenu1.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()
                   + "}";
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        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<PageListModel> 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.RowsCount = pageSize;//每页显示
                    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);
            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<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
                    gvList.Add(gvMx1);
                    //主表赋值
                    UtilityHelper.SetValueByObj(this.panel1.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<DataTable>(array.ToString());
                    if (dt.Rows.Count > 0)
                    {
                        gcMx1.BindingContext = new BindingContext();
                        gcMx1.DataSource = dt;
                        gcMx1.ForceInitialize();
                    }
                    else
                    {
                        Gs.DevApp.ToolBox.UtilityHelper.SetDefaultTable(gcMx1, gvMx1);
                    }
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}