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_SYS { public partial class Form_DepartmentsMain : XtraForm { #region 变量 /// /// 操作标记 1:新增 2:修改 /// private int Flag = 0; /// /// 当前页 /// public int curPage = 1; /// /// 每页大小 /// public int pageSize = 100; /// /// 所有记录条数 /// public int totalNumber = 0; #endregion #region 分页实现 public void ExportEvents(bool singlePage)//单页,所有 { //导出GridControl代码写在这。 } public void RefreshGridList() { FillGridListCtrlQuery(curPage);//自己实现FillGridListCtrlQuery函数。 } /// /// 绑定数据源 /// /// private void FillGridListCtrlQuery(int curPage) { try { DataTable ResultDT = DBHelpClass.Get(string.Format("api/admin/T_SYS_Departments?pageIndex={0}&pageSize={1}&keyWord={2}", curPage, pageSize, txt_Key.Text.ToString().Trim())); gridC_Departments.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_myPagerEvents(int curPage, int pageSize) { userControlForPage.myPagerEvents += MyPagerEvents; } private void userControlForPage_exportEvents(bool singlePage) { userControlForPage.exportEvents += ExportEvents; } #endregion public Form_DepartmentsMain() { InitializeComponent(); } /// /// 窗体加载 /// /// /// private void Form_DepartmentsMain_Load(object sender, EventArgs e) { RefreshGridList(); //详情控件初始化 PublicClass.EnabledControl(this.groupD_Detail, true, false); BindData(); } private void txt_Key_TextChanged(object sender, EventArgs e) { //列表分页数据绑定 RefreshGridList(); ckb_DeleteFlag.Checked = true; } /// /// 查询 /// /// /// private void btn_Select_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { //列表分页数据绑定 RefreshGridList(); } /// /// 新增 /// /// /// private void btn_Insert_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { PublicClass.EnabledControl(this.groupD_Detail, false, true); btn_Delete.Enabled = false; Flag = 1; } /// /// 修改 /// /// /// private void btn_Update_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { BindDetail(); PublicClass.EnabledControl(groupD_Detail, false, false); btn_Delete.Enabled = false; } /// /// 删除 /// /// /// private void btn_Delete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (grv_Departments.DataRowCount > 0) { int selectRow = grv_Departments.GetSelectedRows()[0]; int ID = Convert.ToInt32(grv_Departments.GetRowCellValue(selectRow, "ID").ToString()); string DepartmentName = grv_Departments.GetRowCellValue(selectRow, "DepartmentName").ToString(); if (ID == 0) { XtraMessageBox.Show("请先选择要删除的科室!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (XtraMessageBox.Show(string.Format("确定要删除科室【{0}】?", DepartmentName), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { List list = new List(); T_SYS_DepartmentsDTO model = new T_SYS_DepartmentsDTO(); string Url = "api/admin/T_SYS_Departments/LogicalDelete"; model.ID = ID; model.DeleteFlag = 1; list.Add(model); //初始化两个工厂 ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); //访问 ListEntity t = client.Post(Url, list); if (t.Success) { XtraMessageBox.Show("删除科室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); PublicClass.EnabledControl(this.groupD_Detail, true, false); Flag = 0; //列表分页数据绑定 RefreshGridList(); BindParent(); } else { XtraMessageBox.Show("删除科室失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "删除:\r\n" + ex); } } /// /// 保存 /// /// /// private void btn_Save_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { if (string.IsNullOrEmpty(txt_DepartmentName.Text.ToString().Trim())) { XtraMessageBox.Show("科室名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); txt_DepartmentName.Focus(); return; } if (PublicClass.ToString(LUEdit_Hospital.EditValue, "-1") == "-1") { XtraMessageBox.Show("请选择所属机构!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); LUEdit_Hospital.Focus(); return; } List list = new List(); T_SYS_DepartmentsDTO model = new T_SYS_DepartmentsDTO(); string Url = string.Empty; if (Flag == 1) { Url = "api/admin/T_SYS_Departments"; model.GUID = Guid.NewGuid().ToString(); model.CreationDate = PublicClass.DateTimeNow(); } else { Url = "api/admin/T_SYS_Departments/Update"; model.ID = Convert.ToInt32(txt_DepartmentName.Tag.ToString()); model.GUID = txt_Description.Tag.ToString(); } model.HospitalGuid = PublicClass.ToString(LUEdit_Hospital.EditValue, ""); //0为顶级科室编号 int ParentID = PublicClass.ToInt32(LUEdit_Parent.EditValue, -1); model.ParentID = ParentID == -1 ? 0 : ParentID; model.DepartmentName = txt_DepartmentName.Text.ToString().Trim(); //model.DeleteFlag = ckb_DeleteFlag.Checked == true ? 0 : 1; model.Description = txt_Description.Text.ToString(); model.OrderBy = Convert.ToInt32(txt_OrderBy.Text.ToString().Trim() == "" ? "0" : txt_OrderBy.Text.ToString().Trim()); model.isFollowUp = checkEdit1.Checked == true ? 0 : 1; list.Add(model); //初始化两个工厂 ClientFactory httpClient = new HttpClientFactory(); Client client = httpClient.VisitFactory(); //访问 ListEntity t = client.Post(Url, list); if (t.Success) { XtraMessageBox.Show("保存科室信息成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); PublicClass.EnabledControl(this.groupD_Detail, true, false); Flag = 0; //列表分页数据绑定 RefreshGridList(); BindParent(); btn_Delete.Enabled = true; //定位 PublicClass.LocationForGridView(grv_Departments, model.GUID, 1); } else { XtraMessageBox.Show("保存失败,请稍后重试!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "保存:\r\n" + ex); } } /// /// 退出 /// /// /// private void btn_Exit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { this.Close(); } #region 方法 /// /// 绑定数据 /// private void BindData() { //绑定医院 BindHospital(); //绑定上级科室 BindParent(); } /// /// 绑定详情 /// private void BindDetail() { try { if (grv_Departments.DataRowCount > 0) { int selectRow = grv_Departments.GetSelectedRows()[0]; long ID = Convert.ToInt64(grv_Departments.GetRowCellValue(selectRow, "ID").ToString()); DataTable DetailDT = DBHelpClass.GetDataRow(string.Format("api/admin/T_SYS_Departments/{0}", ID)); if (DetailDT != null && DetailDT.Rows.Count > 0) { Flag = 2;//修改标识 LUEdit_Hospital.EditValue = PublicClass.ToString(DetailDT.Rows[0]["HospitalGUID"], "-1"); string Parent = PublicClass.ToString(DetailDT.Rows[0]["ParentID"], "0"); LUEdit_Parent.EditValue = Parent == "0" ? "-1" : Parent; txt_DepartmentName.Tag = DetailDT.Rows[0]["ID"].ToString(); txt_DepartmentName.Text = DetailDT.Rows[0]["DepartmentName"].ToString(); txt_Description.Tag = DetailDT.Rows[0]["GUID"].ToString(); txt_Description.Text = DetailDT.Rows[0]["Description"].ToString(); txt_OrderBy.Text = DetailDT.Rows[0]["OrderBy"].ToString(); ckb_DeleteFlag.Checked = DetailDT.Rows[0]["DeleteFlag"].ToString().Trim() == "0" ? true : false; checkEdit1.Checked = DetailDT.Rows[0]["isFollowUp"].ToString().Trim() == "0" ? true : false; } } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定详情:\r\n" + ex); } } /// /// 绑定机构信息 /// private void BindHospital() { try { DataTable ResultDT = DBHelpClass.Get("api/base/T_Base_Hospital/GetList"); PublicClass.SetLookUpList(LUEdit_Hospital, ResultDT, "guid", "name", true, "请选择"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定机构信息:\r\n" + ex); } } /// /// 绑定上级科室 /// private void BindParent() { try { DataTable ResultDT = DBHelpClass.Get("api/admin/T_SYS_Departments/GetList"); PublicClass.SetLookUpList(ref LUEdit_Parent, ResultDT, 0, 3, true, "顶级科室"); } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "绑定上级科室:\r\n" + ex); } } #endregion private void gridC_Departments_MouseClick(object sender, MouseEventArgs e) { try { GridHitInfo hi = grv_Departments.CalcHitInfo(new Point(e.X, e.Y)); //单击数据行 if (hi.InRow)//单击的是列头 hi.InColumn { PublicClass.EnabledControl(this.groupD_Detail, true, false); BindDetail(); } } catch (Exception ex) { PublicClass.WriteErrorLog(this.Text, "gridC_Departments_MouseClick:\r\n" + ex); } } } }