StableVersion4.3/HL_FristAidPlatform_SYS/Form_UserMain.cs

673 lines
24 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DevExpress.XtraEditors;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
namespace HL_FristAidPlatform_SYS
{
public partial class Form_UserMain : XtraForm
{
#region 变量
/// <summary>
/// 当前页
/// </summary>
private int curPage = 1;
/// <summary>
/// 每页大小
/// </summary>
private int pageSize = 100;
/// <summary>
/// 所有记录条数
/// </summary>
private int totalNumber = 0;
/// <summary>
/// 当前用户编号
/// </summary>
private long Cur_UserId = 0;
/// <summary>
/// 当前对应账号数据源
/// </summary>
private DataTable Cur_UserMatchCentre_List = new DataTable();
/// <summary>
/// 当前对应账号数据源 单个操作
/// </summary>
private DataTable Cur_UserMatchCentreDT = new DataTable();
#endregion
#region 分页实现
public void ExportEvents(bool singlePage)//单页,所有
{
//导出GridControl代码写在这。
}
public void RefreshGridList()
{
FillGridListCtrlQuery(curPage);//自己实现FillGridListCtrlQuery函数。
}
/// <summary>
/// 绑定数据源
/// </summary>
/// <returns></returns>
private void FillGridListCtrlQuery(int curPage)
{
try
{
int gender = PublicClass.ToInt32(lookUpEdit_SelGender.EditValue, -1);
string keyStr = txt_Key.Text.ToString().Trim();
DataTable ResultDT = DBHelpClass.Get(string.Format("api/admin/T_SYS_User?pageIndex={0}&pageSize={1}&gender={2}&keyWord={3}", curPage, pageSize, gender, keyStr));
grid_User.DataSource = ResultDT;//显示分页结果
totalNumber = DBHelpClass.TotalNumber;
userControlForPage.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示。
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定数据源:\r\n" + ex);
}
}
private void MyPagerEvents(int curPage, int pageSize)
{
this.curPage = curPage;
this.pageSize = pageSize;
FillGridListCtrlQuery(curPage);
}
private void userControlForPage_exportEvents(bool singlePage)
{
userControlForPage.exportEvents += ExportEvents;
}
private void userControlForPage_myPagerEvents(int curPage, int pageSize)
{
userControlForPage.myPagerEvents += MyPagerEvents;
}
#endregion
public Form_UserMain()
{
InitializeComponent();
}
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_UserMain_Load(object sender, EventArgs e)
{
BindData();
RereadOnly(true, false);
//列表分页数据绑定
RefreshGridList();
txt_Key.Focus();
}
#region 绑定数据
/// <summary>
/// 绑定数据
/// </summary>
private void BindData()
{
BindGender();
BindSystemModule();
}
/// <summary>
/// 绑定性别
/// </summary>
private void BindGender()
{
try
{
DataTable GenderDT = DBHelpClass.Get("/api/base/T_Base_Gender/GetList");
PublicClass.SetLookUpList(ref lookUpEdit_SelGender, GenderDT, 1, 2, true, "全部");
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定性别:\r\n" + ex);
}
}
/// <summary>
/// 绑定所属系统模块
/// </summary>
private void BindSystemModule()
{
try
{
DataTable ResultDT = DBHelpClass.Get("/api/admin/T_SYS_SystemModule/GetIsHaveTimeAxisList?isHaveTimeAxis=0");
PublicClass.SetLookUpList(lookUp_Sel_SystemModuleID, ResultDT, "ID", "ShortName", true, "请选择");
PublicClass.SetLookUpList(lookUp_SystemModuleID, ResultDT, "ID", "ShortName", true);
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定所属系统模块:\r\n" + ex);
}
}
#endregion
#region 用户
/// <summary>
/// 关键词更改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txt_Key_TextChanged(object sender, EventArgs e)
{
//列表分页数据绑定
RefreshGridList();
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Select_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
//列表分页数据绑定
RefreshGridList();
}
/// <summary>
/// 性别选择
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lookUpEdit_SelGender_Closed(object sender, DevExpress.XtraEditors.Controls.ClosedEventArgs e)
{
RefreshGridList();
}
/// <summary>
/// 新增
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Insert_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Form_UserEdit frm = new Form_UserEdit(1);
if (frm.ShowDialog() == DialogResult.OK)
{
//列表分页数据绑定
RefreshGridList();
}
}
/// <summary>
/// 修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
if (grv_User.DataRowCount > 0)
{
int selectRow = grv_User.GetSelectedRows()[0];
long ID = Convert.ToInt64(grv_User.GetRowCellValue(selectRow, "ID").ToString());
Form_UserEdit frm = new Form_UserEdit(2, ID);
if (frm.ShowDialog() == DialogResult.OK)
{
//列表分页数据绑定
RefreshGridList();
//定位
PublicClass.LocationForGridView(grv_User, ID.ToString(), 0);
}
}
}
/// <summary>
/// 删除
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
#region 删除
if (grv_User.DataRowCount > 0)
{
int selectRow = grv_User.GetSelectedRows()[0];
long ID = Convert.ToInt64(grv_User.GetRowCellValue(selectRow, "ID").ToString());
string LoginName = grv_User.GetRowCellValue(selectRow, "LoginName").ToString();
if (ID == 0)
{
XtraMessageBox.Show("请先选择要删除的用户!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (XtraMessageBox.Show(string.Format("确定要删除用户【{0}】?", LoginName), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
List<T_SYS_UserDTO> list = new List<T_SYS_UserDTO>();
T_SYS_UserDTO model = new T_SYS_UserDTO();
string Url = "api/admin/T_SYS_User/LogicalDelete";
model.ID = ID;
model.DeleteFlag = 1;
list.Add(model);
//初始化两个工厂
ClientFactory<T_SYS_UserDTO> httpClient = new HttpClientFactory<T_SYS_UserDTO>();
Client<T_SYS_UserDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_SYS_UserDTO> t = client.Post(Url, list);
if (t.Success)
{
XtraMessageBox.Show("删除用户成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//列表分页数据绑定
RefreshGridList();
}
else
{
XtraMessageBox.Show("删除用户失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex);
}
}
/// <summary>
/// 退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Exit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
this.Close();
}
/// <summary>
/// 单击用户列表绑定对应列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void grid_User_MouseClick(object sender, MouseEventArgs e)
{
try
{
if (grv_User.DataRowCount > 0)
{
int selectRow = grv_User.GetSelectedRows()[0];
Cur_UserId = PublicClass.ToInt64(grv_User.GetRowCellValue(selectRow, "ID"), 0);
BindList_MatchCentre(Cur_UserId);
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "单击用户列表绑定对应列表:\r\n" + ex);
}
}
#endregion 用户
#region 匹配
/// <summary>
/// 平台类型筛选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void lookUp_Sel_SystemModuleID_EditValueChanged(object sender, EventArgs e)
{
BindList_MatchCentre(Cur_UserId);
}
/// <summary>
/// 新增
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_MatchCentre_Add_Click(object sender, EventArgs e)
{
RereadOnly(false, true);
Cur_UserMatchCentreDT = null;
btn_MatchCentre_Update.Enabled = false;
btn_MatchCentre_Delete.Enabled = false;
}
/// <summary>
/// 修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_MatchCentre_Update_Click(object sender, EventArgs e)
{
BindDetail_MatchCentre();
RereadOnly(false, false);
btn_MatchCentre_Add.Enabled = false;
btn_MatchCentre_Delete.Enabled = false;
}
/// <summary>
/// 删除对应账号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_MatchCentre_Delete_Click(object sender, EventArgs e)
{
try
{
#region 删除
if (grv_MatchCentre.DataRowCount > 0)
{
int selectRow = grv_MatchCentre.GetSelectedRows()[0];
string Guid = PublicClass.ToString(grv_MatchCentre.GetRowCellValue(selectRow, "GUID"), "");
string CentreUser = PublicClass.ToString(grv_MatchCentre.GetRowCellValue(selectRow, "CentreUser"), "");
if (string.IsNullOrEmpty(Guid))
{
XtraMessageBox.Show("请先选择要删除的对应账号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (XtraMessageBox.Show(string.Format("确定要删除对应账号【{0}】?", CentreUser), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
List<T_SYS_UserMatchCentreDTO> list = new List<T_SYS_UserMatchCentreDTO>();
T_SYS_UserMatchCentreDTO model = new T_SYS_UserMatchCentreDTO();
string Url = "api/admin/T_SYS_UserMatchCentre/LogicalDelete";
model.GUID = Guid;
model.DeleteFlag = 1;
list.Add(model);
//初始化两个工厂
ClientFactory<T_SYS_UserMatchCentreDTO> httpClient = new HttpClientFactory<T_SYS_UserMatchCentreDTO>();
Client<T_SYS_UserMatchCentreDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_SYS_UserMatchCentreDTO> t = client.Post(Url, list);
if (t.Success)
{
XtraMessageBox.Show("删除对应账号成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
RereadOnly(true, true);
BindList_MatchCentre(Cur_UserId);
}
else
{
XtraMessageBox.Show("删除对应账号失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "删除对应账号:\r\n" + ex);
}
}
/// <summary>
/// 保存对应账号
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_MatchCentre_Save_Click(object sender, EventArgs e)
{
try
{
#region 保存
if (Cur_UserId == 0)
{
XtraMessageBox.Show("请在左侧用户列表中选择对应的用户账号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string SystemModuleID = PublicClass.ToString(lookUp_SystemModuleID.EditValue, "-1");
if (SystemModuleID == "-1")
{
XtraMessageBox.Show("请选择平台类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lookUp_SystemModuleID.Focus();
return;
}
if (string.IsNullOrEmpty(txt_CentreUser.Text.ToString().Trim()))
{
XtraMessageBox.Show("对应账号名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_CentreUser.Focus();
return;
}
//新增时判断
if (Cur_UserMatchCentreDT == null)
{
if (Cur_UserMatchCentre_List != null && Cur_UserMatchCentre_List.Rows.Count > 0)
{
//判断是否存在当前院区
string whereStr = string.Format("UserID={0} And SystemModuleID={1}", Cur_UserId, SystemModuleID);
DataRow[] drs = Cur_UserMatchCentre_List.Select(whereStr);
if (drs.Length > 0)
{
XtraMessageBox.Show(string.Format("当前用户已经匹配{0}平台账号!", lookUp_SystemModuleID.Text), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
}
}
#region 存储到数据库
List<T_SYS_UserMatchCentreDTO> list = new List<T_SYS_UserMatchCentreDTO>();
T_SYS_UserMatchCentreDTO model = new T_SYS_UserMatchCentreDTO();
string Url = string.Empty;
if (Cur_UserMatchCentreDT != null && Cur_UserMatchCentreDT.Rows.Count > 0)
{
Url = "/api/admin/T_SYS_UserMatchCentre/UpdateNotNullColumns";
model.GUID = txt_CentreUser.Tag.ToString();
model.DeleteFlag = PublicClass.ToInt32(Cur_UserMatchCentreDT.Rows[0]["DeleteFlag"], 0);
model.CreatorID = PublicClass.ToInt32(Cur_UserMatchCentreDT.Rows[0]["CreatorID"], 0);
model.EditorID = Information.User.ID;
model.Editor = Information.User.FullName;
model.EditTime = PublicClass.DateTimeNow();
}
else
{
Url = "api/admin/T_SYS_UserMatchCentre/AddNotNullColumns";
model.GUID = Guid.NewGuid().ToString();
model.DeleteFlag = 0;
model.CreatorID = Information.User.ID;
model.Creator = Information.User.FullName;
model.CreationDate = PublicClass.DateTimeNow();
}
model.SystemModuleID = PublicClass.ToInt64(lookUp_SystemModuleID.EditValue, 0);
model.UserID = Cur_UserId;
model.CentreUser = txt_CentreUser.Text.Trim();
model.Remark = txt_Remark.Text.Trim();
list.Add(model);
//初始化两个工厂
ClientFactory<T_SYS_UserMatchCentreDTO> httpClient = new HttpClientFactory<T_SYS_UserMatchCentreDTO>();
Client<T_SYS_UserMatchCentreDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_SYS_UserMatchCentreDTO> t = client.Post(Url, list);
if (t.Success)
{
XtraMessageBox.Show("保存对应账号成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
RereadOnly(true, true);
BindList_MatchCentre(Cur_UserId);
btn_MatchCentre_Delete.Enabled = true;
btn_MatchCentre_Add.Enabled = true;
btn_MatchCentre_Update.Enabled = true;
//定位
PublicClass.LocationForGridView(grv_MatchCentre, model.GUID, 0);
}
else
{
XtraMessageBox.Show("保存对应账号失败(请确保账号名称唯一)", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endregion
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "保存对应账号:\r\n" + ex);
}
}
/// <summary>
/// 绑定账号对应列表
/// </summary>
private void BindList_MatchCentre(long userId)
{
try
{
if (userId > 0)
{
string whereStr = string.Empty;
long systemModuleID = PublicClass.ToInt64(lookUp_Sel_SystemModuleID.EditValue, 0);
if (systemModuleID > 0)
{
whereStr += "&systemModuleId=" + systemModuleID;
}
Cur_UserMatchCentre_List = DBHelpClass.Get(string.Format("api/admin/T_SYS_UserMatchCentre/GetByUserID?userId={0}{1}", userId, whereStr));
}
grid_MatchCentre.DataSource = Cur_UserMatchCentre_List;//显示分页结果
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定数据源:\r\n" + ex);
}
}
/// <summary>
/// 绑定对应详情
/// </summary>
private void BindDetail_MatchCentre()
{
try
{
#region 绑定详情
if (grv_MatchCentre.DataRowCount > 0)
{
RereadOnly(true, false);
int selectRow = grv_MatchCentre.GetSelectedRows()[0];
string Guid = PublicClass.ToString(grv_MatchCentre.GetRowCellValue(selectRow, "GUID"), "");
Cur_UserMatchCentreDT = DBHelpClass.GetDataRow(string.Format("api/admin/T_SYS_UserMatchCentre/{0}", Guid));
if (Cur_UserMatchCentreDT != null && Cur_UserMatchCentreDT.Rows.Count > 0)
{
lookUp_SystemModuleID.EditValue = PublicClass.ToString(Cur_UserMatchCentreDT.Rows[0]["SystemModuleID"], "-1");
txt_CentreUser.Tag = PublicClass.ToString(Cur_UserMatchCentreDT.Rows[0]["GUID"], "");
txt_CentreUser.Text = PublicClass.ToString(Cur_UserMatchCentreDT.Rows[0]["CentreUser"], "");
txt_Remark.Text = PublicClass.ToString(Cur_UserMatchCentreDT.Rows[0]["Remark"], "");
}
}
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定详情:\r\n" + ex);
}
}
/// <summary>
/// 自定义显示列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void grv_MatchCentre_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
//患者自愿放弃后续治疗
if (e.Column.FieldName == "SystemModuleID")
{
string value = PublicClass.ToString(e.Value, "");
if (value == PublicClassForDataBase.Config10001)
{
e.DisplayText = "胸痛中心";
}
else if (value == PublicClassForDataBase.Config10002)
{
e.DisplayText = "卒中中心";
}
else if (value == PublicClassForDataBase.Config10003)
{
e.DisplayText = "创伤救治中心";
}
else if (value == PublicClassForDataBase.Config10004)
{
e.DisplayText = "危重孕产妇中心";
}
else if (value == PublicClassForDataBase.Config10005)
{
e.DisplayText = "危重新生儿中心";
}
else
{
e.DisplayText = "";
}
}
}
/// <summary>
/// 单击显示详情
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void grid_MatchCentre_MouseClick(object sender, MouseEventArgs e)
{
BindDetail_MatchCentre();
btn_MatchCentre_Delete.Enabled = true;
btn_MatchCentre_Add.Enabled = true;
btn_MatchCentre_Update.Enabled = true;
}
/// <summary>
/// 控件显示隐藏
/// </summary>
/// <param name="isbool"></param>
private void RereadOnly(bool isbool, bool isClear)
{
lookUp_SystemModuleID.ReadOnly = isbool;
txt_CentreUser.ReadOnly = isbool;
txt_Remark.ReadOnly = isbool;
if (isClear)
{
lookUp_SystemModuleID.EditValue = "-1";
txt_CentreUser.Text = "";
txt_Remark.Text = "";
}
}
#endregion 匹配
}
}