StableVersion4.3/HL_FristAidPlatform_Base/Form_ConfigMain.cs

346 lines
12 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.Web.UI.WebControls;
using System.Windows.Forms;
namespace HL_FristAidPlatform_Base
{
public partial class Form_ConfigMain : XtraForm
{
#region 变量
/// <summary>
/// 操作标记 1:新增 2:修改
/// </summary>
private int Flag = 0;
/// <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 strParameter = string.Empty;
//指定用户编号拥有所有系统参数设置权限,默认1,多个用户用#分割
if (!PublicHelp.IsHaveAllDistrictRightForConfigSet(Information.User.ID))
{
strParameter += "&isPublic=0";
}
else
{
strParameter += "&isPublic=-1";
}
if (!string.IsNullOrEmpty(txt_Key.Text.ToString().Trim()))
{
strParameter += "&keyWord=" + txt_Key.Text.ToString().Trim();
}
string Url = string.Format(string.Format("api/base/T_Base_Config?pageIndex={0}&pageSize={1}{2}", curPage, pageSize, strParameter));
DataTable ResultDT = DBHelpClass.Get(Url);
grid_Config.DataSource = ResultDT;//显示分页结果
grv_Config.BestFitColumns();//列宽自适应
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_ConfigMain()
{
InitializeComponent();
}
/// <summary>
/// 窗体加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form_ConfigMain_Load(object sender, EventArgs e)
{
RefreshGridList();
//详情控件初始化
PublicClass.EnabledControl(this.group_Detail, true, false);
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Select_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
RefreshGridList();
}
private void txt_Key_TextChanged(object sender, EventArgs 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_Detail, false, true);
txt_ID.Focus();
Flag = 1;
//指定用户编号拥有所有系统参数设置权限,默认1,多个用户用#分割
if (!PublicHelp.IsHaveAllDistrictRightForConfigSet(Information.User.ID))
{
ckb_IsPublic.Checked = true;
ckb_IsPublic.ReadOnly = true;
}
else
{
ckb_IsPublic.Checked = true;
ckb_IsPublic.ReadOnly = false;
}
}
/// <summary>
/// 修改
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
BindDetail();
PublicClass.EnabledControl(group_Detail, false, false);
txt_ID.ReadOnly = true;
//指定用户编号拥有所有系统参数设置权限,默认1,多个用户用#分割
if (!PublicHelp.IsHaveAllDistrictRightForConfigSet(Information.User.ID))
{
ckb_IsPublic.Checked = true;
ckb_IsPublic.ReadOnly = true;
}
else
{
ckb_IsPublic.Checked = true;
ckb_IsPublic.ReadOnly = false;
}
}
/// <summary>
/// 保存
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_Save_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
{
try
{
#region 保存
string Url = string.Empty;
if (string.IsNullOrEmpty(txt_ID.Text.ToString().Trim()))
{
XtraMessageBox.Show("参数编号不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_ID.Focus();
return;
}
else
{
if (Flag == 1)
{
#region 判断是否存在
DataTable CheckDT = DBHelpClass.GetDataRow(string.Format("api/base/T_Base_Config/{0}", txt_ID.Text.ToString().Trim()));
if (CheckDT != null && CheckDT.Rows.Count > 0)
{
XtraMessageBox.Show(string.Format("参数编号【{0}】已存在!请更换其他参数编号!", txt_ID.Text.ToString().Trim()), "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txt_ID.Focus();
return;
}
#endregion
}
}
List<T_Base_ConfigDTO> list = new List<T_Base_ConfigDTO>();
T_Base_ConfigDTO model = new T_Base_ConfigDTO();
if (Flag == 1)
{
Url = "api/base/T_Base_Config";
model.GUID = Guid.NewGuid().ToString();
model.CreationDate = PublicClass.DateTimeNow();
}
else
{
Url = "api/base/T_Base_Config/Update";
model.GUID = txt_ID.Tag.ToString();
model.CreationDate = txt_CreationDate.Text.ToString();
}
model.ID = Convert.ToInt32(txt_ID.Text.ToString());
model.Config = txt_Config.Text.ToString().Trim();
model.Note = txt_Note.Text.ToString().Trim();
model.IsPublic = ckb_IsPublic.Checked == true ? 0 : 1;
list.Add(model);
//初始化两个工厂
ClientFactory<T_Base_ConfigDTO> httpClient = new HttpClientFactory<T_Base_ConfigDTO>();
Client<T_Base_ConfigDTO> client = httpClient.VisitFactory();
//访问
ListEntity<T_Base_ConfigDTO> t = client.Post(Url, list);
if (t.Success)
{
XtraMessageBox.Show("保存参数配置信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
PublicClass.EnabledControl(this.group_Detail, true, false);
Flag = 0;
//列表分页数据绑定
RefreshGridList();
//定位
PublicClass.LocationForGridView(grv_Config, model.GUID, 1);
}
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)
{
Close();
}
private void grid_Config_MouseClick(object sender, MouseEventArgs e)
{
GridHitInfo hi = grv_Config.CalcHitInfo(new Point(e.X, e.Y));
//单击数据行
if (hi.InRow)//单击的是列头 hi.InColumn
{
PublicClass.EnabledControl(this.group_Detail, true, false);
BindDetail();
}
}
#region 方法
/// <summary>
/// 绑定详情
/// </summary>
private void BindDetail()
{
try
{
if (grv_Config.DataRowCount > 0)
{
int selectRow = grv_Config.GetSelectedRows()[0];
long ID = Convert.ToInt64(grv_Config.GetRowCellValue(selectRow, "ID").ToString());
DataTable DetailDT = DBHelpClass.GetDataRow(string.Format("/api/base/T_Base_Config/{0}", ID));
if (DetailDT != null && DetailDT.Rows.Count > 0)
{
Flag = 2;//修改标识
txt_ID.Tag = DetailDT.Rows[0]["GUID"].ToString();
txt_ID.Text = DetailDT.Rows[0]["ID"].ToString();
txt_Config.Text = DetailDT.Rows[0]["Config"].ToString();
txt_Note.Text = DetailDT.Rows[0]["Note"].ToString();
txt_CreationDate.Text = DetailDT.Rows[0]["CreationDate"].ToString();
ckb_IsPublic.Checked = DetailDT.Rows[0]["IsPublic"].ToString().Trim() == "0" ? true : false;
}
}
}
catch (Exception ex)
{
PublicClass.WriteErrorLog(this.Text, "绑定详情:\r\n" + ex);
}
}
#endregion
/// <summary>
/// 颜色绘制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void grv_Config_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
{
GridView View = sender as GridView;
if (e.Column.FieldName == "IsPublicCase")//设字体颜色
{
string cellValue = PublicClass.ToString(e.CellValue, "");
if (!string.IsNullOrEmpty(cellValue))
{
if (cellValue == "否")
{
e.Appearance.ForeColor = Color.Red;
}
}
}
}
}
}