예제 #1
0
 private void pbDelete_Click(object sender, EventArgs e)
 {
     try
     {
         if (dgvPurchase.Rows.Count > 0)
         {
             this.gbInfor.Text = "Deleting.....";
             // Thực hiện lệnh
             // Lấy thứ tự record hiện hành
             int r = dgvPurchase.CurrentCell.RowIndex;
             // Lấy MaKH của record hiện hành
             string strCMND = dgvPurchase.Rows[r].Cells[0].Value.ToString();
             // Viết câu lệnh SQL
             // Hiện thông báo xác nhận việc xóa mẫu tin
             // Khai báo biến traloi
             DialogResult traloi;
             // Hiện hộp thoại hỏi đáp
             traloi = MessageBox.Show("Are you sure?", "Delete row",
                                      MessageBoxButtons.YesNo, MessageBoxIcon.Question);
             // Kiểm tra có nhắp chọn nút Ok không?
             if (traloi == DialogResult.Yes)
             {
                 BLUseService blUseService = new BLUseService();
                 if (bool.Parse(dgvPurchase.Rows[r].Cells["Paid"].Value.ToString()) == true)
                 {
                     blUseService.DeleteUseService(dgvPurchase.Rows[r].Cells["RoomID"].Value.ToString(), ref err);
                     dbUseRoom.DeleteUseRoom(dgvPurchase.Rows[r].Cells["RoomID"].Value.ToString(), ref err);
                 }
                 dbPurchase.DeletePurchase(ref err, this.txtPurchaseID.Text);
                 if (err == "")
                 {
                     // Thông báo
                     MessageBox.Show("Deleted successfully!");
                     // Cập nhật lại DataGridView
                     LoadData();
                 }
                 else
                 {
                     this.gbInfor.Text = "Information";
                     // Thông báo
                     MessageBox.Show("Client is still using room !", "Delete failed!");
                 }
             }
             else
             {
                 this.gbInfor.Text = "Information";
                 // Thông báo
                 MessageBox.Show("Delete failed!");
             }
         }
     }
     catch (SqlException)
     {
         this.gbInfor.Text = "Information";
         MessageBox.Show("Delete failed!");
     }
 }
