Browse Source

星历加速

gongqiuhong 9 months ago
parent
commit
2891d34c65

+ 3 - 0
XdCxRhDW.App/App.config

@@ -29,6 +29,9 @@
 		<!--是否启用平台设备状态收集功能 启用=1,禁用=0-->
 		<add key="UseGatherDevState" value="0"/>
 
+		<!--参估绘图外部程序的路径(可设置为绝对路径,也可设置为平台目录的相对路径)-->
+		<add key="CgDrawExe" value="Draw\Everything.exe"/>
+
 	</appSettings>
 	<startup>
 		<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />

+ 48 - 67
XdCxRhDW.App/Controllers/PosController.cs

@@ -163,7 +163,7 @@ namespace XdCxRhDW.App.Controllers
                     }
                 }
             }
-            var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+            var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
             if (xl1 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
@@ -375,17 +375,14 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
-
         }
 
         /// <summary>
@@ -420,14 +417,14 @@ namespace XdCxRhDW.App.Controllers
                         }
                     }
                 }
-                var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+                var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
                 if (xl1 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl2 = await XlRepository.GetLatest2Async(dto.AdjaCode, dto.SigTime);
+                var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
                 if (xl2 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
@@ -449,7 +446,7 @@ namespace XdCxRhDW.App.Controllers
                     return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
                 }
 
-                 //#warning 测试代码
+                //#warning 测试代码
                 //var tarEcef = PhysicsHelper.GeoToEcef((110, 17, 0));
                 //var ecefXl1 = (ephMain.data.X, ephMain.data.Y, ephMain.data.Z);
                 //var ecefXl2 = (ephAdja.data.X, ephAdja.data.Y, ephAdja.data.Z);
@@ -571,15 +568,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
 
@@ -692,15 +687,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
 
@@ -739,14 +732,14 @@ namespace XdCxRhDW.App.Controllers
                         }
                     }
                 }
-                var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+                var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
                 if (xl1 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl2 = await XlRepository.GetLatest2Async(dto.AdjaCode, dto.SigTime);
+                var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
                 if (xl2 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
@@ -781,15 +774,13 @@ namespace XdCxRhDW.App.Controllers
                 return Success(MapDto(posRes));
 
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
 
@@ -825,14 +816,14 @@ namespace XdCxRhDW.App.Controllers
                         }
                     }
                 }
-                var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+                var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
                 if (xl1 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl2 = await XlRepository.GetLatest2Async(dto.AdjaCode, dto.SigTime);
+                var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
                 if (xl2 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
@@ -955,15 +946,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
         #endregion
@@ -1115,14 +1104,14 @@ namespace XdCxRhDW.App.Controllers
                     }
                 }
             }
-            var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+            var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
             if (xl1 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                 return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
             }
             Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-            var xl2 = await XlRepository.GetLatest2Async(dto.AdjaCode, dto.SigTime);
+            var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
             if (xl2 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");
@@ -1356,15 +1345,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
 
@@ -1400,21 +1387,21 @@ namespace XdCxRhDW.App.Controllers
                         }
                     }
                 }
-                var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+                var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
                 if (xl1 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl2 = await XlRepository.GetLatest2Async(dto.Adja1Code, dto.SigTime);
+                var xl2 = await XlRepository.GetLatestAsync(dto.Adja1Code, dto.SigTime);
                 if (xl2 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.Adja1Code}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.Adja1Code}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.Adja1Code}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl3 = await XlRepository.GetLatest2Async(dto.Adja2Code, dto.SigTime);
+                var xl3 = await XlRepository.GetLatestAsync(dto.Adja2Code, dto.SigTime);
                 if (xl3 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.Adja2Code}卫星的星历!");
@@ -1532,15 +1519,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
 
@@ -1658,15 +1643,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
 
@@ -1702,21 +1685,21 @@ namespace XdCxRhDW.App.Controllers
                         }
                     }
                 }
-                var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+                var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
                 if (xl1 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl2 = await XlRepository.GetLatest2Async(dto.Adja1Code, dto.SigTime);
+                var xl2 = await XlRepository.GetLatestAsync(dto.Adja1Code, dto.SigTime);
                 if (xl2 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.Adja1Code}卫星的星历!");
                     return Error<PosResDto>($"系统缺少编号{dto.Adja1Code}卫星的星历!");
                 }
                 Serilog.Log.Information($"卫星{dto.Adja1Code}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-                var xl3 = await XlRepository.GetLatest2Async(dto.Adja2Code, dto.SigTime);
+                var xl3 = await XlRepository.GetLatestAsync(dto.Adja2Code, dto.SigTime);
                 if (xl3 == null)
                 {
                     Serilog.Log.Error($"系统缺少编号{dto.Adja2Code}卫星的星历!");
@@ -1829,15 +1812,13 @@ namespace XdCxRhDW.App.Controllers
                     return Success(MapDto(posRes));
                 }
             }
-            catch (DbUpdateException)
+            catch (Exception)
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime, true))
                 {
-                    if (!db.IsTableFieldSync())
-                        throw new Exception("表结构不一致,本次定位异常,已自动同步结构");
-                    else
-                        throw;
+                    db.SyncDb();
                 }
+                throw;
             }
         }
         #endregion
@@ -1994,21 +1975,21 @@ namespace XdCxRhDW.App.Controllers
                     }
                 }
             }
-            var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+            var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
             if (xl1 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                 return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
             }
             Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-            var xl2 = await XlRepository.GetLatest2Async(dto.Adja1Code, dto.SigTime);
+            var xl2 = await XlRepository.GetLatestAsync(dto.Adja1Code, dto.SigTime);
             if (xl2 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.Adja1Code}卫星的星历!");
                 return Error<PosResDto>($"系统缺少编号{dto.Adja1Code}卫星的星历!");
             }
             Serilog.Log.Information($"卫星{dto.Adja1Code}使用发布时刻为{xl2.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-            var xl3 = await XlRepository.GetLatest2Async(dto.Adja2Code, dto.SigTime);
+            var xl3 = await XlRepository.GetLatestAsync(dto.Adja2Code, dto.SigTime);
             if (xl3 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.Adja2Code}卫星的星历!");
@@ -2275,14 +2256,14 @@ namespace XdCxRhDW.App.Controllers
                     }
                 }
             }
-            var xl1 = await XlRepository.GetLatest2Async(dto.MainCode, dto.SigTime);
+            var xl1 = await XlRepository.GetLatestAsync(dto.MainCode, dto.SigTime);
             if (xl1 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.MainCode}卫星的星历!");
                 return Error<PosResDto>($"系统缺少编号{dto.MainCode}卫星的星历!");
             }
             Serilog.Log.Information($"卫星{dto.MainCode}使用发布时刻为{xl1.TimeUTC:yyyyMMddHHmmss}的星历进行推算");
-            var xl2 = await XlRepository.GetLatest2Async(dto.AdjaCode, dto.SigTime);
+            var xl2 = await XlRepository.GetLatestAsync(dto.AdjaCode, dto.SigTime);
             if (xl2 == null)
             {
                 Serilog.Log.Error($"系统缺少编号{dto.AdjaCode}卫星的星历!");

+ 26 - 14
XdCxRhDW.App/Controllers/ResultController.cs

@@ -236,25 +236,37 @@ namespace XdCxRhDW.App.Controllers
                     var dayFile = Path.Combine(dir, item);
                     using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
                     {
-                        if (db == null) continue;
-                        var query = db.PosRes.Where(p => p.SigTime >= start && p.SigTime <= end && p.TaskInfoID == dto.TaskInfoID);
-                        if (!dto.IncludeInvalidate)
-                            query = query.Where(p => p.PosLon != 999);
-                        if (dto.TarFrequpHz != null && dto.TarFrequpHz > 0)
-                            query = query.Where(p => p.FreqUpHz == dto.TarFrequpHz.Value);
-                        var posRes = await query.Include(p => p.CheckRes).OrderByDescending(p => p.SigTime).ToListAsync();
-
-                        foreach (var itemPos in posRes)
+                        for (int i = 0; i < 2; i++)
                         {
-                            if (itemPos.TargetInfoID > 0)
+                            try
                             {
-                                itemPos.TargetInfo = targets.FirstOrDefault(p => p.ID == itemPos.TargetInfoID);
-                                if (itemPos.TargetInfo != null && !string.IsNullOrWhiteSpace(itemPos.TargetInfo.TargeColor))
-                                    itemPos.ColorKey = itemPos.TargetInfo.TargeColor;
+                                if (db == null) continue;
+                                var query = db.PosRes.Where(p => p.SigTime >= start && p.SigTime <= end && p.TaskInfoID == dto.TaskInfoID);
+                                if (!dto.IncludeInvalidate)
+                                    query = query.Where(p => p.PosLon != 999);
+                                if (dto.TarFrequpHz != null && dto.TarFrequpHz > 0)
+                                    query = query.Where(p => p.FreqUpHz == dto.TarFrequpHz.Value);
+                                var posRes = await query.Include(p => p.CheckRes).OrderByDescending(p => p.SigTime).ToListAsync();
+
+                                foreach (var itemPos in posRes)
+                                {
+                                    if (itemPos.TargetInfoID > 0)
+                                    {
+                                        itemPos.TargetInfo = targets.FirstOrDefault(p => p.ID == itemPos.TargetInfoID);
+                                        if (itemPos.TargetInfo != null && !string.IsNullOrWhiteSpace(itemPos.TargetInfo.TargeColor))
+                                            itemPos.ColorKey = itemPos.TargetInfo.TargeColor;
 
+                                    }
+                                }
+                                posList.AddRange(posRes);
+                                break;
+                            }
+                            catch (Exception ex)
+                            {
+                                db.SyncDb();
                             }
                         }
-                        posList.AddRange(posRes);
+                        
                     }
                 }
                 return Success(posList);

+ 1 - 1
XdCxRhDW.App/EditForms/SatEditor.cs

@@ -38,7 +38,7 @@ namespace XdCxRhDW.App.EditForms
         }
         private async void SatEditor_Load(object sender, EventArgs e)
         {
-            var listXl = await XlRepository.GetAllAsync();
+            var listXl = await XlRepository.GetAllSat();
             this.searchLookUpEdit1.UseDefault().SetData(listXl,nameof(XlInfo.Sat)).UseDoubleClickToSelectAll();
             if (this.Text == "编辑卫星" && info != null)
             {

+ 44 - 29
XdCxRhDW.App/MainForm.cs

@@ -136,38 +136,44 @@ namespace XdCxRhDW
         }
         private void CheckDb()
         {
-            using (RHDWContext db = new RHDWContext())
+            try
             {
-                if (File.Exists(db.DbFile))
+                using (RHDWContext db = new RHDWContext())
                 {
-                    FileInfo fInfo = new FileInfo(db.DbFile);
-                    if (fInfo.IsReadOnly)
+                    if (File.Exists(db.DbFile))
                     {
-                        fInfo.IsReadOnly = false;
+                        FileInfo fInfo = new FileInfo(db.DbFile);
+                        if (fInfo.IsReadOnly)
+                        {
+                            fInfo.IsReadOnly = false;
+                        }
+
                     }
 
                 }
-
-            }
-            using (RHDWLogContext db = new RHDWLogContext())
-            {
-                if (File.Exists(db.DbFile))
+                using (RHDWLogContext db = new RHDWLogContext())
                 {
-                    FileInfo fInfo = new FileInfo(db.DbFile);
-                    if (fInfo.IsReadOnly)
+                    if (File.Exists(db.DbFile))
                     {
-                        fInfo.IsReadOnly = false;
+                        FileInfo fInfo = new FileInfo(db.DbFile);
+                        if (fInfo.IsReadOnly)
+                        {
+                            fInfo.IsReadOnly = false;
+                        }
                     }
                 }
+                using (RHDWContext db = new RHDWContext())
+                {
+                    db.SyncDb();
+                }
+                using (RHDWLogContext db = new RHDWLogContext())
+                {
+                    db.SyncDb();
+                }
             }
-
-            using (RHDWContext db = new RHDWContext())
-            {
-                db.SyncDb();
-            }
-            using (RHDWLogContext db = new RHDWLogContext())
+            catch (Exception ex)
             {
-                db.SyncDb();
+                LogHelper.Error("同步数据库结构异常",ex).Wait(5000);
             }
         }
         private void StartWebApi()
@@ -219,7 +225,8 @@ namespace XdCxRhDW
                         var res = await HttpHelper.PostRequestAsync<RecordRes>(SysConfig.GetUrl("Xl/ImportTleAsync"), dto);
                         if (res.code == 200)
                         {
-                            Serilog.Log.Information($"星历文件[{file}]自动导入成功!");
+
+                            LogHelper.Info($"星历文件[{file}]自动导入成功!").Wait(5000);
                             //导入完成的文件放在备份目录
                             var baseDirectory = Path.Combine(backUpDir, "TleBackUp");
                             Directory.CreateDirectory(baseDirectory);
@@ -230,12 +237,12 @@ namespace XdCxRhDW
                         }
                         else
                         {
-                            Serilog.Log.Information($"星历文件[{file}]自动导入失败.{res.msg}");
+                            LogHelper.Error($"星历文件[{file}]自动导入失败.{res.msg}").Wait(5000);
                         }
                     }
                     catch (Exception ex)
                     {
-                        Serilog.Log.Error(ex, $"星历文件[{file}]自动导入失败");
+                        LogHelper.Error($"星历文件[{file}]自动导入失败",ex).Wait(5000);
                     }
                 }
 
