gongqiuhong 1 year ago
parent
commit
7bb3cb88e0

+ 14 - 13
DataSimulation.Forms/EditForms/TaskEditor.Designer.cs

@@ -29,21 +29,21 @@
         private void InitializeComponent()
         {
             this.components = new System.ComponentModel.Container();
-            DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions3 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject9 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject10 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject11 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject12 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions4 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject13 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject14 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject15 = new DevExpress.Utils.SerializableAppearanceObject();
-            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject16 = new DevExpress.Utils.SerializableAppearanceObject();
             DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions1 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
             DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject1 = new DevExpress.Utils.SerializableAppearanceObject();
             DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject2 = new DevExpress.Utils.SerializableAppearanceObject();
             DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject3 = new DevExpress.Utils.SerializableAppearanceObject();
             DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject4 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions2 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject5 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject6 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject7 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject8 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.XtraEditors.Controls.EditorButtonImageOptions editorButtonImageOptions3 = new DevExpress.XtraEditors.Controls.EditorButtonImageOptions();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject9 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject10 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject11 = new DevExpress.Utils.SerializableAppearanceObject();
+            DevExpress.Utils.SerializableAppearanceObject serializableAppearanceObject12 = new DevExpress.Utils.SerializableAppearanceObject();
             this.layoutControl1 = new DevExpress.XtraLayout.LayoutControl();
             this.txtHj = new DevExpress.XtraEditors.SearchLookUpEdit();
             this.gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView();
@@ -156,6 +156,7 @@
             this.txtHj.StyleController = this.layoutControl1;
             this.txtHj.TabIndex = 17;
             this.txtHj.EditValueChanged += new System.EventHandler(this.txtHj_EditValueChanged);
+           // this.txtHj.CustomDisplayText += new DevExpress.XtraEditors.Controls.CustomDisplayTextEventHandler(this.txtHj_CustomDisplayText);
             // 
             // gridView1
             // 
@@ -197,7 +198,7 @@
             this.txtSpeed.Location = new System.Drawing.Point(12, 467);
             this.txtSpeed.Name = "txtSpeed";
             this.txtSpeed.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
-            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "m/s", -1, false, true, false, editorButtonImageOptions3, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject9, serializableAppearanceObject10, serializableAppearanceObject11, serializableAppearanceObject12, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "m/s", -1, false, true, false, editorButtonImageOptions1, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject1, serializableAppearanceObject2, serializableAppearanceObject3, serializableAppearanceObject4, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
             this.txtSpeed.Properties.MaskSettings.Set("MaskManagerType", typeof(DevExpress.Data.Mask.NumericMaskManager));
             this.txtSpeed.Properties.MaskSettings.Set("mask", "f3");
             this.txtSpeed.Size = new System.Drawing.Size(291, 23);
@@ -209,7 +210,7 @@
             this.txtBand.Location = new System.Drawing.Point(12, 423);
             this.txtBand.Name = "txtBand";
             this.txtBand.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
-            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "MHz", -1, false, true, false, editorButtonImageOptions4, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject13, serializableAppearanceObject14, serializableAppearanceObject15, serializableAppearanceObject16, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "MHz", -1, false, true, false, editorButtonImageOptions2, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject5, serializableAppearanceObject6, serializableAppearanceObject7, serializableAppearanceObject8, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
             this.txtBand.Properties.MaskSettings.Set("MaskManagerType", typeof(DevExpress.Data.Mask.NumericMaskManager));
             this.txtBand.Properties.MaskSettings.Set("mask", "f3");
             this.txtBand.Size = new System.Drawing.Size(291, 23);
@@ -221,7 +222,7 @@
             this.txtFreqUp.Location = new System.Drawing.Point(12, 379);
             this.txtFreqUp.Name = "txtFreqUp";
             this.txtFreqUp.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
-            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "MHz", -1, false, true, false, editorButtonImageOptions1, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject1, serializableAppearanceObject2, serializableAppearanceObject3, serializableAppearanceObject4, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "MHz", -1, false, true, false, editorButtonImageOptions3, new DevExpress.Utils.KeyShortcut(System.Windows.Forms.Keys.None), serializableAppearanceObject9, serializableAppearanceObject10, serializableAppearanceObject11, serializableAppearanceObject12, "", null, null, DevExpress.Utils.ToolTipAnchor.Default)});
             this.txtFreqUp.Properties.MaskSettings.Set("MaskManagerType", typeof(DevExpress.Data.Mask.NumericMaskManager));
             this.txtFreqUp.Properties.MaskSettings.Set("mask", "f3");
             this.txtFreqUp.Size = new System.Drawing.Size(291, 23);

