private void addTuyenDi(TuyenDi m) { try { bool kq = TuyenDiDB.add(m); if (kq) { loadData(); ClearInput(); } else { MessageBox.Show("Them ko thanh cong"); } } catch (Exception e) { if (e.Message.Contains("UNIQUE")) { MessageBox.Show("Email trung lap"); } else { MessageBox.Show("Khong the thuc hien duoc: " + e.Message); } } }
private void btnUpdate_Click(object sender, EventArgs e) { if (!isInputValid()) { return; } string maTuyenDi = txtMaTuyenDi.Text.Trim(); string benXeDi = txtBenXeDi.Text.Trim(); string benXeDen = txtBenXeDen.Text.Trim(); DialogResult result = MessageBox.Show("Ban co muon cap nhat " + maTuyenDi, "Cap nhat thong tin ", MessageBoxButtons.YesNo); if (result != DialogResult.Yes) { return; } TuyenDi m = new TuyenDi(maTuyenDi, benXeDi, benXeDen); bool ketQua = TuyenDiDB.update(m); // thong bao if (ketQua) { MessageBox.Show("Cap nhat thanh cong"); } else { MessageBox.Show("Cap nhat ko thanh cong"); } list = TuyenDiDB.getAll(); gridView.DataSource = null; gridView.DataSource = list; }
private void Display(TuyenDi c) { txtMaTuyenDi.Text = c.MaTuyenDi; txtBenXeDi.Text = c.BenXeDi; txtBenXeDen.Text = c.BenXeDen; setEditMode(true); }
public bool update(TuyenDi c) { String sql = "update TuyenDi set benXeDi = @benXeDi, benXeDen = @benXeDen where maTuyenDi = @maTuyenDi"; SqlParameter p1 = new SqlParameter("@maTuyenDi", c.MaTuyenDi); SqlParameter p2 = new SqlParameter("@benXeDi", c.BenXeDi); SqlParameter p3 = new SqlParameter("@benXeDen", c.BenXeDen); SqlParameter[] param = { p1, p2, p3 }; return(manager.executeUpdate(sql, param)); }
private void btnAdd_Click(object sender, EventArgs e) { string maTuyenDi = txtMaTuyenDi.Text.Trim(); string benXeDi = txtBenXeDi.Text.Trim(); string benXeDen = txtBenXeDen.Text.Trim(); TuyenDi m = new TuyenDi(maTuyenDi, benXeDi, benXeDen); list.Add(m); gridView.DataSource = null; gridView.DataSource = list; addTuyenDi(m); }
private void gridView_CellClick(object sender, DataGridViewCellEventArgs e) { int row = e.RowIndex; if (row < 0 || row >= list.Count) { return; } TuyenDi c = list[row]; Display(c); }
public bool add(TuyenDi c) { try { String sql = "insert into TuyenDi values(@maTuyenDi, @benXeDi, @benXeDen)"; SqlParameter p1 = new SqlParameter("@maTuyenDi", c.MaTuyenDi); SqlParameter p2 = new SqlParameter("@benXeDi", c.BenXeDi); SqlParameter p3 = new SqlParameter("@benXeDen", c.BenXeDen); SqlParameter[] param = { p1, p2, p3 }; return(manager.executeUpdate(sql, param)); } catch (Exception e) { return(false); } }
public List <TuyenDi> getAll() { String sql = "select * from TuyenDi"; DataTable table = manager.executeQuery(sql); List <TuyenDi> list = new List <TuyenDi>(); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string maTuyenDi = (string)row["maTuyenDi"]; string benXeDi = (string)row["benXeDi"]; string benXeDen = (string)row["benXeDen"]; TuyenDi c = new TuyenDi(maTuyenDi, benXeDi, benXeDen); list.Add(c); } return(list); }