@@ -252,11 +259,16 @@ namespace XdCxRhDW
                     using (RHDWContext db = new RHDWContext())
                     {
                         DateTime dt = DateTime.Now.AddDays(-180);
-                        var clearData = await db.XlInfos.Where(p => p.UpdateTime < dt).ToListAsync();
+                        var clearData = await db.XlInfos.Where(p => p.UpdateTime < dt).Take(1000).ToListAsync();
                         if (clearData.Any())
                         {
-                            db.XlInfos.RemoveRange(clearData);
+                            //db.XlInfos.RemoveRange(clearData);
                             await db.SaveChangesAsync();
+                            await Task.Delay(2000);
+                        }
+                        else
+                        {
+                            await Task.Delay(60 * 1000);
                         }
                     }
                 }
@@ -264,7 +276,7 @@ namespace XdCxRhDW
                 {
                     await LogHelper.Error("清理过期星历异常", ex);
                 }
-                await Task.Delay(3600 * 1000);
+
             }
         }
 
@@ -277,7 +289,7 @@ namespace XdCxRhDW
                 {
                     using (RHDWContext db = new RHDWContext())
                     {
-                        var calcItems = await db.XlInfos.Where(p => p.Lon == null).OrderByDescending(p => p.SatCode).ToListAsync();
+                        var calcItems = await db.XlInfos.Where(p => p.Lon == null).OrderByDescending(p => p.SatCode).Take(1000).ToListAsync();
                         if (calcItems.Any())
                         {
                             var satInfo = await db.SatInfos.ToListAsync();
@@ -321,13 +333,16 @@ namespace XdCxRhDW
                             });
 
                         }
+                        else
+                        {
+                            await Task.Delay(60 * 1000);
+                        }
                     }
                 }
                 catch (Exception ex)
                 {
                     LogHelper.Error($"推算XYZ星历出错!", ex).Wait(5000);
                 }
-                await Task.Delay(60 * 1000);
             }
         }
 
@@ -380,7 +395,7 @@ namespace XdCxRhDW
                 }
                 catch (Exception ex)
                 {
-                    Serilog.Log.Error(ex, "清理日志信息异常!");
+                    await LogHelper.Error("清理日志信息异常", ex);
                 }
             }
             await Task.Delay(3600 * 1000);

+ 55 - 23
XdCxRhDW.App/UserControl/CtrlCgRes.Designer.cs

@@ -45,6 +45,8 @@ namespace XdCxRhDW.App.UserControl
             this.itemEnd = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem6 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem();
+            this.btnDraw = new DevExpress.XtraEditors.SimpleButton();
+            this.layoutControlItem4 = new DevExpress.XtraLayout.LayoutControlItem();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).BeginInit();
             this.layoutControl1.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.gridCg)).BeginInit();
@@ -63,6 +65,7 @@ namespace XdCxRhDW.App.UserControl
             ((System.ComponentModel.ISupportInitialize)(this.itemEnd)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).BeginInit();
             this.SuspendLayout();
             // 
             // layoutControl1
@@ -73,6 +76,7 @@ namespace XdCxRhDW.App.UserControl
             this.layoutControl1.Controls.Add(this.txtEndTime);
             this.layoutControl1.Controls.Add(this.btnSearch);
             this.layoutControl1.Controls.Add(this.txtTask);
+            this.layoutControl1.Controls.Add(this.btnDraw);
             this.layoutControl1.Dock = System.Windows.Forms.DockStyle.Fill;
             this.layoutControl1.Location = new System.Drawing.Point(0, 0);
             this.layoutControl1.Name = "layoutControl1";
@@ -83,10 +87,10 @@ namespace XdCxRhDW.App.UserControl
             // 
             // gridCg
             // 
-            this.gridCg.Location = new System.Drawing.Point(2, 30);
+            this.gridCg.Location = new System.Drawing.Point(2, 26);
             this.gridCg.MainView = this.gridView1;
             this.gridCg.Name = "gridCg";
-            this.gridCg.Size = new System.Drawing.Size(1196, 433);
+            this.gridCg.Size = new System.Drawing.Size(1196, 437);
             this.gridCg.TabIndex = 4;
             this.gridCg.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
             this.gridView1});
@@ -143,9 +147,9 @@ namespace XdCxRhDW.App.UserControl
             // 
             // btnSearch
             // 
-            this.btnSearch.Location = new System.Drawing.Point(964, 4);
+            this.btnSearch.Location = new System.Drawing.Point(962, 2);
             this.btnSearch.Name = "btnSearch";
-            this.btnSearch.Size = new System.Drawing.Size(84, 21);
+            this.btnSearch.Size = new System.Drawing.Size(86, 20);
             this.btnSearch.StyleController = this.layoutControl1;
             this.btnSearch.TabIndex = 9;
             this.btnSearch.Text = "查询";
@@ -182,7 +186,8 @@ namespace XdCxRhDW.App.UserControl
             this.itemStart,
             this.itemEnd,
             this.layoutControlItem6,
-            this.layoutControlItem1});
+            this.layoutControlItem1,
+            this.layoutControlItem4});
             this.layoutControlGroup1.Name = "Root";
             this.layoutControlGroup1.Padding = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
             this.layoutControlGroup1.Size = new System.Drawing.Size(1200, 465);
@@ -191,9 +196,9 @@ namespace XdCxRhDW.App.UserControl
             // layoutControlItem2
             // 
             this.layoutControlItem2.Control = this.gridCg;
-            this.layoutControlItem2.Location = new System.Drawing.Point(0, 28);
+            this.layoutControlItem2.Location = new System.Drawing.Point(0, 24);
             this.layoutControlItem2.Name = "layoutControlItem2";
-            this.layoutControlItem2.Size = new System.Drawing.Size(1200, 437);
+            this.layoutControlItem2.Size = new System.Drawing.Size(1200, 441);
             this.layoutControlItem2.TextSize = new System.Drawing.Size(0, 0);
             this.layoutControlItem2.TextVisible = false;
             // 
@@ -203,11 +208,11 @@ namespace XdCxRhDW.App.UserControl
             this.layoutControlItem3.ControlAlignment = System.Drawing.ContentAlignment.TopLeft;
             this.layoutControlItem3.CustomizationFormText = "时间选择";
             this.layoutControlItem3.Location = new System.Drawing.Point(250, 0);
-            this.layoutControlItem3.MaxSize = new System.Drawing.Size(170, 28);
-            this.layoutControlItem3.MinSize = new System.Drawing.Size(170, 28);
+            this.layoutControlItem3.MaxSize = new System.Drawing.Size(170, 24);
+            this.layoutControlItem3.MinSize = new System.Drawing.Size(170, 24);
             this.layoutControlItem3.Name = "layoutControlItem3";
             this.layoutControlItem3.Padding = new DevExpress.XtraLayout.Utils.Padding(12, 2, 2, 2);
-            this.layoutControlItem3.Size = new System.Drawing.Size(170, 28);
+            this.layoutControlItem3.Size = new System.Drawing.Size(170, 24);
             this.layoutControlItem3.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.layoutControlItem3.Spacing = new DevExpress.XtraLayout.Utils.Padding(4, 0, 2, 0);
             this.layoutControlItem3.Text = "时间选择";
@@ -221,11 +226,11 @@ namespace XdCxRhDW.App.UserControl
             this.itemStart.ControlAlignment = System.Drawing.ContentAlignment.TopLeft;
             this.itemStart.CustomizationFormText = "开始时间";
             this.itemStart.Location = new System.Drawing.Point(420, 0);
-            this.itemStart.MaxSize = new System.Drawing.Size(270, 28);
-            this.itemStart.MinSize = new System.Drawing.Size(270, 28);
+            this.itemStart.MaxSize = new System.Drawing.Size(270, 24);
+            this.itemStart.MinSize = new System.Drawing.Size(270, 24);
             this.itemStart.Name = "itemStart";
             this.itemStart.Padding = new DevExpress.XtraLayout.Utils.Padding(12, 2, 2, 2);
-            this.itemStart.Size = new System.Drawing.Size(270, 28);
+            this.itemStart.Size = new System.Drawing.Size(270, 24);
             this.itemStart.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.itemStart.Spacing = new DevExpress.XtraLayout.Utils.Padding(4, 0, 2, 0);
             this.itemStart.Text = "开始时间";
@@ -240,11 +245,11 @@ namespace XdCxRhDW.App.UserControl
             this.itemEnd.ControlAlignment = System.Drawing.ContentAlignment.TopLeft;
             this.itemEnd.CustomizationFormText = "结束时间";
             this.itemEnd.Location = new System.Drawing.Point(690, 0);
-            this.itemEnd.MaxSize = new System.Drawing.Size(270, 28);
-            this.itemEnd.MinSize = new System.Drawing.Size(270, 28);
+            this.itemEnd.MaxSize = new System.Drawing.Size(270, 24);
+            this.itemEnd.MinSize = new System.Drawing.Size(270, 24);
             this.itemEnd.Name = "itemEnd";
             this.itemEnd.Padding = new DevExpress.XtraLayout.Utils.Padding(12, 2, 2, 2);
-            this.itemEnd.Size = new System.Drawing.Size(270, 28);
+            this.itemEnd.Size = new System.Drawing.Size(270, 24);
             this.itemEnd.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.itemEnd.Spacing = new DevExpress.XtraLayout.Utils.Padding(4, 0, 2, 0);
             this.itemEnd.Text = "结束时间";
@@ -259,11 +264,10 @@ namespace XdCxRhDW.App.UserControl
             this.layoutControlItem6.ControlAlignment = System.Drawing.ContentAlignment.TopLeft;
             this.layoutControlItem6.CustomizationFormText = "layoutControlItemSearch";
             this.layoutControlItem6.Location = new System.Drawing.Point(960, 0);
-            this.layoutControlItem6.MaxSize = new System.Drawing.Size(90, 26);
-            this.layoutControlItem6.MinSize = new System.Drawing.Size(90, 26);
+            this.layoutControlItem6.MaxSize = new System.Drawing.Size(90, 24);
+            this.layoutControlItem6.MinSize = new System.Drawing.Size(90, 24);
             this.layoutControlItem6.Name = "layoutControlItem6";
-            this.layoutControlItem6.Padding = new DevExpress.XtraLayout.Utils.Padding(4, 2, 4, 1);
-            this.layoutControlItem6.Size = new System.Drawing.Size(240, 28);
+            this.layoutControlItem6.Size = new System.Drawing.Size(90, 24);
             this.layoutControlItem6.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.layoutControlItem6.Text = "layoutControlItemSearch";
             this.layoutControlItem6.TextSize = new System.Drawing.Size(0, 0);
@@ -275,10 +279,10 @@ namespace XdCxRhDW.App.UserControl
             this.layoutControlItem1.ControlAlignment = System.Drawing.ContentAlignment.TopLeft;
             this.layoutControlItem1.CustomizationFormText = "时间选择";
             this.layoutControlItem1.Location = new System.Drawing.Point(0, 0);
-            this.layoutControlItem1.MaxSize = new System.Drawing.Size(250, 0);
-            this.layoutControlItem1.MinSize = new System.Drawing.Size(250, 28);
+            this.layoutControlItem1.MaxSize = new System.Drawing.Size(250, 24);
+            this.layoutControlItem1.MinSize = new System.Drawing.Size(250, 24);
             this.layoutControlItem1.Name = "layoutControlItem1";
-            this.layoutControlItem1.Size = new System.Drawing.Size(250, 28);
+            this.layoutControlItem1.Size = new System.Drawing.Size(250, 24);
             this.layoutControlItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.layoutControlItem1.Spacing = new DevExpress.XtraLayout.Utils.Padding(4, 0, 2, 0);
             this.layoutControlItem1.Text = "任务";
@@ -286,6 +290,31 @@ namespace XdCxRhDW.App.UserControl
             this.layoutControlItem1.TextSize = new System.Drawing.Size(24, 14);
             this.layoutControlItem1.TextToControlDistance = 5;
             // 
