private void btnThem_Click(object sender, EventArgs e) { if (txtHoTen.Text.Length > 50 || txtHoTenCha.Text.Length > 50 || txtHoTenMe.Text.Length > 50 || txtDiaChi.Text.Length > 100) { MessageBox.Show("Các trường họ tên không được quá dài (ít hơn 50 ký tự)", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (String.IsNullOrEmpty(txtHoTen.Text) || String.IsNullOrEmpty(txtHoTenCha.Text) || String.IsNullOrEmpty(txtHoTenMe.Text) || String.IsNullOrEmpty(txtDiaChi.Text) || String.IsNullOrEmpty(txtSDT.Text)) { MessageBox.Show("Phải nhập đầy đủ trưởng thông tin. Không có ghi rõ: 'Không có'", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if ((DateTime.Now - dateNgaySinh.Value).TotalDays <= 1095 || (DateTime.Now - dateNgaySinh.Value).TotalDays >= 2190) { MessageBox.Show("Nhà trường chỉ nhận trẻ từ 3 đến 6 tuổi vào học", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } Tre hocsinhmoi = new Tre(txtMaHocSinh.Text, txtHoTen.Text, rdbNam.Checked == true ? (int)GioiTinh.Nam : (int)GioiTinh.Nu, Convert.ToDateTime(dateNgaySinh.Value.ToShortDateString()), txtHoTenCha.Text, txtHoTenMe.Text, txtDiaChi.Text, txtSDT.Text); string ngaytiepnhan = DateTime.Now.ToString("dd-MM-yyyy"); PhieuTiepNhanTre phieumoi = new PhieuTiepNhanTre(txtMaHocSinh.Text, txtMaPhieu.Text, ngaytiepnhan, txtNguoiTiepNhan.Text); try { if (TreBLL.ThemTre(hocsinhmoi) && PhieuTiepNhanBLL.ThemPhieu(phieumoi)) { MessageBox.Show("Đã thêm trẻ thành công", "Thông báo", MessageBoxButtons.OK); CleanInput(); loadDataGridView(); } else { MessageBox.Show("Lỗi khi thêm trẻ", "Thông báo", MessageBoxButtons.OK); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); MessageBox.Show("Vui lòng nhập đầy đủ thông tin cần thiết!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public static bool ThemPhieu(PhieuTiepNhanTre phieumoi) { DataTable dt = PhieuTiepNhanDAL.ThemPhieu(phieumoi); foreach (DataRow row in dt.Rows) { if (row.ItemArray[0].ToString().Trim() == "0") { return(true); } } return(false); }
public static DataTable ThemPhieu(PhieuTiepNhanTre phieumoi) { DataAccessHelper.GetInstance().Open(); SqlCommand cmd = DataAccessHelper.GetInstance().Command("THEM_PHIEU_TIEP_NHAN"); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@MaTre", phieumoi.MaTre); cmd.Parameters.AddWithValue("@MaPhieu", phieumoi.MaPhieu); cmd.Parameters.AddWithValue("@NgayTiepNhanTre", phieumoi.NgayTiepNhan); cmd.Parameters.AddWithValue("@NguoiTiepNhan", phieumoi.NguoiTiepNhan); SqlDataAdapter da = new SqlDataAdapter(cmd); DataAccessHelper.GetInstance().SetDataTable(new DataTable()); da.Fill(DataAccessHelper.GetInstance().GetDataTable()); DataAccessHelper.GetInstance().Close(); return(DataAccessHelper.GetInstance().GetDataTable()); }
public static void ThemTreVaoDBTuExcel(DataTable data, string ngayTiepNhan, string nguoiTiepNhan) { if (data == null || data.Rows.Count == 0) { MessageBox.Show("Không có dữ liệu để import"); return; } try { for (int i = 0; i < data.Rows.Count; i++) { string maTre = TreBLL.GenMaTre(); Tre tre = new Tre(maTre, data.Rows[i][0].ToString().Trim(), // Họ tên Convert.ToInt32(data.Rows[i][1].ToString()), // Giới tính, DateTime.Parse(data.Rows[i][2].ToString().Trim()), // Ngày sinh data.Rows[i][3].ToString().Trim(), // Họ tên cha data.Rows[i][4].ToString().Trim(), // Họ tên mẹ data.Rows[i][5].ToString().Trim(), // Địa chỉ data.Rows[i][6].ToString().Trim()); // SĐT PhieuTiepNhanTre phieumoi = new PhieuTiepNhanTre(maTre, PhieuTiepNhanBLL.GenMaPhieu(), ngayTiepNhan, nguoiTiepNhan); try { TreBLL.ThemTre(tre); PhieuTiepNhanBLL.ThemPhieu(phieumoi); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } MessageBox.Show("Import hoàn tất", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("File nhập vào không đúng định dạng!\nVui lòng xem HDSD để chuẩn bị file có định dạng đúng", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }