public MainForm() { InitializeComponent(); #region 初始化表格 customerView.ColumnCount = Customer.getColumnHeader().Count; supplierView.ColumnCount = Supplier.getColumnHeader().Count; makingView.ColumnCount = Making.getColumnHeader().Count; daomuView.ColumnCount = Daomu.getColumnHeader().Count; for (int i = 0; i < Customer.getColumnHeader().Count; i++) { customerView.Columns[i].Name = Customer.getColumnHeader()[i]; } for (int i = 0; i < Supplier.getColumnHeader().Count; i++) { supplierView.Columns[i].Name = Supplier.getColumnHeader()[i]; } for (int i = 0; i < Making.getColumnHeader().Count; i++) { makingView.Columns[i].Name = Making.getColumnHeader()[i]; } for (int i = 0; i < Daomu.getColumnHeader().Count; i++) { daomuView.Columns[i].Name = Daomu.getColumnHeader()[i]; } #endregion }
private void enterButton_Click(object sender, EventArgs e) { Making m = new Making(); m._Id = this.idTextBox.Text; m._Name = this.nameTextBox.Text; m._Price = (int)Convert.ToDecimal(this.priceTextBox.Text); m._S_id = this.s_idTextBox.Text; m._Type = this.typeComboBox.SelectedIndex; m._Unit = this.unitComboBox.SelectedIndex; if (!this.isEdit) { if (this.connect.add(m)) { MessageBox.Show("新增資料成功!!"); this.makings.Add(m); reset(); } } else { if (this.connect.edit(m, this.makings.ElementAt(index))) { MessageBox.Show("修改資料成功!!"); this.makings.RemoveAt(index); this.makings.Insert(index, m); } else { showData(); } } }
public bool add(Making m) { bool result = false; string addSQL = "INSERT INTO making ("; foreach (string s in m.getSQLStruct()) { addSQL = addSQL + s + ","; } addSQL = addSQL.Substring(0, addSQL.Length - 1); addSQL = addSQL + ") VALUES ("; foreach (string s in m.getSQLData()) { addSQL = addSQL + "'" + s + "',"; } addSQL = addSQL.Substring(0, addSQL.Length - 1); addSQL = addSQL + ")"; try { MySqlCommand cmd = new MySqlCommand(addSQL, conn); MySqlDataReader myData = cmd.ExecuteReader(); result = true; myData.Close(); } catch (MySql.Data.MySqlClient.MySqlException ex) { MessageBox.Show("錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message); } return(result); }
private void showData() { Making m = makings.ElementAt(index); this.idTextBox.Text = m._Id; this.nameTextBox.Text = m._Name; this.typeComboBox.SelectedIndex = m._Type; this.s_idTextBox.Text = m._S_id; this.unitComboBox.SelectedIndex = m._Unit; this.priceTextBox.Text = m._Price.ToString(); this.pageTextBox.Text = (index + 1).ToString(); }
public bool del(Making m) { bool result = false; string addSQL = "DELETE FROM making WHERE id='" + m._Id + "'"; try { MySqlCommand cmd = new MySqlCommand(addSQL, conn); MySqlDataReader myData = cmd.ExecuteReader(); result = true; myData.Close(); } catch (MySql.Data.MySqlClient.MySqlException ex) { MessageBox.Show("錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message); } return(result); }
public bool edit(Making m, Making old) { bool result = false; string addSQL = "UPDATE making SET "; for (int i = 0; i < m.getSQLStruct().Count; i++) { addSQL = addSQL + m.getSQLStruct().ElementAt(i) + " = '" + m.getSQLData().ElementAt(i) + "',"; } addSQL = addSQL.Substring(0, addSQL.Length - 1); addSQL = addSQL + " WHERE id = '" + old._Id + "'"; try { MySqlCommand cmd = new MySqlCommand(addSQL, conn); MySqlDataReader myData = cmd.ExecuteReader(); result = true; myData.Close(); } catch (MySql.Data.MySqlClient.MySqlException ex) { MessageBox.Show("錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message); } return(result); }