+            // btnDraw
+            // 
+            this.btnDraw.Location = new System.Drawing.Point(1052, 2);
+            this.btnDraw.Name = "btnDraw";
+            this.btnDraw.Size = new System.Drawing.Size(86, 20);
+            this.btnDraw.StyleController = this.layoutControl1;
+            this.btnDraw.TabIndex = 9;
+            this.btnDraw.Text = "绘图";
+            this.btnDraw.Click += new System.EventHandler(this.btnDraw_Click);
+            // 
+            // layoutControlItem4
+            // 
+            this.layoutControlItem4.Control = this.btnDraw;
+            this.layoutControlItem4.ControlAlignment = System.Drawing.ContentAlignment.TopLeft;
+            this.layoutControlItem4.CustomizationFormText = "layoutControlItemSearch";
+            this.layoutControlItem4.Location = new System.Drawing.Point(1050, 0);
+            this.layoutControlItem4.MaxSize = new System.Drawing.Size(90, 24);
+            this.layoutControlItem4.MinSize = new System.Drawing.Size(90, 24);
+            this.layoutControlItem4.Name = "layoutControlItem4";
+            this.layoutControlItem4.Size = new System.Drawing.Size(150, 24);
+            this.layoutControlItem4.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
+            this.layoutControlItem4.Text = "layoutControlItemSearch";
+            this.layoutControlItem4.TextSize = new System.Drawing.Size(0, 0);
+            this.layoutControlItem4.TextVisible = false;
+            // 
             // CtrlCgRes
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
@@ -312,6 +341,7 @@ namespace XdCxRhDW.App.UserControl
             ((System.ComponentModel.ISupportInitialize)(this.itemEnd)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).EndInit();
             this.ResumeLayout(false);
 
         }
@@ -333,5 +363,7 @@ namespace XdCxRhDW.App.UserControl
         private DevExpress.XtraLayout.LayoutControlItem layoutControlItem1;
         private DevExpress.XtraEditors.SearchLookUpEdit txtTask;
         private DevExpress.XtraGrid.Views.Grid.GridView searchLookUpEdit1View;
+        private DevExpress.XtraEditors.SimpleButton btnDraw;
+        private DevExpress.XtraLayout.LayoutControlItem layoutControlItem4;
     }
 }

+ 47 - 4
XdCxRhDW.App/UserControl/CtrlCgRes.cs

@@ -22,6 +22,7 @@ using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Forms;
 using XdCxRhDW.Entity;
+using XdCxRhDW.Framework;
 using XdCxRhDW.Repostory;
 
 namespace XdCxRhDW.App.UserControl
@@ -143,6 +144,7 @@ namespace XdCxRhDW.App.UserControl
         {
             try
             {
+
                 DateTime start = DateTime.MinValue;
                 DateTime end = DateTime.MinValue;
                 if (txtTimeCho.Text == "自定义")
@@ -190,23 +192,64 @@ namespace XdCxRhDW.App.UserControl
                     {
                         if (db != null)
                         {
-                            var cgRes = await db.CgRes.Where(w => w.SigTime >= start && w.SigTime <= end && w.TaskID == ((TaskInfo)txtTask.EditValue).ID).OrderByDescending(o => o.SigTime).ToListAsync();
-                            list.AddRange(cgRes);
+                            for (int i = 0; i < 2; i++)
+                            {
+                                try
+                                {
+                                    var cgRes = await db.CgRes.Where(w => w.SigTime >= start && w.SigTime <= end && w.TaskID == ((TaskInfo)txtTask.EditValue).ID).OrderByDescending(o => o.SigTime).ToListAsync();
+                                    list.AddRange(cgRes);
+                                    break;
+                                }
+                                catch (Exception ex)
+                                {
+                                    db.SyncDb();
+                                }
+                            }
+
                         }
                     }
                     endDay = endDay.AddDays(-1);
                 }
                 return list;
-
             }
-            catch (TaskCanceledException) { }//屏蔽掉取消查询的异常
+            catch (TaskCanceledException) { }
             catch (Exception ex)
             {
+
                 Serilog.Log.Error(ex, "参估结果查询异常");
                 MsgBoxHelper.ShowError("参估结果查询异常");
             }
             return new List<CgRes>();
         }
 
+        private void btnDraw_Click(object sender, EventArgs e)
+        {
+            try
+            {
+                var exeFile = AppConfigHelper.Get("CgDrawExe");
+                if (string.IsNullOrWhiteSpace(exeFile))
+                {
+                    MsgBoxHelper.ShowError("请在平台配置文件中设置绘图程序路径CgDrawExe");
+                    return;
+                }
+                if (!File.Exists(exeFile))
+                {
+                    MsgBoxHelper.ShowError($"找不到绘图程序[{exeFile}]");
+                    return;
+                }
+                FileInfo f = new FileInfo(exeFile);
+                var dir = Path.GetDirectoryName(f.FullName);
+                var file = list.ToCsvFile($"{dir}\\CgDraw{DateTime.Now:yyyyMMddHHmmss}.csv");
+                Process.Start(new ProcessStartInfo()
+                {
+                    FileName = f.FullName,
+                    Arguments = file,
+                });
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Error("参估绘图异常", ex).Wait(5000);
+            }
+        }
     }
 }

+ 1 - 1
XdCxRhDW.App/UserControl/CtrlSat.cs

@@ -34,7 +34,7 @@ namespace XdCxRhDW.App.UserControl
             }
             catch (Exception ex)
             {
-                Serilog.Log.Error(ex, "查询卫星信息异常");
+                await LogHelper.Error("查询卫星信息异常", ex);
                 DxHelper.MsgBoxHelper.ShowError("查询卫星信息异常");
             }
         }

+ 70 - 53
XdCxRhDW.App/UserControl/CtrlXl.Designer.cs

@@ -30,10 +30,11 @@
         {
             System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(CtrlXl));
             this.layoutControl1 = new DevExpress.XtraLayout.LayoutControl();
+            this.txtSat = new DevExpress.XtraEditors.SearchLookUpEdit();
+            this.searchLookUpEdit1View = new DevExpress.XtraGrid.Views.Grid.GridView();
             this.btnGo = new DevExpress.XtraEditors.SimpleButton();
             this.txtGoPage = new DevExpress.XtraEditors.TextEdit();
             this.dataNavigator1 = new DevExpress.XtraEditors.DataNavigator();
-            this.ucCtrlPage = new XdCxRhDW.App.UserControl.UcCtrlPage();
             this.btnImp = new DevExpress.XtraEditors.SimpleButton();
             this.gridXl = new DevExpress.XtraGrid.GridControl();
             this.gridView1 = new DevExpress.XtraGrid.Views.Grid.GridView();
@@ -43,7 +44,6 @@
             this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem2 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem3 = new DevExpress.XtraLayout.LayoutControlItem();
-            this.layoutControlItem4 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem5 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem6 = new DevExpress.XtraLayout.LayoutControlItem();
             this.layoutControlItem7 = new DevExpress.XtraLayout.LayoutControlItem();
@@ -51,8 +51,11 @@
             this.simpleLabelItem2 = new DevExpress.XtraLayout.SimpleLabelItem();
             this.layoutControlItem8 = new DevExpress.XtraLayout.LayoutControlItem();
             this.emptySpaceItem1 = new DevExpress.XtraLayout.EmptySpaceItem();
+            this.layoutControlItem4 = new DevExpress.XtraLayout.LayoutControlItem();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).BeginInit();
             this.layoutControl1.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.txtSat.Properties)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.searchLookUpEdit1View)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.txtGoPage.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.gridXl)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.gridView1)).BeginInit();
@@ -62,7 +65,6 @@
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem7)).BeginInit();
@@ -70,14 +72,15 @@
             ((System.ComponentModel.ISupportInitialize)(this.simpleLabelItem2)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem8)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).BeginInit();
             this.SuspendLayout();
             // 
             // layoutControl1
             // 
+            this.layoutControl1.Controls.Add(this.txtSat);
             this.layoutControl1.Controls.Add(this.btnGo);
             this.layoutControl1.Controls.Add(this.txtGoPage);
             this.layoutControl1.Controls.Add(this.dataNavigator1);
-            this.layoutControl1.Controls.Add(this.ucCtrlPage);
             this.layoutControl1.Controls.Add(this.btnImp);
             this.layoutControl1.Controls.Add(this.gridXl);
             this.layoutControl1.Controls.Add(this.btnOpen);
@@ -91,20 +94,40 @@
             this.layoutControl1.TabIndex = 0;
             this.layoutControl1.Text = "layoutControl1";
             // 
+            // txtSat
+            // 
+            this.txtSat.Location = new System.Drawing.Point(69, 40);
+            this.txtSat.Name = "txtSat";
+            this.txtSat.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
+            new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
+            this.txtSat.Properties.PopupView = this.searchLookUpEdit1View;
+            this.txtSat.Size = new System.Drawing.Size(566, 20);
+            this.txtSat.StyleController = this.layoutControl1;
+            this.txtSat.TabIndex = 12;
+            this.txtSat.EditValueChanged += new System.EventHandler(this.TxtSat_EditValueChanged);
+            // 
+            // searchLookUpEdit1View
+            // 
+            this.searchLookUpEdit1View.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus;
+            this.searchLookUpEdit1View.Name = "searchLookUpEdit1View";
+            this.searchLookUpEdit1View.OptionsSelection.EnableAppearanceFocusedCell = false;
+            this.searchLookUpEdit1View.OptionsView.ShowGroupPanel = false;
+            // 
             // btnGo
             // 
-            this.btnGo.ImageOptions.SvgImage = ((DevExpress.Utils.Svg.SvgImage)(resources.GetObject("simpleButton1.ImageOptions.SvgImage")));
+            this.btnGo.ImageOptions.SvgImage = ((DevExpress.Utils.Svg.SvgImage)(resources.GetObject("btnGo.ImageOptions.SvgImage")));
             this.btnGo.ImageOptions.SvgImageSize = new System.Drawing.Size(16, 16);
-            this.btnGo.Location = new System.Drawing.Point(615, 403);
+            this.btnGo.Location = new System.Drawing.Point(615, 440);
             this.btnGo.Name = "btnGo";
             this.btnGo.Size = new System.Drawing.Size(20, 20);
             this.btnGo.StyleController = this.layoutControl1;
             this.btnGo.TabIndex = 11;
             this.btnGo.ToolTip = "跳转";
+            this.btnGo.Click += new System.EventHandler(this.btnGo_Click);
             // 
             // txtGoPage
             // 
-            this.txtGoPage.Location = new System.Drawing.Point(535, 403);
+            this.txtGoPage.Location = new System.Drawing.Point(535, 440);
             this.txtGoPage.Name = "txtGoPage";
             this.txtGoPage.Properties.AutoHeight = false;
             this.txtGoPage.Size = new System.Drawing.Size(76, 20);
@@ -119,7 +142,7 @@
             this.dataNavigator1.Buttons.Next.Visible = false;
             this.dataNavigator1.Buttons.Prev.Visible = false;
             this.dataNavigator1.Buttons.Remove.Visible = false;
-            this.dataNavigator1.Location = new System.Drawing.Point(160, 403);
+            this.dataNavigator1.Location = new System.Drawing.Point(160, 440);
             this.dataNavigator1.Name = "dataNavigator1";
             this.dataNavigator1.Size = new System.Drawing.Size(152, 21);
             this.dataNavigator1.StyleController = this.layoutControl1;
@@ -129,17 +152,6 @@
             this.dataNavigator1.TextStringFormat = "第{0}页/共{1}页";
             this.dataNavigator1.ButtonClick += new DevExpress.XtraEditors.NavigatorButtonClickEventHandler(this.dataNavigator1_ButtonClick);
             // 
-            // ucCtrlPage
-            // 
-            this.ucCtrlPage.CurrentPage = 0;
-            this.ucCtrlPage.Location = new System.Drawing.Point(12, 428);
-            this.ucCtrlPage.Margin = new System.Windows.Forms.Padding(4);
-            this.ucCtrlPage.Name = "ucCtrlPage";
-            this.ucCtrlPage.PageSize = 0;
-            this.ucCtrlPage.Size = new System.Drawing.Size(623, 33);
-            this.ucCtrlPage.TabIndex = 7;
-            this.ucCtrlPage.TotalPages = 0;
-            // 
             // btnImp
             // 
             this.btnImp.ImageOptions.SvgImage = ((DevExpress.Utils.Svg.SvgImage)(resources.GetObject("btnImp.ImageOptions.SvgImage")));
@@ -162,10 +174,10 @@
             this.gridXl.EmbeddedNavigator.Buttons.Remove.Visible = false;
             this.gridXl.EmbeddedNavigator.TextLocation = DevExpress.XtraEditors.NavigatorButtonsTextLocation.Begin;
             this.gridXl.EmbeddedNavigator.TextStringFormat = "第{0}页/共{1}页";
-            this.gridXl.Location = new System.Drawing.Point(10, 38);
+            this.gridXl.Location = new System.Drawing.Point(10, 62);
             this.gridXl.MainView = this.gridView1;
             this.gridXl.Name = "gridXl";
-            this.gridXl.Size = new System.Drawing.Size(627, 363);
+            this.gridXl.Size = new System.Drawing.Size(627, 376);
             this.gridXl.TabIndex = 5;
             this.gridXl.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
             this.gridView1});
@@ -177,19 +189,19 @@
             // 
             // btnOpen
             // 
-            this.btnOpen.Location = new System.Drawing.Point(76, 12);
+            this.btnOpen.Location = new System.Drawing.Point(69, 12);
             this.btnOpen.Name = "btnOpen";
             this.btnOpen.Properties.AutoHeight = false;
             this.btnOpen.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
             new DevExpress.XtraEditors.Controls.EditorButton()});
