HeadBar.cs 5.2 KB

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