酒店客房计算帮助 [英] Hotel Room Calculation Help

查看:93
本文介绍了酒店客房计算帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个程序,我需要它使用我声明的价格乘以客户需要的房间数量乘以他们需要房间的天数.我已经将所有房间价格声明为表单级别变量,并且我需要的所有计算都在计算"区域内(基本上是一个按钮).

当前唯一可以正确计算的房间是标准双人间的大小.我不知道为什么该程序为其他三个房间返回$ 0.任何帮助表示赞赏!

对于其他三个房间,

I have this program and I need it to use the prices I''ve declared multiplied by the number of rooms a customer needs multiplied by the amount of days they need the room(s). I''ve declared all the room prices as form level variables and all the calculations I need are in the region Calculations (basically one button).

Currently the only room that is being calculated correctly is the Standard Double room size. I cannot figure out why the program is returning $0 for the other three rooms. Any help is appreciated!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoomLogic
{
    public partial class Form1 : Form
    {
        private const decimal StandardDoubleRate = 189.99M; //price for a standard double room
        private const decimal DeLuxeDoubleRate = 199.99M; //price for a DeLuxe double room
        private const decimal LuxuryDoubleRate = 229.99M; //price for a Luxury Double room
        private const decimal LuxuryKingRate = 339.99M; //price for a Luxury King rooom

        //sales tax for the state
        private const decimal SalesTaxRate = 0.0825M;

        //current rate
        private decimal StandardRate, DeLuxeRate, DoubleRate, KingRate, TotalRoomsRate;

        //date time variables to get the check in and check out dates
        private DateTime DateIn;
        private DateTime DateOut;
        
        //variables to hold the number of children and adults in each room
        private decimal AdultsTotal;
        private decimal ChildrenTotal;
        private decimal TotalRooms;
        private decimal ExtraAdultCost;
        private decimal TotalCost;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = this.Text + "   " + DateTime.Now.ToShortDateString() + "   " + DateTime.Now.ToShortDateString();

            dtpIn.Value = DateTime.Today; //shows the check in date time picker as today''s date

            dtpOut.Value = dtpIn.Value.AddDays(1); //shows the check out date time picker as today''s date.
        }//end form load event

        //check changed event
        private void chkStandard_CheckedChanged(object sender, EventArgs e)
        {
            StandardRate = StandardDoubleRate * numStandard.Value;
        }

        private void chkDeLuxe_CheckedChanged(object sender, EventArgs e)
        {
            DeLuxeRate = DeLuxeDoubleRate * numDeLuxe.Value;
        }

        private void chkDouble_CheckedChanged(object sender, EventArgs e)
        {
            DoubleRate = LuxuryDoubleRate * numDouble.Value;
        }

        private void chkKing_CheckedChanged(object sender, EventArgs e)
        {
            KingRate = LuxuryKingRate * numKing.Value;
        }

        # region Calculations

        public void btnCalc_Click(object sender, EventArgs e)
        {
            //clears list for neatness each time the room rate is calculated
            lstOutput.Items.Clear();

            long Days;
            decimal CostDays;

            /* All calculations for room cost will take place inside this button.
             * Steps:
             * 1.  Calc the number of days the people will be staying in the room(s).
             * 2.  Calcuate the cost of the rooms(s) based on that.
             * 
             * calculate the number of elasped days and return a long integer to calculate number of days from start to finish.
             */

            DateIn = dtpIn.Value;
            DateOut = dtpOut.Value;

            Days = DateOut.Subtract(DateIn).Days;
            MessageBox.Show("Total days = " + Days.ToString());

            MessageBox.Show("Standard Total: " + StandardRate);
            MessageBox.Show("DeLuxe Total: " + DeLuxeRate);
            MessageBox.Show("King Total: " + KingRate);

            //calculate the Room cost based on days needed
            TotalRoomsRate = StandardRate + DeLuxeRate + DoubleRate + KingRate;

            CostDays = TotalRoomsRate * Days;

            AdultsTotal = this.numAdults.Value;
            ChildrenTotal = this.numChildren.Value;

            decimal TotalPeople = AdultsTotal + ChildrenTotal;
            TotalRooms = numStandard.Value + numDeLuxe.Value + numDouble.Value + numKing.Value;
            //MessageBox.Show("Total Rooms = " + TotalRooms.ToString());  Working

            //if statment to decide if enough rooms are purchased for the party.
            if (AdultsTotal > 4 & TotalRooms < 2)
            {
                MessageBox.Show("Must reserve/purchase additional rooms to accomodate party amount.");
            }
            else if (ChildrenTotal > 4 & TotalRooms < 2)
            {
                MessageBox.Show("Must reserve/purchase additional rooms to accomodate party amount.");
            }

            if (AdultsTotal > 2 & AdultsTotal < 5 & TotalRooms < 2)
            {
                ExtraAdultCost = (AdultsTotal - 2) * 10;
            }
            else if (AdultsTotal > 4 & AdultsTotal < 9 & TotalRooms < 3)
            {
                ExtraAdultCost = (AdultsTotal - 4) * 10;
            }
            else if (AdultsTotal > 6 & AdultsTotal < 13 & TotalRooms < 4)
            {
                ExtraAdultCost = (AdultsTotal - 6) * 10;
            }

            TotalCost = ((CostDays + ExtraAdultCost) * SalesTaxRate) + CostDays + ExtraAdultCost;
            lstOutput.Items.Add("The total room cost for your stay is: " + CostDays.ToString("C"));
            lstOutput.Items.Add("The cost for extra adults staying is: " + ExtraAdultCost.ToString("C"));
            lstOutput.Items.Add("The total cost of your stay is: " + TotalCost.ToString("C"));
            
        #endregion

        }
    }
}