-            this.btnOpen.Size = new System.Drawing.Size(459, 24);
+            this.btnOpen.Size = new System.Drawing.Size(466, 24);
             this.btnOpen.StyleController = this.layoutControl1;
             this.btnOpen.TabIndex = 4;
             // 
             // txtCountPerPage
             // 
             this.txtCountPerPage.EditValue = "5000";
-            this.txtCountPerPage.Location = new System.Drawing.Point(42, 403);
+            this.txtCountPerPage.Location = new System.Drawing.Point(42, 440);
             this.txtCountPerPage.Name = "txtCountPerPage";
             this.txtCountPerPage.Properties.AutoHeight = false;
             this.txtCountPerPage.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
@@ -204,6 +216,7 @@
             this.txtCountPerPage.Size = new System.Drawing.Size(76, 21);
             this.txtCountPerPage.StyleController = this.layoutControl1;
             this.txtCountPerPage.TabIndex = 10;
+            this.txtCountPerPage.EditValueChanged += new System.EventHandler(this.txtCountPerPage_EditValueChanged);
             // 
             // Root
             // 
@@ -213,14 +226,14 @@
             this.layoutControlItem1,
             this.layoutControlItem2,
             this.layoutControlItem3,
-            this.layoutControlItem4,
             this.layoutControlItem5,
             this.layoutControlItem6,
             this.layoutControlItem7,
             this.simpleLabelItem1,
             this.simpleLabelItem2,
             this.layoutControlItem8,
-            this.emptySpaceItem1});
+            this.emptySpaceItem1,
+            this.layoutControlItem4});
             this.Root.Name = "Root";
             this.Root.Size = new System.Drawing.Size(647, 473);
             this.Root.TextVisible = false;
@@ -234,16 +247,18 @@
             this.layoutControlItem1.Name = "layoutControlItem1";
             this.layoutControlItem1.Size = new System.Drawing.Size(527, 28);
             this.layoutControlItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
-            this.layoutControlItem1.Text = "星历文件:";
+            this.layoutControlItem1.Text = "星历文件";
+            this.layoutControlItem1.TextAlignMode = DevExpress.XtraLayout.TextAlignModeItem.CustomSize;
             this.layoutControlItem1.TextSize = new System.Drawing.Size(52, 14);
+            this.layoutControlItem1.TextToControlDistance = 5;
             // 
             // layoutControlItem2
             // 
             this.layoutControlItem2.Control = this.gridXl;
-            this.layoutControlItem2.Location = new System.Drawing.Point(0, 28);
+            this.layoutControlItem2.Location = new System.Drawing.Point(0, 52);
             this.layoutControlItem2.Name = "layoutControlItem2";
             this.layoutControlItem2.Padding = new DevExpress.XtraLayout.Utils.Padding(0, 0, 0, 0);
-            this.layoutControlItem2.Size = new System.Drawing.Size(627, 363);
+            this.layoutControlItem2.Size = new System.Drawing.Size(627, 376);
             this.layoutControlItem2.TextSize = new System.Drawing.Size(0, 0);
             this.layoutControlItem2.TextVisible = false;
             // 
@@ -259,22 +274,10 @@
             this.layoutControlItem3.TextSize = new System.Drawing.Size(0, 0);
             this.layoutControlItem3.TextVisible = false;
             // 
-            // layoutControlItem4
-            // 
-            this.layoutControlItem4.Control = this.ucCtrlPage;
-            this.layoutControlItem4.Location = new System.Drawing.Point(0, 416);
-            this.layoutControlItem4.MaxSize = new System.Drawing.Size(0, 37);
-            this.layoutControlItem4.MinSize = new System.Drawing.Size(5, 37);
-            this.layoutControlItem4.Name = "layoutControlItem4";
-            this.layoutControlItem4.Size = new System.Drawing.Size(627, 37);
-            this.layoutControlItem4.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
-            this.layoutControlItem4.TextSize = new System.Drawing.Size(0, 0);
-            this.layoutControlItem4.TextVisible = false;
-            // 
             // layoutControlItem5
             // 
             this.layoutControlItem5.Control = this.dataNavigator1;
-            this.layoutControlItem5.Location = new System.Drawing.Point(148, 391);
+            this.layoutControlItem5.Location = new System.Drawing.Point(148, 428);
             this.layoutControlItem5.MaxSize = new System.Drawing.Size(156, 25);
             this.layoutControlItem5.MinSize = new System.Drawing.Size(156, 25);
             this.layoutControlItem5.Name = "layoutControlItem5";
@@ -286,7 +289,7 @@
             // layoutControlItem6
             // 
             this.layoutControlItem6.Control = this.txtGoPage;
-            this.layoutControlItem6.Location = new System.Drawing.Point(523, 391);
+            this.layoutControlItem6.Location = new System.Drawing.Point(523, 428);
             this.layoutControlItem6.MaxSize = new System.Drawing.Size(80, 24);
             this.layoutControlItem6.MinSize = new System.Drawing.Size(80, 24);
             this.layoutControlItem6.Name = "layoutControlItem6";
@@ -298,7 +301,7 @@
             // layoutControlItem7
             // 
             this.layoutControlItem7.Control = this.txtCountPerPage;
-            this.layoutControlItem7.Location = new System.Drawing.Point(30, 391);
+            this.layoutControlItem7.Location = new System.Drawing.Point(30, 428);
             this.layoutControlItem7.MaxSize = new System.Drawing.Size(80, 25);
             this.layoutControlItem7.MinSize = new System.Drawing.Size(80, 25);
             this.layoutControlItem7.Name = "layoutControlItem7";
@@ -310,19 +313,19 @@
             // simpleLabelItem1
             // 
             this.simpleLabelItem1.AllowHotTrack = false;
-            this.simpleLabelItem1.Location = new System.Drawing.Point(0, 391);
+            this.simpleLabelItem1.Location = new System.Drawing.Point(0, 428);
             this.simpleLabelItem1.MaxSize = new System.Drawing.Size(30, 25);
             this.simpleLabelItem1.MinSize = new System.Drawing.Size(30, 25);
             this.simpleLabelItem1.Name = "simpleLabelItem1";
             this.simpleLabelItem1.Size = new System.Drawing.Size(30, 25);
             this.simpleLabelItem1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.simpleLabelItem1.Text = "每页";
-            this.simpleLabelItem1.TextSize = new System.Drawing.Size(52, 14);
+            this.simpleLabelItem1.TextSize = new System.Drawing.Size(24, 14);
             // 
             // simpleLabelItem2
             // 
             this.simpleLabelItem2.AllowHotTrack = false;
-            this.simpleLabelItem2.Location = new System.Drawing.Point(110, 391);
+            this.simpleLabelItem2.Location = new System.Drawing.Point(110, 428);
             this.simpleLabelItem2.MaxSize = new System.Drawing.Size(38, 25);
             this.simpleLabelItem2.MinSize = new System.Drawing.Size(38, 25);
             this.simpleLabelItem2.Name = "simpleLabelItem2";
@@ -330,12 +333,12 @@
             this.simpleLabelItem2.Size = new System.Drawing.Size(38, 25);
             this.simpleLabelItem2.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom;
             this.simpleLabelItem2.Text = "条";
-            this.simpleLabelItem2.TextSize = new System.Drawing.Size(52, 14);
+            this.simpleLabelItem2.TextSize = new System.Drawing.Size(24, 14);
             // 
             // layoutControlItem8
             // 
             this.layoutControlItem8.Control = this.btnGo;
-            this.layoutControlItem8.Location = new System.Drawing.Point(603, 391);
+            this.layoutControlItem8.Location = new System.Drawing.Point(603, 428);
             this.layoutControlItem8.MaxSize = new System.Drawing.Size(24, 24);
             this.layoutControlItem8.MinSize = new System.Drawing.Size(24, 24);
             this.layoutControlItem8.Name = "layoutControlItem8";
@@ -347,11 +350,22 @@
             // emptySpaceItem1
             // 
             this.emptySpaceItem1.AllowHotTrack = false;
-            this.emptySpaceItem1.Location = new System.Drawing.Point(304, 391);
+            this.emptySpaceItem1.Location = new System.Drawing.Point(304, 428);
             this.emptySpaceItem1.Name = "emptySpaceItem1";
             this.emptySpaceItem1.Size = new System.Drawing.Size(219, 25);
             this.emptySpaceItem1.TextSize = new System.Drawing.Size(0, 0);
             // 
+            // layoutControlItem4
+            // 
+            this.layoutControlItem4.Control = this.txtSat;
+            this.layoutControlItem4.Location = new System.Drawing.Point(0, 28);
+            this.layoutControlItem4.Name = "layoutControlItem4";
+            this.layoutControlItem4.Size = new System.Drawing.Size(627, 24);
+            this.layoutControlItem4.Text = "卫星";
+            this.layoutControlItem4.TextAlignMode = DevExpress.XtraLayout.TextAlignModeItem.CustomSize;
+            this.layoutControlItem4.TextSize = new System.Drawing.Size(50, 20);
+            this.layoutControlItem4.TextToControlDistance = 7;
+            // 
             // CtrlXl
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
@@ -362,6 +376,8 @@
             this.Load += new System.EventHandler(this.CtrlXl_Load);
             ((System.ComponentModel.ISupportInitialize)(this.layoutControl1)).EndInit();
             this.layoutControl1.ResumeLayout(false);
+            ((System.ComponentModel.ISupportInitialize)(this.txtSat.Properties)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.searchLookUpEdit1View)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.txtGoPage.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.gridXl)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.gridView1)).EndInit();
@@ -371,7 +387,6 @@
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem3)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem5)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem6)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem7)).EndInit();
@@ -379,6 +394,7 @@
             ((System.ComponentModel.ISupportInitialize)(this.simpleLabelItem2)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem8)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.emptySpaceItem1)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem4)).EndInit();
             this.ResumeLayout(false);
 
         }
@@ -394,8 +410,6 @@
         private DevExpress.XtraLayout.LayoutControlItem layoutControlItem2;
         private DevExpress.XtraEditors.SimpleButton btnImp;
         private DevExpress.XtraLayout.LayoutControlItem layoutControlItem3;
-        private UcCtrlPage ucCtrlPage;
-        private DevExpress.XtraLayout.LayoutControlItem layoutControlItem4;
         private DevExpress.XtraEditors.TextEdit txtGoPage;
         private DevExpress.XtraEditors.DataNavigator dataNavigator1;
         private DevExpress.XtraLayout.LayoutControlItem layoutControlItem5;
@@ -407,5 +421,8 @@
         private DevExpress.XtraEditors.SimpleButton btnGo;
         private DevExpress.XtraLayout.LayoutControlItem layoutControlItem8;
         private DevExpress.XtraEditors.ComboBoxEdit txtCountPerPage;
+        private DevExpress.XtraEditors.SearchLookUpEdit txtSat;
+        private DevExpress.XtraGrid.Views.Grid.GridView searchLookUpEdit1View;
+        private DevExpress.XtraLayout.LayoutControlItem layoutControlItem4;
     }
 }

+ 127 - 94
XdCxRhDW.App/UserControl/CtrlXl.cs

@@ -5,6 +5,7 @@ using ExtensionsDev;
 using System;
 using System.Collections.Generic;
 using System.Data.Entity;
+using System.Diagnostics;
 using System.Linq;
 using System.Threading.Tasks;
 using System.Windows.Forms;
@@ -21,86 +22,33 @@ namespace XdCxRhDW.App.UserControl
         int maxCount = 0;
         int maxPage = 0;
         int currentPage = 1;
