private void btnThueXe_Click(object sender, EventArgs e) { if (lookKhachHang.ItemIndex == -1) { MessageBox.Show("Vui lòng chọn Khách Hàng...", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (dtChoose.Rows.Count == 0) { MessageBox.Show("Danh sách chọn trống...", "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // Insert ThueXe ThueXe tx = new ThueXe(iD, Convert.ToInt64(lookKhachHang.EditValue), frmDichVu.iDNhanVien, DateTime.Now, tongTien, "", true); try { if (tx == null) { throw new Exception("Lỗi khởi tạo!"); } new ThueXeBLL().Add(tx); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Insert CTThueXe foreach (DataRow dr in dtChoose.Rows) { ChiTietThueXe cttx = new ChiTietThueXe(iD, dr[CHOOSEcolID.FieldName].ToString(), Convert.ToDateTime(dr[CHOOSEcolNgayNhan.FieldName]), Convert.ToDateTime(dr[CHOOSEcolNgayTra.FieldName]), Convert.ToDecimal(dr[CHOOSEcolGiaThue.FieldName])); try { if (cttx == null) { throw new Exception("Lỗi khởi tạo!"); } new ChiTietThueXeBLL().Add(cttx); } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message, "Chú ý!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } MessageBox.Show("Thuê xe thành công...", "Thông báo!", MessageBoxButtons.OK, MessageBoxIcon.Information); uscThueXe_Load(sender, e); }
public Boolean Add(ChiTietThueXe cttx) { try { return(new ChiTietThueXeDAL().Add(cttx)); } catch (DBConcurrencyException ex) { throw ex; } }
public Boolean Add(ChiTietThueXe cttx) { try { _db.ChiTietThueXes.Add(cttx); _db.SaveChanges(); return(true); } catch (Exception ex) { throw ex; } }