using System;
|
using System.Collections.Generic;
|
using System.Data;
|
using System.Threading.Tasks;
|
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;
|
|
namespace Gs.DevApp.DevFrm.User
|
{
|
public partial class User : XtraForm
|
{
|
private List<FilterEntity> _filterList = new List<FilterEntity>();
|
public User()
|
{
|
InitializeComponent();
|
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;
|
List<DevExpress.XtraGrid.Views.Grid.GridView> gvList = new List<DevExpress.XtraGrid.Views.Grid.GridView>();
|
gvList.Add(gridView1);
|
Gs.DevApp.ToolBox.UtilityHelper.getGridViewConfig(this.GetType().FullName, gvList);
|
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;
|
}
|
private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
|
{
|
Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1);
|
Task.Delay(100);
|
getPageList(1);
|
}
|
|
/// <summary>
|
/// 分页事件
|
/// </summary>
|
/// <param name="curPage"></param>
|
/// <param name="pageSize"></param>
|
private void PageBar1_PagerEvent(int curPage, int pageSize)
|
{
|
getPageList(curPage);
|
}
|
|
/// <summary>
|
/// 查询事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
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);
|
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);
|
}
|
|
/// <summary>
|
/// 取消事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
|
{
|
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1);
|
}
|
|
/// <summary>
|
/// 删除事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
|
{
|
string rowGuid, rowName;
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
|
lbGuid, txt_userName, gridView1, "userName");
|
if (string.IsNullOrEmpty(rowGuid))
|
{
|
MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
|
if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?"))
|
return;
|
var lst = new List<string>();
|
lst.Add(rowGuid);
|
var _obj = lst;
|
try
|
{
|
var strJson = UtilityHelper.HttpPost("", "User/DeleteModel",
|
JsonConvert.SerializeObject(_obj));
|
var _rtn = UtilityHelper.ReturnToDynamic(strJson);
|
if (_rtn.rtnCode > 0)
|
{
|
if (xtraTabControl1.SelectedTabPageIndex == 0)
|
{ }
|
else
|
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 2);
|
getPageList(this.pageBar1.CurrentPage);
|
}
|
|
MsgHelper.Warning("提示:" + _rtn.rtnMsg);
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
/// <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());
|
else
|
{
|
_filterList.Clear();
|
if (gridView1.ActiveFilter.Count > 0)
|
{
|
gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
|
gridView1.ActiveFilter.Clear();
|
gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
|
}
|
getPageList(1);
|
}
|
}
|
|
/// <summary>
|
/// 修改事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
|
{
|
string rowGuid, rowName;
|
(rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
|
lbGuid, txt_userName, gridView1);
|
if (string.IsNullOrEmpty(rowGuid))
|
{
|
MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3);
|
UtilityHelper.ChangeEnableByControl(panel1.Controls, true);
|
}
|
|
/// <summary>
|
/// 新增事件
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
|
{
|
lbGuid.Text = "";
|
Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4);
|
UtilityHelper.CleanValueByControl(panel1.Controls, true);
|
txt_password.Visible = lbPwd.Visible = true;
|
txt_account.Enabled = txt_password.Enabled = 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()))
|
{
|
MsgHelper.Warning("登录账号不能为空!");
|
txt_account.Focus();
|
return;
|
}
|
|
if (string.IsNullOrEmpty(txt_password.Text.Trim()))
|
{
|
MsgHelper.Warning("密码不能为空!");
|
txt_password.Focus();
|
return;
|
}
|
|
if (string.IsNullOrEmpty(txt_userName.Text.Trim()))
|
{
|
MsgHelper.Warning("姓名不能为空!");
|
txt_userName.Focus();
|
return;
|
}
|
|
var _obj = new
|
{
|
Guid = UtilityHelper.ToGuid(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(),
|
isStatus = txt_isStatus.Checked,
|
remark = txt_remark.Text.Trim(),
|
isSys = 0,
|
staffId = txt_staffId.GetId()
|
};
|
try
|
{
|
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(panel1.Controls, false);
|
}
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// </summary>
|
/// <param name="curPage">第几页</param>
|
/// <param name="pageSize">每页几条</param>
|
private void getPageList(int curPage)
|
{
|
var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList);
|
var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "a.ACCOUNT asc ,a.CREATE_TIME",
|
"desc", "", _sbSqlWhere.ToString());
|
var json = JsonConvert.SerializeObject(pgq);
|
try
|
{
|
var strReturn =
|
UtilityHelper.HttpPost("", "User/GetListPage", json);
|
var dd = UtilityHelper.ReturnToTablePage(strReturn);
|
if (dd.rtnCode > 0)
|
{
|
DataTable dt = dd.rtnData.list;
|
gcMain.BindingContext = new BindingContext();
|
gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
|
if (dt.Rows.Count > 0)
|
{
|
gcMain.DataSource = dt;
|
gcMain.ForceInitialize();
|
gridView1.BestFitColumns();
|
}
|
else
|
UtilityHelper.SetDefaultTable(gcMain, 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)
|
{
|
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))
|
{
|
MsgHelper.Warning("请先选择你要操作的行!");
|
return;
|
}
|
var _obj = new
|
{
|
guid = strGuid //主建
|
};
|
try
|
{
|
var strJson = UtilityHelper.HttpPost("", "User/GetModel",
|
JsonConvert.SerializeObject(_obj));
|
var _rtn = UtilityHelper.ReturnToDynamic(strJson);
|
if (_rtn.rtnCode > 0)
|
{
|
var dy = _rtn.rtnData;
|
lbGuid.Text = strGuid;
|
UtilityHelper.SetValueByObj(panel1.Controls, dy, isEdit);
|
txt_account.Enabled = txt_password.Enabled =
|
txt_password.Visible =
|
lbPwd.Visible = tipPwd.Visible = false;
|
}
|
else
|
{
|
MsgHelper.Warning("提示:" + _rtn.rtnMsg);
|
}
|
}
|
catch (Exception ex)
|
{
|
MsgHelper.Warning("提示:" + ex.Message);
|
}
|
}
|
/// <summary>
|
/// 角色
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
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();
|
}
|
}
|
/// <summary>
|
/// 密码
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
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();
|
}
|
}
|
/// <summary>
|
/// 个人权限
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void repositoryItemButtonEdit3_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 RoleSelectAction(userGuid);
|
frm.ShowDialog();
|
}
|
}
|
|
/// <summary>
|
/// 权限集合
|
/// </summary>
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
private void repositoryItemButtonEdit4_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 ViewRole(userGuid);
|
frm.ShowDialog();
|
}
|
}
|
}
|
}
|