Exemple #1
0
        private void btnCelculatePayment_Click(object sender, EventArgs e)
        {
            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("ไม่มีรายการปรับปรุง", "เสร็จสมบูรณ์", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else
                    {
                        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);
                    }
                }

                MessageBox.Show("คำนวนใบเสร็จรับเงินเสร็จสมบูรณ์", "เสร็จสมบูรณ์", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.paymentViewTableAdapter.FillByCheckInID(
                    this.apartmentDataSet.PaymentView, CheckInID);
                this.serviceChargesTableAdapter.FillByCheckInID(
                    this.apartmentDataSet.ServiceCharges, CheckInID);
            }
            else
            {
                MessageBox.Show("ไม่มีรายการปรับปรุง", "เสร็จสมบูรณ์", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #2
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);
            }
        }
        private void btnChange_Click(object sender, EventArgs e)
        {
            if (dtpEndStay.MinDate.Subtract(dtpEndStay.Value).Days == 0)
            {
                DialogResult result = MessageBox.Show("คุณไม่ได้เปลี่ยนแปลงเวลาออก, คุณต้องเปลี่ยนแปลงอีกครั้งหรือไม่", "คุณไม่ได้เปลี่ยนแปลงเวลาออก", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (result.Equals(DialogResult.No))
                {
                    DialogResult = System.Windows.Forms.DialogResult.No;
                    Console.WriteLine("No Change date.");
                }
            }

            checkInsTableAdapter.UpdateCheckInEndStay(dtpEndStay.Value, CheckInID);

            PaymentsTableAdapter paymentsTableAdapter = new PaymentsTableAdapter();
            DateTime             checkInDate          = (DateTime)checkInsTableAdapter.GetMaxEndDate(CheckInID);
            DateTime             paymentDate          = (DateTime)paymentsTableAdapter.GetMaxEndDate(CheckInID);

            if (checkInDate.Subtract(paymentDate).Days > 0)
            {
                double roomAmount = checkInDate.Subtract(paymentDate).Days *Convert.ToDouble(checkInsTableAdapter.GetRoomPrice(CheckInID));


                int paymentId = Convert.ToInt32(paymentsTableAdapter.GetMaxIDAsCheckInFromRoom(CheckInID));
                if (paymentId > 0)
                {
                    try
                    {
                        ServiceChargesTableAdapter serviceChargesTableAdapter = new ServiceChargesTableAdapter();
                        if (0 != Convert.ToDouble(serviceChargesTableAdapter.GetServiceAmount(CheckInID)))
                        {
                            paymentsTableAdapter.UpdateRoomAmount(roomAmount, paymentDate.ToString(), dtpEndStay.Value.ToString(), paymentId);
                            paymentsTableAdapter.UpdateServiceAmount(paymentId, CheckInID);
                            serviceChargesTableAdapter.UpdatePayID(paymentId, CheckInID);
                        }
                        else
                        {
                            paymentsTableAdapter.UpdateRoomAmount(roomAmount, paymentDate.ToString(), dtpEndStay.Value.ToString(), paymentId);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        throw;
                    }
                }
                else
                {
                    ServiceChargesTableAdapter serviceChargesTableAdapter = new ServiceChargesTableAdapter();
                    double servicesAmount = Convert.ToDouble(serviceChargesTableAdapter.GetServiceAmount(CheckInID));

                    try
                    {
                        paymentsTableAdapter.Insert(
                            CheckInID,
                            paymentDate,
                            dtpEndStay.Value,
                            roomAmount,
                            servicesAmount,
                            servicesAmount + roomAmount,
                            null,
                            0,
                            null,
                            null);

                        int payId = Convert.ToInt32(paymentsTableAdapter.GetMaxID());
                        serviceChargesTableAdapter.UpdatePayID(payId, CheckInID);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                        throw;
                    }
                }
            }
            MessageBox.Show("การเปลี่ยนแปลงเสร็จสมบูรณ์");
            DialogResult = System.Windows.Forms.DialogResult.Yes;
        }