+ 10 - 4
DataSimulation.Forms/EditForms/TaskEditor.cs

@@ -23,6 +23,8 @@ namespace DataSimulation.Forms.EditForms
     public partial class TaskEditor : DevExpress.XtraEditors.XtraForm
     {
         public TaskInfo info;
+        public List<SimulationInfo> simulationInfo=new List<SimulationInfo>();
+        List<string> hjText = new List<string>();
         public TaskEditor()
         {
             InitializeComponent();
@@ -41,11 +43,12 @@ namespace DataSimulation.Forms.EditForms
             this.radioSimulationType.SelectedIndex = 0;
         }
 
-        public TaskEditor(TaskInfo info)
+        public TaskEditor(TaskInfo info, List<SimulationInfo> simulationInfo)
           : this()
         {
             this.Text = "编辑任务";
             this.info = info;
+            this.simulationInfo = simulationInfo;   
         }
 
         private async void TaskEditor_Load(object sender, EventArgs e)
@@ -79,9 +82,7 @@ namespace DataSimulation.Forms.EditForms
             var hjList = await SimulationCache.GetAllAsync();
             this.txtHj.Properties.DataSource = hjList;
             this.txtHj.Properties.ValueMember = nameof(SimulationInfo);
-            // this.txtHj.Properties.KeyMember = nameof(SimulationInfo.CreateTime);
             this.txtHj.Properties.DisplayMember = nameof(SimulationInfo.SimulationName);
-            this.txtHj.SetSearchGridLookUpEditMultiSelected<SimulationInfo>();
 
             using (SimulationContext db = new SimulationContext())
             {
@@ -101,8 +102,10 @@ namespace DataSimulation.Forms.EditForms
                     this.txtRefStation.Properties.Items.Add(new ImageComboBoxItem(item.RefName, item.ID));
                 }
             }
+            
             if (this.Text == "编辑任务" && info != null)
             {
+                hjText = simulationInfo.Select(s => s.SimulationName).ToList();
                 using (SimulationContext db = new SimulationContext())
                 {
                     var satMain = await db.SatInfos.Where(w => w.SatCode == info.MainSat).FirstOrDefaultAsync();
@@ -121,6 +124,8 @@ namespace DataSimulation.Forms.EditForms
                     this.txtSpeed.EditValue = info.Speed;
                 }
             }
+            
+            this.txtHj.SetSearchGridLookUpEditMultiSelected<SimulationInfo>(simulationInfo,hjText);
         }
 
         /// <summary>
@@ -200,6 +205,7 @@ namespace DataSimulation.Forms.EditForms
                 info.Band = (long)(Convert.ToDouble(txtBand.EditValue) * 1e6);
                 info.Speed = Convert.ToInt64(txtSpeed.EditValue);
                 info.isHistory = false;
+                simulationInfo = txtHj.Properties.Tag.MapTo<List<SimulationInfo>>();
                 this.DialogResult = DialogResult.OK;
             }
             catch (Exception ex)
@@ -235,6 +241,6 @@ namespace DataSimulation.Forms.EditForms
                 }
                 mapControl.SetFlightLine(flightInfos);
             }
-        }
+        }       
     }
 }

+ 5 - 8
DataSimulation.Forms/ExtensionsDev/SearchLookUpEditExtension.cs

