/// <summary> /// 导出为EXCEL /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uiSymbolButton_exportExcel_Click(object sender, EventArgs e) { string str = KeyData_DailyData.ExportToExcel(); KeyData_Today.ExportToExcel(); KeyData_Total.ExportToExcel(); System.Diagnostics.Process.Start(Path.GetDirectoryName(str)); }
/// <summary> /// 保存数据 /// </summary> private void SaveData() { //判断是否过天 if (!CheckDate()) { //保存数据 KeyData_Today.SaveKeyData(); KeyData_Total.SaveKeyData(); KeyData_DailyData.SaveKeyData(); } //更新label uiLabel_lastSave.Text = "上次更新时间为:" + DateTime.Now.ToString("MM月dd日HH时mm分ss秒"); //记录日志 if (ConfigureData.configure.IsLog) { LogHelper.Info("保存记录"); } }
/// <summary> /// 判断是否过天 /// </summary> private bool CheckDate() { //如果记录的天数已经过了,清空并重新记录。 if (KeyData_Today.todayData.Date != DateTime.Now.ToString("yyyy-MM-dd")) { //先更新总数据和每日数据 KeyData_Total.UpdateData(); KeyData_DailyData.UpdateData(); //保存并重置当天数据 KeyData_Today.ResetCount(); //保存数据 KeyData_Today.SaveKeyData(); KeyData_Total.SaveKeyData(); KeyData_DailyData.SaveKeyData(); return(true); } return(false); }
/// <summary> /// 格式化数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uiSymbolButton_clear_Click(object sender, EventArgs e) { List <string> items = new List <string> { "仅格式化计数数据", "格式化所有数据(包括坐标)" }; int select = -1; if (this.ShowSelectDialog(ref select, items)) { if (select == 0)//仅格式化计数数据 { KeyData_DailyData.Reset(); KeyData_Today.ResetCount(); KeyData_Total.ResetCount(); } else if (select == 1)//格式化所有 { KeyData_DailyData.Reset(); KeyData_Today.Reset(); KeyData_Total.Reset(); } } }
/// <summary> /// 每日数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void uiButton_daily_Click(object sender, EventArgs e) { //添加数据 int MaxCount = int.MinValue; int MinCount = int.MaxValue; Daily daily = null; List <string> items = new List <string>() { "7日", "15日", "30日" }; int index = 0; int day = 0; if (this.ShowSelectDialog(ref index, items)) { //根据index,确定day变量大小 switch (index) { case 0: day = 7; break; case 1: day = 15; break; case 2: day = 30; break; } //初始化Option UIBarOption option = new UIBarOption(); option.Title = new UITitle(); option.Title.Text = "每日数据"; option.Title.SubText = "BarChart"; //添加数据 var series = new UIBarSeries(); series.Name = "Total"; int x = -1; for (int i = -day; i <= -1; i++) { x = KeyData_DailyData.FindByRange(DateTime.Now.AddDays(i).Date.ToString("yyyy-MM-dd"), day); if (x != -1) { daily = KeyData_DailyData.dailyData.dailies[x]; //获取常规数据 series.AddData(daily.Total); option.XAxis.Data.Add(daily.Date); //获取最大最小数据 MaxCount = MaxCount > daily.Total ? MaxCount : daily.Total; MinCount = MinCount < daily.Total ? MinCount : daily.Total; } else { //自动补完 series.AddData(0); option.XAxis.Data.Add(DateTime.Now.AddDays(i).Date.ToString("yyyy-MM-dd")); } } //更新数据面板 uiLabel_total.Text = "总数:不做计算"; uiLabel_date.Text = "日期:" + DateTime.Now.AddDays(-day).Date.ToString("yyyy-MM-dd") + "至" + KeyData_DailyData.dailyData.EndDate; option.Series.Add(series); //添加最大最小数据线 if (MaxCount != int.MinValue) { option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "最大为" + MaxCount, Value = MaxCount }); } if (MinCount != int.MaxValue) { option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Blue, Name = "最小为" + MinCount, Value = MinCount, Left = UILeftAlignment.Right }); } //x轴上不显示标签 option.XAxis.AxisLabel.Show = false; //显示tip option.ToolTip = new UIBarToolTip(); //其他设置 option.YAxis.Scale = true; option.XAxis.Name = "日期"; option.YAxis.Name = "数值"; uiBarChart1.SetOption(option); } }
/// <summary> /// 加载键盘数据 /// </summary> private void LoadKeyData() { KeyData_DailyData.LoadKeyData(); KeyData_Today.LoadKeyData(); KeyData_Total.LoadKeyData(); }