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_RfidInstallationAddr : XtraForm { #region 变量 /// /// 操作标记 1:新增 2:修改 /// private int Flag = 0; #endregion public Form_RfidInstallationAddr() { InitializeComponent(); } private void Form_RfidInstallationAddr_Load(object sender, EventArgs e) { PublicClass.EnabledControl(group_Detail, true, false); BindData(); //筛选条件中所属模块默认当前选择的系统 LUEdit_SelSystemModule.EditValue = PublicClassForDataBase.Config104; BindList(); } private void LUEdit_SelSystemModule_EditValueChanged(object sender, EventArgs e) { BindList(); } private void txt_Key_TextChanged(object sender, EventArgs e) { BindList(); } private void cmb_DeleteFlag_SelectedIndexChanged(object sender, EventArgs e) { BindList(); } /// /// 查询 /// /// /// private void btn_Select_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { BindList(); } /// /// 新增 /// /// /// private void btn_Insert_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { PublicClass.EnabledControl(group_Detail, false, true); txt_CreationDate.ReadOnly = true; txt_CreationDate.Text = PublicClass.DateTimeNow(); txt_Creator.Text = Information.User.FullName; ckb_DeleteFlag.Checked = true; Flag = 1; txt_Code.Focus(); } /// /// 修改 /// /// /// private void btn_Update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { BindDetail(); PublicClass.EnabledControl(group_Detail, false, false); txt_Code.Focus(); } /// /// 保存 /// /// /// private void btn_Save_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { #region 保存 #region 验证 if (string.IsNullOrEmpty(txt_Code.Text.ToString().Trim())) { XtraMessageBox.Show("RFID用户码标志不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_Code.Focus(); return; } if (PublicClass.ToString(LUEdit_SystemModule.EditValue, "-1") == "-1") { XtraMessageBox.Show("请选择所属系统/模块!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); LUEdit_SystemModule.Focus(); return; } if (PublicClass.ToString(LUEdit_TimeAxisID.EditValue, "-1") == "-1") { XtraMessageBox.Show("请选择对应的时间节点!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); LUEdit_TimeAxisID.Focus(); return; } #endregion List list = new List(); T_Base_RfidInstallationAddrDTO model = new T_Base_RfidInstallationAddrDTO(); string Url = string.Empty; if (Flag == 1) { Url = "api/base/T_Base_RfidInstallationAddr"; model.GUID = Guid.NewGuid().ToString(); model.CreationDate = PublicClass.DateTimeNow(); model.CreatorID = Information.User.ID; } else { Url = "api/base/T_Base_RfidInstallationAddr/Update"; model.ID = PublicClass.ToInt64(txt_CreationDate.Tag, 0); model.GUID = txt_Code.Tag.ToString(); model.CreationDate = txt_CreationDate.Text.ToString(); model.CreatorID = Convert.ToInt64(txt_Creator.Tag.ToString()); } model.Code = txt_Code.Text.ToString().Trim(); model.SystemModuleID = PublicClass.ToInt64(LUEdit_SystemModule.EditValue, 0); model.TimeAxisID = PublicClass.ToInt64(LUEdit_TimeAxisID.EditValue, 0); model.Address = txt_Address.Text.ToString(); model.Remarks = txt_Remarks.Text.ToString(); model.DeleteFlag = ckb_DeleteFlag.Checked == true ? 0 : 1; model.Creator = txt_Creator.Text.ToString(); list.Add(model); string CheckUrl = string.Format("/api/base/T_Base_RfidInstallationAddr/ValidityJudgment?id={0}&code={1}&systemModuleID={2}&timeAxisID={3}", model.ID, model.Code, model.SystemModuleID, model.TimeAxisID); DataTable CheckDT = DBHelpClass.Get(CheckUrl); //有数据不能修改 if (CheckDT != null && CheckDT.Rows.Count > 0) { XtraMessageBox.Show("保存失败,系统中已经存在相同配置,请勿重复添加!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { //初始化两个工厂 ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); //访问 ListEntity t = client.Post(Url, list); if (t.Success) { XtraMessageBox.Show("保存RFID设备安装地址信息管理信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); PublicClass.EnabledControl(this.group_Detail, true, false); Flag = 0; BindList(); btn_Delete.Enabled = true; //定位 PublicClass.LocationForGridView(grv_RfidInstallationAddr, model.GUID, 1); } else { XtraMessageBox.Show("保存失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "保存:\r\n" + ex); } } /// /// 退出 /// /// /// private void btn_Exit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { Close(); } private void grid_RfidInstallationAddr_MouseClick(object sender, MouseEventArgs e) { try { GridHitInfo hi = grv_RfidInstallationAddr.CalcHitInfo(new Point(e.X, e.Y)); //单击数据行 if (hi.InRow)//单击的是列头 hi.InColumn { PublicClass.EnabledControl(group_Detail, true, false); BindDetail(); } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "双击:\r\n" + ex); } } #region 方法 /// /// 绑定数据 /// private void BindData() { BindSystemModule(); } /// /// 绑定所属系统模块 /// private void BindSystemModule() { try { DataTable ResultDT = DBHelpClass.Get("/api/admin/T_SYS_SystemModule/GetIsHaveTimeAxisList?isHaveTimeAxis=0"); PublicClass.SetLookUpList(ref LUEdit_SelSystemModule, ResultDT, 0, 2, false); PublicClass.SetLookUpList(ref LUEdit_SystemModule, ResultDT, 0, 2, true, "请选择"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定所属系统模块:\r\n" + ex); } } /// /// 绑定时间节点组 /// private void LUEdit_SystemModule_EditValueChanged(object sender, EventArgs e) { try { long SystemModuleID = PublicClass.ToInt64(LUEdit_SystemModule.EditValue, -1); DataTable ResultDT = DBHelpClass.Get(string.Format("/api/base/T_Base_TimeAxis/GetListBySystemModuleID?systemModuleID={0}", SystemModuleID)); PublicClass.SetLookUpList(ref LUEdit_TimeAxisID, ResultDT, 5, 9, true, "全部"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定时间节点组:\r\n" + ex); } } /// /// 绑定列表数据 /// private void BindList() { try { if (PublicClass.ToString(LUEdit_SelSystemModule.EditValue, "-1") == "-1") { XtraMessageBox.Show("请选择查询条件中所属系统/模块条件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); LUEdit_SelSystemModule.Focus(); return; } string systemModuleID = LUEdit_SelSystemModule.EditValue.ToString(); int DeleteFlag = -1; if (cmb_DeleteFlag.Text.ToString().Trim() == "启用") DeleteFlag = 0; else if (cmb_DeleteFlag.Text.ToString().Trim() == "禁用") DeleteFlag = 1; else DeleteFlag = -1; DataTable ResultDT = DBHelpClass.Get(string.Format("api/base/T_Base_RfidInstallationAddr?keyWord={0}&systemModuleID={1}&deleteFlag={2}", txt_Key.Text.ToString().Trim(), systemModuleID, DeleteFlag)); grv_RfidInstallationAddr.BestFitColumns();//列宽自适应 grid_RfidInstallationAddr.DataSource = ResultDT; } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定列表数据:\r\n" + ex); } } /// /// 绑定详情 /// private void BindDetail() { try { if (grv_RfidInstallationAddr.DataRowCount > 0) { int selectRow = grv_RfidInstallationAddr.GetSelectedRows()[0]; long id = PublicClass.ToInt64(grv_RfidInstallationAddr.GetRowCellValue(selectRow, "ID").ToString(), 0); DataTable DetailDT = DBHelpClass.GetDataRow(string.Format("api/base/T_Base_RfidInstallationAddr/{0}", id)); if (DetailDT != null && DetailDT.Rows.Count > 0) { Flag = 2;//修改标识 txt_CreationDate.Tag = DetailDT.Rows[0]["ID"].ToString(); txt_Code.Tag = DetailDT.Rows[0]["GUID"].ToString(); txt_Code.Text = DetailDT.Rows[0]["Code"].ToString(); LUEdit_SystemModule.EditValue = PublicClass.ToString(DetailDT.Rows[0]["SystemModuleID"], "-1"); LUEdit_TimeAxisID.EditValue = PublicClass.ToString(DetailDT.Rows[0]["TimeAxisID"], "-1"); txt_Address.Text = DetailDT.Rows[0]["Address"].ToString(); txt_Remarks.Text = DetailDT.Rows[0]["Remarks"].ToString(); ckb_DeleteFlag.Checked = DetailDT.Rows[0]["DeleteFlag"].ToString().Trim() == "0" ? true : false; txt_CreationDate.Text = DetailDT.Rows[0]["CreationDate"].ToString(); txt_Creator.Tag = DetailDT.Rows[0]["CreatorID"].ToString(); txt_Creator.Text = DetailDT.Rows[0]["Creator"].ToString(); } } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定列表数据:\r\n" + ex); } } #endregion /// /// 颜色绘制 /// /// /// private void grv_RfidInstallationAddr_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { //是否放弃治疗 if (e.Column.FieldName == "DeleteFlagCase") { string value = PublicClass.ToString(e.CellValue, ""); if (value == "否") { e.Appearance.ForeColor = Color.Red;//字体颜色 } } } /// /// 绘制行号 /// /// /// private void grv_RfidInstallationAddr_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e) { if (e.Info.IsRowIndicator && e.RowHandle > -1) { e.Info.DisplayText = (e.RowHandle + 1).ToString(); } } } }