HeadBar.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Runtime.InteropServices;
  5. using UAS_MES.CustomControl.AccordionMenu;
  6. using System.Windows.Forms;
  7. using UAS_MES.DataOperate;
  8. using UAS_MES.Entity;
  9. using UAS_MES.PublicMethod;
  10. namespace UAS_MES.CustomControl
  11. {
  12. public partial class HeadBar : UserControl
  13. {
  14. //需要关闭前提示窗口的在这里加
  15. private List<string> NeedConfirm = new List<string>() { "Main" };
  16. [DllImport("user32.dll")]
  17. public static extern bool ReleaseCapture();
  18. [DllImport("user32.dll")]
  19. public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
  20. public const int WM_SYSCOMMAND = 0x0112;
  21. public const int SC_MOVE = 0xF010;
  22. public const int HTCAPTION = 0x0002;
  23. //定义委托
  24. public delegate void OnHeadBarClick(object sender, EventArgs e);
  25. //定义事件
  26. public event OnHeadBarClick HeadBarDoubleClick;
  27. string Title1;
  28. public string Title
  29. {
  30. get
  31. {
  32. return Title1;
  33. }
  34. set
  35. {
  36. Title1 = value;
  37. }
  38. }
  39. public HeadBar()
  40. {
  41. InitializeComponent();
  42. }
  43. /// <summary>
  44. /// 用于对窗体的关闭,判断主窗体的时候退出程序,非主窗体时关闭该窗体,同时回收内存
  45. /// </summary>
  46. /// <param name="sender"></param>
  47. /// <param name="e"></param>
  48. public void CloseWindow_Click(object sender, EventArgs e)
  49. {
  50. //判断是否需要关闭前的提示
  51. if (NeedConfirm.Contains(this.FindForm().Name))
  52. {
  53. string logout_confirm = MessageBox.Show(this.ParentForm, "是否退出程序", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  54. if (logout_confirm == "Yes")
  55. {
  56. this.FindForm().Close();
  57. //杀死全部未关闭的进程
  58. System.Environment.Exit(0);
  59. }
  60. }
  61. else
  62. {
  63. this.FindForm().Close();
  64. //杀死全部未关闭的进程
  65. System.Environment.Exit(0);
  66. }
  67. }
  68. private void panel1_Click(object sender, EventArgs e)
  69. {
  70. HeadBarDoubleClick?.Invoke(sender, new EventArgs());
  71. }
  72. private void MinWindow_Click(object sender, EventArgs e)
  73. {
  74. this.FindForm().WindowState = FormWindowState.Minimized;
  75. }
  76. private void HeadBar_Load(object sender, EventArgs e)
  77. {
  78. TitleLabel.Text = Title1;
  79. if (!NeedConfirm.Contains(this.FindForm().Name))
  80. {
  81. LoginOut.Visible = false;
  82. }
  83. }
  84. private void pictureBox1_Click(object sender, EventArgs e)
  85. {
  86. //判断是否需要关闭前的提示
  87. if (NeedConfirm.Contains(this.FindForm().Name))
  88. {
  89. string logout_confirm = MessageBox.Show(this.ParentForm, "退出登录?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question).ToString();
  90. if (logout_confirm == "Yes")
  91. {
  92. //注销的时候切换回默认数据库
  93. SystemInf.ConnectionString = Properties.Settings.Default.Properties["MES"].DefaultValue.ToString();
  94. DataHelper.DBConnectionString = SystemInf.ConnectionString;
  95. //清除上个用户的权限信息
  96. SystemInf.Caller.Clear();
  97. //清除已经打开过的窗口的信息
  98. AccordionMenu.AccordionMenu.OpenedFormName.Clear();
  99. //注销的时候将除了登陆窗口之外的全部窗口关闭
  100. for (int i = 0; i < Application.OpenForms.Count; i++)
  101. {
  102. if (Application.OpenForms[i].Name != "Login")
  103. Application.OpenForms[i].Close();
  104. }
  105. this.FindForm().Hide();
  106. Login login = new Login();
  107. login.ShowDialog();
  108. this.FindForm().Close();
  109. }
  110. }
  111. }
  112. private void LoginOut_MouseEnter(object sender, EventArgs e)
  113. {
  114. this.Cursor = Cursors.Hand;
  115. }
  116. private void LoginOut_MouseLeave(object sender, EventArgs e)
  117. {
  118. this.Cursor = Cursors.Default;
  119. }
  120. }
  121. }