@@ -103,23 +103,22 @@ namespace ExtensionsDev
 
         }
 
-        public static SearchLookUpEdit SetSearchGridLookUpEditMultiSelected<T>(this SearchLookUpEdit ctrl,string nullText = "请选择")
+        public static SearchLookUpEdit SetSearchGridLookUpEditMultiSelected<T>(this SearchLookUpEdit ctrl, List<T> selectedV, List<string> selectedT, string nullText = "请选择")
         {
             var view = ctrl.Properties.PopupView as DevExpress.XtraGrid.Views.Grid.GridView;
             view.OptionsSelection.MultiSelect = true;
             view.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
             view.OptionsSelection.CheckBoxSelectorColumnWidth = 45;
-            ctrl.EditValue = null;
+            ctrl.EditValue =null ;
             ctrl.Properties.NullText = null;
-            ctrl.Properties.NullValuePrompt = nullText;
+            ctrl.Properties.NullValuePrompt = selectedT.Count> 0? string.Join(",", selectedT.ToArray()): nullText;
             ctrl.Properties.AllowFocused = false;
             ctrl.Properties.ShowNullValuePrompt = ShowNullValuePromptOptions.Default;
             ctrl.Properties.ShowAddNewButton = false;
+           
             var values = new List<T>();
-            //var keys = new List<string>();
             var texts = new List<string>();
             ctrl.Properties.Tag = values;
-            // ctrl.Tag = keys;
             ctrl.Popup += (s, e) =>
             {
                 view.ClearSelection();
@@ -127,7 +126,7 @@ namespace ExtensionsDev
                 for (int i = 0; i < view.RowCount; i++)
                 {
                     var value = view.GetRow(i);
-                    if (values.Any(a=>a.ToJsonStr()==value.ToJsonStr()))
+                    if (selectedV.Any(a=>a.ToJsonStr()==value.ToJsonStr()))
                     {
                         view.SelectRow(i);
                     }
@@ -145,8 +144,6 @@ namespace ExtensionsDev
                     values.Add(value);
                     var text = view.GetRowCellDisplayText(row, ctrl.Properties.DisplayMember);
                     texts.Add(text);
-                    //var key = view.GetRowCellDisplayText(row, ctrl.Properties.KeyMember);
-                    //keys.Add(key);
                 }
                 ctrl.RefreshEditValue();
             };

+ 38 - 3
DataSimulation.Forms/UserControl/CtrlHome.cs

@@ -2,6 +2,7 @@
 using DataSimulation.Repostory;
 using DataSimulation.Repostory.EFContext;
 using DataSimulation.Repostory.Model;
+using DevExpress.Office.Crypto;
 using DevExpress.Utils;
 using DevExpress.Utils.About;
 using DevExpress.XtraBars.Customization;
@@ -111,6 +112,7 @@ namespace DataSimulation.Forms.UserControl
                     TaskEditor frm = new TaskEditor();
                     if (frm.ShowDialog() != DialogResult.OK) return;
                     var addItem = frm.info;
+                    var addItemTaskSimulations = frm.simulationInfo;
                     // var taskListCache = await TaskCache.GetAllAsync();
                     if (taskList.ToList().Any(p => p.TaskName == addItem.TaskName))
                     {
@@ -119,8 +121,20 @@ namespace DataSimulation.Forms.UserControl
                     }
                     using (SimulationPartContext db = SimulationPartContext.GetContext(DateTime.Now))
                     {
-                        db.TaskInfos.Add(addItem);
+                        var taskInfo = db.TaskInfos.Add(addItem);
                         await db.SaveChangesAsync();
+                        if (addItemTaskSimulations != null)
+                        {
+                            foreach (var task in addItemTaskSimulations)
+                            {
+                                db.TaskSimulations.Add(new TaskSimulation()
+                                {
+                                    TaskId = taskInfo.ID,
+                                    SimulationId = task.ID,
+                                });
+                            }
+                            await db.SaveChangesAsync();
+                        }
                     }
                     taskList.Insert(0, addItem);
                     gridView.RefreshData();
@@ -137,11 +151,20 @@ namespace DataSimulation.Forms.UserControl
                 try
                 {
                     var editItem = gridView.GetFocusedRow() as TaskInfo;
-                    TaskEditor frm = new TaskEditor(editItem);
+                    var taskSimu = TaskCache.GetTaskSimulationAsync(editItem.ID).Result;
+                    var taskSimuId = taskSimu.Select(s => s.SimulationId);
+                    List<SimulationInfo> taskSimuInfo = new List<SimulationInfo>();
+                    foreach (var id in taskSimuId)
+                    {
+                        var res= SimulationCache.GetAllAsync().Result.Find(w => id==w.ID);
+                        taskSimuInfo.Add(res);
+                    }
+                    TaskEditor frm = new TaskEditor(editItem, taskSimuInfo);
                     if (frm.ShowDialog() != DialogResult.OK) return;
                     editItem = frm.info;
+                    taskSimuInfo = frm.simulationInfo;
                     var taskListCache = await TaskCache.GetAllAsync();
-                    if (taskListCache.ToList().Any(p => p.TaskName == editItem.TaskName))
+                    if (taskListCache.ToList().Where(w=>w.ID!=editItem.ID).Any(p => p.TaskName == editItem.TaskName))
                     {
                         DxHelper.MsgBoxHelper.ShowWarning("任务名称重复");
                         return;
@@ -161,6 +184,18 @@ namespace DataSimulation.Forms.UserControl
                             find.Adja1Sat = editItem.Adja1Sat;
                             find.Adja2Sat = editItem.Adja2Sat;
                         }
+                        SimulationCache.RemoveTaskSimulationAsync(editItem.ID);
+                        if (taskSimuInfo != null)
+                        {
+                            foreach (var task in taskSimuInfo)
+                            {
+                                db.TaskSimulations.Add(new TaskSimulation()
+                                {
+                                    TaskId = editItem.ID,
+                                    SimulationId = task.ID,
+                                });
+                            }
+                        }
                         await db.SaveChangesAsync();
                     }
                     gridView.RefreshData();

+ 27 - 1
DataSimulation.Repostory/SimulationCache.cs

@@ -70,7 +70,33 @@ namespace DataSimulation.Repostory
                 return null;
             }
         }
