StableVersion4.3/HL_FristAidPlatform_Base/Form_Hospital_TreatmentUnit...

537 lines
20 KiB
C#

using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using HL_FristAidPlatform_DTO;
using HL_FristAidPlatform_Public;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
namespace HL_FristAidPlatform_Base
{
public partial class Form_Hospital_TreatmentUnitMain : XtraForm
{
#region 变量
/// <summary>
/// 当前维护的通知类型 用于修改和单击列表
/// </summary>
private DataTable Cur_TreatmentUnit_DT = new DataTable();
/// <summary>
/// 当前页
/// </summary>
public int curPage = 1;
/// <summary>
/// 每页大小
/// </summary>
public int pageSize = 100;
/// <summary>
/// 所有记录条数
/// </summary>
public int totalNumber = 0;
#endregion
#region 分页实现
public void ExportEvents(bool singlePage)//单页,所有
{
//导出GridControl代码写在这。
}
public void RefreshGridList()
{
FillGridListCtrlQuery(curPage);//自己实现FillGridListCtrlQuery函数。
}
/// <summary>
/// 绑定数据源
/// </summary>
/// <returns></returns>
private void FillGridListCtrlQuery(int curPage)
{
try
{
string whereStr = string.Empty;
string HospitalGuid = PublicClass.ToString(lookUp_Sel_HospitalGuid.EditValue, "");
if (!string.IsNullOrEmpty(HospitalGuid))
{
whereStr += "&hospitalGuid=" + HospitalGuid;
}
string systemModuleID = PublicClass.ToString(lookUp_Sel_SystemModuleID.EditValue, "");
if (!string.IsNullOrEmpty(systemModuleID))
{
whereStr += "&systemModuleID=" + systemModuleID;
}
string Key = PublicClass.ToString(txt_Sel_Key.Text, "");
if (!string.IsNullOrEmpty(Key))
{
whereStr += "&key=" + Key;
}
DataTable ResultDT = DBHelpClass.Get(string.Format("api/base/T_Base_Hospital_TreatmentUnit?pageIndex={0}&pageSize={1}{2}", curPage, pageSize, whereStr));
grid_TreatmentUnit.DataSource = ResultDT;//显示分页结果
totalNumber = DBHelpClass.TotalNumber;
userControlForPage.RefreshPager(pageSize, totalNumber, curPage);//更新分页控件显示。
grv_TreatmentUnit.GroupPanelText = string.Format("统计:当前列表中共有【{0}】条数据。", totalNumber);
}
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_Hospital_TreatmentUnitMain()
{
InitializeComponent();
}
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_Hospital_TreatmentUnitMain_Load(object sender, EventArgs e)
{
BindData();
//详情控件初始化
PublicClass.EnabledControl(group_TreatmentUnit_Detail, true, false);
RefreshGridList();
}
/// <summary>
/// 窗体快捷键注册
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_Hospital_TreatmentUnitMain_KeyDown(object sender, KeyEventArgs e)
{
//同时按下 Ctrl+S 时执行保存方法
if (e.KeyCode == Keys.S && e.Control)
{
btn_Save_ItemClick(null, null);
}
}
#region BindData
/// <summary>
/// 查询绑定
/// </summary>
private void BindData()
{
BindHospital();
BindSystemModule();
}
/// <summary>
/// 绑定所属医院
/// </summary>
private void BindHospital()
{
try
{
DataTable ResultDT = DBHelpClass.Get("api/base/T_Base_Hospital/GetList");
PublicClass.SetLookUpList(ref lookUp_Sel_HospitalGuid, ResultDT, 1, 3, false, "请选择");
PublicClass.SetLookUpList(ref lookUp_HospitalGuid, ResultDT, 1, 3, false);
//没有所有院区权限 只读
if (!PublicHelp.IsHaveAllDistrictRight(Information.User.ID))
{
//lookUp_Sel_HospitalGuid.ReadOnly = true;
//lookUp_HospitalGuid.ReadOnly = true;
}
lookUp_Sel_HospitalGuid.EditValue = Information.Hospital.GUID;
lookUp_HospitalGuid.EditValue = Information.Hospital.GUID;
}
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?isOpen=0&deleteFlag=0");
PublicClass.SetLookUpList(ref lookUp_Sel_SystemModuleID, ResultDT, 3, 5, false);
PublicClass.SetLookUpList(ref lookUp_SystemModuleID, ResultDT, 3, 5, false);
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定所属系统模块:\r\n" + ex);
}
}
#endregion BindData
#region 菜单事件
/// <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 btn_Insert_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
PublicClass.EnabledControl(group_TreatmentUnit_Detail, false, true);
Cur_TreatmentUnit_DT = null;
//禁用修改按钮
btn_Update.Enabled = false;
btn_Delete.Enabled = false;
ckb_DeleteFlag.Checked = true;
}
/// <summary>
/// 修改事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Bind_Detail();
PublicClass.EnabledControl(group_TreatmentUnit_Detail, false, false);
btn_Insert.Enabled = false;
btn_Delete.Enabled = false;
}
/// <summary>
/// 删除事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Delete();
}
/// <summary>
/// 保存事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Save_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Save();
}
/// <summary>
/// 退出
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Exit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
Close();
}
/// <summary>
/// 关键词
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void txt_Sel_Key_Version_TextChanged(object sender, EventArgs e)
{
RefreshGridList();
}
/// <summary>
/// 单击显示详情
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void grid_TreatmentUnit_MouseClick(object sender, MouseEventArgs e)
{
try
{
GridHitInfo hi = grv_TreatmentUnit.CalcHitInfo(new Point(e.X, e.Y));
//单击数据行
if (hi.InRow)//单击的是列头 hi.InColumn
{
PublicClass.EnabledControl(this.group_TreatmentUnit_Detail, true, false);
Bind_Detail();
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "单击显示详情:\r\n" + ex);
}
}
#endregion
#region 方法
/// <summary>
/// 绑定详情
/// </summary>
private void Bind_Detail()
{
try
{
if (grv_TreatmentUnit.DataRowCount > 0)
{
int selectRow = grv_TreatmentUnit.GetSelectedRows()[0];
string ID = grv_TreatmentUnit.GetRowCellValue(selectRow, "ID").ToString();
Cur_TreatmentUnit_DT = DBHelpClass.GetDataRow(string.Format("api/base/T_Base_Hospital_TreatmentUnit/{0}", ID));
if (Cur_TreatmentUnit_DT != null && Cur_TreatmentUnit_DT.Rows.Count > 0)
{
string HospitalGuid = PublicClass.ToString(Cur_TreatmentUnit_DT.Rows[0]["HospitalGuid"], "-1");
lookUp_HospitalGuid.EditValue = HospitalGuid == "0" ? "-1" : HospitalGuid;
string SystemModuleID = PublicClass.ToString(Cur_TreatmentUnit_DT.Rows[0]["SystemModuleID"], "-1");
lookUp_SystemModuleID.EditValue = SystemModuleID == "0" ? "-1" : SystemModuleID;
txt_UnitName.Tag = Cur_TreatmentUnit_DT.Rows[0]["ID"].ToString();
txt_UnitName.Text = Cur_TreatmentUnit_DT.Rows[0]["UnitName"].ToString();
txt_ContactNumber.Tag = Cur_TreatmentUnit_DT.Rows[0]["GUID"].ToString();
txt_ContactNumber.Text = Cur_TreatmentUnit_DT.Rows[0]["ContactNumber"].ToString();
txt_Fax.Text = Cur_TreatmentUnit_DT.Rows[0]["Fax"].ToString();
txt_ContactAddress.Text = Cur_TreatmentUnit_DT.Rows[0]["ContactAddress"].ToString();
txt_Introduce.Text = Cur_TreatmentUnit_DT.Rows[0]["Introduce"].ToString();
txt_OrderBy.Text = Cur_TreatmentUnit_DT.Rows[0]["OrderBy"].ToString();
ckb_DeleteFlag.Checked = Cur_TreatmentUnit_DT.Rows[0]["DeleteFlag"].ToString().Trim() == "0" ? true : false;
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定详情:\r\n" + ex);
}
}
/// <summary>
/// 保存
/// </summary>
private void Save()
{
try
{
#region 保存
if (PublicClass.ToString(lookUp_HospitalGuid.EditValue, "-1") == "-1")
{
XtraMessageBox.Show("请选择所属医院!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lookUp_HospitalGuid.Focus();
return;
}
if (PublicClass.ToString(lookUp_SystemModuleID.EditValue, "-1") == "-1")
{
XtraMessageBox.Show("请选择所属系统!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
lookUp_SystemModuleID.Focus();
return;
}
if (string.IsNullOrEmpty(txt_UnitName.Text.Trim()))
{
XtraMessageBox.Show("单元名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_UnitName.Focus();
return;
}
List<T_Base_Hospital_TreatmentUnitDTO> list = new List<T_Base_Hospital_TreatmentUnitDTO>();
T_Base_Hospital_TreatmentUnitDTO model = new T_Base_Hospital_TreatmentUnitDTO();
string Url = string.Empty;
if (Cur_TreatmentUnit_DT != null && Cur_TreatmentUnit_DT.Rows.Count > 0)
{
Url = "api/base/T_Base_Hospital_TreatmentUnit/UpdateNotNullColumns";
model.ID = Convert.ToInt32(txt_UnitName.Tag.ToString());
model.GUID = txt_ContactNumber.Tag.ToString();
model.DeleteFlag = PublicClass.ToInt32(Cur_TreatmentUnit_DT.Rows[0]["DeleteFlag"], 0);
model.CreatorID = PublicClass.ToInt64(Cur_TreatmentUnit_DT.Rows[0]["CreatorID"], 0);
model.CreationDate = Cur_TreatmentUnit_DT.Rows[0]["CreationDate"].ToString();
}
else
{
Url = "api/base/T_Base_Hospital_TreatmentUnit/AddNotNullColumns";
model.GUID = Guid.NewGuid().ToString();
model.DeleteFlag = 0;
model.CreationDate = DateTime.Now.ToString();
}
model.HospitalGuid = PublicClass.ToString(lookUp_HospitalGuid.EditValue, "");
long SystemModuleID = PublicClass.ToInt64(lookUp_SystemModuleID.EditValue, -1);
model.SystemModuleID = SystemModuleID == -1 ? 0 : SystemModuleID;
model.UnitName = txt_UnitName.Text.Trim();
model.ContactNumber = txt_ContactNumber.Text.Trim();
model.Fax = txt_Fax.Text.Trim();
model.ContactAddress = txt_ContactAddress.Text.Trim();
model.Introduce = txt_Introduce.Text.Trim();
model.OrderBy = Convert.ToInt32(txt_OrderBy.Text.ToString().Trim() == "" ? "0" : txt_OrderBy.Text.ToString().Trim());
model.DeleteFlag = ckb_DeleteFlag.Checked == true ? 0 : 1;
list.Add(model);
//初始化两个工厂
ClientFactory<T_Base_Hospital_TreatmentUnitDTO> httpClient = new HttpClientFactory<T_Base_Hospital_TreatmentUnitDTO>();
Client<T_Base_Hospital_TreatmentUnitDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_Base_Hospital_TreatmentUnitDTO> t = client.Post(Url, list);
if (t.Success)
{
PublicClass.EnabledControl(group_TreatmentUnit_Detail, true, false);
if (Cur_TreatmentUnit_DT != null && Cur_TreatmentUnit_DT.Rows.Count > 0)
{
XtraMessageBox.Show("保存成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
//保存成功刷新列表
RefreshGridList();
//定位
PublicClass.LocationForGridView(grv_TreatmentUnit, model.GUID, 1);
//启用
btn_Insert.Enabled = true;
btn_Update.Enabled = true;
btn_Delete.Enabled = true;
}
else
{
XtraMessageBox.Show("保存失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "保存:\r\n" + ex);
}
}
/// <summary>
/// 删除
/// </summary>
private void Delete()
{
try
{
#region 删除
if (grv_TreatmentUnit.DataRowCount > 0)
{
int selectRow = grv_TreatmentUnit.GetSelectedRows()[0];
string GUID = grv_TreatmentUnit.GetRowCellValue(selectRow, "GUID").ToString();
string UnitName = grv_TreatmentUnit.GetRowCellValue(selectRow, "UnitName").ToString();
if (string.IsNullOrEmpty(GUID))
{
XtraMessageBox.Show("请先选择要删除的救治单元!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
if (XtraMessageBox.Show(string.Format("确定要删除救治单元【{0}】?", UnitName), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
List<GUIDDTO> list = new List<GUIDDTO>();
GUIDDTO model = new GUIDDTO();
string Url = "api/base/T_Base_Hospital_TreatmentUnit/LogicalDelete";
model.GUID = GUID;
list.Add(model);
//初始化两个工厂
ClientFactory<GUIDDTO> httpClient = new HttpClientFactory<GUIDDTO>();
Client<GUIDDTO> client = httpClient.VisitFactory();
//访问
ListEntity<GUIDDTO> t = client.Post(Url, list);
if (t.Success)
{
XtraMessageBox.Show("删除救治单元成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
PublicClass.EnabledControl(this.group_TreatmentUnit_Detail, true, false);
RefreshGridList();
}
else
{
XtraMessageBox.Show("删除救治单元失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
#endregion
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex);
}
}
#endregion 方法
/// <summary>
/// 自定义显示列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void grv_TreatmentUnit_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 = "";
}
}
}
}
}