lg
2024-09-09 c417c607f22f90e1e1cec2d2a5fcde754f5adb73
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
 
namespace Gs.DevApp.DevFrm.User
{
    public partial class User : DevExpress.XtraEditors.XtraForm
    {
        public User()
        {
            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;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
            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());
        }
 
        /// <summary>
        /// 双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            GridHitInfo info = gridView1.CalcHitInfo(e.Location);
            if (info.InRow)
            {
                GridView view = info.View as GridView;
                if (view != null)
                {
                    DataRow row = view.GetDataRow(info.RowHandle);
                    if (row != null)
                    {
                        string rowGuid = (row["guid"].ToString());
                        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_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 0);
        }
 
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString()))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + dr["userName"].ToString() + "】,确定删除吗?"))
                return;
            var _obj = new
            {
                guidList = dr["guid"].ToString(),//主建
            };
            string strJson = "";
            try
            {
                strJson = UtilityHelper.HttpPost("", "User/DeleteModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _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);
            }
        }
 
        /// <summary>
        /// 刷新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
        }
        /// <summary>
        /// 修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            DataRow dr = gridView1.GetFocusedDataRow();
            if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString()))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            getModel(dr["guid"].ToString(), true, 1);
        }
        /// <summary>
        /// 新增事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValue(this.panel1.Controls, true);
            txt_password.Visible = lbPwd.Visible = true;
        }
        /// <summary>
        /// 保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            if (string.IsNullOrEmpty(txt_account.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("登录账号不能为空!");
                txt_account.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_password.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("密码不能为空!");
                txt_password.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_userName.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("姓名不能为空!");
                txt_userName.Focus();
                return;
            }
            if (txt_isLocked.SelectedIndex <= 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("状态不能为空!");
                txt_isLocked.Focus();
                return;
            }
            var _obj = new
            {
                guid = lbGuid.Text.Trim(),//主建
                account = txt_account.Text.Trim(),
                password = txt_password.Text.Trim(),
                userName = txt_userName.Text.Trim(),
                address = txt_address.Text.Trim(),
                tel = txt_tel.Text.Trim(),
                email = txt_email.Text.Trim(),
                isLocked = txt_isLocked.SelectedIndex,
                flagAdmin = 0,
                flagOnline = 0,
                loginCounter = 0,
                workerID = "",
                remark = txt_remark.Text.Trim(),
                departGuid = "",
                isSys = 0
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "User/EditModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnable(this.panel1.Controls, false);
                }
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        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("", "User/GetListPage", json);
                ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn);
                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();
            }
            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("", "User/GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit);
                    txt_account.Enabled = false;
                    txt_password.Enabled = txt_password.Visible = lbPwd.Visible = tipPwd.Visible = false;
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                int rowhandle = gridView1.FocusedRowHandle;
                DataRow dr = gridView1.GetDataRow(rowhandle);
                string userGuid = dr["guid"].ToString();
                UserSelectRole frm = new UserSelectRole(userGuid);
                frm.ShowDialog();
            }
        }
    }
}