using System;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Windows.Forms;
using UAS_LabelMachine.Entity;
namespace UAS_LabelMachine
{
public partial class Login : Form
{
DataHelper dh;
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)
{
FileInfo f = new FileInfo(@"C:\打印标签\94 大疆 中盒.lab");
Console.WriteLine(f.LastWriteTime);
dh = new DataHelper();
//获取账套信息
dt= (DataTable)dh.ExecuteSql("select ma_function,ms_pwd,ma_user from master where ma_enable<>0", "select");
MasterCombox.DisplayMember = "ma_function";
MasterCombox.ValueMember = "ma_user";
MasterCombox.DataSource = dt;
//读取上次登陆时的用户名和选择的账套
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 = "Data Source=" + IP.Text + "/orcl;User ID=" + MasterCombox.SelectedValue + ";PassWord=" + Ms_Pwd;
DataHelper.DBConnectionString = ConnectionString;
//设置了Connection,重新执行构造函数,重置数据库连接
dh = new DataHelper();
if (dh.CheckExist("employee", "em_code='" + UserName.Text + "' and em_password='" + PassWord.Text + "'"))
{
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_出货标签打印();
main.StartPosition = FormStartPosition.CenterScreen;
Hide();
main.ShowDialog();
Close();
}
else
{
MessageBox.Show("用户名或者密码错误!");
}
}
///
/// 绘制蓝色的背景图
///
///
///
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();
}
private void IP_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
DataHelper.DBConnectionString = "Data Source=" + IP.Text + "/orcl;User ID=DATACENTER;PassWord=select!#%*(";
}
}
}