123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- using DataSimulation.Forms.EditForms;
- using DataSimulation.Repostory;
- using DataSimulation.Repostory.EFContext;
- using DataSimulation.Repostory.Model;
- using DevExpress.Utils;
- using DevExpress.XtraEditors.ButtonsPanelControl;
- using DevExpress.XtraMap;
- using DxHelper;
- using ExtensionsDev;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.Entity;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace DataSimulation.Forms.UserControl
- {
- public partial class CtrlHome : DevExpress.XtraEditors.XtraUserControl
- {
- List<TaskInfo> taskList = new List<TaskInfo>();
- public CtrlHome()
- {
- InitializeComponent();
- gridControl.Init<TaskInfo>().UseFilter();
- layoutControl1.UseDefault();
- mapControl
- .UseDefalutOptions()
- .UseClearAll()
- .UseDistanceLine()
- .UseMarkDot()
- .UseExportImg()
- .UseExportXlsx()
- .UseExportCsv()
- .SetMapLayerType(null)
- .UseDrawRect(rect =>
- {
- (double startLon, double startLat, double centerLon, double centerLat, double endLon, double endLat, double lonRange, double latRange) = rect;
- }).UseFlightLine()
- ;
- }
- private async void CtrlHome_Load(object sender, EventArgs e)
- {
- try
- {
- var yearDirs = Directory.EnumerateDirectories(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart")).OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name));//年目录,倒叙排列
- foreach (var yearDir in yearDirs)
- {
- //每一天的db文件,倒序排列
- var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir), "*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
- foreach (var dayFile in dayFiles)
- {
- using (SimulationPartContext db = SimulationPartContext.GetContext(dayFile))
- {
- taskList.AddRange(await db.TaskInfos.ToListAsync());
- var runningList = await db.TaskInfos.Where(p => p.TaskState == EnumTaskState.Running).ToListAsync();
- foreach (var item in runningList)
- {
- item.TaskState = EnumTaskState.Stopped;
- }
- await db.SaveChangesAsync();
- }
- }
- }
- gridControl.DataSource = taskList;
- gridView.Columns[nameof(TaskInfo.TaskName)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
- this.svgImageCollection1.Add("Stopped", SvgHelper.CreateCycle("#1E8B58"));
- this.svgImageCollection1.Add("Running", SvgHelper.CreateCycle("#2E8B57"));
- }
- catch (Exception)
- {
- throw;
- }
- }
- private async void layoutControlGroup_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
- {
-
- var txt = (e.Button as GroupBoxButton).Caption;
- if (txt == "新建任务")
- {
- try
- {
- TaskEditor frm = new TaskEditor();
- if (frm.ShowDialog() != DialogResult.OK) return;
- var addItem = frm.info;
- var taskList = await TaskCache.GetAllAsync();
- //if (await taskList.ToList().(p => p.TaskName == addItem.TaskName))
- //{
- // DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
- // return;
- //}
- //using (SimulationContext db = new RHDWContext())
- //{
- // if (await db.TaskInfos.AnyAsync(p => p.TaskName == addItem.TaskName))
- // {
- // DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
- // return;
- // }
- // if (addItem.PosType == EnumPosType.X1D1CX)
- // {
- // addItem.Adja1Sat = null;
- // addItem.Adja2Sat = null;
- // }
- // else if (addItem.PosType == EnumPosType.X2D1 || addItem.PosType == EnumPosType.X2Dfo || addItem.PosType == EnumPosType.RH)
- // {
- // addItem.Adja2Sat = null;
- // }
- // db.TaskInfos.Add(addItem);
- // await db.SaveChangesAsync();
- //}
- //list.Insert(0, addItem);
- //gridView1.RefreshData();
- //gridView1.FocusedRowHandle = 0;
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, "保存任务异常");
- DxHelper.MsgBoxHelper.ShowError("保存任务异常");
- }
- }
- }
- }
- }
|