public Dictionary <string, object> AddSetting(SettingModel model)
        {
            PredicSettingBll PredicSettingBll = new PredicSettingBll();
            // Type t = typeof(SettingModel);
            string      path   = HttpContext.Current.Server.MapPath("/App_Data/selfsetting.xml");
            XmlDocument xmldoc = new XmlDocument();

            xmldoc.Load(path);
            // PropertyInfo[] properties = t.GetProperties();
            xmldoc.SelectSingleNode("root").SelectSingleNode("selecttimes").Attributes[0].Value  = model.selecttimes;
            xmldoc.SelectSingleNode("root").SelectSingleNode("weekendbili").Attributes[0].Value  = model.weekendbili;
            xmldoc.SelectSingleNode("root").SelectSingleNode("mothtimes").Attributes[0].Value    = model.mothtimes.ToString();
            xmldoc.SelectSingleNode("root").SelectSingleNode("showcount").Attributes[0].Value    = model.showcount.ToString();
            xmldoc.SelectSingleNode("root").SelectSingleNode("daorutime").Attributes[0].Value    = model.daorutime;
            xmldoc.SelectSingleNode("root").SelectSingleNode("daorudir").Attributes[0].Value     = model.daorudir;
            xmldoc.SelectSingleNode("root").SelectSingleNode("daorunowdate").Attributes[0].Value = model.daorunowdate;
            xmldoc.Save(path);
            if (string.IsNullOrEmpty(model.daorutime))
            {
                var scheduler = StdSchedulerFactory.GetDefaultScheduler();
                if (scheduler.CheckExists(new TriggerKey("trigger", "triggers")))
                {
                    scheduler.UnscheduleJob(new TriggerKey("trigger", "triggers"));
                }
            }
            else
            {
                PredicSettingBll.ZiDongDaoRu(model.daorutime);
            }
            return(new Dictionary <string, object>
            {
                { "code", "1" }
            });
        }
Beispiel #2
0
        public ActionResult PredicSettingAdd()
        {
            PredicSettingBll bll   = new PredicSettingBll();
            PredicSetting    model = new PredicSetting();

            if (Request.QueryString["id"] != null)
            {
                model = bll.GetModel(int.Parse(Request.QueryString["id"].ToString()));
            }
            return(View(model));
        }
        public string  GetYuji1(string factorysation, string signal, string createtime)
        {
            IDatabase   database = DataFactory.Database();
            string      path     = HttpContext.Current.Server.MapPath("/App_Data/selfsetting.xml");
            XmlDocument xmldoc   = new XmlDocument();

            xmldoc.Load(path);
            // PropertyInfo[] properties = t.GetProperties();
            int    totalday  = int.Parse(xmldoc.SelectSingleNode("root").SelectSingleNode("mothtimes").Attributes[0].Value);
            var    list      = database.FindListBySql <M_HitchInfo>("SELECT sum(HappenTimes)AS HappenTimes, CreateTime FROM [M_HitchInfo] where  FactorySation = '" + factorysation + "' and Signal = '" + signal + "' and DATEDIFF(month, CreateTime, '" + createtime + "') = 0  group by CreateTime");
            int    monthdyas = DateTimeHelper.GetDaysOfMonth(DateTime.Parse(createtime));
            string month     = DateTime.Parse(createtime).Month.ToString();
            string year      = DateTime.Parse(createtime).Year.ToString();
            int    day       = DateTime.Parse(createtime).Day;
            //计算出每天的次数集合
            List <int> listtimes = new List <int>();

            for (int i = 1; i < monthdyas + 1; i++)
            {
                var model = list.Find(a => a.CreateTime == DateTime.Parse(year + "-" + month + "-" + i.ToString()));
                if (model == null)
                {
                    listtimes.Add(0);
                }
                else
                {
                    listtimes.Add(model.HappenTimes);
                }
            }
            string bili = xmldoc.SelectSingleNode("root").SelectSingleNode("weekendbili").Attributes[0].Value;

            string[] arrbili = bili.Split(':');
            //工作日节假日的具体比例
            List <int> shijilist = new List <int>();

            PredicSettingBll PredicSettingBll = new PredicSettingBll();
            string           ScaleDetial      = "";

            if (PredicSettingBll.IsExits(factorysation, signal, ref ScaleDetial))
            {
                string[] arr = ScaleDetial.Split(':');
                for (int i = 0; i < arr.Length; i++)
                {
                    shijilist.Add(int.Parse(arr[i]));
                }
            }
            else
            {  //每月的周末和工作日
                List <int> listdays = DateTimeHelper.GetMonthArr(DateTime.Parse(createtime));
                for (int i = 0; i < listdays.Count; i++)
                {
                    //工作日
                    if (listdays[i] == 0)
                    {
                        shijilist.Add(int.Parse(arrbili[1]));
                    }
                    else
                    {
                        shijilist.Add(int.Parse(arrbili[0]));
                    }
                }
            }


            int bilisum = 0;

            foreach (var item in shijilist)
            {
                bilisum += item;
            }
            List <int> shiji    = new List <int>();
            List <int> yuji     = new List <int>();
            List <int> list2    = new List <int>();
            List <int> list3    = new List <int>();
            int        shijisum = 0;

            for (int i = 0; i < shijilist.Count; i++)
            {
                //预计
                int inta = 0;
                //已用
                int intb = 0;
                if (i == 0)
                {
                    inta = totalday * shijilist[i] / bilisum;
                    if (listtimes[i] == 0)
                    {
                        intb = inta;
                    }
                    else
                    {
                        intb = listtimes[i];
                    }
                    list3.Add(intb);
                }
                else
                {
                    int a = totalday - M_HitchInfoBll.GetListSum(list3);
                    int b = bilisum - (M_HitchInfoBll.GetListSum(list2));
                    inta = shijilist[i] * a / b;
                    if (listtimes[i] == 0)
                    {
                        list3.Add(inta);
                    }
                    else
                    {
                        list3.Add(listtimes[i]);
                    }
                }

                list2.Add(shijilist[i]);
                //  int shengyu = shijilist[i] * (totalday- M_HitchInfoBll.GetRestCount(listtimes, i)) / (bilisum - (M_HitchInfoBll.GetRestCount(shijilist, i)));
                shiji.Add(listtimes[i]);
                yuji.Add(inta);
                shijisum += listtimes[i];
                if (shijisum > totalday)
                {
                    break;
                }
            }

            string result = "";

            for (int i = 0; i < shiji.Count; i++)
            {
                if (day == i + 1)
                {
                    result = shiji[i].ToString() + "," + yuji[i].ToString();
                }
            }
            return(result);
        }