+        int? satCode = null;
         public CtrlXl()
         {
             InitializeComponent();
             this.layoutControl1.UseDefault();
             btnOpen.UseChooseFile().UseDoubleClickToSelectAll();
-
-            this.ucCtrlPage.CurrentPage = 1;
-            this.ucCtrlPage.PageSize = Convert.ToInt32(this.ucCtrlPage.CboPageSize.Text);
-            this.ucCtrlPage.TotalPages = 1;
-            this.ucCtrlPage.ClickPageButtonEvent += ucPageDemo_ClickPageButtonEvent;
-            this.ucCtrlPage.ChangedPageSizeEvent += ucPageDemo_ChangedPageSizeEvent;
-            this.ucCtrlPage.JumpPageEvent += ucPageDemo_JumpPageEvent;
-
-            //var customBtn=gridXl.EmbeddedNavigator.Buttons.CustomButtons.Add();
-            //customBtn.Hint = "跳转";
-            //customBtn.Visible = true;
-            //customBtn.Enabled = true;
-            //customBtn.ImageIndex = 11;
-        }
-
-        /// <summary>
-        /// 页数跳转
-        /// </summary>
-        /// <param name="jumpPage">跳转页</param>
-        void ucPageDemo_JumpPageEvent(int jumpPage)
-        {
-            if (jumpPage <= this.ucCtrlPage.TotalPages)
-            {
-                if (jumpPage > 0)
-                {
-                    this.ucCtrlPage.JumpPageCtrl.Text = string.Empty;
-                    this.ucCtrlPage.JumpPageCtrl.Text = jumpPage.ToString();
-                    this.ShowDatas(jumpPage);
-                }
-                else
-                {
-                    jumpPage = 1;
-                    this.ucCtrlPage.JumpPageCtrl.Text = string.Empty;
-                    this.ucCtrlPage.JumpPageCtrl.Text = jumpPage.ToString();
-                    this.ShowDatas(jumpPage);
-                }
-            }
-            else
-            {
-                this.ucCtrlPage.JumpPageCtrl.Text = string.Empty;
-                MessageBox.Show(@"超出当前最大页数", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
-            }
-        }
-        /// <summary>
-        /// 改变每页展示数据长度
-        /// </summary>
-        void ucPageDemo_ChangedPageSizeEvent()
-        {
-            this.ShowDatas(1);
-        }
-        /// <summary>
-        /// 页数改变按钮(最前页,最后页,上一页,下一页)
-        /// </summary>
-        /// <param name="current"></param>
-        void ucPageDemo_ClickPageButtonEvent(int current)
-        {
-            this.ShowDatas(current);
+            var sat = XlRepository.GetAllSat().Result;
+            txtSat.UseDefault("不限制", true).SetData(sat, nameof(SatInfo.Sat));
         }
 
-        /// <summary>
-        /// 数据展示
-        /// </summary>
-        /// <param name="currentPage">当前页</param>
-        private async void ShowDatas(int currentPage)
+        private async void TxtSat_EditValueChanged(object sender, EventArgs e)
         {
-            await LoadData(currentPage);
-        }
-        private async void CtrlXl_Load(object sender, EventArgs e)
-        {
-            this.maxCount = await XlRepository.GetCount();
+            var sat = txtSat.EditValue as SatInfo;
+            satCode = sat?.SatCode;
+            this.maxCount = await XlRepository.GetCount(satCode);
             var countPerPage = Convert.ToInt32(txtCountPerPage.Text);
             this.maxPage = maxCount / countPerPage;
             if (maxCount % countPerPage != 0)
                 maxPage++;
-            dataNavigator1.DataSource = list;
+            currentPage = 1;
+            dataNavigator1.TextStringFormat = $"第{1}页/共{maxPage}页";
+            await LoadPageData(1);
+
+        }
+
+        private async void CtrlXl_Load(object sender, EventArgs e)
+        {
             gridXl.UseDefault(list).UseRowNumber().UseDeleteAsync<XlInfo>(Del).UseExportXlsx()
             .AddMenu("星历推算", SvgHelper.LoadFromFile("Image\\XlCalc.svg"), () =>
             {
@@ -119,41 +67,35 @@ namespace XdCxRhDW.App.UserControl
                 form.ShowDialog();
             });
             await LoadData(1);
+            dataNavigator1.TextStringFormat = $"第{currentPage}页/共{maxPage}页";
+            dataNavigator1.DataSource = list;
+            dataNavigator1.Buttons.First.Enabled = false;
+            dataNavigator1.Buttons.PrevPage.Enabled = false;
         }
         public async Task LoadData(int currentPage)
         {
             try
             {
-                var dtResult = await XlRepository.GetPageAsync(currentPage, this.ucCtrlPage.PageSize);
-                int totalPages = 0;
-                int totalRows = 0;
-                if (null == dtResult || dtResult.Count == 0)
-                {
-                    this.ucCtrlPage.PageInfo.Text = string.Format("第{0}/{1}页", "1", "1");
-                    this.ucCtrlPage.TotalRows.Text = @"0";
-                    this.ucCtrlPage.CurrentPage = 1;
-                    this.ucCtrlPage.TotalPages = 1;
-                }
-                else
-                {
-                    totalRows = Convert.ToInt32(dtResult.First().TotalRows);
-                    totalPages = totalRows % this.ucCtrlPage.PageSize == 0 ? totalRows / this.ucCtrlPage.PageSize : (totalRows / this.ucCtrlPage.PageSize) + 1;
-                    this.ucCtrlPage.PageInfo.Text = string.Format("第{0}/{1}页", currentPage, totalPages);
-                    this.ucCtrlPage.TotalRows.Text = totalRows.ToString();
-                    this.ucCtrlPage.CurrentPage = currentPage;
-                    this.ucCtrlPage.TotalPages = totalPages;
-                }
-                list.Clear();
-                list.AddRange(dtResult);
-                gridView1.RefreshData();
+                this.maxCount = await XlRepository.GetCount(satCode);
+                var countPerPage = Convert.ToInt32(txtCountPerPage.Text);
+                this.maxPage = maxCount / countPerPage;
+                if (maxCount % countPerPage != 0)
+                    maxPage++;
+                await LoadPageData(1);
             }
             catch (Exception ex)
             {
-                Serilog.Log.Error(ex, "加载星历信息异常");
+                await LogHelper.Error("加载星历信息异常", ex);
                 DxHelper.MsgBoxHelper.ShowError("加载星历信息异常");
             }
         }
-
+        private async Task LoadPageData(int currentPage)
+        {
+            var dtResult = await XlRepository.GetPageAsync(currentPage, Convert.ToInt32(txtCountPerPage.Text), satCode);
+            list.Clear();
+            list.AddRange(dtResult);
+            gridView1.RefreshData();
+        }
         private async void btnImp_Click(object sender, EventArgs e)
         {
             this.layoutControl1.Enabled = false;
@@ -233,7 +175,7 @@ namespace XdCxRhDW.App.UserControl
             }
         }
 
-        private void dataNavigator1_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
+        private async void dataNavigator1_ButtonClick(object sender, NavigatorButtonClickEventArgs e)
         {
             if (e.Button.ButtonType == NavigatorButtonType.First)
             {
@@ -242,6 +184,7 @@ namespace XdCxRhDW.App.UserControl
                 dataNavigator1.Buttons.PrevPage.Enabled = false;
                 dataNavigator1.Buttons.Last.Enabled = true;
                 dataNavigator1.Buttons.NextPage.Enabled = true;
+
             }
             else if (e.Button.ButtonType == NavigatorButtonType.Last)
             {
@@ -272,9 +215,99 @@ namespace XdCxRhDW.App.UserControl
                     dataNavigator1.Buttons.First.Enabled = false;
                     dataNavigator1.Buttons.PrevPage.Enabled = false;
                 }
-
             }
+            await LoadPageData(currentPage);
             dataNavigator1.TextStringFormat = $"第{currentPage}页/共{maxPage}页";
         }
+
+        private async void btnGo_Click(object sender, EventArgs e)
+        {
+            int.TryParse(txtGoPage.Text, out int _currentPage);
+            if (_currentPage > maxPage)
+            {
+                _currentPage = maxPage;
+            }
+            if (_currentPage > 0)
+            {
+                currentPage = _currentPage;
+                if (currentPage == 1 && currentPage < maxPage)
+                {
+                    dataNavigator1.Buttons.First.Enabled = false;
+                    dataNavigator1.Buttons.PrevPage.Enabled = false;
+                    dataNavigator1.Buttons.Last.Enabled = true;
+                    dataNavigator1.Buttons.NextPage.Enabled = true;
+                }
+                else if (currentPage == 1 && currentPage == maxPage)
+                {
+                    dataNavigator1.Buttons.First.Enabled = false;
+                    dataNavigator1.Buttons.PrevPage.Enabled = false;
+                    dataNavigator1.Buttons.First.Enabled = false;
+                    dataNavigator1.Buttons.PrevPage.Enabled = false;
+                }
+                else if (currentPage == maxPage)
+                {
+                    dataNavigator1.Buttons.First.Enabled = true;
+                    dataNavigator1.Buttons.PrevPage.Enabled = true;
+                    dataNavigator1.Buttons.Last.Enabled = false;
+                    dataNavigator1.Buttons.NextPage.Enabled = false;
+                    if (dataNavigator1.Position == 0)
+                        dataNavigator1.Position = 1;
+                }
+                else
+                {
+                    dataNavigator1.Buttons.First.Enabled = true;
+                    dataNavigator1.Buttons.PrevPage.Enabled = true;
+                    dataNavigator1.Buttons.Last.Enabled = true;
+                    dataNavigator1.Buttons.NextPage.Enabled = true;
+                    dataNavigator1.Position = 1;
+                }
+                dataNavigator1.TextStringFormat = $"第{currentPage}页/共{maxPage}页";
+                await LoadPageData(currentPage);
+            }
+        }
+
+        private async void txtCountPerPage_EditValueChanged(object sender, EventArgs e)
+        {
+            int.TryParse(txtCountPerPage.Text, out int countPerPage);
+            if (countPerPage > 0)
+            {
+                this.maxPage = maxCount / countPerPage;
+                if (maxCount % countPerPage != 0)
+                    maxPage++;
+                if (currentPage > maxPage)
+                    currentPage = maxPage;
+                if (currentPage == 1 && currentPage < maxPage)
+                {
+                    dataNavigator1.Buttons.First.Enabled = false;
+                    dataNavigator1.Buttons.PrevPage.Enabled = false;
+                    dataNavigator1.Buttons.Last.Enabled = true;
+                    dataNavigator1.Buttons.NextPage.Enabled = true;
+                }
+                else if (currentPage == 1 && currentPage == maxPage)
+                {
+                    dataNavigator1.Buttons.First.Enabled = false;
+                    dataNavigator1.Buttons.PrevPage.Enabled = false;
+                    dataNavigator1.Buttons.First.Enabled = false;
+                    dataNavigator1.Buttons.PrevPage.Enabled = false;
+                }
+                else if (currentPage == maxPage)
+                {
+                    dataNavigator1.Buttons.First.Enabled = true;
+                    dataNavigator1.Buttons.PrevPage.Enabled = true;
+                    dataNavigator1.Buttons.Last.Enabled = false;
+                    dataNavigator1.Buttons.NextPage.Enabled = false;
+                }
+                else
+                {
+                    dataNavigator1.Buttons.First.Enabled = true;
+                    dataNavigator1.Buttons.PrevPage.Enabled = true;
+                    dataNavigator1.Buttons.Last.Enabled = true;
+                    dataNavigator1.Buttons.NextPage.Enabled = true;
+                    dataNavigator1.Position = 1;
+                }
+                dataNavigator1.TextStringFormat = $"第{currentPage}页/共{maxPage}页";
+                await LoadPageData(currentPage);
+            }
+        }
     }
 }

+ 1 - 1
XdCxRhDW.App/UserControl/CtrlXl.resx

@@ -118,7 +118,7 @@
     <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
   </resheader>
   <assembly alias="DevExpress.Data.v23.2" name="DevExpress.Data.v23.2, Version=23.2.3.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
-  <data name="simpleButton1.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
+  <data name="btnGo.ImageOptions.SvgImage" type="DevExpress.Utils.Svg.SvgImage, DevExpress.Data.v23.2" mimetype="application/x-microsoft.net.object.bytearray.base64">
     <value>
         AAEAAAD/////AQAAAAAAAAAMAgAAAFlEZXZFeHByZXNzLkRhdGEudjIzLjIsIFZlcnNpb249MjMuMi4z
         LjAsIEN1bHR1cmU9bmV1dHJhbCwgUHVibGljS2V5VG9rZW49Yjg4ZDE3NTRkNzAwZTQ5YQUBAAAAHURl

+ 0 - 212
XdCxRhDW.App/UserControl/UcCtrlPage.Designer.cs

