using INIFILE; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Data.OleDb; using System.Data.SqlClient; using System.Net; using System.Windows.Forms.DataVisualization.Charting; using SetTools.Views; namespace SetTools { public partial class FormDevice : Form { public String ConSql = @"Provider=Microsoft.Jet.OleDb.4.0; Data Source = " + System.IO.Directory.GetCurrentDirectory() + "\\rqdata.mdb"; public string UA = ""; public string UB = ""; public string UL = ""; SerialPort sp1 = new SerialPort();//sp1.ReceivedBytesThreshold = 1;//只要有1个字符送达端口时便触发DataReceived事件 public FormDevice() { InitializeComponent(); } /// /// 程序启动时 /// /// /// private void FormDevice_Load(object sender, EventArgs e) { INIFILE.Profile.LoadProfile();//加载所有 } /// /// 时间控件 /// /// /// private void TmSend_Tick(object sender, EventArgs e) { } /// /// /// 延时不卡界面 /// /// public void Delay(int milliSecond) { int start = Environment.TickCount; while (Math.Abs(Environment.TickCount - start) < milliSecond) { Application.DoEvents(); } } /// /// 打开串口 /// /// /// private void BtnOpen_Click(object sender, EventArgs e) { this.Close(); } /// /// 开始停止 /// /// /// private void BtnSend_Click(object sender, EventArgs e) { if(textBox1.Text != "" && textBox2.Text != "") { OleDbConnection conn; conn = new OleDbConnection(ConSql); try { string UC = ""; string UD = ""; string UE = ""; int j = 0; conn.Open();//打开数据 //建立SQL语句 string sqlstr = ""; sqlstr = @"select * from [YunXin_Admin] where AdminName = '" + textBox1.Text + "' and Password = '" + textBox2.Text + "'"; OleDbCommand cmd = conn.CreateCommand(); cmd.CommandText = sqlstr; //建立读取G OleDbDataReader odrReader; odrReader = cmd.ExecuteReader(); while (odrReader.Read()) { //比较用户名和密码 DateTime dt1 = Convert.ToDateTime(odrReader[10].ToString()); DateTime dt2 = DateTime.Now; if ( (odrReader[1].ToString() == textBox1.Text) && (odrReader[2].ToString() == textBox2.Text) && (DateTime.Compare(dt1, dt2) > 0)) { UL = odrReader[0].ToString();//人员编号 UA = odrReader[1].ToString();//登录用户名 UB = odrReader[3].ToString();//人名 string sHostName = Dns.GetHostName(); IPHostEntry ipE = Dns.GetHostEntry(sHostName); IPAddress[] IpA = ipE.AddressList; UC += "|"; UC += IpA[1]; UD = "登录"; j = 1; } else { MessageBox.Show("用户名或密码有误!或账号已过期!"); } } //关闭连接 C#操作Access之读取mdb odrReader.Close(); conn.Close();//关闭数据库 if(j == 1) { this.Hide(); UE = Convert.ToString( DateTime.Now.ToString("G") ); conn.Open(); cmd = conn.CreateCommand(); cmd.CommandText = @"INSERT INTO YunXin_AdminLog([AdminName], [UserName], [LoginIP], [LoginSoft],[LoginTime])VALUES('" + UA + "', '"; cmd.CommandText += UB + "', '" + UC + "', '" + UD + "', '"; cmd.CommandText += UE + "')"; cmd.ExecuteNonQuery(); conn.Close(); FormMain fm = new FormMain(); fm.Ua = UA; fm.Ub = UB; fm.Uc = UL; fm.ConSql = ConSql; fm.Show(); } } catch (SqlException ex) { Console.WriteLine(ex.Message); } finally { conn.Close(); } } else { MessageBox.Show("用户名或密码 不能为空!"); } } private void FormDevice_FormClosing(object sender, FormClosingEventArgs e) { try { sp1.Close(); } catch { sp1.Close(); } } private void button2_Click(object sender, EventArgs e) { Register Re = new Register(); Re.Show(); } } }