예제 #2
0
 private void btnPaid_Click(object sender, EventArgs e)
 {
     if (dgvPurchase.Rows.Count > 0)
     {
         int r = dgvPurchase.CurrentCell.RowIndex;
         if (Convert.ToBoolean(this.dgvPurchase.Rows[r].Cells["Paid"].Value) == false)
         {
             BLPurchase   blPurchase   = new BLPurchase();
             BLUseService blUseService = new BLUseService();
             BLRoom       blRoom       = new BLRoom();
             blPurchase.UpdatePurchase(this.txtPurchaseID.Text, decimal.Parse(this.txtTotal.Text), this.dtpPurchaseDate.Text, this.cmbRoomID.SelectedValue.ToString(), this.cmbStaffID.Text, 1, ref err);
             dbUseRoom.UpdateUseRoomStatus(this.cmbRoomID.SelectedValue.ToString(), ref err);
             blUseService.UpdateStatusUseService(this.cmbRoomID.SelectedValue.ToString(), ref err);
             blRoom.UpdateStatusRoom(this.cmbRoomID.SelectedValue.ToString(), ref err);
             LoadData();
             MessageBox.Show("Paid", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
 }
        private void pbSave_Click(object sender, EventArgs e)
        {
            try
            {
                // Mở kết nối
                // Thêm dữ liệu
                if (Them)
                {
                    string roomid    = cmbRoomID.Text.Trim();
                    string serviceid = cmbServiceID.Text.Trim();
                    for (int i = 0; i < dgvUseService.Rows.Count; i++)
                    {
                        string temproomid    = dgvUseService.Rows[i].Cells["RoomID"].Value.ToString().Trim();
                        string tempserviceid = dgvUseService.Rows[i].Cells["ServiceID"].Value.ToString().Trim();
                        if (roomid == temproomid && serviceid == tempserviceid)
                        {
                            MessageBox.Show("Existed '" + roomid + "' and '" + serviceid + "', please type another one !");
                            txtAmount.ResetText();
                            pbCancel_Click(sender, e);
                            return;
                        }
                    }

                    if (dgvUseService.Rows.Count > 0)
                    {
                        int    r = dgvUseService.CurrentCell.RowIndex;
                        string current_roomid = dgvUseService.Rows[r].Cells["RoomID"].Value.ToString().Trim(); //roomid đang được chọn
                        for (int i = 0; i < dgvUseService.Rows.Count; i++)                                     //kiểm tra trùng mã phòng nếu đã thanh toán thì không được thêm vào
                        {
                            string temproomid = dgvUseService.Rows[i].Cells["RoomID"].Value.ToString().Trim();
                            if (current_roomid == temproomid)
                            {
                                string tempstatus = dgvUseService.Rows[i].Cells["Paid"].Value.ToString().Trim();
                                if (tempstatus == "True")
                                {
                                    MessageBox.Show("You have to delete paid roomid before adding '" + roomid + "'");
                                    txtAmount.ResetText();
                                    pbCancel_Click(sender, e);
                                    return;
                                }
                            }
                        }
                    }

                    if (this.cmbRoomID.Text == "" || this.cmbServiceID.Text == "" || this.txtAmount.Text == "")
                    {
                        if (this.cmbRoomID.Text == "")
                        {
                            MessageBox.Show("No Room ID selected !");
                            pbCancel_Click(sender, e);
                            return;
                        }
                        else
                        {
                            if (this.cmbServiceID.Text == "")
                            {
                                MessageBox.Show("No Service ID selected !");
                                pbCancel_Click(sender, e);
                                return;
                            }
                            else
                            {
                                MessageBox.Show("Please don't leave blank input");
                                pbCancel_Click(sender, e);
                                return;
                            }
                        }
                    }
                    try
                    {
                        // Thực hiện lệnh
                        BLUseService blUseService = new BLUseService();
                        if (this.cmbRoomID.Text != "" && this.cmbServiceID.Text != "")
                        {
                            int Amount = 0;
                            if (this.txtAmount.Text != "")
                            {
                                Amount = int.Parse(this.txtAmount.Text);
                            }
                            blUseService.AddUseService(this.cmbRoomID.SelectedValue.ToString(), this.cmbServiceID.SelectedValue.ToString(), this.dtpDateIn.Text, Amount, ref err);

                            // Load lại dữ liệu trên DataGridView
                            LoadData();

                            // Thông báo
                            MessageBox.Show("Added successfully!");
                        }
                    }
                    catch (SqlException)
                    {
                        MessageBox.Show("Added failed!");
                    }
                }
                else
                {
                    int r = dgvUseService.CurrentCell.RowIndex;
                    if (bool.Parse(dgvUseService.Rows[r].Cells["Paid"].Value.ToString()) == true) //không thể edit dòng nào đã thanh toán rồi
                    {
                        MessageBox.Show("Cannot edit paid rooms !");
                        pbCancel_Click(sender, e);
                        return;
                    }
                    if (this.cmbRoomID.Text == "" || this.cmbServiceID.Text == "" || this.txtAmount.Text == "")
                    {
                        if (this.cmbRoomID.Text == "")
                        {
                            MessageBox.Show("No Room ID selected !");
                            pbCancel_Click(sender, e);
                            return;
                        }
                        else
                        {
                            if (this.cmbServiceID.Text == "")
                            {
                                MessageBox.Show("No Service ID selected !");
                                pbCancel_Click(sender, e);
                                return;
                            }
                            else
                            {
                                MessageBox.Show("Please don't leave blank input");
                                pbCancel_Click(sender, e);
                                return;
                            }
                        }
                    }
                    // Thực hiện lệnh
                    BLUseService blUseService = new BLUseService();
                    blUseService.UpdateUseService(this.cmbRoomID.SelectedValue.ToString(), this.cmbServiceID.SelectedValue.ToString(), this.dtpDateIn.Text, int.Parse(this.txtAmount.Text), ref err);
                    // Thông báo
                    MessageBox.Show("Edited successfully!");
                    // Load lại dữ liệu trên DataGridView
                    LoadData();
                }
                // Đóng kết nối
            }
            catch { }
        }