Login.cs 5.7 KB

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