推荐答案

0.任何帮助表示赞赏!

0 for the other three rooms. Any help is appreciated!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RoomLogic
{
    public partial class Form1 : Form
    {
        private const decimal StandardDoubleRate = 189.99M; //price for a standard double room
        private const decimal DeLuxeDoubleRate = 199.99M; //price for a DeLuxe double room
        private const decimal LuxuryDoubleRate = 229.99M; //price for a Luxury Double room
        private const decimal LuxuryKingRate = 339.99M; //price for a Luxury King rooom

        //sales tax for the state
        private const decimal SalesTaxRate = 0.0825M;

        //current rate
        private decimal StandardRate, DeLuxeRate, DoubleRate, KingRate, TotalRoomsRate;

        //date time variables to get the check in and check out dates
        private DateTime DateIn;
        private DateTime DateOut;
        
        //variables to hold the number of children and adults in each room
        private decimal AdultsTotal;
        private decimal ChildrenTotal;
        private decimal TotalRooms;
        private decimal ExtraAdultCost;
        private decimal TotalCost;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = this.Text + "   " + DateTime.Now.ToShortDateString() + "   " + DateTime.Now.ToShortDateString();

            dtpIn.Value = DateTime.Today; //shows the check in date time picker as today''s date

            dtpOut.Value = dtpIn.Value.AddDays(1); //shows the check out date time picker as today''s date.
        }//end form load event

        //check changed event
        private void chkStandard_CheckedChanged(object sender, EventArgs e)
        {
            StandardRate = StandardDoubleRate * numStandard.Value;
        }

        private void chkDeLuxe_CheckedChanged(object sender, EventArgs e)
        {
            DeLuxeRate = DeLuxeDoubleRate * numDeLuxe.Value;
        }

        private void chkDouble_CheckedChanged(object sender, EventArgs e)
        {
            DoubleRate = LuxuryDoubleRate * numDouble.Value;
        }

        private void chkKing_CheckedChanged(object sender, EventArgs e)
        {
            KingRate = LuxuryKingRate * numKing.Value;
        }

        # region Calculations

        public void btnCalc_Click(object sender, EventArgs e)
        {
            //clears list for neatness each time the room rate is calculated
            lstOutput.Items.Clear();

            long Days;
            decimal CostDays;

            /* All calculations for room cost will take place inside this button.
             * Steps:
             * 1.  Calc the number of days the people will be staying in the room(s).
             * 2.  Calcuate the cost of the rooms(s) based on that.
             * 
             * calculate the number of elasped days and return a long integer to calculate number of days from start to finish.
             */

            DateIn = dtpIn.Value;
            DateOut = dtpOut.Value;

            Days = DateOut.Subtract(DateIn).Days;
            MessageBox.Show("Total days = " + Days.ToString());

            MessageBox.Show("Standard Total: " + StandardRate);
            MessageBox.Show("DeLuxe Total: " + DeLuxeRate);
            MessageBox.Show("King Total: " + KingRate);

            //calculate the Room cost based on days needed
            TotalRoomsRate = StandardRate + DeLuxeRate + DoubleRate + KingRate;

            CostDays = TotalRoomsRate * Days;

            AdultsTotal = this.numAdults.Value;
            ChildrenTotal = this.numChildren.Value;

            decimal TotalPeople = AdultsTotal + ChildrenTotal;
            TotalRooms = numStandard.Value + numDeLuxe.Value + numDouble.Value + numKing.Value;
            //MessageBox.Show("Total Rooms = " + TotalRooms.ToString());  Working

            //if statment to decide if enough rooms are purchased for the party.
            if (AdultsTotal > 4 & TotalRooms < 2)
            {
                MessageBox.Show("Must reserve/purchase additional rooms to accomodate party amount.");
            }
            else if (ChildrenTotal > 4 & TotalRooms < 2)
            {
                MessageBox.Show("Must reserve/purchase additional rooms to accomodate party amount.");
            }

            if (AdultsTotal > 2 & AdultsTotal < 5 & TotalRooms < 2)
            {
                ExtraAdultCost = (AdultsTotal - 2) * 10;
            }
            else if (AdultsTotal > 4 & AdultsTotal < 9 & TotalRooms < 3)
            {
                ExtraAdultCost = (AdultsTotal - 4) * 10;
            }
            else if (AdultsTotal > 6 & AdultsTotal < 13 & TotalRooms < 4)
            {
                ExtraAdultCost = (AdultsTotal - 6) * 10;
            }

            TotalCost = ((CostDays + ExtraAdultCost) * SalesTaxRate) + CostDays + ExtraAdultCost;
            lstOutput.Items.Add("The total room cost for your stay is: " + CostDays.ToString("C"));
            lstOutput.Items.Add("The cost for extra adults staying is: " + ExtraAdultCost.ToString("C"));
            lstOutput.Items.Add("The total cost of your stay is: " + TotalCost.ToString("C"));
            
        #endregion

        }
    }
}


