| | |
| | | { |
| | | public partial class FrmMain : FluentDesignForm |
| | | { |
| | | private static readonly Dictionary<string, XtraTabPage> TabPageDic = |
| | | new Dictionary<string, XtraTabPage>(); |
| | | private string OldorgFids = ""; |
| | | /// <summary> |
| | | /// tab临时选项卡 |
| | | /// </summary> |
| | | private static readonly Dictionary<string, XtraTabPage> TabPageDic = new Dictionary<string, XtraTabPage>(); |
| | | |
| | | public FrmMain() |
| | | { |
| | | InitializeComponent(); |
| | |
| | | barPwd.ItemClick += BarPwd_ItemClick; |
| | | barExit.ItemClick += BarExit_ItemClick; |
| | | FormClosing += FrmMain_FormClosing; |
| | | barEasy.ItemClick += BarEasy_ItemClick; |
| | | getTree(); |
| | | tab.MouseDown += Tab_MouseDown; |
| | | tabCloseCurrent.Click += (s, e) => |
| | |
| | | } |
| | | } |
| | | }; |
| | | GetOrg(); |
| | | barOrg.EditValueChanged += (s, e) => |
| | | { |
| | | if (barOrg.EditValue == null) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowInformation("请选择你需要的组织!"); |
| | | return; |
| | | } |
| | | string _val = barOrg.EditValue.ToString(); |
| | | if (string.IsNullOrEmpty(_val)) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowInformation("请选择你需要的组织!"); |
| | | return; |
| | | } |
| | | if (OldorgFids == _val) |
| | | return; |
| | | var _obj = new |
| | | { |
| | | edtUserGuid = LoginInfoModel.CurrentUser.LoginUserGuid, |
| | | userGuid = LoginInfoModel.CurrentUser.LoginUserGuid, |
| | | userOrgFids = _val, |
| | | }; |
| | | try |
| | | { |
| | | var strJson = UtilityHelper.HttpPost("", "User/SetUserOrg", |
| | | JsonConvert.SerializeObject(_obj)); |
| | | var _rtn = UtilityHelper.ReturnToDynamic(strJson); |
| | | MsgHelper.ShowInformation("提示:" + _rtn.rtnData.outMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | }; |
| | | barMenu.ItemClick += (s, e) => |
| | | { |
| | | Gs.DevApp.DevFrm.User.SysMenu frm = new SysMenu(); |
| | | frm.ShowDialog(); |
| | | }; |
| | | // tab.ContextMenuStrip = cms1; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 显示右键菜单 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void Tab_MouseDown(object sender, MouseEventArgs e) |
| | | { |
| | | if (e.Button == MouseButtons.Right) |
| | |
| | | cms1.Show(tab, e.Location); |
| | | } |
| | | } |
| | | |
| | | private void BarEasy_ItemClick(object sender, ItemClickEventArgs e) |
| | | { |
| | | //var frm = new EasyCode(); |
| | | //frm.ShowDialog(); |
| | | } |
| | | |
| | | private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) |
| | | { |
| | | if (MsgHelper.AskQuestion("确定要退出系统吗?")) |
| | |
| | | { |
| | | getTree(); |
| | | } |
| | | /// <summary> |
| | | /// 读取左则模块菜单 |
| | | /// </summary> |
| | | private void getTree() |
| | | { |
| | | toolTime.Text = "登录时间" + LoginInfoModel.CurrentUser.LoginTime; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 新增选项卡页 |
| | | /// 新增选项卡页 |
| | | /// </summary> |
| | | /// <param name="tabControl">选项卡控件</param> |
| | | /// <param name="tabPageName">当期选项卡页name名称</param> |
| | | /// <param name="tabText">当前选项卡页Text标题</param> |
| | | /// <param name="newFormName">当前选项卡中的新窗体路径,类名</param> |
| | | /// <param name="newFormName"></param> |
| | | /// <param name="imgIcon">当前选项卡中的新窗体路径,类名</param> |
| | | /// <param name="InitializeVal">初始值,用于子窗体中调用父窗体的值</param> |
| | | public void AddTabpage(XtraTabControl tabControl, string tabPageName, |
| | | string tabText, string newFormName, Image imgIcon,string InitializeVal="") |
| | | string tabText, string newFormName, Image imgIcon, string InitializeVal = "") |
| | | { |
| | | if (IsTabpageExsit(tabControl, tabPageName)) return; |
| | | var newPage = new XtraTabPage(); |
| | |
| | | return; |
| | | } |
| | | foreach (XtraTabPage item in tabControl.TabPages) |
| | | { |
| | | if (item.Name == name) |
| | | { |
| | | //后来加上,为了释放窗体资源beg |
| | | //foreach (Control control in item.Controls) |
| | | //{ |
| | | // if (control is Form) |
| | | // { |
| | | // Form myForm = control as Form; |
| | | // myForm.Invoke((MethodInvoker)delegate { myForm.Dispose(); }); // 确保 UI 线程安全地释放资源 |
| | | // } |
| | | //} |
| | | //后来加上,为了释放窗体资源end |
| | | tabControl.TabPages.Remove(item); |
| | | item.Dispose(); |
| | | TabPageDic.Remove(name); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// 在选项卡中生成窗体 |
| | | /// </summary> |
| | | /// <param name="form">窗体名称</param> |
| | | private Form AddNewForm(string formName,string InitializeVal) |
| | | private Form AddNewForm(string formName, string InitializeVal) |
| | | { |
| | | try |
| | | { |
| | |
| | | newForm.ControlBox = false; |
| | | newForm.Dock = DockStyle.Fill; |
| | | newForm.Visible = true; |
| | | //实现子窗体的委托beg |
| | | EventInfo evt = newForm.GetType().GetEvent("UpdateParent", |
| | | BindingFlags.NonPublic | BindingFlags.Instance |
| | | | BindingFlags.Public |
| | | ); |
| | | if (evt != null) |
| | | evt.AddEventHandler(newForm, new EventHandler<UpdateParentEventArgs>(UpdateParent_OnChange)); |
| | | if (!string.IsNullOrEmpty(InitializeVal)) { |
| | | Assembly assembly = Assembly.GetExecutingAssembly(); |
| | | Type type = assembly.GetType(formName); |
| | | MethodInfo method = type.GetMethod("Initialize"); // 获取Initialize方法的信息 |
| | | if (method != null) |
| | | method.Invoke(newForm, new object[] { InitializeVal }); // 调用Initialize方法并传递参数 |
| | | } |
| | | //实现子窗体的委托end |
| | | shiXian(newForm, formName, InitializeVal); |
| | | return newForm; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | MsgHelper.ShowError("请检查是否开通了该模块!"); |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | //实现子窗体的委托beg |
| | | private void UpdateParent_OnChange(object sender, UpdateParentEventArgs e) |
| | | { |
| | | List<string> _val = e.StringList; |
| | | string _formName = _val[0];//类名 |
| | | string _parm1= _val[1]; |
| | | var _obj = new |
| | | { |
| | | guid = _formName //主建 |
| | | }; |
| | | try |
| | | { |
| | | var strJson = UtilityHelper.HttpPost("", "MenuAction/GetModelByNameSpace", |
| | | JsonConvert.SerializeObject(_obj)); |
| | | var _rtn = UtilityHelper.ReturnToDynamic(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | var dy = _rtn.rtnData; |
| | | string tabPageName = dy.guid.ToString() + "_page"; |
| | | string tabText = dy.name.ToString(); //当前选项卡页Text标题 |
| | | string newFormName = dy.formPath.ToString(); //存路径,类名 |
| | | Image imgIcon = UtilityHelper.GetImgFromResource(dy.icon.ToString(), 2); |
| | | AddTabpage(tab, tabPageName, tabText,newFormName, imgIcon, _parm1); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | //实现子窗体的委托end |
| | | |
| | | /// <summary> |
| | | /// 用户退出 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | private int _userOut() |
| | | { |
| | | var _obj = new |
| | |
| | | return 1; |
| | | } |
| | | } |
| | | private void GetOrg() |
| | | |
| | | #region 实现子窗体的委托,主要用于子页面中访问父页面方法 |
| | | private void UpdateParent_OnChange(object sender, UpdateParentEventArgs e) |
| | | { |
| | | string userGuid = LoginInfoModel.CurrentUser.LoginUserGuid; |
| | | var pgq = new PageQueryModel(1, 999999, "FID", "asc", userGuid, " and IS_STATUS=1"); |
| | | var json = JsonConvert.SerializeObject(pgq); |
| | | List<string> _val = e.StringList; |
| | | string _formName = _val[0];//类名 |
| | | string _parm1 = _val[1]; |
| | | var _obj = new |
| | | { |
| | | guid = _formName //主建 |
| | | }; |
| | | try |
| | | { |
| | | var strReturn = UtilityHelper.HttpPost("", "Organization/GetListPage", json); |
| | | var _rtn = UtilityHelper.ReturnToTablePage(strReturn); |
| | | var dt = _rtn.rtnData.list; |
| | | repositoryItemCheckedComboBoxEdit1.DataSource = dt; |
| | | repositoryItemCheckedComboBoxEdit1.DisplayMember = "name"; |
| | | repositoryItemCheckedComboBoxEdit1.ValueMember = "fid"; |
| | | var _obj = UtilityHelper.ReturnToDynamic(strReturn); |
| | | barOrg.EditValue = _obj.rtnData.extendText; |
| | | OldorgFids = _obj.rtnData.extendText; |
| | | var strJson = UtilityHelper.HttpPost("", "MenuAction/GetModelByNameSpace", |
| | | JsonConvert.SerializeObject(_obj)); |
| | | var _rtn = UtilityHelper.ReturnToDynamic(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | var dy = _rtn.rtnData; |
| | | string tabPageName = dy.guid.ToString() + "_page"; |
| | | string tabText = dy.name.ToString(); //当前选项卡页Text标题 |
| | | string newFormName = dy.formPath.ToString(); //存路径,类名 |
| | | Image imgIcon = UtilityHelper.GetImgFromResource(dy.icon.ToString(), 2); |
| | | //先关闭 |
| | | RemoveTabPage(tab, tabPageName); |
| | | AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon, _parm1); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.Warning("提示:" + ex.Message); |
| | | MsgHelper.ShowError("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void shiXian(Form newForm, string formName, string InitializeVal) |
| | | { |
| | | EventInfo evt = newForm.GetType().GetEvent("ToUpdateParent", |
| | | BindingFlags.NonPublic | BindingFlags.Instance |
| | | | BindingFlags.Public |
| | | ); |
| | | if (evt != null) |
| | | evt.AddEventHandler(newForm, new EventHandler<UpdateParentEventArgs>(UpdateParent_OnChange)); |
| | | if (!string.IsNullOrEmpty(InitializeVal)) |
| | | { |
| | | Assembly assembly = Assembly.GetExecutingAssembly(); |
| | | Type type = assembly.GetType(formName); |
| | | MethodInfo method = type.GetMethod("Initialize"); // 获取Initialize方法的信息 |
| | | if (method != null) |
| | | method.Invoke(newForm, new object[] { InitializeVal }); // 调用Initialize方法并传递参数 |
| | | } |
| | | } |
| | | #endregion |
| | | |
| | | } |
| | | } |