private void btnUpdateMA_Click(object sender, EventArgs e) { con = SQLConnection.GetConnection(); try { con.Open(); bool proceed = (dgvMA.Rows.Count - 1) <= int.Parse(SQLConnection.SelectTS("TS_SLMonAn")); if (proceed) { adapter = new SqlDataAdapter("SELECT * FROM MONAN", con); SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter); cmdBuilder.GetUpdateCommand(); cmdBuilder.GetInsertCommand(); cmdBuilder.GetDeleteCommand(); adapter.Update(ds, "MonAn"); MessageBox.Show("Thành công!", "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Information); changes = true; } else { MessageBox.Show("Lỗi!\n\nQuá số lượng món ăn cho phép", "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("Lỗi!\n\n" + ex.Message, "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Warning); } changes = true; }
private void btnUpdateRoom_Click(object sender, EventArgs e) { con = SQLConnection.GetConnection(); using (con) { try { con.Open(); string TS_LoaiPhong = SQLConnection.SelectTS("TS_LoaiPhong"); string[] loaiPhong = TS_LoaiPhong.Split(','); bool proceed = true; for (int i = 0; i < dgvRoom.Rows.Count - 1; i++) { proceed = loaiPhong.Any(dgvRoom.Rows[i].Cells[1].Value.ToString().Contains); if (!proceed) { break; } } if (proceed) { adapter = new SqlDataAdapter("SELECT * FROM PHONG", con); SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter); cmdBuilder.GetUpdateCommand(); cmdBuilder.GetInsertCommand(); cmdBuilder.GetDeleteCommand(); adapter.Update(ds, "Phong"); MessageBox.Show("Thành công!", "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Information); changes = true; } else { MessageBox.Show("Lỗi!\n\nSai loại phòng", "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("Lỗi!\n\n" + ex.Message, "Control Panel", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void DoiPhong_Load(object sender, EventArgs e) { LoadCBPhong(); lblPhi.Text = "Phí đổi phòng: " + SQLConnection.SelectTS("TS_DoiPhongPhat"); }
private void btnAccept_Click(object sender, EventArgs e) { try { string where1 = "IDPhong = N'" + soPhongCu + "'"; DateTime checkIn = Convert.ToDateTime(SQLConnection.SelectOne("NgayDen", "PhieuDatPhong", where1)); DateTime checkOut = Convert.ToDateTime(SQLConnection.SelectOne("NgayDi", "PhieuDatPhong", where1)); int diffDays = SoNgayO(checkIn, checkOut); string where2 = "IDPhong = N'" + cbPhongMoi.SelectedValue.ToString() + "'"; int tongPhongMoi = diffDays * Convert.ToInt32(SQLConnection.SelectOne("GiaPhong", "Phong", where2)); string _IDPhieuDatPhong = SQLConnection.SelectOne("IDPhieuDatPhong", "PhieuDatPhong", where1); string where3 = "IDPhieuDatPhong = " + _IDPhieuDatPhong; int phatDoiPhong = int.Parse(SQLConnection.SelectOne("PhiDoiPhong", "PhieuDatPhong", where1)) + int.Parse(SQLConnection.SelectTS("TS_DoiPhongPhat")); int soLanDoiPhong = int.Parse(SQLConnection.SelectOne("SoLanDoiPhong", "PhieuDatPhong", where1)) + 1; string val = "PhiDoiPhong = " + phatDoiPhong + ", SoLanDoiPhong = " + soLanDoiPhong + ", IDPhong = N'" + cbPhongMoi.SelectedValue.ToString() + "'" + ", TongCong = " + tongPhongMoi; SQLConnection.Update("PhieuDatPhong", val, where3); string valTrong = "TinhTrang = 0"; string valCoNguoi = "TinhTrang = 1"; SQLConnection.Update("Phong", valTrong, where1); SQLConnection.Update("Phong", valCoNguoi, where2); MessageBox.Show("Thành Công!", "Đổi phòng", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public DoiPhong(string soPhong) { InitializeComponent(); lblPhong.Text = "Phòng cũ: " + soPhong; soPhongCu = soPhong; string where1 = "IDPhong = N'" + soPhongCu + "'"; if (int.Parse(SQLConnection.SelectOne("SoLanDoiPhong", "PhieuDatPhong", where1)) >= int.Parse(SQLConnection.SelectTS("TS_SoLanDoiPhong"))) { MessageBox.Show("Vượt quá số lần đổi cho phép", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); LockControl(); } }