BaseFormRelease.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary
  10. {
  11. public partial class BaseFormRelease : BaseForm360
  12. {
  13. public BaseFormRelease()
  14. {
  15. InitializeComponent();
  16. this.btnAppFormMenu.MouseClick += new MouseEventHandler(btnAppFormMenu_MouseClick);
  17. this.Load += BaseFormRelease_Load;
  18. InitializationSystemMeun();
  19. this.BackColor = LYFZ.ComponentLibrary.GetUIResources.FrmContentBackgroundColor;
  20. this.MouseMove += BaseFormRelease_MouseMove;
  21. this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
  22. }
  23. public static LYFZ.StandardInterface.IToolMenuClick iMainDropzoneForm = null;
  24. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  25. {
  26. if (keyData == Keys.F12)
  27. {
  28. // System.Environment.Exit(0);
  29. if (iMainDropzoneForm != null)
  30. {
  31. try
  32. {
  33. this.Close();
  34. }
  35. catch { }
  36. finally
  37. {
  38. iMainDropzoneForm.ShowLogin(this);
  39. }
  40. }
  41. }
  42. return base.ProcessCmdKey(ref msg, keyData);
  43. }
  44. bool isLoginValidation = false;
  45. /// <summary>
  46. /// 是否进行登录验证
  47. /// </summary>
  48. public bool IsLoginValidation
  49. {
  50. get { return isLoginValidation; }
  51. set { isLoginValidation = value; }
  52. }
  53. public void ShowLoginAgain(bool isMessageBoxCustom = true)
  54. {
  55. try
  56. {
  57. if (typeof(LYFZ.StandardInterface.IToolMenuClick).IsAssignableFrom(this.ParentForm.GetType()))
  58. {
  59. Control[] contols = this.Controls.Find("plExMainContainer", true);
  60. if (contols.Length > 0)
  61. {
  62. contols[0].Enabled = false;
  63. }
  64. LYFZ.StandardInterface.IToolMenuClick iParentForm = (LYFZ.StandardInterface.IToolMenuClick)this.ParentForm;
  65. iParentForm.ShowLogin(this);
  66. }
  67. }
  68. catch
  69. {
  70. try
  71. {
  72. if (typeof(LYFZ.StandardInterface.IToolMenuClick).IsAssignableFrom(this.GetType()))
  73. {
  74. LYFZ.StandardInterface.IToolMenuClick iParentForm = (LYFZ.StandardInterface.IToolMenuClick)this;
  75. iParentForm.ShowLogin(null);
  76. }
  77. else
  78. {
  79. LoginMessageBoxCustom(isMessageBoxCustom);
  80. }
  81. }
  82. catch
  83. {
  84. LoginMessageBoxCustom(isMessageBoxCustom);
  85. }
  86. }
  87. }
  88. /// <summary>
  89. /// 重新登录
  90. /// </summary>
  91. /// <param name="isMessageBoxCustom">是否弹出显示用户登录超时提示</param>
  92. public void LoginAgain(bool isMessageBoxCustom = true)
  93. {
  94. if (!IsLoginValidation || BLL.BLL_ErpUser.CloseTuthenticationLogin) { return; }
  95. LYFZ.BLL.BLL_ErpUser.UpdateDynamicTimeAccount();
  96. if (LYFZ.BLL.BLL_ErpUser.WhetherTimesOut)
  97. {
  98. ShowLoginAgain(isMessageBoxCustom);
  99. }
  100. }
  101. /// <summary>
  102. /// 登录超时提醒
  103. /// </summary>
  104. void LoginMessageBoxCustom(bool isMessageBoxCustom = true)
  105. {
  106. try
  107. {
  108. if (isMessageBoxCustom)
  109. {
  110. MessageBox.Show("用户登录超时,请重新登录。", "提示");
  111. this.Close();
  112. }
  113. }
  114. catch { }
  115. }
  116. void BaseFormRelease_MouseMove(object sender, MouseEventArgs e)
  117. {
  118. LoginAgain(false);
  119. }
  120. void BaseFormRelease_Load(object sender, EventArgs e)
  121. {
  122. this.plFormMainContent.BackColor = LYFZ.ComponentLibrary.GetUIResources.FrmContentBackgroundColor;
  123. }
  124. /// <summary>
  125. /// 是否覆盖基窗体的OnPaint
  126. /// </summary>
  127. protected bool isOverrideOnPaint = false;
  128. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  129. {
  130. base.OnPaint(e);
  131. if (!isOverrideOnPaint)
  132. {
  133. this.plFormMainContent.Location = new Point(0, this.TitleBgImageHeight);
  134. this.plFormMainContent.Width = this.Width;
  135. this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight;
  136. }
  137. }
  138. /// <summary>
  139. /// 刷新系统菜单
  140. /// </summary>
  141. public void RefreshSystemMeun()
  142. {
  143. InitializationSystemMeun();
  144. }
  145. /// <summary>
  146. /// 显示系统菜单
  147. /// </summary>
  148. /// <param name="sender"></param>
  149. /// <param name="e"></param>
  150. private void btnAppFormMenu_MouseClick(object sender, MouseEventArgs e)
  151. {
  152. Button btn = sender as Button;
  153. Point point = new Point();
  154. point.Y = btn.Height;
  155. if (e.Button == MouseButtons.Left)
  156. {
  157. this.cmsSystemMeunList.Show(btn, point);
  158. }
  159. }
  160. static bool isRights = false;
  161. /// <summary>
  162. /// 是否开启权限控制
  163. /// </summary>
  164. public static bool IsRights
  165. {
  166. get { return BaseFormRelease.isRights; }
  167. set { BaseFormRelease.isRights = value; }
  168. }
  169. bool GetRights(string keyName)
  170. {
  171. if (IsRights)
  172. {
  173. return LYFZ.BLL.BLL_ErpUser.GetRights(LYFZ.Model.Model_UserRights.GetSystemMenuPet(), keyName);
  174. }
  175. else { return true; }
  176. }
  177. /// <summary>
  178. /// 获取菜单项并包括所有子项
  179. /// </summary>
  180. /// <param name="item"></param>
  181. /// <returns></returns>
  182. protected ToolStripMenuItem GetToolStripMenuItem(LYFZ.Model.Model_SystemToolsMenu.Item item)
  183. {
  184. ToolStripMenuItem menuItem = new ToolStripMenuItem(item.Text);
  185. menuItem.Image = LYFZ.WinAPI.CustomPublicMethod.GetMenuItemImage(item.Icon);
  186. menuItem.Name = item.KeyName;
  187. menuItem.Tag = item;
  188. try
  189. {
  190. SetDefaultChecked(menuItem, item.OpenMode);
  191. SetMenuItem_Click(menuItem);
  192. if (item.IsChildMenu)
  193. {
  194. foreach (LYFZ.Model.Model_SystemToolsMenu.Item subItem in item.ChildItems)
  195. {
  196. if (subItem.Type.ToLower() == "separator")
  197. {
  198. menuItem.DropDownItems.Add(GetToolStripSeparator(subItem));
  199. }
  200. else
  201. {
  202. if (!item.Disable && GetRights(subItem.KeyName))
  203. {
  204. ToolStripMenuItem subMenuItem = GetToolStripMenuItem(subItem);
  205. if (!subItem.IsChildMenu || subMenuItem.DropDownItems.Count > 0)
  206. menuItem.DropDownItems.Add(subMenuItem);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. catch { }
  213. return menuItem;
  214. }
  215. /// <summary>
  216. /// 设置默认是否选择
  217. /// </summary>
  218. /// <param name="menuItem"></param>
  219. private void SetDefaultChecked(ToolStripMenuItem menuItem, string openMode)
  220. {
  221. try
  222. {
  223. LYFZ.BLL.BLL_Config bllConfig = new BLL.BLL_Config();
  224. LYFZ.Model.Model_Config modelConfig = bllConfig.GetModel_SysConfig();
  225. switch (openMode)
  226. {
  227. case "SetShowToolsDescription":
  228. menuItem.Checked = bllConfig.Get_IsShowToolsDescription();
  229. break;
  230. case "SetInterfaceSelect":
  231. try
  232. {
  233. string thisInterface = bllConfig.GetInterfaceSelect();
  234. string menuItemInterface = menuItem.Name.Split('_')[0];
  235. if (thisInterface.ToLower() == menuItemInterface.ToLower())
  236. {
  237. menuItem.Checked = true;
  238. }
  239. }
  240. catch { }
  241. break;
  242. }
  243. }
  244. catch { }
  245. }
  246. /// <summary>
  247. /// 设置菜单项单击事件 要在派生窗体中重写实现功能
  248. /// </summary>
  249. /// <param name="menuItem"></param>
  250. protected virtual void SetMenuItem_Click(ToolStripMenuItem menuItem)
  251. {
  252. //请在派生窗体中重写实现功能
  253. }
  254. /// <summary>
  255. /// 获取菜单分隔线
  256. /// </summary>
  257. /// <param name="item"></param>
  258. /// <returns></returns>
  259. protected ToolStripSeparator GetToolStripSeparator(LYFZ.Model.Model_SystemToolsMenu.Item item)
  260. {
  261. ToolStripSeparator spItem = new ToolStripSeparator();
  262. spItem.Name = item.KeyName;
  263. return spItem;
  264. }
  265. /// <summary>
  266. /// 是否重写系统菜单
  267. /// </summary>
  268. public bool IsOverrideSystemMeun = false;
  269. /// <summary>
  270. /// 当IsOverrideSystemMeun为true时设置设置重写的的菜单项
  271. /// </summary>
  272. public List<LYFZ.Model.Model_SystemToolsMenu.Item> MenuItems = null;
  273. /// <summary>
  274. /// 初始化系统菜单
  275. /// </summary>
  276. protected void InitializationSystemMeun()
  277. {
  278. if (this.IsShowBtnFormMenu)
  279. {
  280. try
  281. {
  282. LYFZ.BLL.BLL_SystemToolsMenu bllMenu = new BLL.BLL_SystemToolsMenu(false);
  283. if (!IsOverrideSystemMeun)
  284. {
  285. MenuItems = bllMenu.GetSystemMenuList();
  286. }
  287. this.cmsSystemMeunList.Items.Clear();
  288. if (MenuItems != null)
  289. {
  290. foreach (LYFZ.Model.Model_SystemToolsMenu.Item item in MenuItems)
  291. {
  292. string ToolStripItemType = item.Type.ToLower();
  293. switch (ToolStripItemType)
  294. {
  295. case "separator":
  296. this.cmsSystemMeunList.Items.Add(GetToolStripSeparator(item));
  297. break;
  298. default:
  299. if (!item.Disable && GetRights(item.KeyName))
  300. {
  301. ToolStripMenuItem tItem = GetToolStripMenuItem(item);
  302. if (!item.IsChildMenu || tItem.DropDownItems.Count>0)
  303. {
  304. this.cmsSystemMeunList.Items.Add(tItem);
  305. }
  306. }
  307. break;
  308. }
  309. }
  310. }
  311. }
  312. catch { }
  313. }
  314. }
  315. protected override void CreateHandle()
  316. {
  317. if (!IsHandleCreated)
  318. {
  319. try
  320. {
  321. base.CreateHandle();
  322. }
  323. catch { }
  324. finally
  325. {
  326. if (!IsHandleCreated)
  327. {
  328. base.RecreateHandle();
  329. }
  330. }
  331. }
  332. }
  333. }
  334. }