@@ -1,212 +0,0 @@
-namespace XdCxRhDW.App.UserControl
-{
-    partial class UcCtrlPage
-    {/// <summary> 
-     /// 必需的设计器变量。
-     /// </summary>
-        private System.ComponentModel.IContainer components = null;
-        /// <summary>
-        /// 清理所有正在使用的资源。
-        /// </summary>
-        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
-        protected override void Dispose(bool disposing)
-        {
-            if (disposing && (components != null))
-            {
-                components.Dispose();
-            }
-            base.Dispose(disposing);
-        }
-
-        #region 组件设计器生成的代码
-
-        /// <summary>
-        /// 设计器支持所需的方法 - 不要
-        /// 使用代码编辑器修改此方法的内容。
-        /// </summary>
-        private void InitializeComponent()
-        {
-            this.btnFrist = new System.Windows.Forms.Button();
-            this.lblPage = new System.Windows.Forms.Label();
-            this.btnPreviou = new System.Windows.Forms.Button();
-            this.btnNext = new System.Windows.Forms.Button();
-            this.btnLast = new System.Windows.Forms.Button();
-            this.cboPageSize = new System.Windows.Forms.ComboBox();
-            this.label1 = new System.Windows.Forms.Label();
-            this.label2 = new System.Windows.Forms.Label();
-            this.label3 = new System.Windows.Forms.Label();
-            this.label4 = new System.Windows.Forms.Label();
-            this.lblTotalRows = new System.Windows.Forms.Label();
-            this.txtJumpPage = new System.Windows.Forms.TextBox();
-            this.SuspendLayout();
-            // 
-            // btnFrist
-            // 
-            this.btnFrist.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.btnFrist.ImageIndex = 0;
-            this.btnFrist.Location = new System.Drawing.Point(9, 6);
-            this.btnFrist.Margin = new System.Windows.Forms.Padding(4);
-            this.btnFrist.Name = "btnFrist";
-            this.btnFrist.Size = new System.Drawing.Size(31, 22);
-            this.btnFrist.TabIndex = 0;
-            this.btnFrist.Text = "<<";
-            // 
-            // lblPage
-            // 
-            this.lblPage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.lblPage.AutoSize = true;
-            this.lblPage.Location = new System.Drawing.Point(95, 10);
-            this.lblPage.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.lblPage.Name = "lblPage";
-            this.lblPage.Size = new System.Drawing.Size(50, 14);
-            this.lblPage.TabIndex = 1;
-            this.lblPage.Text = "第1/1页";
-            // 
-            // btnPreviou
-            // 
-            this.btnPreviou.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.btnPreviou.ImageIndex = 3;
-            this.btnPreviou.Location = new System.Drawing.Point(48, 6);
-            this.btnPreviou.Margin = new System.Windows.Forms.Padding(4);
-            this.btnPreviou.Name = "btnPreviou";
-            this.btnPreviou.Size = new System.Drawing.Size(31, 22);
-            this.btnPreviou.TabIndex = 2;
-            this.btnPreviou.Text = "<";
-            // 
-            // btnNext
-            // 
-            this.btnNext.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.btnNext.ImageIndex = 2;
-            this.btnNext.Location = new System.Drawing.Point(159, 6);
-            this.btnNext.Margin = new System.Windows.Forms.Padding(4);
-            this.btnNext.Name = "btnNext";
-            this.btnNext.Size = new System.Drawing.Size(31, 22);
-            this.btnNext.TabIndex = 3;
-            this.btnNext.Text = ">";
-            // 
-            // btnLast
-            // 
-            this.btnLast.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.btnLast.ImageIndex = 1;
-            this.btnLast.Location = new System.Drawing.Point(199, 6);
-            this.btnLast.Margin = new System.Windows.Forms.Padding(4);
-            this.btnLast.Name = "btnLast";
-            this.btnLast.Size = new System.Drawing.Size(31, 22);
-            this.btnLast.TabIndex = 4;
-            this.btnLast.Text = ">>";
-            // 
-            // cboPageSize
-            // 
-            this.cboPageSize.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.cboPageSize.FormattingEnabled = true;
-            this.cboPageSize.Location = new System.Drawing.Point(314, 6);
-            this.cboPageSize.Margin = new System.Windows.Forms.Padding(4);
-            this.cboPageSize.Name = "cboPageSize";
-            this.cboPageSize.Size = new System.Drawing.Size(53, 22);
-            this.cboPageSize.TabIndex = 5;
-            // 
-            // label1
-            // 
-            this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.label1.AutoSize = true;
-            this.label1.Location = new System.Drawing.Point(275, 10);
-            this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(31, 14);
-            this.label1.TabIndex = 6;
-            this.label1.Text = "每页";
-            // 
-            // label2
-            // 
-            this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.label2.AutoSize = true;
-            this.label2.Location = new System.Drawing.Point(372, 10);
-            this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label2.Name = "label2";
-            this.label2.Size = new System.Drawing.Size(19, 14);
-            this.label2.TabIndex = 7;
-            this.label2.Text = "条";
-            // 
-            // label3
-            // 
-            this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.label3.AutoSize = true;
-            this.label3.Location = new System.Drawing.Point(413, 10);
-            this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label3.Name = "label3";
-            this.label3.Size = new System.Drawing.Size(19, 14);
-            this.label3.TabIndex = 8;
-            this.label3.Text = "共";
-            // 
-            // label4
-            // 
-            this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.label4.AutoSize = true;
-            this.label4.Location = new System.Drawing.Point(479, 10);
-            this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.label4.Name = "label4";
-            this.label4.Size = new System.Drawing.Size(19, 14);
-            this.label4.TabIndex = 9;
-            this.label4.Text = "条";
-            // 
-            // lblTotalRows
-            // 
-            this.lblTotalRows.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.lblTotalRows.AutoSize = true;
-            this.lblTotalRows.Location = new System.Drawing.Point(441, 10);
-            this.lblTotalRows.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
-            this.lblTotalRows.Name = "lblTotalRows";
-            this.lblTotalRows.Size = new System.Drawing.Size(14, 14);
-            this.lblTotalRows.TabIndex = 10;
-            this.lblTotalRows.Text = "0";
-            // 
-            // txtJumpPage
-            // 
-            this.txtJumpPage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
-            this.txtJumpPage.Location = new System.Drawing.Point(238, 6);
-            this.txtJumpPage.Margin = new System.Windows.Forms.Padding(4);
-            this.txtJumpPage.Multiline = true;
-            this.txtJumpPage.Name = "txtJumpPage";
-            this.txtJumpPage.Size = new System.Drawing.Size(34, 18);
-            this.txtJumpPage.TabIndex = 11;
-            // 
-            // UcCtrlPage
-            // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
-            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.Controls.Add(this.txtJumpPage);
-            this.Controls.Add(this.lblTotalRows);
-            this.Controls.Add(this.label4);
-            this.Controls.Add(this.label3);
-            this.Controls.Add(this.label2);
-            this.Controls.Add(this.label1);
-            this.Controls.Add(this.cboPageSize);
-            this.Controls.Add(this.btnLast);
-            this.Controls.Add(this.btnNext);
-            this.Controls.Add(this.btnPreviou);
-            this.Controls.Add(this.lblPage);
-            this.Controls.Add(this.btnFrist);
-            this.Margin = new System.Windows.Forms.Padding(4);
-            this.Name = "UcCtrlPage";
-            this.Size = new System.Drawing.Size(516, 34);
-            this.ResumeLayout(false);
-            this.PerformLayout();
-
-        }
-
-        #endregion
-
-        private System.Windows.Forms.Button btnFrist;
-        private System.Windows.Forms.Label lblPage;
-        private System.Windows.Forms.Button btnPreviou;
-        private System.Windows.Forms.Button btnNext;
-        private System.Windows.Forms.Button btnLast;
-        private System.Windows.Forms.ComboBox cboPageSize;
-        private System.Windows.Forms.Label label1;
-        private System.Windows.Forms.Label label2;
-        private System.Windows.Forms.Label label3;
-        private System.Windows.Forms.Label label4;
-        private System.Windows.Forms.Label lblTotalRows;
-        private System.Windows.Forms.TextBox txtJumpPage;
-    }
-}

+ 0 - 215
XdCxRhDW.App/UserControl/UcCtrlPage.cs

@@ -1,215 +0,0 @@
-using DevExpress.XtraEditors;
-using DevExpress.XtraPrinting;
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Configuration;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace XdCxRhDW.App.UserControl
-{
-    public partial class UcCtrlPage : DevExpress.XtraEditors.XtraUserControl
-    {
-
-        private string _cfgPageSize = "100,200,300,500,1000,2000";
-
-        public event EventHandler OnPageChanged;
-
-        public delegate void ClickPageButton(int current);
-        public event ClickPageButton ClickPageButtonEvent;
-
-        public delegate void ChangedPageSize();
-        public event ChangedPageSize ChangedPageSizeEvent;
-
-        public delegate void JumpPage(int jumpPage);
-        public event JumpPage JumpPageEvent;
-
-        public int TotalPages { get; set; }
-
-        private int currentPage;
-        public int CurrentPage
-        {
-            get { return this.currentPage; }
-            set { this.currentPage = value; }
-        }
-
-        private int pageSize;
-        public int PageSize
-        {
-            get { return this.pageSize; }
-            set { this.pageSize = value; }
-        }
-
-        public System.Windows.Forms.ComboBox CboPageSize
-        {
-            set { this.cboPageSize = value; }
-            get { return this.cboPageSize; }
-        }
-
-        public Label PageInfo
-        {
-            set { this.lblPage = value; }
-            get { return this.lblPage; }
-        }
-
-        public Label TotalRows
-        {
-            get { return this.lblTotalRows; }
-            set { this.lblTotalRows = value; }
-        }
-
-        public TextBox JumpPageCtrl
-        {
-            get { return this.txtJumpPage; }
-            set { this.txtJumpPage = value; }
-        }
-
-        public UcCtrlPage()
-        {
-            InitializeComponent();
-            this.InitCboCtrl();
-            this.cboPageSize.TextChanged += cboPageSize_TextChanged;
-            this.cboPageSize.KeyPress += cboPageSize_KeyPress;
-           
-            this.btnFrist.Tag = "F";
-            this.btnPreviou.Tag = "P";
-            this.btnNext.Tag = "N";
-            this.btnLast.Tag = "L";
-            this.btnFrist.Click += btn_Click;
-            this.btnPreviou.Click += btn_Click;
-            this.btnNext.Click += btn_Click;
-            this.btnLast.Click += btn_Click;
-            this.cboPageSize.KeyPress += cboPageSize_KeyPress;
-            this.txtJumpPage.KeyPress += txtJumpPage_KeyPress;
-        }
-
-        void txtJumpPage_KeyPress(object sender, KeyPressEventArgs e)
-        {
-            //text输入验证
-            if (e.KeyChar == 13)
-            {
-                if (null != this.JumpPageEvent)
-                {
-                    if (int.TryParse(this.txtJumpPage.Text, out int pagecount))
-                    {
-                        this.JumpPageEvent(pagecount);
-                    }
-                 
-                }
-            }
-            else
-            {
-                if (e.KeyChar != 8)
-                {
-                    int len = this.txtJumpPage.Text.Length;
-                    if (len < 1 && e.KeyChar == '0')
-                    {
-                        e.Handled = true;
-                    }
-                    else if ((e.KeyChar < '0') || (e.KeyChar > '9'))//这是允许输入0-9数字
-                    {
-                        e.Handled = true;
-                    }
-                }
-            }
-        }
-        void btn_Click(object sender, EventArgs e)
-        {
-            Button btn = sender as Button;
-            if (null != this.ClickPageButtonEvent)
-            {
-                if (null != btn)
-                {
-                    switch (btn.Tag.ToString())
-                    {
-                        case "F":
-                            this.CurrentPage = 1;
-                            break;
-                        case "P":
-                            this.CurrentPage = this.CurrentPage <= 1 ? 1 : this.CurrentPage - 1;
-                            break;
-                        case "N":
-                            this.CurrentPage = this.CurrentPage >= this.TotalPages ? this.TotalPages : this.currentPage + 1;
-                            break;
-                        case "L":
-                            this.CurrentPage = this.TotalPages;
-                            break;
-                        default:
-                            this.CurrentPage = 1;
-                            break;
-                    }
-                    this.ClickPageButtonEvent(this.CurrentPage);
-                }
-            }
-        }
-        void cboPageSize_KeyPress(object sender, KeyPressEventArgs e)
-        {
-            e.Handled = true;
-        }
-        void cboPageSize_TextChanged(object sender, EventArgs e)
-        {
-            this.PageSize = Convert.ToInt32(this.cboPageSize.Text);
-            if (null != ChangedPageSizeEvent)
-            {
-                this.ChangedPageSizeEvent();
-            }
-        }
-        private void InitCboCtrl()
-        {
-            this.cboPageSize.ValueMember = "MValue";
-            this.cboPageSize.DisplayMember = "MText";
-            this.cboPageSize.Text = string.Empty;
-            if (!string.IsNullOrEmpty(_cfgPageSize))
-            {
-                string cfgPageSize = _cfgPageSize.Replace(",", ",");
-                if (cfgPageSize.EndsWith(","))
-                {
-                    cfgPageSize = cfgPageSize.Remove(cfgPageSize.Length - 1);
-                }
-                string[] strPageSize = cfgPageSize.Split(new char[] { ',' });
-                List<string> listPageSize = new List<string>();
-                for (int x = 0; x < strPageSize.Length; x++)
-                {
-                    if (!listPageSize.Contains(strPageSize[x]) && !string.IsNullOrEmpty(strPageSize[x]))
-                    {
-                        listPageSize.Add(strPageSize[x]);
-                    }
-                }
-                List<KeyAndValueEntity> kve = new List<KeyAndValueEntity>();
-                for (int i = 0; i < listPageSize.Count; i++)
-                {
-                    kve.Add(new KeyAndValueEntity() { MValue = i, MText = listPageSize[i] });
-                }
-                this.cboPageSize.DataSource = kve;
-            }
-            else
-            {
-                this.cboPageSize.DataSource = new List<KeyAndValueEntity>()
-            {
-                new KeyAndValueEntity() {MValue = 0,MText = "100"},
-                new KeyAndValueEntity() {MValue = 1,MText = "200"},
-                new KeyAndValueEntity() {MValue = 2,MText = "500"},
-                new KeyAndValueEntity() {MValue = 3,MText = "1000"}
-            };
-            }
-            this.cboPageSize.SelectedText = ((KeyAndValueEntity)cboPageSize.Items[0]).MText;
-        }
-
-    }
-
-    internal class KeyAndValueEntity
-    {
-        public int MValue { get; set; }
-        public string MText { get; set; }
-    }
-
-
-
-}
-
-

+ 0 - 120
XdCxRhDW.App/UserControl/UcCtrlPage.resx

