private void BtnCreate_Click(object sender, EventArgs e) { var lease = new RoomLeaseDTO(); lease.RoomID = this.tbRoomID.Text; lease.RoomTypeID = this.tbRoomType.Text; lease.RoomPrice = Int64.Parse(this.tbRoomPrice.Text.Split()[0].Replace(",", "")); lease.LeaseDate = DateTime.ParseExact(tbRoomDate.Text, "d/M/yyyy", CultureInfo.InvariantCulture).ToString("d"); if (RoomLeaseBUS.InsertRoomLease(lease)) { RoomLeaseDetailDTO detail = new RoomLeaseDetailDTO(); detail.LeaseID = RoomLeaseBUS.GetLastLeaseIDOfRoom(lease.RoomID); foreach (DataGridViewRow row in dgvCustomerData.Rows) { detail.CustomerName = row.Cells["CustomerName"].Value.ToString(); detail.CustomerPassportID = row.Cells["CustomerPassportID"].Value.ToString(); detail.CustomerTypeID = Convert.ToInt32(row.Cells["CustomerTypeID"].Value); detail.CustomerAddress = row.Cells["CustomerAddress"].Value.ToString(); RoomLeaseDetailBUS.InsertDetail(detail); } MainForm mainForm = (MainForm)Owner; mainForm.ReLoadAvailableRoom(); mainForm.ReLoadRoomData(); mainForm.ReCreateLease(); MessageBox.Show("Lập phiếu thuê phòng " + lease.RoomID + " thành công!", "LẬP PHIẾU THUÊ PHÒNG THÀNH CÔNG", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.Close(); }
public static bool InsertDetail(RoomLeaseDetailDTO detail) { try { if (connection.State != ConnectionState.Open) { connection.Open(); } var command = new SqlCommand("ThemChiTietPhieuThue", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@MaPhieu", detail.LeaseID)); command.Parameters.Add(new SqlParameter("@CMND", detail.CustomerPassportID)); command.Parameters.Add(new SqlParameter("@TenKhach", detail.CustomerName)); command.Parameters.Add(new SqlParameter("@MaLoaiKhach", detail.CustomerTypeID)); command.Parameters.Add(new SqlParameter("@DiaChi", detail.CustomerAddress)); command.ExecuteNonQuery(); return(true); } catch (SqlException) { return(false); } finally { connection.Close(); } }
public void AddCustomer(RoomLeaseDetailDTO customer) { this.dgvLeaseCustomer.Rows.Add( customer.CustomerName, customer.CustomerTypeID, CustomerTypeBUS.GetCustomerTypeByID(customer.CustomerTypeID), customer.CustomerPassportID, customer.CustomerAddress); }
public RoomLeaseDetailDTO GetSelectedCustomer() { var detail = new RoomLeaseDetailDTO(); detail.CustomerName = tbCustomerName.Text; detail.CustomerPassportID = tbCustomerPassport.Text; detail.CustomerAddress = rtbCustomerAddress.Text; detail.CustomerTypeID = Convert.ToInt32(dgvLeaseCustomer.CurrentRow.Cells["CustomerTypeID"].Value); return(detail); }
public void EditCustomer(RoomLeaseDetailDTO customer) { this.dgvLeaseCustomer.CurrentRow.SetValues( customer.CustomerName, customer.CustomerTypeID, CustomerTypeBUS.GetCustomerTypeByID(customer.CustomerTypeID), customer.CustomerPassportID, customer.CustomerAddress); var row = this.dgvLeaseCustomer.CurrentRow; this.tbCustomerName.Text = row.Cells["CustomerName"].Value.ToString(); this.tbCustomerPassport.Text = row.Cells["CustomerPassportID"].Value.ToString(); this.tbCustomerType.Text = row.Cells["CustomerType"].Value.ToString(); this.rtbCustomerAddress.Text = row.Cells["CustomerAddress"].Value.ToString(); }
private void BtnConfirm_Click(object sender, EventArgs e) { string[] data = { tbCustomerName.Text, tbCustomerPassport.Text, cbCustomerType.Text, rtbCustomerAddress.Text }; if (data.Any(d => string.IsNullOrWhiteSpace(d))) { MessageBox.Show("Các thông tin không được để trống!", "THÊM THẤT BẠI", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MainForm mainForm = (MainForm)Owner; var customer = new RoomLeaseDetailDTO(); customer.CustomerName = this.tbCustomerName.Text; customer.CustomerPassportID = this.tbCustomerPassport.Text; customer.CustomerTypeID = ((KeyValuePair <string, int>) this.cbCustomerType.SelectedItem).Value; customer.CustomerAddress = this.rtbCustomerAddress.Text; switch (this.Tag) { case "AddForm": { MessageBox.Show("Thêm khách \"" + data[0] + "\" thành công!", "THÊM THÀNH CÔNG", MessageBoxButtons.OK, MessageBoxIcon.Information); mainForm.AddCustomer(customer); break; } case "EditForm": { MessageBox.Show("Sửa khách \"" + data[0] + "\" thành công!", "SỬA THÀNH CÔNG", MessageBoxButtons.OK, MessageBoxIcon.Information); mainForm.EditCustomer(customer); break; } } this.Close(); } }
public static bool InsertDetail(RoomLeaseDetailDTO detail) { return(RoomLeaseDetailDAO.InsertDetail(detail)); }