|
@@ -42,6 +42,7 @@ namespace XdCxRhDW.App.UserControl
|
|
|
TaskInfo tsk;
|
|
|
List<CancellationTokenSource> listCts = new List<CancellationTokenSource>();
|
|
|
Dictionary<int, CancellationTokenSource> dicCts = new Dictionary<int, CancellationTokenSource>();
|
|
|
+ List<ModelPosRes> cache = new List<ModelPosRes>();//定位点缓存,最多1000条记录
|
|
|
public CtrlHome()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -175,6 +176,80 @@ namespace XdCxRhDW.App.UserControl
|
|
|
btnIncludeInvalidate.CheckedChanged += BtnIncludeInvalidate_CheckedChanged;
|
|
|
txtTimeCho_SelectedIndexChanged(null, null);
|
|
|
WaitHelper.CloseForm();
|
|
|
+
|
|
|
+ await Task.Run(() =>
|
|
|
+ {
|
|
|
+ var refreshPosTime = AppConfigHelper.Get("RefreshPosTime", 5);
|
|
|
+ if (refreshPosTime < 1)
|
|
|
+ refreshPosTime = 5;
|
|
|
+ refreshPosTime = refreshPosTime * 1000;
|
|
|
+ while (!this.IsDisposed && !this.Disposing)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //表格处于筛选状态,不刷新数据
|
|
|
+ if (!string.IsNullOrWhiteSpace(gridView2.FindFilterText) || !string.IsNullOrWhiteSpace(gridView2.FilterPanelText))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ var currentTask = gridView1.GetFocusedRow() as TaskInfo;
|
|
|
+ IQueryable<ModelPosRes> refreshQuery = null;
|
|
|
+ List<ModelPosRes> updateItems = null;
|
|
|
+ long? currentFreq = null;
|
|
|
+ if (txtFrequpMHz.EditValue != null)
|
|
|
+ currentFreq = Convert.ToInt64(txtFrequpMHz.EditValue);
|
|
|
+ List<long> freqs = null;
|
|
|
+ lock (this)
|
|
|
+ {
|
|
|
+ refreshQuery = cache.AsQueryable();
|
|
|
+ refreshQuery = refreshQuery.Where(p => p.TaskInfoID == currentTask.ID);
|
|
|
+ freqs = refreshQuery.Select(p => p.FreqUpHz).Distinct().OrderBy(p => p).ToList();
|
|
|
+ if (currentFreq != null)
|
|
|
+ refreshQuery = refreshQuery.Where(p => p.FreqUpHz == currentFreq.Value);
|
|
|
+
|
|
|
+ if (!btnIncludeInvalidate.Checked)
|
|
|
+ {
|
|
|
+ refreshQuery = refreshQuery.Where(p => p.PosLon != 999);
|
|
|
+ }
|
|
|
+ updateItems = refreshQuery.Reverse().ToList();
|
|
|
+ cache.Clear();
|
|
|
+ }
|
|
|
+
|
|
|
+ var items = txtFrequpMHz.Properties.Items.Where(p => p.Value != null).Select(t => Convert.ToInt64(t.Value)).ToList();
|
|
|
+ foreach (var item in freqs)
|
|
|
+ {
|
|
|
+ if (!items.Contains(item))
|
|
|
+ {
|
|
|
+ this.Invoke(new Action(() =>
|
|
|
+ {
|
|
|
+ this.txtFrequpMHz.Properties.Items.Add(new ImageComboBoxItem((item / 1e6).ToString("f3"), item));
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (txtTimeCho.Text == "自定义") continue;
|
|
|
+ if (!updateItems.Any()) continue;
|
|
|
+ var hours = Convert.ToInt32(txtTimeCho.EditValue);
|
|
|
+ var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
|
|
|
+ ds.InsertRange(0, updateItems);
|
|
|
+ var max = ds.First().SigTime;
|
|
|
+ ds.RemoveAll(p => (max - p.SigTime).TotalHours > hours);
|
|
|
+ this.Invoke(new Action(() =>
|
|
|
+ {
|
|
|
+ mapControl1.DelPosItem<ModelPosRes>(p => (max - p.SigTime).TotalHours > hours);
|
|
|
+ mapControl1.AddPosItems(updateItems);
|
|
|
+ gridView2.RefreshData();
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _ = LogHelper.Error("刷新定位点出错", ex);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ Thread.Sleep(refreshPosTime);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void GridView2_ColumnFilterChanged(object sender, EventArgs e)
|
|
@@ -221,82 +296,15 @@ namespace XdCxRhDW.App.UserControl
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- bool canQuery = true;
|
|
|
- private DateTime lasetUpdateTime = DateTime.MinValue;
|
|
|
private void OnPosAdd(ModelPosRes posRes)
|
|
|
{
|
|
|
- try
|
|
|
- {
|
|
|
- //表格处于筛选状态,不刷新数据
|
|
|
- if (!string.IsNullOrWhiteSpace(gridView2.FindFilterText) || !string.IsNullOrWhiteSpace(gridView2.FilterPanelText))
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var currentTask = gridView1.GetFocusedRow() as TaskInfo;
|
|
|
- if (currentTask.ID == posRes.TaskInfoID)
|
|
|
- {
|
|
|
- lock (this)
|
|
|
- {
|
|
|
- var items = txtFrequpMHz.Properties.Items.Where(p => p.Value != null).Select(t => Convert.ToInt64(t.Value)).ToList();
|
|
|
- if (!items.Contains(posRes.FreqUpHz))
|
|
|
- {
|
|
|
- canQuery = false;
|
|
|
- items.Add(posRes.FreqUpHz);
|
|
|
- items.Sort();
|
|
|
- var selectdItem = this.txtFrequpMHz.SelectedItem;
|
|
|
- this.Invoke(new Action(() =>
|
|
|
- {
|
|
|
- this.txtFrequpMHz.Properties.Items.Clear();
|
|
|
- this.txtFrequpMHz.Properties.Items.Add(new ImageComboBoxItem("全部", null));
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- this.txtFrequpMHz.Properties.Items.Add(new ImageComboBoxItem((item / 1e6).ToString("f3"), item));
|
|
|
- }
|
|
|
- this.txtFrequpMHz.SelectedItem = selectdItem;
|
|
|
- }));
|
|
|
- canQuery = true;
|
|
|
- }
|
|
|
- }
|
|
|
- if (txtFrequpMHz.EditValue != null && posRes.FreqUpHz != Convert.ToInt64(txtFrequpMHz.EditValue))
|
|
|
- return;
|
|
|
- if (posRes.PosLon == 999 && !btnIncludeInvalidate.Checked)
|
|
|
- return;
|
|
|
- if (txtTimeCho.Text == "自定义")
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- var hours = Convert.ToInt32(txtTimeCho.EditValue);
|
|
|
- var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
|
|
|
- List<ModelPosRes> removeItems = null;
|
|
|
- lock (this)
|
|
|
- {
|
|
|
- ds.Insert(0, posRes);
|
|
|
- var max = ds.Max(p => p.SigTime);
|
|
|
- removeItems = ds.Where(p => (max - p.SigTime).TotalHours > hours).ToList();
|
|
|
- foreach (var item in removeItems)
|
|
|
- {
|
|
|
- ds.Remove(item);
|
|
|
- }
|
|
|
- }
|
|
|
- this.Invoke(new Action(() =>
|
|
|
- {
|
|
|
- mapControl1.DelPosItem(removeItems);
|
|
|
- mapControl1.AddPosItem(posRes);
|
|
|
- }));
|
|
|
- //if ((DateTime.Now - lasetUpdateTime).TotalSeconds > 5)
|
|
|
- {
|
|
|
- this.Invoke(new Action(() =>
|
|
|
- {
|
|
|
- gridView2.RefreshData();
|
|
|
- }));
|
|
|
- lasetUpdateTime = DateTime.Now;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
+ lock (this)
|
|
|
{
|
|
|
- _ = LogHelper.Error("定位完成后刷新UI出错", ex);
|
|
|
+ cache.Add(posRes);
|
|
|
+ if (cache.Count > 1000)
|
|
|
+ cache.RemoveAt(0);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
private async void GridView1_FocusedRowObjectChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowObjectChangedEventArgs e)
|
|
|
{
|
|
@@ -787,7 +795,6 @@ namespace XdCxRhDW.App.UserControl
|
|
|
|
|
|
private void txtFrequpMHz_SelectedIndexChanged(object sender, EventArgs e)
|
|
|
{
|
|
|
- if (!canQuery) return;
|
|
|
txtTimeCho_SelectedIndexChanged(null, null);
|
|
|
}
|
|
|
private async void txtTimeCho_SelectedIndexChanged(object sender, EventArgs e)
|