Exemplo n.º 1
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="section"></param>
 /// <returns></returns>
 public Response UpdateHourSection(HourSectionInfo section)
 {
     return(hourSectionManager.Update(section));
 }
Exemplo n.º 2
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="section"></param>
 /// <returns></returns>
 public Response AddHourSection(HourSectionInfo section)
 {
     return(hourSectionManager.Add(section));
 }
Exemplo n.º 3
0
        public ActionResult ModifyHourSectionRule()
        {
            Response resp    = new Response();
            CWTariff cwtarff = new CWTariff();
            string   hID     = Request.Form["HourID"];

            if (string.IsNullOrEmpty(hID))
            {
                resp.Message = "传输故障,ID为空";
                return(Json(resp));
            }
            int             hourID      = Convert.ToInt32(hID);
            HourSectionInfo hoursection = cwtarff.FindHourSection(hourID);

            if (hoursection == null)
            {
                resp.Message = "传输故障,找不到对应时间段,ID-" + hID;
                return(Json(resp));
            }
            //如果修改时间区间,则要判断
            string start = Request.Form["StartTime"];
            string end   = Request.Form["EndTime"];

            DateTime st_dtime  = DateTime.Parse("2017-1-1 " + start + ":00");
            DateTime end_dtime = DateTime.Parse("2017-1-1 " + end + ":00").AddSeconds(-1);

            if (DateTime.Compare(st_dtime, end_dtime) > 0)
            {
                end_dtime = end_dtime.AddDays(1);
            }

            List <HourSectionInfo> timeSlotLst = cwtarff.FindHourSectionList(hr => true);

            foreach (HourSectionInfo section in timeSlotLst)
            {
                if (section.ID == hourID)
                {
                    continue;
                }
                DateTime sttime  = section.StartTime;
                DateTime endtime = section.EndTime.AddSeconds(-1);
                #region
                if (DateTime.Compare(sttime, st_dtime) < 0 && DateTime.Compare(endtime, st_dtime) > 0)
                {
                    resp.Message = "当前时段设置错误,原来-" + sttime.ToString() + ",现-" + st_dtime.ToString();
                    return(Json(resp));
                }

                if (DateTime.Compare(sttime, end_dtime) < 0 && DateTime.Compare(endtime, end_dtime) > 0)
                {
                    resp.Message = "当前时段设置错误,原来-" + sttime.ToString() + ",现-" + end_dtime.ToString();
                    return(Json(resp));
                }
                if (DateTime.Compare(st_dtime, sttime) < 0 && DateTime.Compare(end_dtime, sttime) > 0)
                {
                    resp.Message = "当前时段设置错误,现-" + st_dtime.ToString() + ",原来 - " + sttime.ToString();
                    return(Json(resp));
                }
                if (DateTime.Compare(st_dtime, endtime) < 0 && DateTime.Compare(end_dtime, endtime) > 0)
                {
                    resp.Message = "当前时段设置错误,现-" + st_dtime.ToString() + ",原来 - " + endtime.ToString();
                    return(Json(resp));
                }
                #endregion

                if (DateTime.Compare(endtime, DateTime.Parse("2017-1-1 23:59:59")) > 0)
                {
                    DateTime newstart = DateTime.Parse("2017-1-1");
                    DateTime newend   = endtime.AddDays(-1);

                    if (DateTime.Compare(newstart, st_dtime) < 0 && DateTime.Compare(newend, st_dtime) > 0)
                    {
                        resp.Message = "当前时段设置错误,现-" + st_dtime.ToString() + ",原来 New- " + newstart.ToString();
                        return(Json(resp));
                    }

                    if (DateTime.Compare(newstart, end_dtime) < 0 && DateTime.Compare(newend, end_dtime) > 0)
                    {
                        resp.Message = "当前时段设置错误,现-" + end_dtime.ToString() + ",原来 New- " + newstart.ToString();
                        return(Json(resp));
                    }
                }
            }

            if (DateTime.Compare(end_dtime, DateTime.Parse("2017-1-1 23:59:59")) > 0)
            {
                DateTime newend = DateTime.Parse("2017-1-1 " + end + ":00").AddSeconds(-1);
                foreach (HourSectionInfo section in timeSlotLst)
                {
                    if (section.ID == hourID)
                    {
                        continue;
                    }
                    DateTime sttime  = section.StartTime;
                    DateTime endtime = section.EndTime.AddSeconds(-1);

                    if (DateTime.Compare(sttime, newend) < 0 && DateTime.Compare(endtime, newend) > 0)
                    {
                        resp.Message = "当前时段设置错误,原来-" + sttime.ToString() + ",现-" + newend.ToString();
                        return(Json(resp));
                    }
                }
            }

            string topfee       = Request.Form["SectionTopFee"];
            string freetime     = Request.Form["SectionFreeTime"];
            string firstvoid    = Request.Form["FirstVoidTime"];
            string firstfee     = Request.Form["FirstVoidFee"];
            string intervalvoid = Request.Form["IntervalVoidTime"];
            string intervalfee  = Request.Form["IntervalVoidFee"];

            hoursection.StartTime        = st_dtime;
            hoursection.EndTime          = end_dtime.AddSeconds(1);
            hoursection.SectionTopFee    = Convert.ToSingle(topfee);
            hoursection.SectionFreeTime  = freetime;
            hoursection.FirstVoidTime    = firstvoid;
            hoursection.FirstVoidFee     = Convert.ToSingle(firstfee);
            hoursection.IntervalVoidTime = intervalvoid;
            hoursection.IntervalVoidFee  = Convert.ToSingle(intervalfee);
            resp = cwtarff.UpdateHourSection(hoursection);

            return(Json(resp));
        }
