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());
}
///
/// 双击事件
///
///
///
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);
}
}
}
}
///
/// 分页事件
///
///
///
private void PageBar1_PagerEvent(int curPage, int pageSize)
{
getPageList(curPage, pageSize);
}
///
/// 取消事件
///
///
///
private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
{
UtilityHelper.ChangeTab(xtraTabControl1, 0);
}
///
/// 删除事件
///
///
///
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 _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);
}
}
///
/// 刷新事件
///
///
///
private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
{
UtilityHelper.ChangeTab(xtraTabControl1, 0);
getPageList(1, UtilityHelper.GetPageSize());
}
///
/// 修改事件
///
///
///
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);
}
///
/// 新增事件
///
///
///
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;
}
///
/// 保存事件
///
///
///
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 _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);
}
}
///
///
///
/// 第几页
/// 每页几条
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 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 _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();
}
}
}
}