Пример #1
0
        public static double CaculateSmsMoney(List <Sd> sdList)
        {
            double money  = 0;
            var    listKg = new KgBUS()
            {
            }.TatCa();

            foreach (var kg in listKg)
            {
                foreach (var sd in sdList)
                {
                    foreach (DateTime date in EachDay(sd.TgBd.Value, sd.TgKt.Value))
                    {
                        TimeSpan fromDate = new TimeSpan();
                        TimeSpan toDate   = new TimeSpan();
                        if (date.Date == sd.TgBd.Value.Date && date.Date == sd.TgKt.Value.Date)
                        {
                            fromDate = sd.TgBd.Value.TimeOfDay;
                            toDate   = sd.TgKt.Value.TimeOfDay;
                        }
                        else if (date.Date == sd.TgBd.Value.Date)
                        {
                            fromDate = sd.TgBd.Value.TimeOfDay;
                            toDate   = new TimeSpan(23, 59, 59);
                        }
                        else if (date.Date == sd.TgKt.Value.Date)
                        {
                            fromDate = new TimeSpan(0, 0, 0);
                            toDate   = sd.TgKt.Value.TimeOfDay;
                        }
                        else
                        {
                            fromDate = new TimeSpan(0, 0, 0);
                            toDate   = new TimeSpan(23, 59, 59);
                        }
                        TimeSpan time = new TimeSpan();

                        time = GetTimeSpanIntersect(kg.GioBd.Value.Add(new TimeSpan(0, 0, 1)), kg.GioKt.Value, fromDate, toDate);

                        money += ((double)time.TotalSeconds / 60) * double.Parse(kg.GiaCuoc);
                    }
                }
            }



            return(Math.Ceiling(money));
        }