@@ -1,120 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<root>
-  <!-- 
-    Microsoft ResX Schema 
-    
-    Version 2.0
-    
-    The primary goals of this format is to allow a simple XML format 
-    that is mostly human readable. The generation and parsing of the 
-    various data types are done through the TypeConverter classes 
-    associated with the data types.
-    
-    Example:
-    
-    ... ado.net/XML headers & schema ...
-    <resheader name="resmimetype">text/microsoft-resx</resheader>
-    <resheader name="version">2.0</resheader>
-    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
-    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
-    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
-    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
-    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
-        <value>[base64 mime encoded serialized .NET Framework object]</value>
-    </data>
-    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
-        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
-        <comment>This is a comment</comment>
-    </data>
-                
-    There are any number of "resheader" rows that contain simple 
-    name/value pairs.
-    
-    Each data row contains a name, and value. The row also contains a 
-    type or mimetype. Type corresponds to a .NET class that support 
-    text/value conversion through the TypeConverter architecture. 
-    Classes that don't support this are serialized and stored with the 
-    mimetype set.
-    
-    The mimetype is used for serialized objects, and tells the 
-    ResXResourceReader how to depersist the object. This is currently not 
-    extensible. For a given mimetype the value must be set accordingly:
-    
-    Note - application/x-microsoft.net.object.binary.base64 is the format 
-    that the ResXResourceWriter will generate, however the reader can 
-    read any of the formats listed below.
-    
-    mimetype: application/x-microsoft.net.object.binary.base64
-    value   : The object must be serialized with 
-            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
-            : and then encoded with base64 encoding.
-    
-    mimetype: application/x-microsoft.net.object.soap.base64
-    value   : The object must be serialized with 
-            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
-            : and then encoded with base64 encoding.
-
-    mimetype: application/x-microsoft.net.object.bytearray.base64
-    value   : The object must be serialized into a byte array 
-            : using a System.ComponentModel.TypeConverter
-            : and then encoded with base64 encoding.
-    -->
-  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
-    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
-    <xsd:element name="root" msdata:IsDataSet="true">
-      <xsd:complexType>
-        <xsd:choice maxOccurs="unbounded">
-          <xsd:element name="metadata">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" />
-              </xsd:sequence>
-              <xsd:attribute name="name" use="required" type="xsd:string" />
-              <xsd:attribute name="type" type="xsd:string" />
-              <xsd:attribute name="mimetype" type="xsd:string" />
-              <xsd:attribute ref="xml:space" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="assembly">
-            <xsd:complexType>
-              <xsd:attribute name="alias" type="xsd:string" />
-              <xsd:attribute name="name" type="xsd:string" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="data">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
-                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
-              </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
-              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
-              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
-              <xsd:attribute ref="xml:space" />
-            </xsd:complexType>
-          </xsd:element>
-          <xsd:element name="resheader">
-            <xsd:complexType>
-              <xsd:sequence>
-                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
-              </xsd:sequence>
-              <xsd:attribute name="name" type="xsd:string" use="required" />
-            </xsd:complexType>
-          </xsd:element>
-        </xsd:choice>
-      </xsd:complexType>
-    </xsd:element>
-  </xsd:schema>
-  <resheader name="resmimetype">
-    <value>text/microsoft-resx</value>
-  </resheader>
-  <resheader name="version">
-    <value>2.0</value>
-  </resheader>
-  <resheader name="reader">
-    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
-  </resheader>
-  <resheader name="writer">
-    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
-  </resheader>
-</root>

+ 0 - 9
XdCxRhDW.App/XdCxRhDW.App.csproj

@@ -340,12 +340,6 @@
     <Compile Include="UserControl\CtrlDraw.Designer.cs">
       <DependentUpon>CtrlDraw.cs</DependentUpon>
     </Compile>
-    <Compile Include="UserControl\UcCtrlPage.cs">
-      <SubType>UserControl</SubType>
-    </Compile>
-    <Compile Include="UserControl\UcCtrlPage.Designer.cs">
-      <DependentUpon>UcCtrlPage.cs</DependentUpon>
-    </Compile>
     <Compile Include="X2D1PosRef\LinearInterpolation.cs" />
     <Compile Include="X2D1PosRef\X2D1PosRefService.cs" />
     <Compile Include="PopupControl\ShowCgCtrl.cs">
@@ -656,9 +650,6 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <EmbeddedResource Include="UserControl\UcCtrlPage.resx">
-      <DependentUpon>UcCtrlPage.cs</DependentUpon>
-    </EmbeddedResource>
     <EmbeddedResource Include="UserControl\UCEphXYZ.resx">
       <DependentUpon>UCEphXYZ.cs</DependentUpon>
     </EmbeddedResource>

+ 6 - 0
XdCxRhDW.Entity/03.XdCxRhDW.Entity.csproj

@@ -86,6 +86,12 @@
     <None Include="App.config" />
     <None Include="packages.config" />
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\XdCxRhDW.Framework\01.XdCxRhDW.Framework.csproj">
+      <Project>{cd41cedf-e0b8-41cc-867b-3b57f476b450}</Project>
+      <Name>01.XdCxRhDW.Framework</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
     <PropertyGroup>

+ 1 - 0
XdCxRhDW.Entity/BaseEntity.cs

@@ -28,6 +28,7 @@ namespace XdCxRhDW.Entity
         public DateTime CreateTime { get; set; }
 
         [Display(Name = "更新时间")]
+        [Index]
         public DateTime UpdateTime { get; set; }
 
     }

+ 6 - 7
XdCxRhDW.Entity/XlInfo.cs

@@ -9,16 +9,13 @@ using System.Threading.Tasks;
 namespace XdCxRhDW.Entity
 {
     [Table("XlInfo")]
+    [IndexCombined(nameof(XlInfo.SatCode), nameof(XlInfo.TimeUTC))]//创建组合索引加速多个条件的查询
     public class XlInfo : BaseEntity
     {
-
-
-        [Display(Name = "总条数", AutoGenerateField = false)]
-        public int TotalRows { get; set; }
-
-        [Display(Name = "卫星编号",AutoGenerateField = false)]
+        [Display(Name = "卫星编号", AutoGenerateField = false)]
+        [Index]
         public int SatCode { get; set; }
-        [Display(Name = "卫星名称",AutoGenerateField = false)]
+        [Display(Name = "卫星名称", AutoGenerateField = false)]
 
         public string SatName { get; set; }
 
@@ -26,9 +23,11 @@ namespace XdCxRhDW.Entity
         public string Sat => $"{SatName}({SatCode})";
 
         [Display(Name = "发布时间(UTC)")]
+        [IndexAttribute]
         public DateTime TimeUTC { get; set; }
 
         [Display(Name = "轨道经度")]
+        [Index]
         public double? Lon { get; set; }
 
         [Display(Name = "双行根数1")]

+ 2 - 0
XdCxRhDW.Framework/01.XdCxRhDW.Framework.csproj

@@ -78,6 +78,8 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AppConfigHelper.cs" />
+    <Compile Include="IndexCombinedAttribute.cs" />
+    <Compile Include="ListExtension.cs" />
     <Compile Include="RandomHelper.cs" />
     <Compile Include="ColorHelper.cs" />
     <Compile Include="ColorRGB.cs" />

+ 15 - 0
XdCxRhDW.Framework/IndexCombinedAttribute.cs

@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
+public class IndexCombinedAttribute : Attribute
+{
+    public string[] Names { get; private set; }
+    public IndexCombinedAttribute(params string[] names)
+    {
+        this.Names = names;
+    }
+}

+ 59 - 0
XdCxRhDW.Framework/ListExtension.cs

@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+public static class ListExtension
+{
+    /// <summary>
+    /// Save the List data to CSV file
+    /// </summary>
+    /// <param name="list">data source</param>
+    /// <param name="file">file</param>
+    /// <returns>success flag</returns>
+    public static string ToCsvFile<T>(this List<T> list, string file)
+    {
+        PropertyInfo[] props = GetPropertyInfoArray<T>();
+        using (var sw = new StreamWriter(file))
+        {
+            StringBuilder strColumn = new StringBuilder();
+            for (int i = 0; i < props.Length; i++)
+            {
+                strColumn.Append(props[i].Name);
+                strColumn.Append(",");
+            }
+            strColumn.Remove(strColumn.Length - 1, 1);
+            sw.WriteLine(strColumn);    //write the column name
+            for (int i = 0; i < list.Count; i++)
+            {
+                StringBuilder strValue = new StringBuilder();
+                int idx = 0;
+                foreach (var prop in props)
+                {
+                    var val = prop.GetValue(list[i]);
+                    strValue.Append(val);
+                    if (idx < props.Length-1)
+                        strValue.Append(",");
+                    idx++;
+                }
+                sw.WriteLine(strValue); //write the row value
+            }
+        }
+        FileInfo f = new FileInfo(file);
+        return f.FullName;
+    }
+
+
+    private static PropertyInfo[] GetPropertyInfoArray<T>()
+    {
+        PropertyInfo[] props = null;
+        Type type = typeof(T);
+        object obj = Activator.CreateInstance(type);
+        props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
+        return props.Where(p => p.CanRead && !p.GetMethod.IsVirtual && !p.GetMethod.IsAbstract).ToArray();
+    }
+
+}

+ 114 - 78
XdCxRhDW.Repostory/EFContext/RHDWContext.cs

@@ -5,6 +5,7 @@ using System.ComponentModel.DataAnnotations.Schema;
 using System.Data.Common;
 using System.Data.Entity;
 using System.Data.Entity.Core.Common;
+using System.Data.Entity.Core.Common.CommandTrees;
 using System.Data.Entity.Core.Metadata.Edm;
 using System.Data.Entity.Infrastructure;
 using System.Data.Entity.Infrastructure.Interception;
@@ -14,10 +15,12 @@ using System.Data.SQLite;
 using System.Data.SQLite.EF6;
 using System.IO;
 using System.Linq;
+using System.Linq.Expressions;
 using System.Reflection;
 using System.Text;
 using System.Text.RegularExpressions;
 using System.Threading.Tasks;
+using System.Windows;
 using XdCxRhDW.Entity;
 
 namespace XdCxRhDW.Repostory
@@ -39,11 +42,120 @@ namespace XdCxRhDW.Repostory
             : base(nameOrConnectionString)
         {
         }
+        public DbContextBase(DbConnection con, bool contextOwnsConnection)
+            : base(con, contextOwnsConnection)
+        { 
+        }
 
+        /// <summary>
+        /// 同步数据库表、字段、索引
+        /// </summary>
         public void SyncDb()
         {
             SyncTable();
             SyncTableField();
+            SyncIndex();
+        }
+
+        /// <summary>
+        /// 手动创建组合索引(如果不存在)
+        /// </summary>
+        public void CreateCombinedIndex<TEntityType>(Expression<Func<TEntityType, object>> expr)
+        {
+            var props = ((NewExpression)expr.Body).Members.Select(p => p.Name).OrderBy(p => p).ToList();
+            if (props.Count < 1) return;
+            var name = string.Join("_", props);
+            var tableName = typeof(TEntityType).GetCustomAttribute<TableAttribute>()?.Name;
+            if (string.IsNullOrWhiteSpace(tableName))
+                tableName = typeof(TEntityType).Name;
+            string indexName = $"IX_{tableName}_{name}";
+            StringBuilder sb = new StringBuilder();
+            int idx = 0;
+            foreach (var item in props)
+            {
+                if (idx < props.Count - 1)
+                    sb.Append($"'{item}',");
+                else
+                    sb.Append($"'{item}'");
+                idx++;
+            }
+            var columnStr = sb.ToString();
+            var index = this.Database.SqlQuery<string>($"SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='{tableName}' and name='{indexName}'").FirstOrDefault();
+            if (index == null)
+                this.Database.ExecuteSqlCommand($"CREATE INDEX '{indexName}' ON {tableName} ({columnStr})");
+        }
+
+        /// <summary>
+        /// 手动创建组合索引(如果不存在)
+        /// </summary>
+        public void CreateCombinedIndex(string tableName, string[] propNames)
+        {
+            if (string.IsNullOrWhiteSpace(tableName)) return;
+            if (propNames == null || propNames.Length == 0) return;
+            var props = propNames.OrderBy(p => p).ToList();
+            var name = string.Join("_", props);
+            string indexName = $"IX_{tableName}_{name}";
+            StringBuilder sb = new StringBuilder();
+            int idx = 0;
+            foreach (var item in props)
+            {
+                if (idx < props.Count - 1)
+                    sb.Append($"'{item}',");
+                else
+                    sb.Append($"'{item}'");
+                idx++;
+            }
+            var columnStr = sb.ToString();
+            var index = this.Database.SqlQuery<string>($"SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='{tableName}' and name='{indexName}'").FirstOrDefault();
+            if (index == null)
+                this.Database.ExecuteSqlCommand($"CREATE INDEX '{indexName}' ON {tableName} ({columnStr})");
+        }
+
+        void SyncIndex()
+        {
+            var tables = this.Database.SqlQuery<string>("select name from sqlite_master where type='table' and  name not like 'sqlite%'").ToList();
+            var props = this.GetType().GetProperties();
+            List<Type> entityTypes = new List<Type>();
+            foreach (var prop in props)
+            {
+                bool isDbSet = prop.PropertyType.IsGenericType && typeof(DbSet<>) == prop.PropertyType.GetGenericTypeDefinition();
+                if (isDbSet)
+                {
+                    var entityType = prop.PropertyType.GenericTypeArguments[0];
+                    entityTypes.Add(entityType);
+                }
+            }
+            foreach (var table in tables)
+            {
+                var res = this.Database.SqlQuery<DbTableColumnInfo>($"PRAGMA table_info([{table}])").ToList();
+                var entityType = entityTypes.FirstOrDefault(p => p.Name == table);
+                if (entityType == null) continue;
+
+                //创建具有Index特性的索引列
+                var entityProps = entityType.GetProperties().Where(p =>
+                    p.CanRead
+                    && p.Name.ToUpper() != "ID"
+                    && p.CanWrite
+                    && !p.GetMethod.IsVirtual
+                    && p.GetCustomAttribute<IndexAttribute>() != null
+                    && p.GetCustomAttribute<NotMappedAttribute>() == null);
+
+                foreach (var prop in entityProps)
+                {
+                    var index = this.Database.SqlQuery<string>($"SELECT name FROM sqlite_master WHERE type='index' AND tbl_name='{table}' and name='IX_{table}_{prop.Name}'").FirstOrDefault();
+                    if (index == null)
+                    {
+                        this.Database.ExecuteSqlCommand($"CREATE INDEX 'IX_{table}_{prop.Name}' ON {table} ('{prop.Name}')");
+                    }
+                }
+
+                //创建类上具有IndexCombined特性的组合索引
+                var attrs = entityType.GetCustomAttributes<IndexCombinedAttribute>();
+                foreach (var item in attrs)
+                {
+                    CreateCombinedIndex(table, item.Names);
+                }
+            }
         }
         void SyncTable()
         {
@@ -188,7 +300,6 @@ namespace XdCxRhDW.Repostory
         }
     }
 
-
     public class RHDWLogContext : DbContextBase
     {
         public string DbFile;
@@ -272,7 +383,7 @@ namespace XdCxRhDW.Repostory
     /// <summary>
     /// 分区表上下文(id为long)
     /// </summary>
-    public class RHDWPartContext : DbContext
+    public class RHDWPartContext : DbContextBase
     {
         private string DbFile;
         public static RHDWPartContext GetContext(string dbFile, bool createDb = false)
@@ -303,82 +414,7 @@ namespace XdCxRhDW.Repostory
             var dbFile = Database.Connection.ConnectionString.Replace("Data Source=", "").Replace("|DataDirectory|\\", "");
             this.DbFile = dbFile;
         }
-
-        public bool IsTableFieldSync()
-        {
-            bool val = true;
-            var tables = this.Database.SqlQuery<string>("select name from sqlite_master where type='table' and  name not like 'sqlite%'").ToList();
-            var props = this.GetType().GetProperties();
-            List<Type> entityTypes = new List<Type>();
-            foreach (var prop in props)
-            {
-                bool isDbSet = prop.PropertyType.IsGenericType && typeof(DbSet<>) == prop.PropertyType.GetGenericTypeDefinition();
-                if (isDbSet)
-                {
-                    var entityType = prop.PropertyType.GenericTypeArguments[0];
-                    entityTypes.Add(entityType);
-                }
-            }
-            foreach (var table in tables)
-            {
-                var res = this.Database.SqlQuery<DbTableColumnInfo>($"PRAGMA table_info([{table}])").ToList();
-                var entityType = entityTypes.FirstOrDefault(p => p.Name == table);
-                if (entityType == null) continue;
-                var entityProps = entityType.GetProperties().Where(p =>
-                    p.CanRead
-                    && p.CanWrite
-                    && !p.GetMethod.IsVirtual
-                    && p.GetCustomAttribute<NotMappedAttribute>() == null);
-                foreach (var prop in entityProps)
-                {
-                    var find = res.Find(p => p.name.ToLower() == prop.Name.ToLower());
-                    if (find == null)
-                    {
-                        string typeStr = "";
-                        var type = prop.PropertyType;
-                        if (prop.PropertyType.IsGenericType)
-                        {
-                            type = prop.PropertyType.GenericTypeArguments[0];
-                        }
-                        if (type == typeof(string))
-                        {
-                            typeStr = "nvarchar";
-                        }
-                        else if (type == typeof(int) || type == typeof(long) || prop.PropertyType.IsEnum)
-                        {
-                            typeStr = "int";
-                        }
-                        else if (type == typeof(double) || type == typeof(float))
-                        {
-                            typeStr = "float";
-                        }
-                        else if (type == typeof(DateTime))
-                        {
-                            typeStr = "datetime";
-                        }
-                        bool isNullable = prop.PropertyType.IsGenericType && prop.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>);
-
-                        string updateTableSql;
-                        if (isNullable)
-                            updateTableSql = $"alter table {table} add column {prop.Name} {typeStr}";
-                        else
-                        {
-                            if (typeStr == "int" || typeStr == "float")
-                                updateTableSql = $"alter table {table} add column {prop.Name} {typeStr} not null default 0";
-                            else if (typeStr == "nvarchar")
-                                updateTableSql = $"alter table {table} add column {prop.Name} {typeStr} not null default ''";
-                            else if (typeStr == "datetime")
-                                updateTableSql = $"alter table {table} add column {prop.Name} {typeStr} not null default '{DateTime.Now:yyyy-MM-dd HH:mm:ss}'";
-                            else
-                                updateTableSql = $"alter table {table} add column {prop.Name} {typeStr}";
-                        }
-                        this.Database.ExecuteSqlCommand(updateTableSql);
-                        val = false;
-                    }
-                }
-            }
-            return val;
-        }
+      
         protected override void OnModelCreating(DbModelBuilder modelBuilder)
         {
             this.Database.Log = msg =>

+ 68 - 45
XdCxRhDW.Repostory/XlRepository.cs

@@ -1,4 +1,5 @@
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Data.Entity;
 using System.IO;
@@ -21,7 +22,7 @@ namespace XdCxRhDW.Repostory
             {
                 using (RHDWContext db = new RHDWContext())
                 {
-                    var res = await db.XlInfos.OrderByDescending(p => p.TimeUTC).OrderByDescending(p => p.Lon).ToListAsync();
+                    var res = await db.XlInfos.OrderByDescending(p => p.TimeUTC).OrderByDescending(p => p.Lon).Take(5000).ToListAsync();
                     return res;
                 }
             }
@@ -31,66 +32,63 @@ namespace XdCxRhDW.Repostory
                 return null;
             }
         }
