/// <summary> /// 获取最新阀值数据 /// </summary> /// <returns></returns> public AkThresholdModel GetNewThreshold() { AkThresholdModel mode = null; string sql = string.Format("select top(1) * from {0} order by DataDate desc", this.tableName); DataTable dt = SqlServerHelper.Instance.GetDataTable(AkConfig.ConnAlohaReporting, sql); if (dt != null && dt.Rows.Count > 0) { DataRow dr = dt.Rows[0]; mode = new AkThresholdModel() { Id = dr.Field <int>("Id"), DataDate = dr.Field <string>("DataDate"), BreakFastValue = dr.Field <int>("BreakFastValue"), LunchValue = dr.Field <int>("LunchValue"), AfternoonTeaValue = dr.Field <int>("AfternoonTeaValue"), SupperValue = dr.Field <int>("SupperValue"), PeriodNum = dr.Field <int>("PeriodNum"), PeriodStartDate = dr.Field <string>("PeriodStartDate"), PeriodEndDate = dr.Field <string>("PeriodEndDate"), CreateTime = dr.Field <string>("CreateTime"), UpdateTime = dr.Field <string>("UpdateTime") }; } return(mode); }
/// <summary> /// 新增、修改阀值 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Save(AkThresholdModel model) { string sql = string.Format("SELECT count(1) FROM {0} where DataDate ='{1}'", this.tableName, model.DataDate); //记录存在则修改、否则新增 bool exist = SqlServerHelper.Instance.ExistRecode(AkConfig.ConnAlohaReporting, sql); object[] param = null; if (exist) { param = new object[] { this.tableName, model.BreakFastValue, model.LunchValue, model.AfternoonTeaValue, model.SupperValue, model.PeriodNum, model.PeriodStartDate, model.PeriodEndDate, model.UpdateTime, model.DataDate }; sql = string.Format("Update {0} set " + "BreakFastValue ={1}," + "LunchValue ={2}," + "AfternoonTeaValue ={3}," + "SupperValue ={4}," + "PeriodNum ={5}," + "PeriodStartDate ='{6}'," + "PeriodEndDate ='{7}'," + "UpdateTime ='{8}'" + "where DataDate ='{9}'", param); } else { param = new object[] { this.tableName, model.DataDate, model.BreakFastValue, model.LunchValue, model.AfternoonTeaValue, model.SupperValue, model.PeriodNum, model.PeriodStartDate, model.PeriodEndDate, model.CreateTime, model.UpdateTime }; sql = string.Format("insert into {0}(DataDate,BreakFastValue,LunchValue,AfternoonTeaValue,SupperValue,PeriodNum,PeriodStartDate,PeriodEndDate,CreateTime,UpdateTime) " + @"VALUES('{1}',{2},{3},{4},{5},{6},'{7}','{8}','{9}','{10}')", param); } return(SqlServerHelper.Instance.ExecuteNonQuery(AkConfig.ConnAlohaReporting, sql) > 0 ? true : false); }
public void SaveThreshold(string dateTime) { //计算阀值 int breakFastValue = CalculateThresholdValue(AkConfig.SysParam.BreakFast); int lunchValue = CalculateThresholdValue(AkConfig.SysParam.Lunch); int afternoonTeaValue = CalculateThresholdValue(AkConfig.SysParam.AfternoonTea); int supperValue = CalculateThresholdValue(AkConfig.SysParam.Supper); AkThresholdModel newModel = new AkThresholdModel() { DataDate = AkConfig.EndDate, CreateTime = dateTime, UpdateTime = dateTime, BreakFastValue = breakFastValue, LunchValue = lunchValue, AfternoonTeaValue = afternoonTeaValue, SupperValue = supperValue, PeriodNum = AkConfig.PeriodNum, PeriodStartDate = AkConfig.StartDate, PeriodEndDate = AkConfig.EndDate }; AkDaoHelper.Instance_Threshold.Save(newModel); }
/// <summary> /// 测试 /// </summary> public void Test() { AkThresholdModel model = new AkThresholdModel() { DataDate = "20180311", CreateTime = "2018-03-12 15:03:04 111", UpdateTime = "2018-03-12 15:03:04 111", ThresholdValue = 10, PeriodNum = 14, PeriodStartDate = "20180226", PeriodEndDate = "20180311" }; //AkThreshold akThreshold = new AkThreshold(); //var ak1 = AkThreshold.GetThreshold(); //var ak2 = AkThreshold.Save(model); AkRemindModel model1 = new AkRemindModel() { Tasktime = "2018-03-12 15:03:04 111", PeriodNum = 14, IsRemind = 1, HasRemind = -1 }; AkRemind akRemind = new AkRemind(); //var akRemind1 = akRemind.Insert(model1); //var akRemind2 = akRemind.ResetHasRemind(true, 1); }
/// <summary> /// 获取当前餐段阀值 /// </summary> /// <returns></returns> private int getCurThreshold() { int threshold = 0; AkThresholdModel model = AkDaoHelper.Instance_Threshold.GetNewThreshold(); if (model != null) { string curTime = DateTime.Now.ToString("HH:mm:ss"); AkSystemParamModel reastTime = AkConfig.SysParam; if (reastTime != null) { if (curTime.CompareTo(reastTime.BreakFast.StartTime) > 0 && curTime.CompareTo(reastTime.BreakFast.EndTime) < 0) { threshold = model.BreakFastValue; } else if (curTime.CompareTo(reastTime.Lunch.StartTime) > 0 && curTime.CompareTo(reastTime.Lunch.EndTime) < 0) { threshold = model.LunchValue; } else if (curTime.CompareTo(reastTime.AfternoonTea.StartTime) > 0 && curTime.CompareTo(reastTime.AfternoonTea.EndTime) < 0) { threshold = model.AfternoonTeaValue; } else if (curTime.CompareTo(reastTime.Supper.StartTime) > 0 && curTime.CompareTo(reastTime.Supper.EndTime) < 0) { threshold = model.SupperValue; } } } return(threshold); }
/// <summary> /// 分线提醒 /// </summary> /// <returns></returns> public bool Remind() { bool remind = false; bool isHealth = false; try { //@1.计算是否提醒分线 remind = CalculateRemind(out isHealth); //@2.回填是否,已分线 AkDaoHelper.Instance_Remind.ResetHasRemind(isHealth); AkThresholdModel thresholdModel = AkDaoHelper.Instance_Threshold.GetNewThreshold(); //@3.新增提醒记录 AkRemindModel model = new AkRemindModel() { Tasktime = DateTime.Now.ToLongTime(), BreakFastValue = thresholdModel.BreakFastValue, LunchValue = thresholdModel.LunchValue, AfternoonTeaValue = thresholdModel.AfternoonTeaValue, SupperValue = thresholdModel.SupperValue, PeriodNum = AkConfig.PeriodNum, IsRemind = remind ? 1 : 0, HasRemind = -1 }; bool success = AkDaoHelper.Instance_Remind.Save(model); } catch (Exception er) { LogHelper.Error(typeof(AkRemind) + ".Remind Exception error=", er.ToString()); } //Random random = new Random(); //int r = random.Next(100); //if (r % 3 == 0) //{ // remind = true; //} //else //{ // remind = false; //} return(remind); }
/// <summary> /// 检查阀值和当前连接数 /// </summary> void CheckData() { string mess = string.Empty; if (akremind.Count < 3) { //mess += "当前连接数为" + akremind.Count; mess += " 分线程序连接不正确,请联系400报修!"; } AkThresholdModel akThreshold = AkDaoHelper.Instance_Threshold.GetNewThreshold(); //if (akThreshold.BreakFastValue == 0) //{ // mess += "当前早餐阀值为0"; //} //if (akThreshold.LunchValue == 0) //{ // mess += "当前午餐阀值为0"; //} //if (akThreshold.AfternoonTeaValue == 0) //{ // mess += "当前下午茶阀值为0"; //} //if (akThreshold.SupperValue == 0) //{ // mess += "当前晚餐阀值为0"; //} if (akThreshold.BreakFastValue == 0 || akThreshold.LunchValue == 0 || akThreshold.AfternoonTeaValue == 0 || akThreshold.SupperValue == 0) { mess += "餐厅分线阀值数值异常,请打开基本设置,点击保存!"; } if (!string.IsNullOrEmpty(mess)) { MessageBox.Show(mess); } }
/// <summary> /// 开辟线程:计算阀值 /// 计算阀值情况: /// 1).前一天dbf文件已存在 /// 2).Sqlite中,无记录 /// 3).Sqlite有记录,但是最新记录的数据日期 小于 前一天的日期 /// </summary> public void Excute(string dateTime) { DateTime dt = DateTime.Parse(dateTime); if (dt.Hour < 5) { return; } AkThresholdModel akThreshold = null; Task.Factory.StartNew(() => { akThreshold = AkDaoHelper.Instance_Threshold.GetNewThreshold(); DateTime newDate = DateTime.Now; if (akThreshold != null) { newDate = DateTime.Parse(akThreshold.DataDate + " 00:00:00").AddDays(AkConfig.UpdateNum); } if (akThreshold == null || newDate <= DateTime.Now.AddDays(-1)) { SaveThreshold(dateTime); } }); akThreshold = AkDaoHelper.Instance_Threshold.GetNewThreshold(); if (akThreshold.BreakFastValue == 0 || akThreshold.BreakFastValue == 0 || akThreshold.AfternoonTeaValue == 0 || akThreshold.SupperValue == 0) { SaveThreshold(dateTime); } }
private void SetUpWindow_OnLoaded(object sender, RoutedEventArgs e) { //初始化 if (AkConfig.SysParam != null) { //textBoxPeriod.Text = AkConfig.PeriodNum.ToString(); textBoxTime.Text = AkConfig.SysParam.PerTime.ToString(); //textBoxJgTime.Text = AkConfig.SysParam.TaskTime.ToString(); textBoxMin.Text = AkConfig.SysParam.MinLine.ToString(); textBoxMax.Text = AkConfig.SysParam.MaxLine.ToString(); //textBlockConfig.Text = AkIniHelper.inifilepath; } //@1.计算阀值的日期区间,比如:1,7,10,14天,则取设置区间的天数进行阀值计算 List <string> ltPeriod = AkDaoHelper.Instance_SystemParam.GetPeriod("1"); //@2.计算阀值的频率,比如:1,3,5天,则计算阀值的频率则为设置的频率 List <string> ltUpdatePeriod = AkDaoHelper.Instance_SystemParam.GetPeriod("2"); if (ltPeriod != null && ltPeriod.Any()) { int index = 0; for (int i = 0; i < ltPeriod.Count; i++) { var pd = ltPeriod[i]; ComboBoxItem comboBoxItem = new ComboBoxItem(); comboBoxItem.Content = pd; cmboxPeriod.Items.Add(comboBoxItem); if (int.Parse(pd) == AkConfig.PeriodNum) { index = i; } } cmboxPeriod.SelectedIndex = index; } if (ltUpdatePeriod != null && ltUpdatePeriod.Any()) { int index = 0; for (int i = 0; i < ltUpdatePeriod.Count; i++) { var pd = ltUpdatePeriod[i]; ComboBoxItem comboBoxItem = new ComboBoxItem(); comboBoxItem.Content = pd; cmboxTime.Items.Add(comboBoxItem); if (int.Parse(pd) == AkConfig.UpdateNum) { index = i; } } cmboxTime.SelectedIndex = index; } //读取每个阶段的阀值 AkThresholdModel akThreshold = AkDaoHelper.Instance_Threshold.GetNewThreshold(); if (akThreshold != null) { int breakFastValue = akThreshold.BreakFastValue; int itemFastValue = breakFastValue == 0 ? 0 : AkConfig.SysParam.PerTime / breakFastValue; cmbdoxitemZc1.Text = itemFastValue.ToString(); cmbdoxfzZc1.Text = breakFastValue.ToString(); int lunchValue = akThreshold.LunchValue; int itemLunchValue = lunchValue == 0 ? 0 : AkConfig.SysParam.PerTime / lunchValue; cmbdoxitemZc2.Text = itemLunchValue.ToString(); cmbdoxfzZc2.Text = lunchValue.ToString(); int afternoonTeaValue = akThreshold.AfternoonTeaValue; int itemAfternoonTeaValue = afternoonTeaValue == 0 ? 0 : AkConfig.SysParam.PerTime / afternoonTeaValue; cmbdoxitemZc3.Text = itemAfternoonTeaValue.ToString(); cmbdoxfzZc3.Text = afternoonTeaValue.ToString(); int supperValue = akThreshold.SupperValue; int itemSupperValue = supperValue == 0 ? 0 : AkConfig.SysParam.PerTime / supperValue; cmbdoxitemZc4.Text = itemSupperValue.ToString(); cmbdoxfzZc4.Text = supperValue.ToString(); } }