123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- using System;
- using System.Data;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.IO;
- using System.Windows.Forms;
- using UAS_LabelMachine.Entity;
- using UAS_LabelMachine.PublicMethod;
- namespace UAS_LabelMachine
- {
- public partial class Login : Form
- {
- DataHelper dh;
- SqliteDBHelper sdh;
- DataTable dt;
- DataTable Masterdt;
- public Login()
- {
- InitializeComponent();
- StartPosition = FormStartPosition.CenterScreen;
- }
- protected override void WndProc(ref Message m)
- {
- //拦截双击标题栏、移动窗体的系统消息
- if (m.Msg != 0xA3)
- base.WndProc(ref m);
- }
- private void Login_Load(object sender, EventArgs e)
- {
- SystemInf.dh = dh = new DataHelper();
- if (dh.GetConfig("FTPNET", "FTPNET").ToString() != "")
- {
- FTPNet.Visible = true;
- }
- //获取账套信息
- Masterdt = (DataTable)dh.ExecuteSql("select ma_function,ms_pwd,ma_user from master ", "select");
- MasterCombox.DisplayMember = "ma_function";
- MasterCombox.ValueMember = "ma_user";
- MasterCombox.DataSource = Masterdt;
- //读取上次登陆时的用户名和选择的账套
- UserName.Text = Properties.Settings.Default.LastLoginUser;
- MasterCombox.Text = Properties.Settings.Default.LastLoginMaster;
- FTPNet.Checked = Properties.Settings.Default.FTPNET;
- IP.Text = Properties.Settings.Default.IPAddress;
- //如果上次的用户名不为空则直接跳到密码输入框
- if (UserName.Text != "")
- PassWord.Select();
- if (!Directory.Exists("Log"))//若文件夹不存在则新建文件夹
- Directory.CreateDirectory("Log"); //新建文件夹
- string sysdisc = Environment.GetEnvironmentVariable("windir").Substring(0, 1);
- if (!Directory.Exists(sysdisc + @":\打印标签"))
- Directory.CreateDirectory(sysdisc + @":\打印标签");
- FileStream fs = new FileStream("Log/" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
- }
- private void LoginIcon_Click(object sender, EventArgs e)
- {
- //根据匹配的账套在DataTable查找到对应的密码
- string Ms_Pwd = "";
- for (int i = 0; i < Masterdt.Rows.Count; i++)
- {
- if (MasterCombox.SelectedValue == Masterdt.Rows[i]["ma_user"])
- Ms_Pwd = Masterdt.Rows[i]["ms_pwd"].ToString();
- }
- //切换至用户选择的数据源
- //MessageBox.Show(MasterCombox.SelectedValue.ToString());
- 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)));";
- DataHelper.DBConnectionString = ConnectionString;
- //设置当前账套
- SystemInf.Master = MasterCombox.SelectedValue.ToString();
- SystemInf.sdh = sdh = new SqliteDBHelper(SystemInf.Master + ".db3");
- SystemInf.IP = IP.Text;
- //设置了Connection,重新执行构造函数,重置数据库连接
- dh = new DataHelper();
- string oMsg = "";
- if (HttpHandler.CheckUserLogin(UserName.Text, PassWord.Text, MasterCombox.SelectedValue.ToString(), out oMsg))
- {
- dt = (DataTable)dh.ExecuteSql("select em_name,em_type from employee where upper(em_code)='" + UserName.Text.ToUpper() + "'", "select");
- User.UserName = dt.Rows[0]["em_name"].ToString();
- User.UserCode = UserName.Text;
- User.UserAccountType = dt.Rows[0]["em_type"].ToString();
- //保存此次登陆的用户名和密码
- Properties.Settings.Default.LastLoginUser = UserName.Text;
- Properties.Settings.Default.LastLoginMaster = MasterCombox.Text;
- Properties.Settings.Default.IPAddress = IP.Text;
- Properties.Settings.Default.FTPNET = FTPNet.Checked;
- Properties.Settings.Default.Save();
- ftpOperater.Inner = FTPNet.Checked;
- //弹出标签打印的主界面
- UAS_出货标签打印 main = new UAS_出货标签打印(MasterCombox.Text);
- main.StartPosition = FormStartPosition.CenterScreen;
- Hide();
- main.ShowDialog();
- Close();
- }
- else MessageBox.Show(oMsg);
- }
- /// <summary>
- /// 绘制蓝色的背景图
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Login_Paint(object sender, PaintEventArgs e)
- {
- //简单的画一个浅蓝色的背景
- Graphics g = e.Graphics;
- GraphicsPath Rect = new GraphicsPath();
- Pen p = new Pen(Color.CadetBlue, 2);
- Rectangle rect = new Rectangle(141, 80, 600, 300);
- LinearGradientBrush b3 = new LinearGradientBrush(rect, Color.AliceBlue, Color.LightBlue, LinearGradientMode.Vertical);
- g.FillRectangle(b3, rect);
- e.Graphics.DrawRectangle(p, rect);
- }
- private void PassWord_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Enter)
- {
- LoginIcon_Click(sender, e);
- }
- }
- private void Login_FormClosing(object sender, FormClosingEventArgs e)
- {
- Application.Exit();
- }
- }
- }
|