¶Ô±ÈÐÂÎļþ |
| | |
| | | using DevExpress.XtraBars.Navigation; |
| | | using DevExpress.XtraTab; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Reflection; |
| | | using System.Windows.Forms; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using Gs.DevApp.Entity; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace Gs.DevApp.DevFrm |
| | | { |
| | | public partial class FrmMain : DevExpress.XtraBars.FluentDesignSystem.FluentDesignForm |
| | | { |
| | | private static Dictionary<string, XtraTabPage> TabPageDic = new Dictionary<string, XtraTabPage>(); |
| | | public FrmMain() |
| | | { |
| | | InitializeComponent(); |
| | | this.Text = System.Configuration.ConfigurationSettings.AppSettings.Get("ProductName").ToString(); |
| | | tab.CloseButtonClick += Tab_CloseButtonClick; |
| | | tooLoading.Click += TooLoading_Click; |
| | | barPwd.ItemClick += BarPwd_ItemClick; |
| | | barExit.ItemClick += BarExit_ItemClick; |
| | | this.FormClosing += FrmMain_FormClosing; |
| | | this.barEasy.ItemClick += BarEasy_ItemClick; |
| | | getTree(); |
| | | } |
| | | |
| | | private void BarEasy_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | DevFrm.Sys.EasyCode frm = new Sys.EasyCode(); |
| | | frm.ShowDialog(); |
| | | } |
| | | |
| | | private void FrmMain_FormClosing(object sender, FormClosingEventArgs e) |
| | | { |
| | | if (MsgHelper.AskQuestion("ç¡®å®è¦éåºç³»ç»å?")) |
| | | { |
| | | int i = _userOut(); |
| | | if (i > 0) |
| | | { |
| | | this.FormClosing -= new FormClosingEventHandler(this.FrmMain_FormClosing); |
| | | Application.Exit(); |
| | | } |
| | | else |
| | | e.Cancel = true;//åæ¶ãè¿åçªä½ |
| | | } |
| | | else |
| | | e.Cancel = true;//åæ¶ãè¿åçªä½ |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éåº |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void BarExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | if (MsgHelper.AskQuestion("ç¡®å®è¦éåºç³»ç»å?")) |
| | | { |
| | | int i = _userOut(); |
| | | if (i > 0) |
| | | { |
| | | this.FormClosing -= new FormClosingEventHandler(this.FrmMain_FormClosing); |
| | | Application.Exit(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è®¾ç½®ç¨æ·å¯ç |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void BarPwd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) |
| | | { |
| | | User.UserSetPwd frm = new User.UserSetPwd(LoginInfoModel.CurrentUser.LoginUserGuid); |
| | | frm.ShowDialog(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éæ°å è½½ç³»ç» |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void TooLoading_Click(object sender, EventArgs e) |
| | | { |
| | | int i = 100; |
| | | Gs.DevApp.UserControl.ShowDialogForm sdf = new Gs.DevApp.UserControl.ShowDialogForm("æç¤º", "", "请èå¿çåï¼æ£å¨æä½ä¸ï¼"); |
| | | for (int j = 0; j < i; j++) |
| | | { |
| | | sdf.SetCaption("æ§è¡è¿åº¦ï¼" + (j) + "/" + i.ToString() + "ï¼"); |
| | | } |
| | | sdf.Close(); |
| | | getTree(); |
| | | } |
| | | private void getTree() |
| | | { |
| | | toolTime.Text = "ç»å½æ¶é´" + LoginInfoModel.CurrentUser.LoginTime; |
| | | var _obj = new |
| | | { |
| | | userGuid = LoginInfoModel.CurrentUser.LoginUserGuid, |
| | | orgGuid = LoginInfoModel.CurrentUser.LoginOrgGuid, |
| | | }; |
| | | try |
| | | { |
| | | string strJson = UtilityHelper.HttpPost("", "User/GetUserLoginInfo", JsonConvert.SerializeObject(_obj)); |
| | | JObject _job = JObject.Parse(strJson); |
| | | string rtnCode = _job["rtnCode"].ToString(); |
| | | if (int.Parse(rtnCode) > 0) |
| | | { |
| | | this.acrd.Clear(); |
| | | barMsg.Caption = _job["rtnData"]["loginMsg"].ToString(); |
| | | JArray array = new JArray(); |
| | | var d = _job["rtnData"]["list"]; |
| | | foreach (var a in d) |
| | | { |
| | | array.Add(a); |
| | | } |
| | | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmMain)); |
| | | DataTable dt = JsonConvert.DeserializeObject<DataTable>(array.ToString()); |
| | | DataRow[] drGrp = dt.Select("upGuid is null"); |
| | | int gdx = 0, idx = 0; |
| | | foreach (DataRow _dy in drGrp) |
| | | { |
| | | AccordionControlElement _grp = this.acrd.AddGroup(); |
| | | _grp.ImageOptions.Image = UtilityHelper.GetImgFromResource(_dy["icon"].ToString(), 1); |
| | | _grp.Name = _dy["guid"].ToString(); |
| | | _grp.Style = DevExpress.XtraBars.Navigation.ElementStyle.Group; |
| | | _grp.Text = _dy["name"].ToString(); |
| | | _grp.Tag = _dy["formPath"].ToString();//åè·¯å¾ï¼ç±»å |
| | | _grp.Click += _grp_Click; |
| | | if (gdx == 0) |
| | | _grp.Expanded = true; |
| | | DataRow[] drItem = dt.Select("upGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy2 in drItem) |
| | | { |
| | | AccordionControlElement _itm = this.acrd.AddItem(); |
| | | _itm.ImageOptions.Image = UtilityHelper.GetImgFromResource(_dy2["icon"].ToString(), 2); |
| | | _itm.Name = _dy2["guid"].ToString(); |
| | | _itm.Style = DevExpress.XtraBars.Navigation.ElementStyle.Item; |
| | | _itm.Text = _dy2["name"].ToString(); |
| | | _itm.Appearance.Normal.Font = new System.Drawing.Font("Tahoma", 10F); |
| | | _itm.Tag = _dy2["formPath"].ToString();//åè·¯å¾ï¼ç±»å |
| | | _itm.Click += _grp_Click; |
| | | _grp.Elements.Add(_itm); |
| | | if (idx == 0 && tab.TabPages.Count <= 0) |
| | | { |
| | | string tabPageName = _itm.Name + "_page"; |
| | | string tabText = _itm.Text;//å½åé项å¡é¡µTextæ é¢ |
| | | string newFormName = _itm.Tag.ToString();//åè·¯å¾ï¼ç±»å |
| | | Image imgIcon = _itm.Image; |
| | | AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon); |
| | | } |
| | | idx++; |
| | | }; |
| | | gdx++; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | ToolBox.MsgHelper.ShowError("æç¤ºï¼åå§å失败ï¼è¯·è系管çåï¼"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.ShowError("æç¤ºï¼" + ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 左侧èåç¹å» |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void _grp_Click(object sender, EventArgs e) |
| | | { |
| | | AccordionControlElement _acd = (AccordionControlElement)sender; |
| | | if (_acd.Elements.Count > 0) return; |
| | | string tabPageName = _acd.Name + "_page"; |
| | | string tabText = _acd.Text; |
| | | string newFormName = _acd.Tag.ToString(); |
| | | Image imgIcon = _acd.Image; |
| | | AddTabpage(tab, tabPageName, tabText, newFormName, imgIcon); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å
³ééé¡¹å¡ |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void Tab_CloseButtonClick(object sender, EventArgs e) |
| | | { |
| | | RemoveTabPage(tab, e); |
| | | } |
| | | /// <summary> |
| | | /// æ°å¢é项å¡é¡µ |
| | | /// </summary> |
| | | /// <param name="tabControl">é项塿§ä»¶</param> |
| | | /// <param name="tabPageName">彿é项å¡é¡µnameåç§°</param> |
| | | /// <param name="tabText">å½åé项å¡é¡µTextæ é¢</param> |
| | | /// <param name="newFormName">å½åé项å¡ä¸çæ°çªä½è·¯å¾ï¼ç±»å</param> |
| | | public void AddTabpage(XtraTabControl tabControl, string tabPageName, string tabText, string newFormName, Image imgIcon) |
| | | { |
| | | if (IsTabpageExsit(tabControl, tabPageName)) |
| | | { |
| | | return; |
| | | } |
| | | XtraTabPage newPage = new XtraTabPage(); |
| | | newPage.Name = tabPageName; |
| | | newPage.Text = tabText; |
| | | newPage.Tooltip = newPage.Name; |
| | | newPage.Appearance.Header.Font = (tab.Appearance.Font); |
| | | newPage.ImageOptions.Image = imgIcon; |
| | | Form fm = AddNewForm(newFormName); |
| | | if (fm != null) |
| | | { |
| | | newPage.Controls.Add(fm); |
| | | tabControl.TabPages.Add(newPage); |
| | | TabPageDic.Add(tabPageName, newPage); |
| | | tabControl.SelectedTabPage = newPage; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç§»é¤é项å¡é¡µ |
| | | /// </summary> |
| | | /// <param name="tabControl"></param> |
| | | /// <param name="tabPageName"></param> |
| | | /// <param name="e"></param> |
| | | public void RemoveTabPage(XtraTabControl tabControl, EventArgs e) |
| | | { |
| | | if (TabPageDic.Count <= 1) |
| | | { |
| | | ToolBox.MsgHelper.Warning("请è³å°ä¿çä¸ä¸ªåè½ï¼"); |
| | | return; |
| | | } |
| | | DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs args = (DevExpress.XtraTab.ViewInfo.ClosePageButtonEventArgs)e; |
| | | string name = args.Page.Tooltip; |
| | | foreach (XtraTabPage item in tabControl.TabPages) |
| | | { |
| | | if (item.Name == name) |
| | | { |
| | | tabControl.TabPages.Remove(item); |
| | | item.Dispose(); |
| | | TabPageDic.Remove(name); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿é项塿¯å¦å·²ç»åå¨ |
| | | /// </summary> |
| | | /// <param name="tabControl">é项塿§ä»¶</param> |
| | | /// <param name="tabPageName">é项å¡åç§°</param> |
| | | /// <returns></returns> |
| | | private bool IsTabpageExsit(XtraTabControl tabControl, string tabPageName) |
| | | { |
| | | foreach (var item in TabPageDic) |
| | | { |
| | | if (item.Key == tabPageName) |
| | | { |
| | | tabControl.SelectedTabPage = item.Value; |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å¨é项å¡ä¸çæçªä½ |
| | | /// </summary> |
| | | /// <param name="form">çªä½åç§°</param> |
| | | private Form AddNewForm(string formName) |
| | | { |
| | | try |
| | | { |
| | | Form newForm = (Form)Assembly.GetExecutingAssembly().CreateInstance(formName); |
| | | if (newForm == null) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowError("è¯·æ£æ¥æ¯å¦å¼éäºè¯¥æ¨¡åï¼"); |
| | | return null; |
| | | } |
| | | newForm.FormBorderStyle = FormBorderStyle.None; |
| | | newForm.TopLevel = false; |
| | | newForm.ControlBox = false; |
| | | newForm.Dock = DockStyle.Fill; |
| | | newForm.Visible = true; |
| | | return newForm; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.ShowError("è¯·æ£æ¥æ¯å¦å¼éäºè¯¥æ¨¡åï¼"); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private int _userOut() |
| | | { |
| | | var _obj = new |
| | | { |
| | | userGuid = LoginInfoModel.CurrentUser.LoginUserGuid, |
| | | }; |
| | | try |
| | | { |
| | | string strJson = UtilityHelper.HttpPost("", "User/UserOut", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.ReturnToDynamic(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | return _rtn.rtnCode; |
| | | ToolBox.MsgHelper.Warning("æç¤ºï¼" + _rtn.rtnData.outMsg); |
| | | return _rtn.rtnCode; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | this.DialogResult = DialogResult.Cancel; |
| | | ToolBox.MsgHelper.Warning("æç¤ºï¼" + ex.Message); |
| | | return -1; |
| | | } |
| | | } |
| | | } |
| | | } |