如果时间少于60分钟,则收取10rs的费用。如果时间超过60分钟,则根据时间增加amt [英] if time is less than 60min make charge of 10rs. and if the time is more than 60min increase the amt according to the time

查看:91
本文介绍了如果时间少于60分钟,则收取10rs的费用。如果时间超过60分钟,则根据时间增加amt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面提到了我的问题

 st =   UPDATE tbl_time set time_out =' + dt1.ToString(  hh:mm:ss)+  'WHERE ID =(SELECT MAX(ID)FROM tbl_time); 
db.ExeQuery(st);
st = 从tbl_time中选择*,其中ID =(从tbl_time中选择MAX(ID));
dr = db.readall(st);
if (dr.Read()== true
{
txt1.Text = dr [ time_in]。ToString();
txt2.Text = dr [ time_out]。ToString();
}
TimeSpan t1 = TimeSpan.Parse(txt1.Text);
TimeSpan t2 = TimeSpan.Parse(txt2.Text);
TimeSpan ts = t2 - t1;
dr.Close();
st = UPDATE tbl_time set tot =' + ts + 'WHERE ID =(SELECT MAX(ID)FROM tbl_time);
db.ExeQuery(st);
st = 从tbl_time中选择*,其中ID =(从tbl_time中选择MAX(ID));
dr = db.readall(st);
if (dr.Read()== true
{
txt3.Text = dr [ tot]。ToString();
}
dr.Close();
TimeSpan t3 = TimeSpan.Parse(txt3.Text);
double fee = 0 ;

// 在ts变量中我存储开始和结束时间即总时间<如果(ts.TotalMinutes < 60 // 这是我的疑问如果用户花费的时间少于60分钟,我想要制作10Rs的费用,即我已经完成
{ // 但如果用户花费120分钟我想要收取20R的费用,但在数据库中它可以节省60次。
// I '我没有得到我的计算错误
st = UPDATE tbl_time set amt =' +费用+ 'WHERE ID =(SELECT MAX(I) D)FROM tbl_time);
db.ExeQuery(st);
}
if (ts.TotalMilliseconds > 60
{
费=(ts.TotalMinutes / 10 )* 10 ;
st = UPDATE tbl_time set amt =' + fee + 'WHERE ID =(SELECT MAX(ID)FROM tbl_time);
db.ExeQuery(st);
}

解决方案

我读到你的问题与另一张海报略有不同,因为我觉得你需要< a href =http://en.wikipedia.org/wiki/Pro_rata> pr-rata [ ^ ]收费最低收费10rs。



如果只是基于小时数然后你可以使用

 double feePerHours = Math.Max(minFee,hourlyFee *(timeInMinutes / 60)); 

我已初始化 minFee hourlyFee 到10rs。注意使用 Math.Max 以确保我从不收取低于10rs的费用。



获得亲rata费用(即一小时内每分钟加一点)你可以使用

 double proRataFee = Math.Max(0,((timeInMinutes  -  60)%60)*(hourlyFee / 60.0)) ; 

请注意,我使用了模运算符 [ ^ ]获得超过一小时的分钟数,即除以60时的余数。我已经也再次使用 Max 确保第一个小时没有开始给我负数。



总数费用只是两个加在一起的。我用这段代码测试了这个

  int  minFee =  10 ; 
double hourlyFee = 10 0 ;

for var timeInMinutes = 40 ; timeInMinutes < = 160 ; timeInMinutes + = 20
{
double feePerHours = Math.Max(minFee,hourlyFee *(timeInMinutes / 60 ));

double proRataFee = Math.Max( 0 ,((timeInMinutes - < span class =code-digit> 60
)% 60 )*(hourlyFee / 60 0 ));

double totalFee = feePerHours + proRataFee;

Console.WriteLine( 时间:{0}分钟;小时费用{1} ,按比例计算{2:0.00}总费用R {3:0.00},timeInMinutes,feePerHours,proRataFee,totalFee);

}

这给了我以下结果:

时间:40分钟; 10小时的费用,按比例计算0.00总费用R10.00 
时间:60分钟; 10小时的费用,按比例计算0.00总费用R10.00
时间:80分钟; 10小时的费用,按比例计算3.33总费用R13.33
时间:100分钟; 10小时的费用,按比例计算6.67总费用R16.67
时间:120分钟; 20小时的费用,按比例计算0.00总费用R20.00
时间:140分钟; 20小时的费用,按比例计算3.33总费用R23.33
时间:160分钟; 20小时的费用,按比例计算6.67总费用R26.67


这是一种实现您想要的简单方法。

  int  CalculateParkingFee(DateTime entryTime,DateTime leaveTime)
{
DateTime effectiveLeaveTime;

TimeSpan ellapsedTime = leaveTime.Subtract(entryTime);

if (ellapsedTime.TotalMinutes% 60 == 0
{
effectiveLeaveTime = leaveTime;
}
else
{
effectiveLeaveTime = new DateTime(leaveTime.Year,leaveTime.Month,leaveTime.Day,leaveTime.Hour, 0 0 ) .AddHours( 1 );
}

double accountableHours = effectiveLeaveTime.Subtract(entryTime).TotalHours;

return int )accountableHours;
}





你可以这样测试:

 MessageBox.Show(CalculateParkingFee( new  DateTime( 2015  2  18  15  0  0 ), new  DateTime( 2015  2  18  15  20  0 ))。ToString()); 
MessageBox.Show(CalculateParkingFee( new DateTime( 2015 2 18 15 0 0 ), new DateTime( 2015 2 18 16 0 0 ))。ToString());
MessageBox.Show(CalculateParkingFee( new DateTime( 2015 2 18 15 0 0 ), new DateTime( 2015 2 18 16 20 0 ))。ToString());





结果如下:

1

1

2


I have mentioned my problem below

st = "UPDATE tbl_time set time_out='" + dt1.ToString("hh:mm:ss") + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
db.ExeQuery(st);
st = "Select * from tbl_time where ID=(Select MAX(ID) from tbl_time)";
dr = db.readall(st);
if (dr.Read() == true)
{
   txt1.Text = dr["time_in"].ToString();
   txt2.Text = dr["time_out"].ToString();
}
TimeSpan t1 = TimeSpan.Parse(txt1.Text);
TimeSpan t2 = TimeSpan.Parse(txt2.Text);
TimeSpan ts = t2 - t1;
dr.Close();
st = "UPDATE tbl_time set tot='" + ts + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
db.ExeQuery(st);
st = "Select * from tbl_time where ID=(Select MAX(ID) from tbl_time)";
dr = db.readall(st);
if (dr.Read() == true)
{
   txt3.Text = dr["tot"].ToString();
}
dr.Close();
TimeSpan t3 = TimeSpan.Parse(txt3.Text);
double fee = 0;
  
// In ts variable i'm storing the start and end time i.e total time
if (ts.TotalMinutes < 60)   // Here is my doubt If the user spend time less than 60 min i want make charge of  10Rs i.e i have done 
{                                        //but if the user spend 120 min i want make charge of 20Rs, but in the database it saving like 60rs.
   // I'm not getting where my calculation is wrong   
   st = "UPDATE tbl_time set amt='" + fee + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
   db.ExeQuery(st);
}
if (ts.TotalMilliseconds > 60)
{
   fee = (ts.TotalMinutes / 10) * 10;
   st = "UPDATE tbl_time set amt='" + fee + "' WHERE ID=(SELECT MAX(ID) FROM tbl_time)";
   db.ExeQuery(st);
}

解决方案

I've read your question slightly differently to the other poster, in that I think you need to pr-rata[^] the charge subject to a minimum charge of 10rs.

If it was just based on the number of hours then you could use

double feePerHours = Math.Max(minFee, hourlyFee * (timeInMinutes / 60));

where I've initialised both minFee and hourlyFee to 10rs. Note the use of Math.Max to ensure I never charge less than 10rs.

To get the pro-rata fee (i.e. the bit to add on for every minute over the hour) you can use

double proRataFee = Math.Max(0, ((timeInMinutes - 60) % 60) * (hourlyFee / 60.0));

Note that I've used the modulo operator[^] to get the number-of-minutes-over-an-hour i.e. the remainder when divided by 60. I've also used Max again to ensure that the first hour doesn't start giving me negative numbers.

The total fee is just the two added together. I tested this with this code

int minFee = 10;
double hourlyFee = 10.0;

for (var timeInMinutes = 40; timeInMinutes <= 160; timeInMinutes += 20)
{
    double feePerHours = Math.Max(minFee, hourlyFee * (timeInMinutes / 60));

    double proRataFee = Math.Max(0, ((timeInMinutes - 60) % 60) * (hourlyFee / 60.0));

    double totalFee = feePerHours + proRataFee;

    Console.WriteLine("Time : {0} minutes; Fee for hours {1}, Pro-rata bit {2:0.00} Total Fee R{3:0.00}", timeInMinutes, feePerHours, proRataFee, totalFee);

}

which gave me these results:

Time : 40 minutes; Fee for hours 10, Pro-rata bit 0.00 Total Fee R10.00
Time : 60 minutes; Fee for hours 10, Pro-rata bit 0.00 Total Fee R10.00
Time : 80 minutes; Fee for hours 10, Pro-rata bit 3.33 Total Fee R13.33
Time : 100 minutes; Fee for hours 10, Pro-rata bit 6.67 Total Fee R16.67
Time : 120 minutes; Fee for hours 20, Pro-rata bit 0.00 Total Fee R20.00
Time : 140 minutes; Fee for hours 20, Pro-rata bit 3.33 Total Fee R23.33
Time : 160 minutes; Fee for hours 20, Pro-rata bit 6.67 Total Fee R26.67


Here is a simple method to achieve what you want.

int CalculateParkingFee(DateTime entryTime, DateTime leaveTime)
{
    DateTime effectiveLeaveTime;

    TimeSpan ellapsedTime = leaveTime.Subtract(entryTime);

    if (ellapsedTime.TotalMinutes % 60 == 0)
    {
        effectiveLeaveTime = leaveTime;
    }
    else
    {
        effectiveLeaveTime = new DateTime(leaveTime.Year, leaveTime.Month, leaveTime.Day, leaveTime.Hour, 0, 0).AddHours(1);
    }

    double accountableHours = effectiveLeaveTime.Subtract(entryTime).TotalHours;

    return (int)accountableHours;
}



You can test it like this:

MessageBox.Show(CalculateParkingFee(new DateTime(2015,2,18,15,0,0), new DateTime(2015,2,18,15,20,0)).ToString());
MessageBox.Show(CalculateParkingFee(new DateTime(2015, 2, 18, 15, 0, 0), new DateTime(2015, 2, 18, 16, 0, 0)).ToString());
MessageBox.Show(CalculateParkingFee(new DateTime(2015, 2, 18, 15, 0, 0), new DateTime(2015, 2, 18, 16, 20, 0)).ToString());



The results are:
1
1
2


这篇关于如果时间少于60分钟,则收取10rs的费用。如果时间超过60分钟,则根据时间增加amt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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