//加载数据库的中料仓的名字 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("定时盘库添加时间时数据库连接失败", "提示"); } }