public void CreateItem(CT_PhieuDKHP cT_PhieuDKHP) { try { if (connection.State != ConnectionState.Open) { connection.Open(); } OleDbCommand command = new OleDbCommand( "INSERT INTO CT_PHIEU_DKHP (MonHoc, SoPhieu) VALUES (@monhoc, @sophieu)", connection); command.Parameters.Add("@monhoc", OleDbType.Numeric).Value = cT_PhieuDKHP.MonHoc; command.Parameters.Add("@sophieu", OleDbType.Numeric).Value = cT_PhieuDKHP.SoPhieu; command.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { connection.Close(); } }
private void XacNhanLuuPhieuDKHP() { phieuDKHP.MaSoSV = sinhVien.MaSo; string errorString = CheckThongTinPhieuDKHP(); if (errorString != "") { MessageBox.Show(errorString, "ERROR"); return; } List <CT_PhieuDKHP> cT_PhieuDKHPs = new List <CT_PhieuDKHP>(); foreach (DataRow row in CT_PhieuDKHPs.Rows) { CT_PhieuDKHP cT_PhieuDKHP = new CT_PhieuDKHP(); int number; if (!int.TryParse(row["MonHoc"].ToString(), out number)) { continue; } cT_PhieuDKHP.MonHoc = number; cT_PhieuDKHPs.Add(cT_PhieuDKHP); } errorString = CheckCT_PhieuDKHPs(cT_PhieuDKHPs); if (errorString == "") { PhieuDKHP_DAL phieuDKHP_DAL = new PhieuDKHP_DAL(dbConnection); CT_PhieuDKHP_DAL cT_PhieuDKHP_DAL = new CT_PhieuDKHP_DAL(dbConnection); phieuDKHP_DAL.CreateItem(phieuDKHP); foreach (CT_PhieuDKHP cT_PhieuDKHP in cT_PhieuDKHPs) { cT_PhieuDKHP_DAL.CreateItem(cT_PhieuDKHP); } MessageBox.Show("Lưu Phiếu ĐKHP thành công"); } else { MessageBox.Show(errorString, "ERROR"); } }