private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { MySqlConnection con = new sql_conn().getconn(); MySqlCommand cmd = null; MySqlDataReader reader = null; try { con.Open(); cmd = new MySqlCommand("select * from sale1 where id = '" + comboBox1.Text + "'", con); reader = cmd.ExecuteReader(); reader.Read(); textBox4.Text = reader[2].ToString(); } catch { } finally { con.Close(); reader.Close(); } try { dataGridView1.Rows.Clear(); con.Open(); reader = null; cmd = new MySqlCommand("select * from sale2 where id = '" + comboBox1.Text + "'", con); reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader[12].ToString().Contains("退货") == false) { int i = dataGridView1.RowCount; dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[1].Value = reader[0].ToString(); dataGridView1.Rows[i].Cells[2].Value = reader[1].ToString(); dataGridView1.Rows[i].Cells[3].Value = reader[9].ToString(); dataGridView1.Rows[i].Cells[4].Value = reader[3].ToString(); dataGridView1.Rows[i].Cells[5].Value = (double.Parse(reader[3].ToString()) / double.Parse(reader[6].ToString())); dataGridView1.Rows[i].Cells[6].Value = reader[10].ToString(); dataGridView1.Rows[i].Cells[7].Value = reader[2].ToString(); dataGridView1.Rows[i].Cells[8].Value = reader[4].ToString(); dataGridView1.Rows[i].Cells[9].Value = reader[8].ToString(); dataGridView1.Rows[i].Cells[10].Value = reader[11].ToString(); dataGridView1.Rows[i].Cells[11].Value = "0"; dataGridView1.Rows[i].Cells[12].Value = "0"; } } } catch { } finally { con.Close(); reader.Close(); } }
private void init() { MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { //comboBox1.Items.Clear(); mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from unit", mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { unit u = new unit(); u.setId(int.Parse(reader[0].ToString())); u.setUn(reader[1].ToString()); units.Add(u); } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
public void custom_change() { MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from customer where name = '" + comboBox1.Text + "'", mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { textBox2.Text = reader[2].ToString(); phone = reader[3].ToString(); } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
public void custon_load() { MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { comboBox1.Items.Clear(); mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from customer", mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { comboBox1.Items.Add(reader[1].ToString()); } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
private void init2() { MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { //comboBox1.Items.Clear(); mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from specification", mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { spe s = new spe(); s.setId(int.Parse(reader[0].ToString())); s.setSpe(reader[1].ToString()); spes.Add(s); comboBox3.Items.Add(reader[1].ToString()); } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
private void init3() { MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { //comboBox1.Items.Clear(); mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from staff where Username in (select username from user)" /*where Part in (select ID from part where orderInsert = '1'))"*/, mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { comboBox6.Items.Add(reader[1].ToString()); } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
public void assignment() { MySqlDataReader reader = null; MySqlConnection conn = new sql_conn().getconn(); try { conn.Open(); MySqlCommand cmd = new MySqlCommand("select * from part where id = " + this.part, conn); reader = cmd.ExecuteReader(); while (reader.Read()) { this.parts = reader[1].ToString(); this.customerinforAdd = reader[2].ToString(); this.customerInforDelete = reader[3].ToString(); this.customerInforUpdate = reader[4].ToString(); this.customerInforSelect = reader[5].ToString(); this.stockIn = reader[6].ToString(); this.stockOut = reader[7].ToString(); this.inventoryinfor = reader[8].ToString(); this.orderInsert = reader[9].ToString(); this.orderExamine = reader[10].ToString(); this.orderSelect = reader[11].ToString(); this.orderUpdate = reader[12].ToString(); this.returnOrderManage = reader[13].ToString(); this.returnGoodsManage = reader[14].ToString(); this.sendGoodsManage = reader[15].ToString(); this.inventoryStatistics = reader[16].ToString(); this.saleStatistics = reader[17].ToString(); this.returnOrderStatistics = reader[18].ToString(); this.returnGoodsStatistics = reader[19].ToString(); this.commodityAdd = reader[20].ToString(); this.commoditySpecificationAdd = reader[21].ToString(); this.commodityInforUpdate = reader[22].ToString(); this.commodityInforDelete = reader[23].ToString(); this.inventory = reader[24].ToString(); this.staffAdd = reader[25].ToString(); this.staffDelete = reader[26].ToString(); this.staffInforSelect = reader[27].ToString(); this.staffInforUpdate = reader[28].ToString(); this.powerUpdate = reader[29].ToString(); this.supplierAdd = reader[30].ToString(); this.supplierUpdate = reader[31].ToString(); this.supplierDelete = reader[32].ToString(); this.supplierSelect = reader[33].ToString(); this.saleExamination = reader[34].ToString(); } } catch { MessageBox.Show("数据库连接失败,请重试"); } finally { conn.Close(); reader.Close(); get(); } }
public void combobox3_load() { if (comboBox5.Text == "" && comboBox4.Text == "" && comboBox3.Text == "") { comboBox3.Items.Clear(); comboBox4.Items.Clear(); comboBox5.Items.Clear(); } MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from commodity ", mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { if (comboBox2.Items.Contains(reader[1].ToString()) == false) { comboBox2.Items.Add(reader[1].ToString()); } for (int i = 0; i < units.LongCount(); i++) { if (units[i].getId().ToString() == reader[3].ToString() && comboBox4.Items.Contains(units[i].getUn().ToString()) == false) { comboBox4.Items.Add(units[i].getUn().ToString()); } } for (int i = 0; i < spes.LongCount(); i++) { if (spes[i].getId().ToString() == reader[2].ToString() && comboBox3.Items.Contains(spes[i].getSpe().ToString()) == false) { comboBox3.Items.Add(spes[i].getSpe().ToString()); } } if (comboBox5.Items.Contains(reader[7].ToString()) == false) { comboBox5.Items.Add(reader[7].ToString()); } } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
private void text5_Lost() { MySqlConnection mysql = new sql_conn().getconn(); MySqlDataReader reader = null; try { /* comboBox3.Items.Clear(); * comboBox4.Items.Clear(); * comboBox5.Items.Clear();*/ mysql.Open(); MySqlCommand cmd = new MySqlCommand("select * from commodity where Approval = '" + textBox5.Text + "'", mysql); reader = cmd.ExecuteReader(); while (reader.Read()) { for (int i = 0; i < units.LongCount(); i++) { if (units[i].getId().ToString() == reader[3].ToString()) { int a = 0; comboBox4.Text = units[i].getUn().ToString(); } } for (int i = 0; i < spes.LongCount(); i++) { if (spes[i].getId().ToString() == reader[2].ToString()) { int a = 0; comboBox3.Text = spes[i].getSpe().ToString(); } } int a1 = 0; comboBox2.Text = reader[1].ToString(); textBox7.Text = reader[5].ToString(); } } catch { MessageBox.Show("网络连接失败,错误代码1"); } finally { mysql.Close(); reader.Close(); } }
public selectCommodity() { MySqlConnection con = null; MySqlDataReader dr = null; InitializeComponent(); try { init(); init2(); this.dataGridView1.MultiSelect = false; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.AllowUserToAddRows = false; dataGridView1.GotFocus += new EventHandler(select); dataGridView1.LostFocus += new EventHandler(lost); button1.Enabled = false; con = new sql_conn().getconn(); con.Open(); MySqlCommand cmd = new MySqlCommand("select * from commodity ", con); dr = cmd.ExecuteReader(); while (dr.Read()) { int i = dataGridView1.RowCount; dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value = dr[1].ToString(); dataGridView1.Rows[i].Cells[1].Value = spes[int.Parse(dr[2].ToString()) - 1].getSpe(); dataGridView1.Rows[i].Cells[2].Value = dr[7].ToString(); dataGridView1.Rows[i].Cells[3].Value = units[int.Parse(dr[3].ToString()) - 1].getUn(); dataGridView1.Rows[i].Cells[4].Value = dr[5].ToString(); dataGridView1.Rows[i].Cells[5].Value = dr[8].ToString(); } } catch (Exception e) { MessageBox.Show("数据获取失败"); MessageBox.Show(e.Message.ToString()); } finally { con.Close(); dr.Close(); } }
private void textBox1_TextChanged(object sender, EventArgs e) { MySqlConnection con = null; try { init(); init2(); dataGridView1.Rows.Clear(); this.dataGridView1.MultiSelect = false; dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView1.GotFocus += new EventHandler(select); dataGridView1.LostFocus += new EventHandler(lost); button1.Enabled = false; con = new sql_conn().getconn(); con.Open(); MySqlCommand cmd = new MySqlCommand("select * from commodity where Name like binary '%" + textBox1.Text + "%' or Approval like binary '%" + textBox1.Text + "%'", con); MySqlDataReader dr1 = null; dr1 = cmd.ExecuteReader(); while (dr1.Read()) { int i = dataGridView1.RowCount; dataGridView1.Rows.Add(); dataGridView1.Rows[i].Cells[0].Value = dr1[1].ToString(); dataGridView1.Rows[i].Cells[1].Value = spes[int.Parse(dr1[2].ToString()) - 1].getSpe(); dataGridView1.Rows[i].Cells[2].Value = dr1[7].ToString(); dataGridView1.Rows[i].Cells[3].Value = units[int.Parse(dr1[3].ToString()) - 1].getUn(); dataGridView1.Rows[i].Cells[4].Value = dr1[5].ToString(); dataGridView1.Rows[i].Cells[5].Value = dr1[8].ToString(); } dr1.Close(); } catch (Exception e1) { MessageBox.Show("数据获取失败"); MessageBox.Show(e1.Message.ToString()); } finally { con.Close(); } }
public int login(String username, String ps) { int flag = 0; MySqlConnection con = new sql_conn().getconn(); MySqlDataReader reader = null; try { con.Open(); MySqlCommand cmd = new MySqlCommand("select * from user", con); reader = cmd.ExecuteReader(); while (reader.Read()) { if (reader[0].ToString() == username) { flag = 1; if (reader[1].ToString() == ps) { flag = 2; user.userName = reader[0].ToString(); user.password = reader[1].ToString(); user.part = reader[2].ToString(); break; } } } con.Close(); reader.Close(); } catch (Exception e) { MessageBox.Show(e.Message); MessageBox.Show("数据库连接失败,请检查网络连接后重试"); flag = -1; } finally { } return(flag); }
private void button3_Click(object sender, EventArgs e) { if (sales.Count > 0) { if (MessageBox.Show("是否确定添加?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { try { MySqlConnection mysql = new sql_conn().getconn(); mysql.Open(); Double sum = 0; for (int i = 0; i < sales.Count; i++) { sum = sum + sales[i].Sum; } MySqlCommand cmd = new MySqlCommand("insert into sale1 values ('" + sales[0].ID1 + "','" + DateTime.Now.ToShortDateString() + "','" + sales[0].Custom + "','" + sales[0].Jsr + "'," + sum + ",'待出库','')", mysql); cmd.ExecuteNonQuery(); for (int i = 0; i < sales.Count; i++) { cmd = new MySqlCommand("insert into sale2 values ('" + sales[i].ID1 + "','" + sales[i].Name + "'," + sales[i].Num + "," + sales[i].Pack + "," + sales[i].Price + ",'" + sales[i].Ph + "','" + sales[i].Data + "','" + sales[i].Spe + "'," + sales[i].Sum + ",'" + sales[i].Gg + "','" + sales[i].Unit + "','" + sales[i].Sbph + "','','')", mysql); cmd.ExecuteNonQuery(); } mysql.Close(); MessageBox.Show("添加成功"); } catch (Exception f) { MessageBox.Show("销售单号已存在"); MySqlConnection mysql = new sql_conn().getconn(); mysql.Open(); MySqlCommand cmd = new MySqlCommand("delete from sale1 where id = '" + sales[0].ID1 + "'", mysql); cmd.ExecuteNonQuery(); } } } else { MessageBox.Show("销售单内无商品"); } }
private void button2_Click(object sender, EventArgs e) { if (MessageBox.Show("是否确定退单?", "确认", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { MySqlConnection con = new sql_conn().getconn(); MySqlCommand cmd = null; try { con.Open(); cmd = new MySqlCommand("update sale1 set remark = '退单中' where id = '" + comboBox1.Text + "'", con); cmd.ExecuteNonQuery(); cmd = new MySqlCommand("update sale2 set remark = '退单中' where id = '" + comboBox1.Text + "'", con); cmd.ExecuteNonQuery(); MessageBox.Show("退单成功,请等待审核"); con.Close(); } catch { MessageBox.Show("退单失败,请重试"); } } }
private void init1() { MySqlConnection con1 = new sql_conn().getconn(); MySqlCommand cmd1 = null; MySqlDataReader reader1 = null; try { con1.Open(); comboBox2.Items.Clear(); cmd1 = new MySqlCommand("select * from staff", con1); reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { comboBox2.Items.Add(reader1[1].ToString()); } } catch (Exception e) { MessageBox.Show(e.Message.ToString()); } finally { con1.Close(); reader1.Close(); } }
private void textBox1_TextChanged(object sender, EventArgs e) { if (textBox1.Text == "请输入订单日期、客户、订单号、负责人") { dataGridView1.Rows.Clear(); MySqlConnection con = new sql_conn().getconn(); MySqlCommand cmd = null; MySqlDataReader reader = null; try { con.Open(); cmd = new MySqlCommand("select * from sale1 where remark not like '%退单%'", con); reader = cmd.ExecuteReader(); while (reader.Read()) { int x = dataGridView1.RowCount; dataGridView1.Rows.Add(); dataGridView1.Rows[x].Cells[0].Value = reader[0].ToString(); dataGridView1.Rows[x].Cells[1].Value = reader[1].ToString(); dataGridView1.Rows[x].Cells[2].Value = reader[2].ToString(); dataGridView1.Rows[x].Cells[3].Value = reader[3].ToString(); dataGridView1.Rows[x].Cells[4].Value = reader[4].ToString(); dataGridView1.Rows[x].Cells[5].Value = reader[5].ToString(); } } catch { MessageBox.Show("数据库连接失败"); } finally { con.Close(); reader.Close(); } } else { dataGridView1.Rows.Clear(); MySqlConnection con1 = new sql_conn().getconn(); MySqlCommand cmd1 = null; try { MySqlDataReader reader1 = null; con1.Open(); cmd1 = new MySqlCommand("select * from sale1 where id like binary '%" + textBox1.Text + "%' or date like binary '%" + textBox1.Text + "%' or customer like binary '%" + textBox1.Text + "%' or manager like binary '%" + textBox1.Text + "%' or state like binary '%" + textBox1.Text + "%'", con1); reader1 = cmd1.ExecuteReader(); while (reader1.Read()) { if (reader1[6].ToString().Contains("退单") == false) { int x = dataGridView1.RowCount; dataGridView1.Rows.Add(); dataGridView1.Rows[x].Cells[0].Value = reader1[0].ToString(); dataGridView1.Rows[x].Cells[1].Value = reader1[1].ToString(); dataGridView1.Rows[x].Cells[2].Value = reader1[2].ToString(); dataGridView1.Rows[x].Cells[3].Value = reader1[3].ToString(); dataGridView1.Rows[x].Cells[4].Value = reader1[4].ToString(); dataGridView1.Rows[x].Cells[5].Value = reader1[5].ToString(); } } reader1.Close(); } catch (Exception e1) { MessageBox.Show("数据库连接失败"); MessageBox.Show(e1.Message); } finally { con1.Close(); } } }