啊鑫
2024-10-25 cefcc903f51610846fa313a3a35bca34e129c1fe
DevApp/Gs.DevApp/DevFrm/User/User.cs
@@ -1,28 +1,31 @@

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using Gs.DevApp.Entity;
using Gs.DevApp.ToolBox;
using Gs.DevApp.UserControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace Gs.DevApp.DevFrm.User
{
    public partial class User : DevExpress.XtraEditors.XtraForm
    public partial class User : XtraForm
    {
        List<FilterEntity> _filterList = new List<FilterEntity>();
        private List<FilterEntity> _filterList = new List<FilterEntity>();
        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;
            this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
            toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
            toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
            toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            getPageList(1, UtilityHelper.GetPageSize());
            pageBar1.PagerEvent += PageBar1_PagerEvent;
@@ -30,15 +33,14 @@
            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);
                var str = "暂未查找到匹配的数据!";
                var f = new Font("微软雅黑", 16);
                var 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);
            };
        }
@@ -50,10 +52,12 @@
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            string rowGuid = Gs.DevApp.ToolBox.UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
            var rowGuid =
                UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
            if (!string.IsNullOrEmpty(rowGuid))
                getModel(rowGuid, false, 999);
        }
        /// <summary>
        /// 分页事件
        /// </summary>
@@ -63,6 +67,7 @@
        {
            getPageList(curPage, pageSize);
        }
        /// <summary>
        /// 查询事件
        /// </summary>
@@ -70,10 +75,11 @@
        /// <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);
            var frm = new ShowFilter(gridView1.Columns, _filterList);
            frm.UpdateParent += Frm_UpdateParent;
            frm.ShowDialog();
        }
        /// <summary>
        /// 查询回调
        /// </summary>
@@ -103,31 +109,35 @@
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_userName, gridView1);
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_userName, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
                return;
            List<string> lst = new List<string>();
            var lst = new List<string>();
            lst.Add(rowGuid);
            var _obj = lst;
            try
            {
                string strJson = UtilityHelper.HttpPost("", "User/DeleteModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                var strJson = UtilityHelper.HttpPost("", "User/DeleteModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getPageList(1, UtilityHelper.GetPageSize());
                }
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
@@ -141,6 +151,7 @@
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
        }
        /// <summary>
        /// 修改事件
        /// </summary>
@@ -149,14 +160,17 @@
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_userName, gridView1);
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_userName, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            getModel(rowGuid, true, 1);
        }
        /// <summary>
        /// 新增事件
        /// </summary>
@@ -166,10 +180,11 @@
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValueByControl(this.panel1.Controls, true);
            UtilityHelper.CleanValueByControl(panel1.Controls, true);
            txt_password.Visible = lbPwd.Visible = true;
            txt_account.Enabled = txt_password.Enabled = true;
        }
        /// <summary>
        /// 保存事件
        /// </summary>
@@ -180,22 +195,25 @@
            toolBarMenu1.isSetBtn = false;
            if (string.IsNullOrEmpty(txt_account.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("登录账号不能为空!");
                MsgHelper.Warning("登录账号不能为空!");
                txt_account.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_password.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("密码不能为空!");
                MsgHelper.Warning("密码不能为空!");
                txt_password.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_userName.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("姓名不能为空!");
                MsgHelper.Warning("姓名不能为空!");
                txt_userName.Focus();
                return;
            }
            var _obj = new
            {
                guid = lbGuid.Text.Trim(),//主建
@@ -211,45 +229,46 @@
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "User/EditModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                var strJson = UtilityHelper.HttpPost("", "User/EditModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnableByControl(this.panel1.Controls, false);
                    UtilityHelper.ChangeEnableByControl(panel1.Controls, false);
                }
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        /// <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_TIME", "asc", "", _sbSqlWhere.ToString());
            string json = JsonConvert.SerializeObject(pgq);
            var _sbSqlWhere = new StringBuilder();
            foreach (var itm in _filterList)
                _sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" +
                                   itm.fileValue + "'");
            var pgq = new PageQueryModel(curPage, pageSize, "CREATE_TIME",
                "asc", "", _sbSqlWhere.ToString());
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                string strReturn = UtilityHelper.HttpPost("", "User/GetListPage", json);
                ReturnModel<PageListModel> dd = UtilityHelper.ReturnToTablePage(strReturn);
                DataTable dt = dd.rtnData.list;
                var strReturn =
                    UtilityHelper.HttpPost("", "User/GetListPage", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = dt;
                gcMain.ForceInitialize();
                int dddd = dd.rtnData.pages;//总页
                var dddd = dd.rtnData.pages; //总页
                pageBar1.TotalPages = dddd;
                pageBar1.RecordCount = dd.rtnData.total;//记录总数
                pageBar1.CurrentPage = curPage;//当前页
@@ -258,62 +277,72 @@
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void getModel(string strGuid, bool isEdit, int tabIdx)
        {
            if (string.IsNullOrEmpty(strGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid,//主建
                guid = strGuid //主建
            };
            try
            {
                string strJson = UtilityHelper.HttpPost("", "User/GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson);
                var strJson = UtilityHelper.HttpPost("", "User/GetModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    var dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit);
                    txt_account.Enabled = txt_password.Enabled = txt_password.Visible = lbPwd.Visible = tipPwd.Visible = false;
                    UtilityHelper.SetValueByObj(panel1.Controls, dy, isEdit);
                    txt_account.Enabled = txt_password.Enabled =
                        txt_password.Visible =
                            lbPwd.Visible = tipPwd.Visible = false;
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                {
                    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();
            }
        }
        private void repositoryItemButtonEdit2_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();
                Gs.DevApp.DevFrm.User.UserSetPwd frm = new Gs.DevApp.DevFrm.User.UserSetPwd(userGuid);
                frm.ShowDialog();
            }
        }
                MsgHelper.Warning("提示:" + ex.Message);
    }
}
        private void repositoryItemButtonEdit1_ButtonClick(object sender,
            ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                var rowhandle = gridView1.FocusedRowHandle;
                var dr = gridView1.GetDataRow(rowhandle);
                var userGuid = dr["guid"].ToString();
                var frm = new UserSelectRole(userGuid);
                frm.ShowDialog();
            }
        }
        private void repositoryItemButtonEdit2_ButtonClick(object sender,
            ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                var rowhandle = gridView1.FocusedRowHandle;
                var dr = gridView1.GetDataRow(rowhandle);
                var userGuid = dr["guid"].ToString();
                var frm = new UserSetPwd(userGuid);
                frm.ShowDialog();
            }
        }
    }
}