private void btnLuuHE_Click(object sender, EventArgs e) { DAL_HEDT hh = new DAL_HEDT(txtMAHE.Text, txtTENHE.Text); DAO_HEDT daoHH = new DAO_HEDT(); int index = valHE == 1 ? dataHE.RowCount : dataHE.CurrentRow.Index; int check = 0; if (valHE == 1) { check = daoHH.Insert_HE(hh); } else if (valHE == 2) { check = daoHH.Update_HE(hh); } else { return; } if (check != 0) { dataHE.DataSource = cn.LoadTable(sqlHE); dataHE.CurrentCell = dataHE.Rows[index].Cells[0]; } else { MessageBox.Show("Không thực hiện được thao tác!", "Thông báo!"); } btnThemHE.Enabled = btnSuaHE.Enabled = btnXoaHE.Enabled = panelTD.Enabled = dataHE.Enabled = true; valHE = 0; txtMAHE.ReadOnly = false; hienthiHE(); }
private void btnXoaHE_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có muốn xóa hệ này?", "Verify!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int cur = dataHE.CurrentRow.Index; DataRow row = cn.LoadTable(sqlHE).Rows[cur]; DAL_HEDT hh = new DAL_HEDT(row); DAO_HEDT daoHH = new DAO_HEDT(); int check = daoHH.Delete_HE(hh); int index = dataHE.CurrentRow.Index == dataHE.RowCount - 1 ? dataHE.RowCount - 2 : cur; if (check != 0) { dataHE.DataSource = cn.LoadTable(sqlHE); if (dataHE.RowCount > 1) { dataHE.CurrentCell = dataHE.Rows[index].Cells[0]; } } else { MessageBox.Show("Không xóa được hệ này!", "Thông báo!"); } hienthiHE(); } }
public List <DAL_HEDT> GetDSHEDT() { DataTable dt = cn.LoadTable("Select * from HEDAOTAO"); List <DAL_HEDT> DSHEDT = new List <DAL_HEDT>(); foreach (DataRow dr in dt.Rows) { DAL_HEDT hh = new DAL_HEDT(dr); DSHEDT.Add(hh); } return(DSHEDT); }
public int Delete_HE(DAL_HEDT hp) { string[] para = new string[1] { "@ma" }; object[] values = new object[1] { hp.MAHE }; int check = 0; try { check = cn.Excute_Sql("XoaHE", CommandType.StoredProcedure, para, values); } catch { } return(check); }
public int Update_HE(DAL_HEDT hp) { string[] para = new string[2] { "@ma", "@ten" }; object[] values = new object[2] { hp.MAHE, hp.TENHE }; int check = 0; try { check = cn.Excute_Sql("SuaHE", CommandType.StoredProcedure, para, values); } catch { } return(check); }