private void btnTraTB_Click(object sender, EventArgs e) { Object.ObjRentDevice rentDevice = new Object.ObjRentDevice(); if (checkNullItem()) { if (CheckDateTimeRent()) { GanDuLieu(rentDevice); { switch (rentDeviceCtrl.Them(rentDevice)) { case 0: text = "Vui lòng chọn mã người dùng khác!"; ThongBao(text); break; case 1: MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LamMoi(); break; } } } else { MessageBox.Show("Vui lòng chọn ngày trả lớn hơn ngày mượn", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Vui lòng điền đầy đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnTraTB_Click(object sender, EventArgs e) { if (checkNullTextBox() == false) { MessageBox.Show("Xin mời nhập đầy đủ thông tin!", "Cảnh báo"); } else { Object.ObjRentDevice objRentDevice = new Object.ObjRentDevice(); SetDataRentDetail(objRentDevice); DialogResult dlg = MessageBox.Show("Bạn có chắc chắn muốn trả thiết bị này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { if (rentDeviceCtrl.UpdatePay(objRentDevice) > 0) { MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); rentDeviceManage.HienThiTra(dgvListRentDevice); HienThiThongTin(); } else { MessageBox.Show("Id Customer hoặc Id Device không tồn tại, vui lòng thử lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
public void UpdateStatusDevicePay(Object.ObjRentDevice objRentDevice) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "UPDATE Device SET Status_Device = N'Không sử dụng' WHERE Id_Device = @idDevice; "; cmd.Parameters.Add("idDevice", SqlDbType.Int).Value = objRentDevice.Id_Device; cls.CapNhatDL(cmd); }
public int UpdatePay(Object.ObjRentDevice objRentDevice) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "UPDATE Rent_Device " + "SET Status_Rent = N'Không sử dụng' " + "WHERE Id_Rent = @idRent; "; cmd.Parameters.Add("idRent", SqlDbType.Int).Value = objRentDevice.Id_Rent; UpdateStatusDevicePay(objRentDevice); return(cls.CapNhatDL(cmd)); }
public int Save(Object.ObjRentDevice cdt) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO Rent_Device(Date_Rent, Date_Pay, Id_Device, Id_Customer, Status_Rent) " + "VALUES (@dateRent, @datePay, @idDevice, @idCustomer, N'Đang sử dụng'); "; cmd.Parameters.Add("dateRent", SqlDbType.DateTime).Value = cdt.Day_Rent; cmd.Parameters.Add("datePay", SqlDbType.DateTime).Value = cdt.Day_Pay; cmd.Parameters.Add("idDevice", SqlDbType.Int).Value = cdt.Id_Device; cmd.Parameters.Add("idCustomer", SqlDbType.Int).Value = cdt.Id_Customer; UpdateStatusDevice(cdt); return(cls.CapNhatDL(cmd)); }
public int Them(Object.ObjRentDevice rentDevice) { if (!KTMaThietBi(Convert.ToInt32(rentDevice.Id_Device))) { return(1); } if (Login.resultLogin == 1) { if (!KTMaNguoiDung(Convert.ToInt32(rentDevice.Id_Customer))) { return(0); } } return(rentDeviceMng.Save(rentDevice)); }
private void SetDataRentDetail(Object.ObjRentDevice objRentDevice) { objRentDevice.Id_Rent = txtId_Rent.Text; objRentDevice.Day_Rent = txtDate_Rent.Text; objRentDevice.Day_Pay = txtDate_Pay.Text; objRentDevice.Id_Device = txtId_Device.Text; objRentDevice.Id_Customer = txtId_Customer.Text; if (rdbMuon.Checked == true) { objRentDevice.Status_Device = "Đang sử dụng"; } else { objRentDevice.Status_Device = "Không sử dụng"; } }
//Hàm xử lý lưu dữ liệu. private void GanDuLieu(Object.ObjRentDevice rentDevice) { try { rentDevice.Day_Rent = txtDate_Rent.Text.Trim(); rentDevice.Day_Pay = txtDate_Pay.Text.Trim(); string value = cbbThietBi.SelectedValue.ToString(); rentDevice.Id_Device = value; rentDevice.Id_Customer = txtId_Customer.Text.Trim(); rentDevice.Status_Device = "Đang sử dụng"; } catch (Exception e) { MessageBox.Show(e.Message); } }
public int Update(Object.ObjRentDevice objRentDevice) { SqlCommand cmd = new SqlCommand(); cmd.CommandText = "UPDATE Rent_Device " + "SET Date_Rent = @dayRent, Date_Pay = @dayPay, " + "Id_Device = @idDevice, " + "Id_Customer = @idCustomer, " + "Status_Rent = @status " + "WHERE Id_Rent = @idRent; "; cmd.Parameters.Add("dayRent", SqlDbType.DateTime).Value = objRentDevice.Day_Rent; cmd.Parameters.Add("dayPay", SqlDbType.DateTime).Value = objRentDevice.Day_Pay; cmd.Parameters.Add("idDevice", SqlDbType.Int).Value = objRentDevice.Id_Device; cmd.Parameters.Add("idCustomer", SqlDbType.Int).Value = objRentDevice.Id_Customer; cmd.Parameters.Add("status", SqlDbType.NVarChar).Value = objRentDevice.Status_Device; cmd.Parameters.Add("idRent", SqlDbType.Int).Value = objRentDevice.Id_Rent; return(cls.CapNhatDL(cmd)); }
private void btnCapNhat_Click(object sender, EventArgs e) { if (checkNullTextBox() == false) { MessageBox.Show("Xin mời nhập đầy đủ thông tin!", "Cảnh báo"); } else { if (CheckDateTimeRent()) { Object.ObjRentDevice objRentDevice = new Object.ObjRentDevice(); SetDataRentDetail(objRentDevice); string Id_Customer = dgvListRentDevice.CurrentRow.Cells[0].Value.ToString(); string Id_Device_Current = txtId_Device.Text; DialogResult dlg = MessageBox.Show("Bạn có chắc chắn muốn đổi dữ liệu này?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlg == DialogResult.Yes) { if (rentDeviceCtrl.Update(objRentDevice) > 0) { MessageBox.Show("Lưu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); rentDeviceManage.HienThi(dgvListRentDevice); HienThiThongTin(); } else { MessageBox.Show("Id Customer hoặc Id Device không tồn tại hoặc thiết bị đã có người sử dụng, vui lòng thử lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show("Vui lòng chọn ngày trả > ngày mượn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public int UpdatePay(Object.ObjRentDevice rentDevice) { return(rentDeviceMng.UpdatePay(rentDevice)); }
private void SetDataCustomerDetail(Object.ObjRentDevice objRentDevice) { objRentDevice.Id_Customer = txtId_Customer.Text; }