Login.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.IO;
  6. using System.Windows.Forms;
  7. using UAS_LabelMachine.Entity;
  8. using UAS_LabelMachine.PublicMethod;
  9. namespace UAS_LabelMachine
  10. {
  11. public partial class Login : Form
  12. {
  13. DataHelper dh;
  14. DataHelper dh1;
  15. //后端操作
  16. SqliteDBHelper adh1;
  17. //数据上传操作
  18. SqliteDBHelper adh2;
  19. DataTable dt;
  20. public Login()
  21. {
  22. InitializeComponent();
  23. StartPosition = FormStartPosition.CenterScreen;
  24. }
  25. protected override void WndProc(ref Message m)
  26. {
  27. //拦截双击标题栏、移动窗体的系统消息
  28. if (m.Msg != 0xA3)
  29. base.WndProc(ref m);
  30. }
  31. private void Login_Load(object sender, EventArgs e)
  32. {
  33. dh = new DataHelper();
  34. dh1 = new DataHelper();
  35. //启动时压缩数据库
  36. adh1 = new SqliteDBHelper("LabelPrint.db3");
  37. adh2 = new SqliteDBHelper("LabelPrint.db3");
  38. SystemInf.dh = dh;
  39. SystemInf.dh1 = dh1;
  40. SystemInf.back_adh = adh1;
  41. SystemInf.adh = adh2;
  42. adh1.ExecuteZip();
  43. //获取账套信息
  44. dt = (DataTable)dh.ExecuteSql("select ma_function,ms_pwd,ma_user from master ", "select");
  45. DataTable MasterDB = dt.Clone();
  46. for (int i = 0; i < dt.Rows.Count; i++)
  47. {
  48. if (DataHelper.Masters.Contains(dt.Rows[i]["ma_user"].ToString()))
  49. {
  50. DataRow dr = MasterDB.NewRow();
  51. dr["ma_user"] = dt.Rows[i]["ma_user"];
  52. dr["ma_function"] = dt.Rows[i]["ma_function"];
  53. MasterDB.Rows.Add(dr);
  54. }
  55. }
  56. MasterCombox.DisplayMember = "ma_function";
  57. MasterCombox.ValueMember = "ma_user";
  58. MasterCombox.DataSource = MasterDB;
  59. //读取上次登陆时的用户名和选择的账套
  60. UserName.Text = Properties.Settings.Default.LastLoginUser;
  61. MasterCombox.Text = Properties.Settings.Default.LastLoginMaster;
  62. IP.Text = Properties.Settings.Default.IPAddress;
  63. //如果上次的用户名不为空则直接跳到密码输入框
  64. if (UserName.Text != "")
  65. PassWord.Select();
  66. if (!Directory.Exists("Log"))//若文件夹不存在则新建文件夹
  67. Directory.CreateDirectory("Log"); //新建文件夹
  68. string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
  69. if (!Directory.Exists(sysdisc + @":\打印标签"))
  70. Directory.CreateDirectory(sysdisc + @":\打印标签");
  71. FileStream fs = new FileStream("Log/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
  72. }
  73. private void LoginIcon_Click(object sender, EventArgs e)
  74. {
  75. //根据匹配的账套在DataTable查找到对应的密码
  76. string Ms_Pwd = "";
  77. for (int i = 0; i < dt.Rows.Count; i++)
  78. {
  79. if (MasterCombox.SelectedValue == dt.Rows[i]["ma_user"])
  80. Ms_Pwd = dt.Rows[i]["ms_pwd"].ToString();
  81. }
  82. //切换至用户选择的数据源
  83. string ConnectionString = "Connection Timeout=0;Pooling=false;Password=" + Ms_Pwd + ";User ID=" + MasterCombox.SelectedValue.ToString() + ";Pooling=false;Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" + IP.Text + ")(PORT=" + DataHelper.OraclePort + ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));";
  84. DataHelper.DBConnectionString = ConnectionString;
  85. //设置了Connection,重新执行构造函数,重置数据库连接
  86. dh = new DataHelper();
  87. string oMsg = "";
  88. if (HttpHandler.CheckUserLogin(UserName.Text, PassWord.Text, MasterCombox.SelectedValue.ToString(), out oMsg))
  89. {
  90. dt = (DataTable)dh.ExecuteSql("select em_name,em_type from employee where em_code='" + UserName.Text + "'", "select");
  91. User.UserName = dt.Rows[0]["em_name"].ToString();
  92. User.UserCode = UserName.Text;
  93. User.UserAccountType = dt.Rows[0]["em_type"].ToString();
  94. //保存此次登陆的用户名和密码
  95. Properties.Settings.Default.LastLoginUser = UserName.Text;
  96. Properties.Settings.Default.LastLoginMaster = MasterCombox.Text;
  97. Properties.Settings.Default.IPAddress = IP.Text;
  98. Properties.Settings.Default.Save();
  99. //弹出标签打印的主界面
  100. UAS_出货标签打印 main = new UAS_出货标签打印(MasterCombox.Text);
  101. main.StartPosition = FormStartPosition.CenterScreen;
  102. Hide();
  103. main.ShowDialog();
  104. Close();
  105. }
  106. else MessageBox.Show(oMsg);
  107. }
  108. /// <summary>
  109. /// 绘制蓝色的背景图
  110. /// </summary>
  111. /// <param name="sender"></param>
  112. /// <param name="e"></param>
  113. private void Login_Paint(object sender, PaintEventArgs e)
  114. {
  115. //简单的画一个浅蓝色的背景
  116. Graphics g = e.Graphics;
  117. GraphicsPath Rect = new GraphicsPath();
  118. Pen p = new Pen(Color.CadetBlue, 2);
  119. Rectangle rect = new Rectangle(141, 80, 600, 300);
  120. LinearGradientBrush b3 = new LinearGradientBrush(rect, Color.AliceBlue, Color.LightBlue, LinearGradientMode.Vertical);
  121. g.FillRectangle(b3, rect);
  122. e.Graphics.DrawRectangle(p, rect);
  123. }
  124. private void PassWord_KeyDown(object sender, KeyEventArgs e)
  125. {
  126. if (e.KeyCode == Keys.Enter)
  127. {
  128. LoginIcon_Click(sender, e);
  129. }
  130. }
  131. private void Login_FormClosing(object sender, FormClosingEventArgs e)
  132. {
  133. Application.Exit();
  134. }
  135. }
  136. }