房间费用的计算。 [英] Calculation of Room Charges.

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

问题描述

大家好,



我想在我的申请中计算房费。条件是,

如果有任何患者在上午12点到晚上11点59分之间应按照客房段收取全天费用,即General Ward,Delux等,

晚上12点之后将收取第二天的费用作为每个病房类型。



有人建议我在sql脚本或编码中这样做吗?



感谢您的未来帮助。



这是代码:



 < span class =code-keyword> decimal  total_A =(Total_Hours /  24 )* ChargesPer24Hour; 
decimal total_B = 0 ;
decimal R = Total_Hours% 24 ;
if (R!= 0
total_B = ChargesPer24Hour;
else
total_B = 0 ;





ChargesPer24从数据库中取出病房类型费用。

Total_Hours,在SQL中完成计算只有而且这个师会给我们确切的一天。

解决方案

第一个立即捕获到任何人的眼睛的错误是:你在第一行中除以24。如果总共减少大约24倍(粗略因为整数类型的离散化)。为什么会这样?



因为你把问题颠倒了。实际总数应该是

 decimal_total = daysOfStay * pricePerDay; 



现在,唯一的问题是 daysOfStay 。通常人们都知道,而不是小时。但我们假设系统只知道签入和签出时间。同样,普通酒店系统不适用于实际停留时间。根据一天的时间,他们计算逗留天数并确定一定的结账时间。如果实际退房时间较早,则会计算入住天数,之后会增加一天。



但如果我们可以假设您使用不同的系统,如何获得实际的逗留时间,将其转换为天还是不?嗯,这可能是我的一个假设,但是......让我们说,

 System.DateTime checkIn = System.DateTime.Now; 

// ...稍后:

System.DateTime checkOut = System.DateTime.Now;

System.TimeSpan timeOfStay = checkOut - checkIn;



现在你可以提取任何时间度量(总毫秒,例如:-))或者天数,或其他任何来自 timeOfStay

http://msdn.microsoft.com/en-us/library/system.timespan%28v=vs.110%29.aspx [ ^ ]。



然后以你想要的方式计算这些钱。无需绕任何东西,最接近的数字或类似的东西。



-SA


< blockquote>大家好,



感谢您给我提出建议和解决方案,我发现解决方案为Sql查询我写的:

 DATEDIFF(HOUR,STARTDATE,ENDDATE)





我必须更换HOUR到DATE,

 DATEDIFF( DATE ,STARTDATE,ENDDATE)+1 





特别感谢@Sergey Alexandrovich Kryukov为我们提供了宝贵的教程类型建议。



谢谢

Hello All,

I want to calculate the room charges in my application.The condition is,
If any patient registered in between 12.01 AM to 11.59 PM should be applicable for whole day charges as per room segment, i.e. General Ward, Delux, etc,
After 12 AM in night it will be applicable to charge the second day charges as per ward type.

Can anyone suggest me to do that in sql script or in coding?

Thanks for Future Help.

This is code:

decimal total_A = (Total_Hours / 24) * ChargesPer24Hour;
decimal total_B = 0;
decimal R = Total_Hours % 24;
if (R != 0)
total_B = ChargesPer24Hour;
else
total_B = 0;



ChargesPer24Hour taking from db for ward type charges.
Total_Hours, calculation done in SQL only and that this division will give us the exact day.

解决方案

The first bug which immediately catches nearly anyone's eye is: you divide by 24 in first line. If gives you total roughly 24 times less ("roughly" because of discretisation of integer type). Why it happens?

Because you put the "problem" upside down. The real total should be

decimal_total = daysOfStay * pricePerDay;


Now, the only problem is the daysOfStay. Usually people know it, not "hours". But let's assume that the system only knows check-in and check-out time. Again, normal hotel systems don't work with actual stay hours. They count days of stay and have certain checkout time, in terms of time of the day. If actual check-out time is earlier, they count days of stay, in later, one day is added.

But if we can assume that you use different system, how to get actual time of stay, to convert it to days or not? Well, it could be too much of assumption on my side, but… Let's say,

System.DateTime checkIn = System.DateTime.Now;

// ...later:

System.DateTime checkOut = System.DateTime.Now;

System.TimeSpan timeOfStay = checkOut - checkIn;


And now you can extract any time measures (total millisecond, for example :-)) or number of days, or anything else from timeOfStay:
http://msdn.microsoft.com/en-us/library/system.timespan%28v=vs.110%29.aspx[^].

And then count those money the way you want. No need to "round" anything, fine nearest number or anything like that.

—SA


Hello All,

Thanks for giving me the suggestions and solution on my query, I have find the solution as Sql query I have write as :

DATEDIFF(HOUR, STARTDATE, ENDDATE)

,

I have to just replace HOUR to DATE,

DATEDIFF(DATE, STARTDATE, ENDDATE)+1



Special thanks to @Sergey Alexandrovich Kryukov for giving us your valuable tutorial type suggestion.

Thanks


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

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