HeadBar.cs 5.4 KB

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