-        public static async Task<int> GetCount()
+        public static async Task<int> GetCount(int? satCode)
         {
             using (RHDWContext db = new RHDWContext())
             {
-               var count=await db.XlInfos.CountAsync();
-                return count;
+                if (satCode == null)
+                {
+                    var count = await db.XlInfos.CountAsync();
+                    return count;
+                }
+                else
+                {
+                    var count = await db.XlInfos.Where(w => w.SatCode == satCode).CountAsync();
+                    return count;
+                }
             }
         }
-        /// <summary>
-        /// 获取数据库所有双行根数
-        /// </summary>
-        /// <returns></returns>
-        public static async Task<List<XlInfo>> GetPageAsync(int currentPage,int pageSize)
+        public static async Task<List<SatInfo>> GetAllSat()
         {
-            string sql = @" SELECT t.*
-                                    FROM
-                                    (
-                                        SELECT COUNT(1) OVER () AS TotalRows,
-                                        ROW_NUMBER() OVER (ORDER BY c.Id) AS Rn,
-                                        c.*
-                                        FROM XlInfo c
-                                    ) t
-                                    WHERE t.Rn BETWEEN ((" + currentPage + " - 1) * " + pageSize + ") + 1 AND " + currentPage + " *  " + pageSize;
-            try
+            using (RHDWContext db = new RHDWContext())
             {
-                using (RHDWContext db = new RHDWContext())
+                string sql = "select * from XlInfo where id in (select max(id) maxid from xlinfo GROUP BY SatCode )";
+                var data = await db.Database.SqlQuery<XlInfo>(sql).ToListAsync();
+                var sats = data.Select(p => new SatInfo()
                 {
-                    var res = await db.XlInfos.SqlQuery(sql).ToListAsync();
-                    return res;
-                }
-            }
-            catch (Exception ex)
-            {
-                Serilog.Log.Error(ex, "加载星历信息异常");
-                return null;
+                    SatCode = p.SatCode,
+                    SatName = p.SatName,
+                    SatLon = p.Lon,
+                }).ToList();
+                return sats;
             }
         }
-
-
         /// <summary>
-        /// 获取某个星某个时刻最近的双行根(可能返回null)
+        /// 获取数据库所有双行根数
         /// </summary>
-        /// <param name="satCode">卫星编号</param>
-        /// <param name="sigTime">时刻</param>
         /// <returns></returns>
-        public static async Task<XlInfo> GetLatestAsync(int satCode, DateTime sigTime)
+        public static async Task<List<XlInfo>> GetPageAsync(int currentPage, int pageSize, int? satCode)
         {
-            var sql = $"SELECT min(abs(JULIANDAY(TimeUTC)-JULIANDAY('{sigTime:yyyy-MM-dd HH:mm:ss}')))" +
-                        $" as NearDaySpan,* FROM XlInfo where satcode={satCode}";
             try
             {
                 using (RHDWContext db = new RHDWContext())
                 {
-                    var res = await db.XlInfos.SqlQuery(sql).FirstOrDefaultAsync();
+                    var topNumber = (currentPage - 1) * pageSize;
+                    StringBuilder sb = new StringBuilder();
+                    sb.Append($"select * from xlinfo ");
+                    if (satCode != null)
+                    {
+                        sb.Append($"where SatCode={satCode} ");
+                    }
+                    sb.Append($"order by TimeUTC desc limit {pageSize} offset {topNumber}");
+                    string sql = sb.ToString();
+                    var res = await db.Database.SqlQuery<XlInfo>(sql).ToListAsync();
                     return res;
                 }
             }
             catch (Exception ex)
             {
-                Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{sigTime:yyyyMMddHHmmss}时刻附近的双行根数出错!Sql={sql}");
+                Serilog.Log.Error(ex, "加载星历信息异常");
                 return null;
             }
         }
@@ -101,21 +99,46 @@ namespace XdCxRhDW.Repostory
         /// <param name="satCode">卫星编号</param>
         /// <param name="sigTime">时刻</param>
         /// <returns></returns>
-        public static async Task<XlInfo> GetLatest2Async(int satCode, DateTime sigTime)
+        public static async Task<XlInfo> GetLatestAsync(int satCode, DateTime sigTime)
         {
-            var sql = $"SELECT min(abs(JULIANDAY(TimeUTC)-JULIANDAY('{sigTime:yyyy-MM-dd HH:mm:ss}')))" +
-                        $" as NearDaySpan,* FROM XlInfo where satcode={satCode}";
             try
             {
+                satCode = 40892;
+                sigTime = new DateTime(2024, 10, 09, 23, 59, 53);
+                //GetLatestAsync方法在索引列上使用了加减运算会导致索引失效,运算变慢,这个函数是对GetLatestAsyncOld的优化
+
+                //老的SQL很慢
+                //SELECT min(abs(JULIANDAY(TimeUTC)-JULIANDAY('2024-10-09 23:59:53'))) as NearDaySpan,* FROM XlInfo where satcode=40892
                 using (RHDWContext db = new RHDWContext())
                 {
-                    var res = await db.XlInfos.SqlQuery(sql).FirstOrDefaultAsync();
-                    return res;
+                    string sql = $"select * from XlInfo where SatCode={satCode} and TimeUTC>='{sigTime:yyyy-MM-dd HH:mm:ss}' order by TimeUTC limit 1";
+                    var max = await db.Database.SqlQuery<XlInfo>(sql).FirstOrDefaultAsync();
+
+                    sql = $"select * from XlInfo where SatCode={satCode} and TimeUTC<='{sigTime:yyyy-MM-dd HH:mm:ss}' order by TimeUTC desc limit 1";
+                    var min = await db.Database.SqlQuery<XlInfo>(sql).FirstOrDefaultAsync();
+
+                    if (max == null && min == null)
+                        return null;
+                    else if (max != null && min == null)
+                        return max;
+                    else if (max == null && min != null)
+                        return min;
+                    else
+                    {
+                        //谁离得更接近就用谁
+                        var val1 = Math.Abs((max.TimeUTC - sigTime).TotalSeconds);
+                        var val2 = Math.Abs((min.TimeUTC - sigTime).TotalSeconds);
+                        if (val1 < val2)
+                            return max;
+                        else
+                            return min;
+                    }
                 }
             }
-            catch
+            catch (Exception ex)
             {
-                throw new Exception($"获取双行根数出错.Sql={sql}");
+                Serilog.Log.Error(ex, $"获取卫星[{satCode}]--{sigTime:yyyyMMddHHmmss}时刻附近的双行根数出错!");
+                return null;
             }
         }
     }