private void btn_Them_Click(object sender, EventArgs e) { DichVuDTO dv = new DichVuDTO(); if (txt_TenDichVu.Text == "") MessageBox.Show("Chưa nhập Tên dịch vụ"); else if (txt_DonGiaDichVu.Text == "") MessageBox.Show("Chưa nhập đơn giá dịch vụ"); else { dv.TenDichVu = txt_TenDichVu.Text; dv.DonGiaDichVu = uint.Parse(txt_DonGiaDichVu.Text); if (DichVuBUS.ThemDichVu(dv)) { DanhSachDichVu_Load(sender, e); int num = dgv_DanhSachDichVu.Rows.Count; madichvu = Convert.ToUInt32(dgv_DanhSachDichVu.Rows[num - 2].Cells[0].Value); txt_MaDichVu.Text = Convert.ToString(madichvu); MessageBox.Show("Thêm thành công"); } else MessageBox.Show("Thêm thất bại"); } }
private void btn_CapNhat_Click(object sender, EventArgs e) { DichVuDTO dv = new DichVuDTO(); dv.MaDichVu = madichvu; if (dv.MaDichVu != 0) if (txt_TenDichVu.Text == "") MessageBox.Show("Chưa nhập Tên dịch vụ"); else if (txt_DonGiaDichVu.Text == "") MessageBox.Show("Chưa nhập đơn giá dịch vụ"); else { dv.TenDichVu = txt_TenDichVu.Text; dv.DonGiaDichVu = uint.Parse(txt_DonGiaDichVu.Text); if (DichVuBUS.CapNhatDichVu(dv)) { DanhSachDichVu_Load(sender, e); MessageBox.Show("Cập nhật thành công"); } else MessageBox.Show("Cập nhật thất bại"); } else MessageBox.Show("Bạn chưa chọn dịch vụ để cập nhật lại thông tin"); }
public static void Update(DichVuDTO dv) { string sql = "Update DICHVU set TenDichVu =('" + dv.TenDichVu + "'), DonGiaDichVu =('" + dv.DonGiaDichVu + "') where MaDichVu=" + dv.MaDichVu + ""; DataBase.ExcuNonQuery(sql); }
public static DataTable SelectDichVuByMaDichVu(DichVuDTO dv) { string sql = "select * from DICHVU where MaDichVu = " + dv.MaDichVu; return DataBase.ExcuQuery(sql); }
public static void Insert(DichVuDTO dv) { string sql = "insert into DICHVU(TenDichVu, DonGiaDichVu) values ('" + dv.TenDichVu + "', " + dv.DonGiaDichVu + ")"; DataBase.ExcuNonQuery(sql); }
public static void Delete(DichVuDTO dv) { string sql = "delete from DICHVU where MaDichVu = " + dv.MaDichVu + ""; DataBase.ExcuNonQuery(sql); }
public static bool XoaDichVu(DichVuDTO dv) { DichVuDAO.Delete(dv); return true; }
public static bool ThemDichVu(DichVuDTO dv) { DichVuDAO.Insert(dv); return true; }
public static bool CapNhatDichVu(DichVuDTO dv) { DichVuDAO.Update(dv); return true; }
private void dgv_ChiTietPhieuDichVu_CellEndEdit(object sender, DataGridViewCellEventArgs e) { stt = e.RowIndex; dgv_ChiTietPhieuDichVu.Rows[stt].Cells[0].Value = (stt + 1).ToString(); if (dgv_ChiTietPhieuDichVu.Rows[stt].Cells[1].Value == null) dgv_ChiTietPhieuDichVu.Rows[stt].Cells[3].ReadOnly = true; else { dgv_ChiTietPhieuDichVu.Rows[stt + 1].ReadOnly = true; uint madichvu; try { madichvu = Convert.ToUInt32(dgv_ChiTietPhieuDichVu.Rows[stt].Cells[1].Value); } catch { MessageBox.Show("Mã dịch vụ phải là số nguyên dương và không được để trống!!"); return; } if (dgv_ChiTietPhieuDichVu.Rows[stt].Cells[3].Value == null) ktra_soluong = false; for (int i = 0; i < dgv_ChiTietPhieuDichVu.Rows.Count - 1; i++) if (Convert.ToUInt32(dgv_ChiTietPhieuDichVu.Rows[stt].Cells[1].Value) == Convert.ToUInt32(dgv_ChiTietPhieuDichVu.Rows[i].Cells[1].Value) && i != stt) { ktra_trungmadichvu = false; ktra_madichvu = false; MessageBox.Show("Dịch vụ trên đã tồn tại trong danh sách!!"); break; } else ktra_trungmadichvu = true; if (ktra_trungmadichvu) { DichVuDTO dv = new DichVuDTO(); dv.MaDichVu = madichvu; DataTable dt = DichVuDAO.SelectDichVuByMaDichVu(dv); if (dt != null && dt.Rows.Count > 0) { dgv_ChiTietPhieuDichVu.Rows[stt].Cells[2].Value = Convert.ToString(dt.Rows[0]["TenDichVu"]); dgv_ChiTietPhieuDichVu.Rows[stt].Cells[4].Value = Convert.ToString(dt.Rows[0]["DonGiaDichVu"]); dongia = Convert.ToUInt32(dgv_ChiTietPhieuDichVu.Rows[stt].Cells[4].Value); dgv_ChiTietPhieuDichVu.Rows[stt].Cells[3].ReadOnly = false; ktra_madichvu = true; } else { MessageBox.Show("Mã dịch vụ trên không có trong danh sách dịch vụ!!"); ktra_madichvu = false; } } if (dgv_ChiTietPhieuDichVu.Rows[stt].Cells[3].Value != null) { try { soluong = Convert.ToUInt32(dgv_ChiTietPhieuDichVu.Rows[stt].Cells[3].Value); } catch { MessageBox.Show("Số lượng phải là số nguyên dương và không được để trống!!"); return; } if (soluong == 0) { MessageBox.Show("Số lượng phải là số nguyên dương và không được để trống!!"); ktra_soluong = false; } else ktra_soluong = true; } if (ktra_madichvu && ktra_soluong) { ktra_chitietphieudichvu = true; long thanhtien = soluong * dongia; dgv_ChiTietPhieuDichVu.Rows[stt].Cells[5].Value = Convert.ToString(thanhtien); dgv_ChiTietPhieuDichVu.Rows[stt + 1].ReadOnly = false; dgv_ChiTietPhieuDichVu.Rows[dgv_ChiTietPhieuDichVu.Rows.Count - 1].Cells[3].ReadOnly = true; } else ktra_chitietphieudichvu = false; if (ktra_chitietphieudichvu && ktra_khachhang) btn_LapPhieu.Enabled = true; else btn_LapPhieu.Enabled = false; } long tongtrigia = 0; for (int i = 0; i < dgv_ChiTietPhieuDichVu.Rows.Count - 1; i++) { tongtrigia += Convert.ToInt64(dgv_ChiTietPhieuDichVu.Rows[i].Cells[5].Value); } txt_TongCong.Text = tongtrigia.ToString(); }
private void btn_Xoa_Click(object sender, EventArgs e) { DichVuDTO dv = new DichVuDTO(); dv.MaDichVu = madichvu; if (dv.MaDichVu != 0) { if (DichVuBUS.XoaDichVu(dv)) { DanhSachDichVu_Load(sender, e); TaoMoi(); MessageBox.Show("Xóa thành công"); } else MessageBox.Show("Xoá thất bại"); } else MessageBox.Show("Bạn chưa chọn dịch vụ để xóa"); }