Login.cs 5.8 KB

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