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; DataHelper dh1; //后端操作 SqliteDBHelper adh1; //数据上传操作 SqliteDBHelper adh2; DataTable dt; 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) { dh = new DataHelper(); dh1 = new DataHelper(); //启动时压缩数据库 adh1 = new SqliteDBHelper("LabelPrint.db3"); adh2 = new SqliteDBHelper("LabelPrint.db3"); SystemInf.dh = dh; SystemInf.dh1 = dh1; SystemInf.back_adh = adh1; SystemInf.adh = adh2; adh1.ExecuteZip(); //获取账套信息 dt = (DataTable)dh.ExecuteSql("select ma_function,ms_pwd,ma_user from master ", "select"); DataTable MasterDB = dt.Clone(); for (int i = 0; i < dt.Rows.Count; i++) { if (DataHelper.Masters.Contains(dt.Rows[i]["ma_user"].ToString())) { DataRow dr = MasterDB.NewRow(); dr["ma_user"] = dt.Rows[i]["ma_user"]; dr["ma_function"] = dt.Rows[i]["ma_function"]; MasterDB.Rows.Add(dr); } } MasterCombox.DisplayMember = "ma_function"; MasterCombox.ValueMember = "ma_user"; MasterCombox.DataSource = MasterDB; //读取上次登陆时的用户名和选择的账套 UserName.Text = Properties.Settings.Default.LastLoginUser; MasterCombox.Text = Properties.Settings.Default.LastLoginMaster; 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 < dt.Rows.Count; i++) { if (MasterCombox.SelectedValue == dt.Rows[i]["ma_user"]) Ms_Pwd = dt.Rows[i]["ms_pwd"].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; //设置了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 em_code='" + UserName.Text + "'", "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.Save(); //弹出标签打印的主界面 UAS_出货标签打印 main = new UAS_出货标签打印(MasterCombox.Text); main.StartPosition = FormStartPosition.CenterScreen; Hide(); main.ShowDialog(); Close(); } else MessageBox.Show(oMsg); } /// /// 绘制蓝色的背景图 /// /// /// 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(); } } }