using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GroupLine.Com; using GroupLine.Model; using NLog; using System; using System.Linq; namespace GroupLine.App.ViewModel { public class ReportTimeConfigViewModel : ViewModelBase { //日志的实例化 private static Logger _Logger = LogManager.GetCurrentClassLogger(); /// /// 当前程序的位置 /// private string Location; private string CurrentRegion = "前组"; private string CurrentCategory = "报表信息"; private string CurrentReportTimeName = "导出时间"; //private string CurrentMachineNameTemplate = "H_RobotHandTemplate.xlsx"; public delegate void PubReportTime(string ReportInfo); public static event PubReportTime PubReportTimeEvent; //private IMapper autoMapper; /// /// 实例化函数 /// public ReportTimeConfigViewModel() { //SearchStartDate = DateTime.Now.AddDays(-1).ToShortDateString(); //SearchEndDate = DateTime.Now.AddDays(10).ToShortDateString(); Location = ConfigHelper.GetValue("Location"); if (Location == "1") { CurrentRegion = "前组"; } else { CurrentRegion = "后组"; } //var config = new MapperConfiguration(cfg => cfg.CreateMap()); //autoMapper = config.CreateMapper(); var ConfigInfo = FSqlContext.FDb.Select().Where(a => a.Region == CurrentRegion && a.Category == CurrentCategory && a.Name == CurrentReportTimeName).ToList(); if (ConfigInfo != null && ConfigInfo.Count() > 0) { DayReportTime = ConfigInfo.FirstOrDefault().Value; } else { DayReportTime = ""; } } ///// ///// 列表集合 ///// //private ObservableCollection _ListH_RobotHandDto; ///// ///// 列表集合 ///// //public ObservableCollection ListH_RobotHandDto //{ // get { return _ListH_RobotHandDto; } // set { _ListH_RobotHandDto = value; } //} #region "属性" /// /// 每日导出时间 /// private string dayReportTime; public string DayReportTime { get { return dayReportTime; } set { dayReportTime = value; RaisePropertyChanged(() => DayReportTime); } } /// /// 搜索条件-开始时间 /// private string searchStartDate; public string SearchStartDate { get { return searchStartDate; } set { searchStartDate = value; RaisePropertyChanged(() => SearchStartDate); } } /// /// 搜索条件-结束时间 /// private string searchEndDate; public string SearchEndDate { get { return searchEndDate; } set { searchEndDate = value; RaisePropertyChanged(() => SearchEndDate); } } #endregion #region "搜索命令" /// /// 搜索命令 /// private RelayCommand saveCmd; public RelayCommand SaveCmd { get { if (saveCmd == null) return new RelayCommand(() => Save()); return saveCmd; } set { saveCmd = value; } } private void Save() { try { //发布报表信息 PubReportTimeEvent(DayReportTime); var ReportConfig = FSqlContext.FDb.Select().Where(a => a.Region == CurrentRegion && a.Category == CurrentCategory && a.Name == "导出时间").OrderByDescending(a => a.CreateTime).ToList(); if (ReportConfig != null && ReportConfig.Count > 0) { FSqlContext.FDb.Update(ReportConfig.FirstOrDefault().Id) //.Set(a => a.CreateTime, DateTime.Now)// FreeSQL会自动更新时间 .Set(a => a.Value, DayReportTime) .ExecuteAffrows(); } else { FSqlContext.FDb.Insert(new SystemConfig() { Region = CurrentRegion, Category = CurrentCategory, Name = CurrentReportTimeName, Value = DayReportTime, }).ExecuteAffrows(); } } catch (Exception ex) { _Logger.Error(String.Format("ErrSource : {0} ErrMsg : {1}", ex.StackTrace.ToString(), ex.Message.ToString())); } } #endregion #region "导出数据" //OutputDataCmd #endregion } }