Exemplo n.º 1
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.º 2
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));
        }