Exemplo n.º 4
0
        /// <summary>
        /// 停车终点出现跨段的
        /// </summary>
        private float calcuteStrideSection(DateTime indate, DateTime outdate, List <HourSectionInfo> timeslotLst, List <HourSectionInfo> allTimeSlots)
        {
            if (timeslotLst.Count == 0)
            {
                return(40001);
            }
            //找出 indate 落在里面的时间段
            HourSectionInfo timeslot = timeslotLst.First(ti =>
                                                         DateTime.Compare(ti.StartTime, DateTime.Parse(ti.StartTime.ToShortDateString() + " " + indate.ToShortTimeString())) == 0 ||
                                                         DateTime.Compare(ti.StartTime, DateTime.Parse(ti.StartTime.ToShortDateString() + " " + indate.AddMinutes(1).ToShortTimeString())) == 0
                                                         );

            if (timeslot == null)
            {
                return(40002);
            }
            string   onlydate = indate.ToShortDateString();
            DateTime st       = DateTime.Parse(onlydate + " " + timeslot.StartTime.ToShortTimeString() + ":00");
            DateTime end      = DateTime.Parse(onlydate + " " + (timeslot.EndTime.AddSeconds(-1)).ToShortTimeString() + ":00");

            //没有出现跨0点
            if (DateTime.Compare(st, end) < 0)
            {
                #region
                if (DateTime.Compare(end, outdate) >= 0)
                {
                    #region
                    TimeSpan ts      = outdate - st;
                    int      minutes = (int)Math.Ceiling(ts.TotalMinutes);
                    //整数部分
                    int integarPart = minutes / (int)TimeSpan.Parse(timeslot.IntervalVoidTime.Trim()).TotalMinutes;
                    //余数部分
                    int remainer = minutes % (int)TimeSpan.Parse(timeslot.IntervalVoidTime.Trim()).TotalMinutes;
                    //不足一个间隔时长的,以一个时长计算(例:不足15分钟的以15分钟计算)
                    if (remainer > 0)
                    {
                        ++integarPart;
                    }
                    //返回费用
                    float sectFee = integarPart * timeslot.IntervalVoidFee;
                    //本段是否有收费限额
                    if (timeslot.SectionTopFee > 0)
                    {
                        if (sectFee > timeslot.SectionTopFee)
                        {
                            return(timeslot.SectionTopFee);
                        }
                    }
                    //没有出现跨段的直接返回值
                    return(sectFee);

                    #endregion
                }
                else //又出现跨段,使用迭代,继续累加
                {
                    #region
                    //计算下些时段集合
                    List <HourSectionInfo> strideTimeslotLst = timeslotLst.FindAll(ti => ti.ID != timeslot.ID);

                    //计算本段内的停车费用,时起始时间及终点时间,以时间段的时间为段
                    TimeSpan ts      = end - st;
                    int      minutes = (int)Math.Ceiling(ts.TotalMinutes);
                    //整数部分
                    int integarPart = minutes / (int)TimeSpan.Parse(timeslot.IntervalVoidTime.Trim()).TotalMinutes;

                    //返回费用
                    float sectFee = integarPart * timeslot.IntervalVoidFee;
                    //本段是否有收费限额
                    if (timeslot.SectionTopFee > 0)
                    {
                        if (sectFee > timeslot.SectionTopFee)
                        {
                            sectFee = timeslot.SectionTopFee;
                        }
                    }
                    //累加下一个时间段的费用
                    return(sectFee + this.calcuteStrideSection(timeslot.EndTime, outdate, strideTimeslotLst, timeslotLst));

                    #endregion
                }
                #endregion
            }
            else //跨0点
            {
                #region
                DateTime nextEnd = end.AddDays(1); //跨时间段,则当前终点加1天
                if (DateTime.Compare(nextEnd, outdate) >= 0)
                {
                    #region
                    TimeSpan ts      = outdate - st;
                    int      minutes = (int)Math.Ceiling(ts.TotalMinutes);
                    //整数部分
                    int integarPart = minutes / (int)TimeSpan.Parse(timeslot.IntervalVoidTime.Trim()).TotalMinutes;
                    //余数部分
                    int remainer = minutes % (int)TimeSpan.Parse(timeslot.IntervalVoidTime.Trim()).TotalMinutes;
                    //不足一个间隔时长的,以一个时长计算(例:不足15分钟的以15分钟计算)
                    if (remainer > 0)
                    {
                        ++integarPart;
                    }
                    //返回费用
                    float sectFee = integarPart * timeslot.IntervalVoidFee;
                    //本段是否有收费限额
                    if (timeslot.SectionTopFee > 0)
                    {
                        if (sectFee > timeslot.SectionTopFee)
                        {
                            return(timeslot.SectionTopFee);
                        }
                    }
                    return(sectFee);

                    #endregion
                }
                else //又出现跨段,使用迭代,继续累加
                {
                    #region
                    //计算下些时段集合
                    List <HourSectionInfo> strideTimeslotLst = timeslotLst.FindAll(ti => ti.StartTime != timeslot.StartTime);
                    if (strideTimeslotLst == null || !strideTimeslotLst.Exists(ti => ti.StartTime == timeslot.EndTime))
                    {
                        strideTimeslotLst = allTimeSlots.FindAll(ti => ti.StartTime != timeslot.StartTime);
                    }

                    TimeSpan ts      = nextEnd - st;
                    int      minutes = (int)Math.Ceiling(ts.TotalMinutes);
                    //整数部分
                    int integarPart = minutes / (int)TimeSpan.Parse(timeslot.IntervalVoidTime.Trim()).TotalMinutes;

                    //返回费用
                    float sectFee = integarPart * timeslot.IntervalVoidFee;
                    //本段是否有收费限额
                    if (timeslot.SectionTopFee > 0)
                    {
                        if (sectFee > timeslot.SectionTopFee)
                        {
                            sectFee = timeslot.SectionTopFee;
                        }
                    }

                    //累加下一个时间段的费用
                    return(sectFee + this.calcuteStrideSection(nextEnd, outdate, strideTimeslotLst, allTimeSlots));

                    #endregion
                }
                #endregion
            }
        }
