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 }
public bool add(Daomu d) { bool result = false; string addSQL = "INSERT INTO daomu ("; foreach (string s in d.getSQLStruct()) { addSQL = addSQL + s + ","; } addSQL = addSQL.Substring(0, addSQL.Length - 1); addSQL = addSQL + ") VALUES ("; foreach (string s in d.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() { Daomu d = daomus.ElementAt(index); this.cabinetTextBox.Text = d._Cabinet.ToString(); this.d_longTextBox.Text = d._D_long.ToString(); this.d_roundTextBox.Text = d._D_round.ToString(); this.d_widthTextBox.Text = d._D_width.ToString(); this.idTextBox.Text = d._Id; this.l_dTextBox.Text = d._L_d.ToString(); this.l_mTextBox.Text = d._L_m.ToString(); this.typeComboBox.SelectedIndex = d._Type; this.w_dTextBox.Text = d._W_d.ToString(); this.w_mTextBox.Text = d._W_m.ToString(); this.pageTextBox.Text = (this.index + 1).ToString(); }
public bool del(Daomu d) { bool result = false; string addSQL = "DELETE FROM daomu WHERE id='" + d._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); }
private void enterButton_Click(object sender, EventArgs e) { Daomu d = new Daomu(); d._Cabinet = (int)Convert.ToDecimal(this.cabinetTextBox.Text); d._D_long = (int)Convert.ToDecimal(this.d_longTextBox.Text); d._D_round = (int)Convert.ToDecimal(this.d_roundTextBox.Text); d._D_width = (int)Convert.ToDecimal(this.d_widthTextBox.Text); d._Id = this.idTextBox.Text; d._L_d = (int)Convert.ToDecimal(this.l_dTextBox.Text); d._L_m = (int)Convert.ToDecimal(this.l_mTextBox.Text); d._Type = this.typeComboBox.SelectedIndex; d._W_d = (int)Convert.ToDecimal(this.w_dTextBox.Text); d._W_m = (int)Convert.ToDecimal(this.w_mTextBox.Text); if (!this.isEdit) { if (this.connect.add(d)) { MessageBox.Show("新增資料成功!!"); this.daomus.Add(d); reset(); } } else { if (this.connect.edit(d, this.daomus.ElementAt(index))) { MessageBox.Show("修改資料成功!!"); this.daomus.RemoveAt(index); this.daomus.Insert(index, d); } else { showData(); } } }
public bool edit(Daomu d, Daomu old) { bool result = false; string addSQL = "UPDATE daomu SET "; for (int i = 0; i < d.getSQLStruct().Count; i++) { addSQL = addSQL + d.getSQLStruct().ElementAt(i) + " = '" + d.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(old._Id + "\n錯誤代碼: " + ex.Number + "\n 錯誤訊息 : " + ex.Message); } return(result); }