using DH.RBAC.Common; using Sunny.UI; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using DH.RBAC.Logic.Sys; using DH.RBAC.Model.Sys; using DH.RBAC.Utility.Other; using AntdUI; namespace DH.RBAC.Page.Sys.Organize { [PageCode("sys-organize")] public partial class OrganizePage : MyPage { private SysOrganizeLogic organizeLogic; Window window; public OrganizePage(Window _window) { window= _window; InitializeComponent(); organizeLogic = new SysOrganizeLogic(); dataGridView.AutoGenerateColumns = false; Load += OrganizePage_Initialize; btnQuery.Click += btnQuery_Click; btnAdd.Click += btnAdd_Click; btnDelete.Click += btnDelete_Click; btnUpdate.Click += btnModify_Click; } /// /// 界面初始化 /// /// /// private void OrganizePage_Initialize(object sender, EventArgs e) { btnQuery_Click(null, null); } /// /// 查询按钮 /// /// /// public void btnQuery_Click(object sender, EventArgs e) { //调用服务器获得数据 int totalCount = 0; List list = organizeLogic.GetList(pagination.ActivePage, pagination.PageSize, txtKeywords.Text, ref totalCount); pagination.TotalCount = totalCount; dataGridView.DataSource = list; } /// /// 关键字Enter键处理 /// /// /// private void txtKeywords_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) btnQuery_Click(sender, null); } /// /// 新增组织机构 /// /// /// private void btnAdd_Click(object sender, EventArgs e) { AddOrganizeForm form = new AddOrganizeForm(); form.ParentPage = this; form.Id = string.Empty; FormHelper.ShowSubForm(form); } /// /// 修改组织机构 /// /// /// private void btnModify_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 0) { AntdUI.Message.warn(window, "请选择一行数据进行修改!", autoClose: 3); return; } int index = dataGridView.SelectedIndex; if (index < 0) { AntdUI.Message.warn(window, "请选择一行数据进行修改!", autoClose: 3); return; } string id = dataGridView.Rows[index].Cells["OrganizeId"].Value.ToString(); AddOrganizeForm form = new AddOrganizeForm(); form.ParentPage = this; form.Id = id; FormHelper.ShowSubForm(form); } /// /// 删除组织机构 /// /// /// private void btnDelete_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 0) { AntdUI.Message.warn(window, "请选择一行数据进行删除!", autoClose: 3); return; } int index = dataGridView.SelectedIndex; if (index < 0) { AntdUI.Message.warn(window, "请选择一行数据进行删除!", autoClose: 3); return; } string id = dataGridView.Rows[index].Cells["OrganizeId"].Value.ToString(); var result = AntdUI.Modal.open(window, "删除警告!", "您是否确定要删除该机构?", TType.Warn); if (result == DialogResult.OK) { try { int row = 0; int count = organizeLogic.GetChildCount(id); if (count > 0) { AntdUI.Message.warn(window, $"操作失败,请先删除该项的{count}个子级机构。", autoClose: 3); return; } row = organizeLogic.Delete(id); if (row == 0) { AntdUI.Message.warn(window, "对不起,操作失败", autoClose: 3); return; } //重新查询 btnQuery_Click(null, null); } catch { AntdUI.Message.warn(window, "网络或服务器异常,请稍后再试", autoClose: 3); } } } /// /// 页码发生改变 /// /// /// /// /// private void pagination_PageChanged(object sender, object pagingSource, int pageIndex, int count) { btnQuery_Click(null, null); } } }