Exemplo n.º 5
0
        public ActionResult AddHourSectionRule()
        {
            Response resp    = new Response();
            CWTariff cwtarff = new CWTariff();

            string hourchgID = Request.Form["HourChgID"];

            if (string.IsNullOrEmpty(hourchgID))
            {
                resp.Message = "周期性计费策略ID为空,传输错误!";
                return(Json(resp));
            }
            int hourID = Convert.ToInt32(hourchgID);
            HourChargeDetail temprule = cwtarff.FindHourChgDetail(hourID);

            if (temprule == null)
            {
                resp.Message = "传输错误,找不到相关的周期性计费,ID-" + hourchgID;
                return(Json(resp));
            }

            //重点是时间段的判断
            string start = Request.Form["StartTime"];
            string end   = Request.Form["EndTime"];

            DateTime st_dtime  = DateTime.Parse("2017-1-1 " + start + ":00");
            DateTime end_dtime = DateTime.Parse("2017-1-1 " + end + ":00").AddSeconds(-1);

            if (DateTime.Compare(st_dtime, end_dtime) > 0)
            {
                end_dtime = end_dtime.AddDays(1);
            }

            List <HourSectionInfo> timeSlotLst = cwtarff.FindHourSectionList(hr => true);

            foreach (HourSectionInfo section in timeSlotLst)
            {
                DateTime sttime  = section.StartTime;
                DateTime endtime = section.EndTime.AddSeconds(-1);
                #region
                if (DateTime.Compare(sttime, st_dtime) < 0 && DateTime.Compare(endtime, st_dtime) > 0)
                {
                    resp.Message = "当前时段设置错误,原来-" + sttime.ToString() + ",现-" + st_dtime.ToString();
                    return(Json(resp));
                }

                if (DateTime.Compare(sttime, end_dtime) < 0 && DateTime.Compare(endtime, end_dtime) > 0)
                {
                    resp.Message = "当前时段设置错误,原来-" + sttime.ToString() + ",现-" + end_dtime.ToString();
                    return(Json(resp));
                }
                if (DateTime.Compare(st_dtime, sttime) < 0 && DateTime.Compare(end_dtime, sttime) > 0)
                {
                    resp.Message = "当前时段设置错误,现-" + st_dtime.ToString() + ",原来 - " + sttime.ToString();
                    return(Json(resp));
                }
                if (DateTime.Compare(st_dtime, endtime) < 0 && DateTime.Compare(end_dtime, endtime) > 0)
                {
                    resp.Message = "当前时段设置错误,现-" + st_dtime.ToString() + ",原来 - " + endtime.ToString();
                    return(Json(resp));
                }
                #endregion

                if (DateTime.Compare(endtime, DateTime.Parse("2017-1-1 23:59:59")) > 0)
                {
                    DateTime newstart = DateTime.Parse("2017-1-1");
                    DateTime newend   = endtime.AddDays(-1);

                    if (DateTime.Compare(newstart, st_dtime) < 0 && DateTime.Compare(newend, st_dtime) > 0)
                    {
                        resp.Message = "当前时段设置错误,现-" + st_dtime.ToString() + ",原来 New- " + newstart.ToString();
                        return(Json(resp));
                    }

                    if (DateTime.Compare(newstart, end_dtime) < 0 && DateTime.Compare(newend, end_dtime) > 0)
                    {
                        resp.Message = "当前时段设置错误,现-" + end_dtime.ToString() + ",原来 New- " + newstart.ToString();
                        return(Json(resp));
                    }
                }
            }

            if (DateTime.Compare(end_dtime, DateTime.Parse("2017-1-1 23:59:59")) > 0)
            {
                DateTime newend = DateTime.Parse("2017-1-1 " + end + ":00").AddSeconds(-1);
                foreach (HourSectionInfo section in timeSlotLst)
                {
                    DateTime sttime  = section.StartTime;
                    DateTime endtime = section.EndTime.AddSeconds(-1);

                    if (DateTime.Compare(sttime, newend) < 0 && DateTime.Compare(endtime, newend) > 0)
                    {
                        resp.Message = "当前时段设置错误,原来-" + sttime.ToString() + ",现-" + newend.ToString();
                        return(Json(resp));
                    }
                }
            }

            string topfee       = Request.Form["SectionTopFee"];
            string freetime     = Request.Form["SectionFreeTime"];
            string firstvoid    = Request.Form["FirstVoidTime"];
            string firstfee     = Request.Form["FirstVoidFee"];
            string intervalvoid = Request.Form["IntervalVoidTime"];
            string intervalfee  = Request.Form["IntervalVoidFee"];

            HourSectionInfo hoursection = new HourSectionInfo()
            {
                HourChgID        = hourID,
                StartTime        = st_dtime,
                EndTime          = end_dtime.AddSeconds(1),
                SectionTopFee    = Convert.ToSingle(topfee),
                SectionFreeTime  = freetime,
                FirstVoidTime    = firstvoid,
                FirstVoidFee     = Convert.ToSingle(firstfee),
                IntervalVoidTime = intervalvoid,
                IntervalVoidFee  = Convert.ToSingle(intervalfee)
            };
            resp = cwtarff.AddHourSection(hoursection);

            return(Json(resp));
        }