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 Autofac; using WinformDevFramework.Core.Configuration; using WinformDevFramework.Core.Winform; using WinformDevFramework.IServices.System; using WinformDevFramework.Services.System; namespace WinformDevFramework { public partial class BaseForm1 : Form { protected FormStatus formStatus = FormStatus.First; public BaseForm1() { InitializeComponent(); } public virtual void Init() { tabControl1.Selecting += TabControl1_Selecting; //设置list不可以编辑 this.dataGridViewList.ReadOnly = true; //设置列宽自适应 dataGridViewList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; dataGridViewList.AutoResizeColumns(); //dataGridViewList.DoubleBuffered(); //设置gridlist 双击事件 this.dataGridViewList.CellDoubleClick += DataGridViewList_CellDoubleClick; } private void TabControl1_Selecting(object? sender, TabControlCancelEventArgs e) { TabControlSelectingFunction(sender, e); } /// /// tab页签禁止切换 /// /// /// public virtual void TabControlSelectingFunction(object? sender, TabControlCancelEventArgs e) { if (formStatus == FormStatus.Edit || formStatus == FormStatus.Add) { e.Cancel = true; } } private void DataGridViewList_CellDoubleClick(object? sender, DataGridViewCellEventArgs e) { if (e.RowIndex >= 0) { DataGridViewListDoubleClick(sender, e); } } /// /// datagridview双击事件 /// /// /// public virtual void DataGridViewListDoubleClick(object? sender, DataGridViewCellEventArgs e) { //跳转到详情页 this.tabControl1.SelectedIndex = 1; //设置功能按钮状态 formStatus = FormStatus.View; } private void Button_Click(object? sender, EventArgs e) { } private void BaseForm1_Load(object sender, EventArgs e) { Init(); } /// /// 设置控件状态 /// /// protected void SetControlStatus(Control groupBox, bool canEdit) { foreach (Control control in groupBox.Controls) { if (control is TextBox) { TextBox textBox = (TextBox)control; textBox.ReadOnly = !canEdit; }else if (control is UITreeView||control is TreeView) { } else if (control.Controls.Count == 0) { control.Enabled = canEdit; } SetControlStatus(control, canEdit); } } /// /// 清楚控件值 /// /// protected void ClearControlsText(Control groupBox) { foreach (Control control in groupBox.Controls) { if (control is DateTimePicker) { control.Text = string.Empty; } else if (control is Label || control is Button || control is CheckBox||control is GroupBox) { } ////else if (control is TextBox && (control.Name.Equals("")|| control.Name.Equals(""))) ////{ ////} else { control.Text = string.Empty; } ClearControlsText(control); } } private void btnAdd_Click(object sender, EventArgs e) { AddFunction( sender, e); } /// /// 新增 /// /// /// public virtual void AddFunction(object sender, EventArgs e) { //跳转到详情页 this.tabControl1.SelectedIndex = 1; //设置功能按钮状态 formStatus = FormStatus.Add; } private void btnEdit_Click(object sender, EventArgs e) { EditFunction(sender, e); } /// /// 编辑 /// /// /// public virtual void EditFunction(object sender, EventArgs e) { formStatus = FormStatus.Edit; } private void btnSave_Click(object sender, EventArgs e) { SaveFunction(sender, e); } /// /// 保存 /// /// /// public virtual void SaveFunction(object sender, EventArgs e) { formStatus = FormStatus.Save; } private void btnCanel_Click(object sender, EventArgs e) { CanelFunction(sender, e); } /// /// 撤销 /// /// /// public virtual void CanelFunction(object sender, EventArgs e) { formStatus = FormStatus.Canel; } private void btnDel_Click(object sender, EventArgs e) { DelFunction(sender, e); } /// /// 删除 /// /// /// public virtual void DelFunction(object sender, EventArgs e) { formStatus = FormStatus.Del; } private void btnResetPW_Click(object sender, EventArgs e) { ResetPWFunction(sender, e); } /// /// 重置密码 /// /// /// public virtual void ResetPWFunction(object sender, EventArgs e) { } private void btnClose_Click(object sender, EventArgs e) { CloseFunction(sender, e); } /// /// 关闭 /// /// /// public virtual void CloseFunction(object sender, EventArgs e) { TabControl parentTabControl = this.Parent.Parent as TabControl; TabPage tabpage = this.Parent as TabPage; parentTabControl.TabPages.Remove(tabpage); } /// /// 设置工具栏按钮是否隐藏 /// protected void SetToolsButton() { //设置工具按钮 var buttons = AppInfo.UserMenus.Where(p => p.ParentID == int.Parse(this.Tag.ToString()) && p.MenuType == "Button").Select(p => p.MenuCode); foreach (Control control in this.flowLayoutPanelTools.Controls) { if (!buttons.Contains(control.Name)) { control.Hide(); } } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) { if (tabControl1.SelectedIndex==0) { formStatus = FormStatus.First; SetToolButtonStatus(formStatus); } else { if (!string.IsNullOrEmpty(txtID.Text)) { formStatus = FormStatus.View; SetToolButtonStatus(formStatus); } } } /// /// 设置工具按钮是否可用 /// public virtual void SetToolButtonStatus(FormStatus status) { } } }