Пример #2
0
        public static double CaculateSmsMoney_TamAnDi(List <Sd> sdList)
        {
            double money  = 0;
            var    listKg = new KgBUS()
            {
            }.TatCa();

            foreach (var kg in listKg)
            {
                foreach (var sd in sdList)
                {
                    foreach (DateTime date in EachDay(sd.TgBd.Value, sd.TgKt.Value))
                    {
                        TimeSpan fromDate = new TimeSpan();
                        TimeSpan toDate   = new TimeSpan();
                        if (date.Date == sd.TgBd.Value.Date && date.Date == sd.TgKt.Value.Date)
                        {
                            fromDate = sd.TgBd.Value.TimeOfDay;
                            toDate   = sd.TgKt.Value.TimeOfDay;
                        }
                        else if (date.Date == sd.TgBd.Value.Date)
                        {
                            fromDate = sd.TgBd.Value.TimeOfDay;
                            toDate   = new TimeSpan(23, 59, 59);
                        }
                        else if (date.Date == sd.TgKt.Value.Date)
                        {
                            fromDate = new TimeSpan(0, 0, 0);
                            toDate   = sd.TgKt.Value.TimeOfDay;
                        }
                        else
                        {
                            fromDate = new TimeSpan(0, 0, 0);
                            toDate   = new TimeSpan(23, 59, 59);
                        }

                        TimeSpan durationKg   = kg.GioKt.Value.Subtract(kg.GioBd.Value);
                        TimeSpan durationKgOk = (durationKg.CompareTo(TimeSpan.Zero) < 0)
                            ? durationKg.Add(new TimeSpan(24, 0, 0))
                            : durationKg;


                        bool     hasZero = durationKg.CompareTo(TimeSpan.Zero) < 0 ? true : false;
                        TimeSpan left    = new TimeSpan();
                        TimeSpan right   = new TimeSpan();
                        bool     isOk    = false;

                        if (hasZero)
                        {
                            if (toDate.CompareTo(fromDate) > 0)
                            {
                                if (toDate.CompareTo(kg.GioBd.Value) >= 0)
                                {
                                    left = new TimeSpan(24, 0, 0).Subtract(toDate);

                                    if (toDate.Equals(kg.GioBd))
                                    {
                                        left = left.Add(new TimeSpan(0, 0, 0, -1));
                                    }
                                    isOk = true;
                                }
                                if (fromDate.CompareTo(kg.GioKt.Value) <= 0)
                                {
                                    right = fromDate.Subtract(TimeSpan.Zero);
                                    isOk  = true;
                                }
                            }
                            else
                            {
                                if (fromDate.CompareTo(kg.GioKt.Value) <= 0)
                                {
                                    right = kg.GioKt.Value.Subtract(fromDate);
                                    isOk  = true;
                                }

                                if (toDate.CompareTo(kg.GioBd.Value) > 0)
                                {
                                    left = toDate.Subtract(kg.GioBd.Value);
                                    isOk = true;
                                }
                            }
                        }
                        else
                        {
                            if (fromDate.CompareTo(kg.GioBd.Value) > 0)
                            {
                                left = fromDate.Subtract(kg.GioBd.Value);
                                isOk = true;
                            }

                            if (toDate.CompareTo(kg.GioKt.Value) <= 0)
                            {
                                right = kg.GioKt.Value.Subtract(toDate);
                                isOk  = true;
                            }

                            if (fromDate.CompareTo(kg.GioBd.Value) < 0 && toDate.CompareTo(kg.GioKt.Value) > 0)
                            {
                                isOk = true;
                            }
                        }

                        if (isOk)
                        {
                            money += (durationKgOk.Subtract(left.Equals(TimeSpan.Zero) ? left.Add(new TimeSpan(0, 0, 1)) : left).Subtract(right).TotalSeconds / 60) * double.Parse(kg.GiaCuoc);
                        }
                        else
                        {
                            money += 0;
                        }
                    }
                }
            }

            //foreach (var sd in sdList)
            //{
            //    TimeSpan tp = (sd.TgKt.Value).Subtract(sd.TgBd.Value);
            //    if (sd.TgBd.Value.Hour >= listKg[0].GioBd.Value.Hours)
            //    {
            //        if (sd.TgKt.Value.Hour < listKg[0].GioKt.Value.Hours)
            //            money += double.Parse(listKg[0].GiaCuoc) * (tp.TotalSeconds / 60);

            //        if (sd.TgKt.Value.Hour >= listKg[0].GioKt.Value.Hours)
            //        {
            //            TimeSpan temp = new TimeSpan(listKg[0].GioKt.Value.Hours, 0, 0);
            //            TimeSpan before = temp.Subtract(sd.TgBd.Value.TimeOfDay);
            //            TimeSpan after = sd.TgKt.Value.TimeOfDay.Subtract(temp);
            //            money += double.Parse(listKg[0].GiaCuoc) * (before.TotalMilliseconds / 60);
            //            money += double.Parse(listKg[1].GiaCuoc) * (after.TotalMilliseconds / 60);
            //        }
            //    }
            //    if (sd.TgBd.Value.Hour >= listKg[1].GioBd.Value.Hours)
            //    {
            //        if (sd.TgKt.Value.Hour < listKg[1].GioKt.Value.Hours)
            //            money += double.Parse(listKg[1].GiaCuoc) * (tp.TotalSeconds / 60);

            //        if (sd.TgKt.Value.Hour >= listKg[1].GioKt.Value.Hours)
            //        {
            //            TimeSpan temp = new TimeSpan(listKg[1].GioKt.Value.Hours, 0, 0);
            //            TimeSpan before = temp.Subtract(sd.TgBd.Value.TimeOfDay);
            //            TimeSpan after = sd.TgKt.Value.TimeOfDay.Subtract(temp);
            //            money += double.Parse(listKg[1].GiaCuoc) * (before.TotalMilliseconds / 60);
            //            money += double.Parse(listKg[0].GiaCuoc) * (after.TotalMilliseconds / 60);
            //        }
            //    }

            //}

            return(Math.Ceiling(money));
        }