-
+        public static async void RemoveTaskSimulationAsync(long taskId)
+        {
+            try
+            {
+                List<SimulationInfo> list = new List<SimulationInfo>();
+                var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart");
+                if (!Directory.Exists(dir))return;
+                var yearDirs = Directory.EnumerateDirectories(dir).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))
+                        {
+                          var res=  await db.TaskSimulations.Where(w => w.TaskId == taskId).ToListAsync();
+                          db.TaskSimulations.RemoveRange(res);
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                Serilog.Log.Error(ex, "加载仿真航迹信息异常");
+            }
+        }
 
     }
 }

+ 33 - 1
DataSimulation.Repostory/TaskCache.cs

@@ -45,6 +45,38 @@ namespace DataSimulation.Repostory
             }
         }
 
-
+        /// <summary>
+        /// 获取任务航迹
+        /// </summary>
+        /// <param name="taskId"></param>
+        /// <returns></returns>
+        public static async Task<List<TaskSimulation>> GetTaskSimulationAsync(long taskId)
+        {
+            try
+            {
+                List<TaskSimulation> list = new List<TaskSimulation>();
+                var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart");
+                if (!Directory.Exists(dir)) return list;
+                var yearDirs = Directory.EnumerateDirectories(dir).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))
+                        {
+                            list.AddRange(await db.TaskSimulations.Where(w=>w.TaskId==taskId).ToListAsync());
+                        }
+                    }
+                }
+                return list;
+            }
+            catch (Exception ex)
+            {
+                Serilog.Log.Error(ex, "加载任务航迹信息异常");
+                return null;
+            }
+        }
     }
 }