//加载数据库的中料仓的名字 private void Time_Load(object sender, EventArgs e) { comboBox4.Text = comboBox4.Items[0].ToString(); string sql = "select * from bininfo"; //DataBase db = new DataBase(); //db.command.CommandText = sql; //db.command.Connection = db.connection; //db.Dr = db.command.ExecuteReader(); MySqlConn msc1 = new MySqlConn(); MySqlDataReader rd = msc1.getDataFromTable(sql); while (rd.Read()) { comboBox3.Items.Add(rd["BinName"].ToString()); } rd.Close(); msc1.Close(); if (comboBox3.Items.Count > 0) { comboBox3.Text = comboBox3.Items[0].ToString(); } }
/// <summary> /// type标志是盘库还是清洁镜头 /// 1表示盘库 /// 2表示镜头除尘 /// 3表示镜头除湿 /// </summary> /// <param name="id">料仓id</param> /// <param name="time">执行时间</param> /// <param name="date">执行日期</param> /// <param name="name">料仓名字</param> /// <param name="type">什么操作</param> private void Add_time(string id, string time, string date, string name, string type) { try { string sql_select = "select * from binauto where BinID = " + id; //DataBase db_select = new DataBase(); //db_select.command.CommandText = sql_select; //db_select.command.Connection = db_select.connection; //db_select.Dr = db_select.command.ExecuteReader(); MySqlConn msc1 = new MySqlConn(); MySqlDataReader rd = msc1.getDataFromTable(sql_select); while (rd.Read()) { if (rd["Time"].ToString().Equals(time)) { MessageBox.Show("此料仓在这个时间已经设置了定时功能", "提示"); return; } } rd.Close(); msc1.Close(); } catch (FormatException fexc) { MessageBox.Show("请查看时间格式或关闭定时窗口重新打开", "提示"); } catch (SqlException sec) { MessageBox.Show("请相关人员检查数据库设置", "提示"); } string sql = "insert into binauto values(" + id + ", '" + time + "'," + date + ", '" + name + "', '" + type + "')"; try { //DataBase db = new DataBase(); //db.command.CommandText = sql; //db.command.Connection = db.connection; MySqlConn msc1 = new MySqlConn(); try { int isR = msc1.nonSelect(sql); if (isR > 0) { change = 1; MessageBox.Show("定时 " + comboBox4.Text + " 时间添加成功", "提示"); } } catch (FormatException exc) { MessageBox.Show("请输入正确的时间:" + exc.ToString(), "提示"); } msc1.Close(); } catch (SqlException se) { string message_error = se.ToString(); string path = System.Windows.Forms.Application.StartupPath; FileStream fs = new FileStream(path + "\\log.txt", FileMode.Create | FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine("错误信息是:" + message_error + " 时间是:" + DateTime.Now.ToString()); sw.Flush(); sw.Close(); fs.Close(); MessageBox.Show("定时盘库添加时间时数据库连接失败", "提示"); } }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.Equals("")) { MessageBox.Show("请输入用户名", "提示"); } else if (textBox2.Text.Equals("")) { MessageBox.Show("请输入密码", "提示"); } else { try { //DataBase db = new DataBase(); //db.command.CommandText = "select * from [user]"; //db.command.Connection = db.connection; //db.Dr = db.command.ExecuteReader(); MySqlConn msc = new MySqlConn(); string sql = "select * from user"; MySqlDataReader rdr = msc.getDataFromTable(sql); user_login.logout(); while (rdr.Read()) { if (rdr["UserName"].ToString().Equals(textBox1.Text.Trim())) {//当存在用户时,首先将用户名提取出来 user_login.name = textBox1.Text; if (rdr["PassWord"].ToString().Equals(textBox2.Text)) {//如果密码也相同,则提取权限 user_login.admin = rdr["Admin"].ToString(); label3.Visible = true; button1.Enabled = false; textBox2.Text = ""; if (SaveUsrInfo == 1) {//点击了保存用户名密码按钮 string path = System.Windows.Forms.Application.StartupPath; FileStream fs = new FileStream(path + "\\userinfo.txt", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(user_login.name + "+" + rdr["PassWord"].ToString()); sw.Flush(); sw.Close(); fs.Close(); } Thread.Sleep(50); new Thread(Invoke_show).Start(); break; //Thread thread = new Thread(show_mainform); //thread.IsBackground = false; //thread.Start(); } else { MessageBox.Show("密码错误", "提示"); } } } if (user_login.name.Equals("")) { MessageBox.Show("用户不存在", "提示"); } rdr.Close(); } catch (Exception exc) { //DataBase database = new DataBase(); //string sql_createT = "create table [user] (UserName nvarchar(MAX), PassWord nvarchar(MAX), Admin int);"; //database.command.CommandText = sql_createT; //database.command.Connection = database.connection; //database.command.ExecuteNonQuery(); //string sql_init = "insert into [user] values ('root', '123', 1);"; //database.command.CommandText = sql_init; //database.command.ExecuteNonQuery(); MessageBox.Show("数据库连接出错,请检查数据库连接\r\n错误代码:" + exc.ToString(), "提示"); return; } } }