我看不到代码中实际计算预订房间总费用的任何地方.您将多个未初始化的变量加在一起,然后乘以看起来总为零的天数.您的计算需要计算出客房费用乘以每次预订的天数乘以成人数量(如果适用)的天数.
I don''t see anywhere in your code where you are actually calculating the total cost of the room that is booked. You add a number of uninitialised variables together and multiply by the number of days which looks to provide a total of zero. Your calculation needs to compute the room cost times the number of days times the number of adults (if applicable) for each booking.


如果您跳过启动房价计算的复选框, :
(这些)
If you skip the checkboxes that initiate the calculations of the room rates:
(these)
private void chkStandard_CheckedChanged(object sender, EventArgs e)
{
    StandardRate = StandardDoubleRate * numStandard.Value;
}






而是将这些计算结果放入有效的btncalc函数中.
所以btnCalc应该像这样开始:






and instead put these calculations in the btncalc function it works.
so btnCalc should start like this:

public void btnCalc_Click(object sender, EventArgs e)
{
    //clears list for neatness each time the room rate is calculated
    lstOutput.Items.Clear();
    long Days;
    decimal CostDays;
    StandardRate = StandardDoubleRate * numStandard.Value;
    DeLuxeRate = DeLuxeDoubleRate * numDeLuxe.Value;
    DoubleRate = LuxuryDoubleRate * numDouble.Value;
    KingRate = LuxuryKingRate * numKing.Value;





(除了成为:)的一天)

日期计算应如下所示:

DateOut.Date.Subtract(DateIn.Date).Days

此外,将费率和增值税硬编码到程序中不是一个好习惯. (每次更改速率时,都必须在程序中进行更改并重新编译...)

这些应该来自外部来源-(文件/数据库等)





(well apart from being a day of :) )

the date calculation should look like this:

DateOut.Date.Subtract(DateIn.Date).Days

Furthermore it''s not good practice to have rates + vat hardcoded into the program. (Every time the rate changes you have to change it in the program and recompile...)

These should come from an external source -(file/database etc)


这篇关于酒店客房计算帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