예제 #1
0
        private void btnCheckOut_Click(object sender, EventArgs e)
        {
            if (DialogResult.No.Equals(MessageBox.Show("คุณยืนยันจะเช็คเอ้าออกจริงหรือไม่", "ยืนยันจะเช็คเอ้าออก", MessageBoxButtons.YesNo, MessageBoxIcon.Information)))
            {
                return;
            }

            PaymentsTableAdapter paymentsTableAdapter = new PaymentsTableAdapter();
            int compareDate = Convert.ToInt32(paymentsTableAdapter.CompareDatePayAndCheckIn(CheckInID));

            if (compareDate == 0)
            {
                int paymentId = Convert.ToInt32(paymentsTableAdapter.GetMaxIDAsCheckIn(CheckInID));
                if (paymentId > 0)
                {
                    if (0 == Convert.ToDouble(serviceChargesTableAdapter.GetServiceAmount(CheckInID)))
                    {
                        MessageBox.Show("คุณยังมียอดค้างชำระ กรุณากลับไปจ่ายให้เรียบร้อย", "แจ้งเตือน 0-0", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        //MessageBox.Show("ไม่มีรายการปรับปรุง", "เสร็จสมบูรณ์", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    paymentsTableAdapter.UpdateServiceAmount(paymentId, CheckInID);
                    serviceChargesTableAdapter.UpdatePayID(paymentId, CheckInID);
                }
                else
                {
                    double servicesAmount = Convert.ToDouble(serviceChargesTableAdapter.GetServiceAmount(CheckInID));
                    if (servicesAmount != 0)
                    {
                        paymentsTableAdapter.Insert(
                            CheckInID,
                            null,
                            null,
                            0,
                            servicesAmount,
                            servicesAmount,
                            null,
                            0,
                            null,
                            null);

                        int payId = Convert.ToInt32(paymentsTableAdapter.GetMaxID());
                        serviceChargesTableAdapter.UpdatePayID(payId, CheckInID);
                    }
                }
                this.paymentViewTableAdapter.FillByCheckInID(
                    this.apartmentDataSet.PaymentView, CheckInID);
                this.serviceChargesTableAdapter.FillByCheckInID(
                    this.apartmentDataSet.ServiceCharges, CheckInID);
            }

            if (Convert.ToInt32(paymentsTableAdapter.CheckPayIt(CheckInID)) == 0)
            {
                try
                {
                    CheckInsTableAdapter checkInTableAdapter = new CheckInsTableAdapter();
                    checkInTableAdapter.UpdateCheckOutDate(DateTime.Now, CheckInID);
                    MessageBox.Show("เช็คเอ้าเสร็จสมบูรณ์", "เสร็จสมบูรณ์", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    DialogResult = System.Windows.Forms.DialogResult.Yes;
                }
                catch (Exception)
                {
                    MessageBox.Show("ไม่สามารถเช็คเอ้าได้ กรุณาลองใหม่อีกครั้ง", "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("คุณยังมียอดค้างชำระ กรุณากลับไปจ่ายให้เรียบร้อย", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
예제 #2
0
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            if (!this.customerDetailPanel.ValidateChildren())
            {
                tabControl1.SelectedIndex = 0;
                return;
            }
            if (this.roomDetailPanel.cbxRoomNO.SelectedItem == null)
            {
                MessageBox.Show("คุณยังไม่ได้เลือกห้องพัก", "คุณยังไม่ได้เลือกห้องพัก", MessageBoxButtons.OK, MessageBoxIcon.Information);
                tabControl1.SelectedIndex = 1;
                return;
            }

            double amountRoom = 0;
            double roomPrices = Convert.ToDouble(((DataRowView)this.roomDetailPanel.fKRoomTypesCustomerTypesBindingSource.Current).Row["Prices"]);

            if (Convert.ToInt32(this.roomDetailPanel.cbxCustomerType.SelectedValue) == 1)
            {
                int days = this.roomDetailPanel.dtpEndStay.Value.Subtract(this.roomDetailPanel.dtpStarStay.Value).Days;
                if (days < 30)
                {
                    amountRoom = (roomPrices / 30) * days;
                    Console.WriteLine("รายเดือน " + amountRoom + " " + days);
                }
            }
            else if (Convert.ToInt32(this.roomDetailPanel.cbxCustomerType.SelectedValue) == 2)
            {
                int days = this.roomDetailPanel.dtpEndStay.Value.Subtract(this.roomDetailPanel.dtpStarStay.Value).Days;
                amountRoom = roomPrices * days;
                Console.WriteLine("รายวัน " + amountRoom + " " + days);
            }



            try
            {
                CustomersTableAdapter customerTableAdapter = new CustomersTableAdapter();

                customerTableAdapter.Insert(
                    this.customerDetailPanel.tbxPeopleID.Text,
                    this.customerDetailPanel.tbxFirstname.Text,
                    this.customerDetailPanel.tbxLastname.Text,
                    Convert.ToByte(this.customerDetailPanel.cbxSex.SelectedIndex),
                    this.customerDetailPanel.dtpBirthDay.Value,
                    this.customerDetailPanel.tbxAddress.Text,
                    this.customerDetailPanel.tbxSubDistrict.Text,
                    this.customerDetailPanel.tbxDistrict.Text,
                    this.customerDetailPanel.cbxProvince.SelectedItem.ToString(),
                    this.customerDetailPanel.cbxCountry.SelectedItem.ToString(),
                    this.customerDetailPanel.tbxTelephone.Text,
                    this.customerDetailPanel.tbxMobile.Text,
                    this.customerDetailPanel.tbxEmail.Text);



                CustomerTypesTableAdapter customerTypesTableAdapter = new CustomerTypesTableAdapter();
                RoomTypesTableAdapter     roomTypesTableAdapter     = new RoomTypesTableAdapter();
                CheckInsTableAdapter      checkInsTableAdapter      = new CheckInsTableAdapter();
                RoomsTableAdapter         roomsTableAdapter         = new RoomsTableAdapter();
                int customerID = Convert.ToInt32(customerTableAdapter.GetMaxID());

                if (BookingID == 0)
                {
                    checkInsTableAdapter.Insert(
                        customerID,
                        Convert.ToInt32(roomDetailPanel.cbxCustomerType.SelectedValue),
                        customerTypesTableAdapter.GetCustomerTypeName(Convert.ToInt32(roomDetailPanel.cbxCustomerType.SelectedValue)),
                        Convert.ToInt32(roomDetailPanel.cbxRoomType.SelectedValue),
                        roomTypesTableAdapter.GetRoomTypeName(Convert.ToInt32(roomDetailPanel.cbxRoomType.SelectedValue)),
                        Convert.ToInt32(this.roomDetailPanel.roomsTableAdapter.GetRoomID(((DataRowView)roomDetailPanel.fKRoomsRoomTypesBindingSource.Current).Row["NO"].ToString())),
                        ((DataRowView)roomDetailPanel.fKRoomsRoomTypesBindingSource.Current).Row["NO"].ToString(),
                        roomPrices,
                        roomDetailPanel.dtpStarStay.Value,
                        roomDetailPanel.dtpEndStay.Value,
                        roomDetailPanel.tbxDescription.Text,
                        MainUI.StaffID,
                        null,
                        DateTime.Now,
                        null,
                        0);
                }
                else
                {
                    checkInsTableAdapter.Insert(
                        customerID,
                        Convert.ToInt32(roomDetailPanel.cbxCustomerType.SelectedValue),
                        customerTypesTableAdapter.GetCustomerTypeName(Convert.ToInt32(roomDetailPanel.cbxCustomerType.SelectedValue)),
                        Convert.ToInt32(roomDetailPanel.cbxRoomType.SelectedValue),
                        roomTypesTableAdapter.GetRoomTypeName(Convert.ToInt32(roomDetailPanel.cbxRoomType.SelectedValue)),
                        Convert.ToInt32(this.roomDetailPanel.roomsTableAdapter.GetRoomID(((DataRowView)roomDetailPanel.fKRoomsRoomTypesBindingSource.Current).Row["NO"].ToString())),
                        ((DataRowView)roomDetailPanel.fKRoomsRoomTypesBindingSource.Current).Row["NO"].ToString(),
                        roomPrices,
                        roomDetailPanel.dtpStarStay.Value,
                        roomDetailPanel.dtpEndStay.Value,
                        roomDetailPanel.tbxDescription.Text,
                        MainUI.StaffID,
                        BookingID,
                        DateTime.Now,
                        null,
                        0);
                }


                PaymentsTableAdapter paymentsTableAdapter = new PaymentsTableAdapter();
                int checKInID = Convert.ToInt32(checkInsTableAdapter.GetMaxID());
                paymentsTableAdapter.Insert(
                    checKInID,
                    this.roomDetailPanel.dtpStarStay.Value,
                    this.roomDetailPanel.dtpEndStay.Value,
                    (int)amountRoom,
                    0,
                    (int)amountRoom,
                    null,
                    0,
                    null,
                    null);


                MessageBox.Show("เช็คอินเสร็จสมบูรณ์", "เสร็จสมบูรณ์", MessageBoxButtons.OK, MessageBoxIcon.Information);


                //เปิดหน้าชำระเงิน
                PaymentDetailUI payment = new PaymentDetailUI();
                payment.PaymentID = Convert.ToInt32(paymentsTableAdapter.GetMaxID());
                payment.ShowDialog();
                this.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());

                MessageBox.Show("ไม่สามารถเช็คอินได้, กรุณาลองใหม่อีกครั้ง ", "ข้อผิดผลาด", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DialogResult = System.Windows.Forms.DialogResult.No;
            }
        }