| | |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraGrid.Columns; |
| | | using DevExpress.XtraGrid.Views.Grid; |
| | | using DevExpress.XtraGrid.Views.Base; |
| | | using Gs.DevApp.Models; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace Gs.DevApp.DevFrm.User |
| | |
| | | { |
| | | InitializeComponent(); |
| | | this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick; |
| | | PageBar1.williamPagerEvent += CtrlGridPaging1_williamPagerEvent; |
| | | GetPageList(1, 10); |
| | | |
| | | 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; |
| | | PageBar1.PagerEvent += PageBar1_PagerEvent; |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | } |
| | | |
| | | private void CtrlGridPaging1_williamPagerEvent(int curPage, int pageSize) |
| | | /// <summary> |
| | | /// 双击事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e) |
| | | { |
| | | //MessageBox.Show("当前页:" + curPage + ",每页展示:" + pageSize + "条"); |
| | | string rowGuid = ""; |
| | | ColumnView cv = (ColumnView)gcMain.FocusedView; |
| | | object rowIdObj = gridView1.GetRowCellValue(cv.FocusedRowHandle, "guid"); |
| | | DataRow myDataRow = gridView1.GetDataRow(gridView1.FocusedRowHandle); |
| | | rowGuid = myDataRow["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) |
| | | { |
| | | UserAdd frm = new UserAdd(""); |
| | | frm.ShowDialog(); |
| | | 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 |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | 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> |
| | | /// |
| | |
| | | /// <param name="pageSize">每页几条</param> |
| | | private void GetPageList(int curPage, int pageSize) |
| | | { |
| | | Models.PageQueryModel pgq = new Models.PageQueryModel(curPage, pageSize, "userName", "asc", "", ""); |
| | | Models.PageQueryModel pgq = new Models.PageQueryModel(curPage, pageSize, "createTime", "asc", "", ""); |
| | | string json = JsonConvert.SerializeObject(pgq); |
| | | string strReturn = ""; |
| | | try |
| | |
| | | strReturn = UtilityHelper.HttpPost("", "User/GetListPage", json); |
| | | ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData.list; |
| | | gc_Main.BindingContext = new BindingContext(); |
| | | gc_Main.DataSource = dt; |
| | | gc_Main.ForceInitialize(); |
| | | 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,//主建 |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | 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 = false; |
| | | } |
| | | else |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |