Преглед на файлове

修改数据库查询和新增

wyq преди 1 година
родител
ревизия
51c66436c1

+ 19 - 18
XdCxRhDW.App/Controllers/PosController.cs

@@ -57,7 +57,7 @@ namespace XdCxRhDW.App.Controllers
                 }
             }
 
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -174,7 +174,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.MainCode}的ECEF星历出错.{ephMain.msg}");
                 return Error<PosResDto>($"推算卫星{dto.MainCode}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -283,7 +283,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -423,7 +423,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
                 return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -535,7 +535,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -670,7 +670,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
                 return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -780,7 +780,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -923,7 +923,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
                 return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1044,7 +1044,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1204,7 +1204,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.Adja2Code}的ECEF星历出错.{ephAdja2.msg}");
                 return Error<PosResDto>($"推算卫星{dto.Adja2Code}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1322,7 +1322,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1476,7 +1476,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.Adja2Code}的ECEF星历出错.{ephAdja2.msg}");
                 return Error<PosResDto>($"推算卫星{dto.Adja2Code}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1591,7 +1591,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1753,7 +1753,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.Adja2Code}的ECEF星历出错.{ephAdja2.msg}");
                 return Error<PosResDto>($"推算卫星{dto.Adja2Code}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -1875,7 +1875,7 @@ namespace XdCxRhDW.App.Controllers
                 }
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -2014,7 +2014,7 @@ namespace XdCxRhDW.App.Controllers
                 Serilog.Log.Error($"推算卫星{dto.AdjaCode}的ECEF星历出错.{ephAdja.msg}");
                 return Error<PosResDto>($"推算卫星{dto.AdjaCode}的ECEF星历出错");
             }
-            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime))
+            using (RHDWPartContext db = RHDWPartContext.GetContext(dto.SigTime,true))
             {
                 var StationRes = db.StationRes.Add(new StationRes()
                 {
@@ -2172,9 +2172,9 @@ namespace XdCxRhDW.App.Controllers
                 foreach (var item in list)
                 {
                     var dayFile = Path.Combine(dir, item);
-                    if (!File.Exists(dayFile)) continue;
                     using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
                     {
+                        if (!db.DatabaseExist) 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);
@@ -2239,9 +2239,9 @@ namespace XdCxRhDW.App.Controllers
                 foreach (var item in list)
                 {
                     var dayFile = Path.Combine(dir, item);
-                    if (!File.Exists(dayFile)) continue;
                     using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
                     {
+                        if (!db.DatabaseExist) 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);
@@ -2317,6 +2317,7 @@ namespace XdCxRhDW.App.Controllers
                     {
                         using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
                         {
+                            if (!db.DatabaseExist) continue;
                             var query = db.PosRes.Where(p => p.TaskInfoID == dto.TaskInfoID);
                             if (!dto.IncludeInvalidate)
                             {

+ 7 - 4
XdCxRhDW.App/EditForms/X1D1DTOParamEditor.cs

@@ -54,15 +54,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 listSat = await db.SatInfos.ToListAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {
@@ -137,7 +140,7 @@ namespace XdCxRhDW.App.EditForms
 
         private async void btnEphCalc_Click(object sender, EventArgs e)
         {
-            
+
             if (this.sigTime.DateTime == DateTime.MinValue)
             {
                 DxHelper.MsgBoxHelper.ShowWarning("信号时间不能为空!");

+ 8 - 5
XdCxRhDW.App/EditForms/X1D1PosParamEditor.cs

@@ -58,17 +58,20 @@ namespace XdCxRhDW.App.EditForms
         private async void X1D1DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
-            CxRes cx;
+            CxRes cx=null;
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
-                cx = await db.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                    cx = await db.CxRes.Where(m => m.ID == info.CxResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X2D1DTOParamEditor.cs

@@ -55,15 +55,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 listSat = await db.SatInfos.ToListAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X2D1PosParamEditor.cs

@@ -50,15 +50,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X2D1DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X2DTOParamEditor.cs

@@ -55,15 +55,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X2DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 listSat = await db.SatInfos.ToListAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X2PosParamEditor.cs

@@ -55,15 +55,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X2DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X3DTOParamEditor.cs

@@ -47,15 +47,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X3DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 listSat = await db.SatInfos.ToListAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X3DfoPosParamEditor.cs

@@ -49,15 +49,18 @@ namespace XdCxRhDW.App.EditForms
         private async void X3DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWContext db = new RHDWContext())
             {
                 settings = await db.SysSetings.FirstOrDefaultAsync();
             }
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 6 - 3
XdCxRhDW.App/EditForms/X3PosParamEditor.cs

@@ -44,11 +44,14 @@ namespace XdCxRhDW.App.EditForms
         private async void X3DTOParamEditor_Load(object sender, EventArgs e)
         {
 
-            StationRes station;
+            StationRes station=null;
             using (RHDWPartContext db = RHDWPartContext.GetContext(info.SigTime))
             {
-                cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
-                station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                if (db.DatabaseExist)
+                {
+                    cg = await db.CgRes.Where(m => m.ID == info.CgResID).FirstOrDefaultAsync();
+                    station = await db.StationRes.Where(m => m.ID == info.StationResID).FirstOrDefaultAsync();
+                }
             }
             if (cg != null)
             {

+ 18 - 11
XdCxRhDW.App/PopupControl/ShowCgCtrl.cs

@@ -30,7 +30,7 @@ namespace XdCxRhDW.App.PopupControl
         }
 
         public ShowCgCtrl(PosRes posItem)
-            :this()
+            : this()
         {
             this.posItem = posItem;
         }
@@ -44,6 +44,10 @@ namespace XdCxRhDW.App.PopupControl
             List<ModelCg> list = new List<ModelCg>();
             using (RHDWPartContext db = RHDWPartContext.GetContext(posItem.SigTime))
             {
+                if (!db.DatabaseExist)
+                {
+                    return;
+                }
                 var cgEntity = db.CgRes.Where(p => p.ID == posItem.CgResID).FirstOrDefault();
                 if (cgEntity == null) return;
 
@@ -98,7 +102,7 @@ namespace XdCxRhDW.App.PopupControl
                     list.Add(item);
                 }
                 //超短
-                if (cgEntity.DtoCdb!=null)
+                if (cgEntity.DtoCdb != null)
                 {
                     ModelCg item = new ModelCg()
                     {
@@ -132,16 +136,19 @@ namespace XdCxRhDW.App.PopupControl
             {
                 using (RHDWPartContext db = RHDWPartContext.GetContext(cgItem.SigTime))
                 {
-                    var data = await db.CgXgfRes.Where(p => p.CgResID == cgItem.ID && p.CgType == cgItem.CgType).ToListAsync();
-                    listXgf.AddRange(data.Select(p => new ModelCgXgf
+                    if (db.DatabaseExist)
                     {
-                        ID = p.ID,
-                        Dto = p.Dto,
-                        Dfo = p.Dfo,
-                        Snr = p.Snr,
-                        CreateTime = p.CreateTime,
-                        UpdateTime = p.UpdateTime,
-                    }));
+                        var data = await db.CgXgfRes.Where(p => p.CgResID == cgItem.ID && p.CgType == cgItem.CgType).ToListAsync();
+                        listXgf.AddRange(data.Select(p => new ModelCgXgf
+                        {
+                            ID = p.ID,
+                            Dto = p.Dto,
+                            Dfo = p.Dfo,
+                            Snr = p.Snr,
+                            CreateTime = p.CreateTime,
+                            UpdateTime = p.UpdateTime,
+                        }));
+                    }
                 }
                 //查询相关峰结果
             }

+ 5 - 2
XdCxRhDW.App/PopupControl/ShowCheckCtrl.cs

@@ -36,9 +36,12 @@ namespace XdCxRhDW.App.PopupControl
                 return;
             using (RHDWPartContext db = RHDWPartContext.GetContext(posItem.SigTime))
             {
-                var items =await db.CheckRes.Where(p => p.ID == posItem.CheckResID).ToListAsync();
+                if (db.DatabaseExist)
+                {
+                    var items = await db.CheckRes.Where(p => p.ID == posItem.CheckResID).ToListAsync();
 
-                this.list.AddRange(items);
+                    this.list.AddRange(items);
+                }
             }
             gridView1.RefreshData();
         }

+ 5 - 2
XdCxRhDW.App/PopupControl/ShowCxCtrl.cs

@@ -34,9 +34,12 @@ namespace XdCxRhDW.App.PopupControl
         {
             using (RHDWPartContext db = RHDWPartContext.GetContext(posItem.SigTime))
             {
-                var items =await db.CxRes.Where(p => p.ID == posItem.CxResID).ToListAsync();
+                if (db.DatabaseExist)
+                {
+                    var items = await db.CxRes.Where(p => p.ID == posItem.CxResID).ToListAsync();
 
-                this.list.AddRange(items);
+                    this.list.AddRange(items);
+                }
             }
             gridView1.RefreshData();
         }

+ 12 - 7
XdCxRhDW.App/UserControl/CtrlCgRes.cs

@@ -68,9 +68,12 @@ namespace XdCxRhDW.App.UserControl
                     var ids = groupItem.Select(m => m.ID).ToList();
                     using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
                     {
-                        List<CgRes> list = await db.CgRes.Where(p => ids.Contains(p.ID)).ToListAsync();
-                        db.CgRes.RemoveRange(list);
-                        await db.SaveChangesAsync();
+                        if (db.DatabaseExist)
+                        {
+                            List<CgRes> list = await db.CgRes.Where(p => ids.Contains(p.ID)).ToListAsync();
+                            db.CgRes.RemoveRange(list);
+                            await db.SaveChangesAsync();
+                        }
                     }
                 }
                 return true;
@@ -158,10 +161,9 @@ namespace XdCxRhDW.App.UserControl
                         var dayFiles = Directory.EnumerateFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, yearDir), "*.db").OrderByDescending(p => Convert.ToInt32(new DirectoryInfo(p).Name.Substring(0, 4)));
                         foreach (var dayFile in dayFiles)
                         {
-
-                            if (!File.Exists(dayFile)) continue;
                             using (RHDWPartContext db = RHDWPartContext.GetContext(dayFile))
                             {
+                                if (!db.DatabaseExist) continue;
                                 if (db.CgRes.Any(p => p.TaskID == ((TaskInfo)txtTask.EditValue).ID))
                                     end = await db.CgRes.Where(p => p.TaskID == ((TaskInfo)txtTask.EditValue).ID).MaxAsync(p => p.SigTime);
                             }
@@ -186,8 +188,11 @@ namespace XdCxRhDW.App.UserControl
                 {
                     using (RHDWPartContext db = RHDWPartContext.GetContext(endDay))
                     {
-                        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);
+                        if (db.DatabaseExist)
+                        {
+                            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);
+                        }
                     }
                     endDay = endDay.AddDays(-1);
                 }

+ 75 - 48
XdCxRhDW.App/UserControl/CtrlHome.cs

@@ -367,17 +367,20 @@ namespace XdCxRhDW.App.UserControl
             if (posItem == null) return;
             using (RHDWPartContext db = RHDWPartContext.GetContext(posItem.SigTime))
             {
-                var station = db.StationRes.Where(p => p.ID == posItem.StationResID).FirstOrDefault();
-                if (station != null)
+                if (db.DatabaseExist)
                 {
-                    mapControl1.DrawFixedImg("Tx", station.SatTxLat, station.SatTxLon, DxHelper.SvgHelper.CreateAnt(width: 16, height: 16), $"[卫星接收天线]\r\n经度:{station.SatTxLon}°\r\n纬度:{station.SatTxLat}°");
-                    if (station.CdbTxLon != null)
-                        mapControl1.DrawFixedImg("Tx", station.CdbTxLat.Value, station.CdbTxLon.Value, DxHelper.SvgHelper.CreateAnt(width: 16, height: 16), $"[超短接收天线]\r\n经度:{station.CdbTxLon.Value}°\r\n纬度:{station.CdbTxLat.Value}°");
-                    if (station.RefLon != null)
-                        mapControl1.DrawFixedImg("Tx", station.RefLat.Value, station.RefLon.Value, DxHelper.SvgHelper.CreatePentagram(width: 16, height: 16), $"[参考站]\r\n经度:{station.RefLon.Value}°\r\n纬度:{station.RefLat.Value}°");
-                    if (station.CxLon != null)
-                        mapControl1.DrawFixedImg("Tx", station.CxLat.Value, station.CxLon.Value, DxHelper.SvgHelper.CreatePentagram(width: 16, height: 16), $"[测向站]\r\n经度:{station.CxLon.Value}°\r\n纬度:{station.CxLat.Value}°");
+                    var station = db.StationRes.Where(p => p.ID == posItem.StationResID).FirstOrDefault();
+                    if (station != null)
+                    {
+                        mapControl1.DrawFixedImg("Tx", station.SatTxLat, station.SatTxLon, DxHelper.SvgHelper.CreateAnt(width: 16, height: 16), $"[卫星接收天线]\r\n经度:{station.SatTxLon}°\r\n纬度:{station.SatTxLat}°");
+                        if (station.CdbTxLon != null)
+                            mapControl1.DrawFixedImg("Tx", station.CdbTxLat.Value, station.CdbTxLon.Value, DxHelper.SvgHelper.CreateAnt(width: 16, height: 16), $"[超短接收天线]\r\n经度:{station.CdbTxLon.Value}°\r\n纬度:{station.CdbTxLat.Value}°");
+                        if (station.RefLon != null)
+                            mapControl1.DrawFixedImg("Tx", station.RefLat.Value, station.RefLon.Value, DxHelper.SvgHelper.CreatePentagram(width: 16, height: 16), $"[参考站]\r\n经度:{station.RefLon.Value}°\r\n纬度:{station.RefLat.Value}°");
+                        if (station.CxLon != null)
+                            mapControl1.DrawFixedImg("Tx", station.CxLat.Value, station.CxLon.Value, DxHelper.SvgHelper.CreatePentagram(width: 16, height: 16), $"[测向站]\r\n经度:{station.CxLon.Value}°\r\n纬度:{station.CxLat.Value}°");
 
+                    }
                 }
             }
         }
@@ -855,9 +858,12 @@ namespace XdCxRhDW.App.UserControl
                     var ids = groupItem.Select(m => m.ID).ToList();
                     using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
                     {
-                        var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
-                        db.PosRes.RemoveRange(array);
-                        await db.SaveChangesAsync();
+                        if (db.DatabaseExist)
+                        {
+                            var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
+                            db.PosRes.RemoveRange(array);
+                            await db.SaveChangesAsync();
+                        }
                     }
                 }
                 return true;
@@ -905,13 +911,16 @@ namespace XdCxRhDW.App.UserControl
                 case EnumPosResType.X2Dfo:
                     try
                     {
-                        StationRes station;
-                        CgRes cg;
+                        StationRes station=null;
+                        CgRes cg=null;
 
                         using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
                         {
-                            cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
-                            station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
+                            if (db.DatabaseExist)
+                            {
+                                cg = await db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefaultAsync();
+                                station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
+                            }
                         }
                         if (cg == null)
                         {
@@ -990,12 +999,15 @@ namespace XdCxRhDW.App.UserControl
         {
             try
             {
-                CxRes cx;
-                StationRes station;
+                CxRes cx=null;
+                StationRes station=null;
                 using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
                 {
-                    cx = await db.CxRes.Where(m => m.ID == item.CxResID.Value).FirstOrDefaultAsync();
-                    station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
+                    if (db.DatabaseExist)
+                    {
+                        cx = await db.CxRes.Where(m => m.ID == item.CxResID.Value).FirstOrDefaultAsync();
+                        station = await db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefaultAsync();
+                    }
                 }
                 if (cx == null)
                 {
@@ -1226,17 +1238,20 @@ namespace XdCxRhDW.App.UserControl
                     var ids = groupItem.Select(m => m.ID).ToList();
                     using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
                     {
-                        var tarItems = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
-                        tarItems.ForEach(t =>
+                        if (db.DatabaseExist)
                         {
-                            var repos = items.First(p => p.ID == t.ID);
-                            t.PosLon = repos.PosLon;
-                            t.PosLat = repos.PosLat;
-                            t.MirrLon = repos.MirrLon;
-                            t.MirrLat = repos.MirrLat;
-                        });
-                        db.PosRes.AddOrUpdate(tarItems);
-                        await db.SaveChangesAsync();
+                            var tarItems = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
+                            tarItems.ForEach(t =>
+                            {
+                                var repos = items.First(p => p.ID == t.ID);
+                                t.PosLon = repos.PosLon;
+                                t.PosLat = repos.PosLat;
+                                t.MirrLon = repos.MirrLon;
+                                t.MirrLat = repos.MirrLat;
+                            });
+                            db.PosRes.AddOrUpdate(tarItems);
+                            await db.SaveChangesAsync();
+                        }
                     }
                 }
                 //var posids = items.Select(s => s.ID);
@@ -1318,9 +1333,12 @@ namespace XdCxRhDW.App.UserControl
                 long? targetID = 0;
                 using (RHDWPartContext db = RHDWPartContext.GetContext(items.First().SigTime))
                 {
-                    var idRes = items.First().ID;
-                    var target = await db.PosRes.Where(p => p.ID == idRes).FirstOrDefaultAsync() as PosRes;
-                    targetID = target.TargetInfoID;
+                    if (db.DatabaseExist)
+                    {
+                        var idRes = items.First().ID;
+                        var target = await db.PosRes.Where(p => p.ID == idRes).FirstOrDefaultAsync() as PosRes;
+                        targetID = target.TargetInfoID;
+                    }
                 }
                 TargetInfo info = null;
                 if (targetID > 0)
@@ -1341,16 +1359,19 @@ namespace XdCxRhDW.App.UserControl
                     var ids = groupItems.Select(p => p.ID);
                     using (RHDWPartContext db = RHDWPartContext.GetContext(groupItems.First().SigTime))
                     {
-                        var tarItems = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
-                        tarItems.ForEach(t =>
+                        if (db.DatabaseExist)
                         {
-                            t.TargetInfoID = tar.ID;
-                            t.ColorKey = tar.TargeColor;
-                        });
-                        posResIdList.AddRange(tarItems.Select(s => s.ID));
-                        mapControl1.UpdatePosItem(tarItems);
-                        db.PosRes.AddOrUpdate(tarItems);
-                        await db.SaveChangesAsync();
+                            var tarItems = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
+                            tarItems.ForEach(t =>
+                            {
+                                t.TargetInfoID = tar.ID;
+                                t.ColorKey = tar.TargeColor;
+                            });
+                            posResIdList.AddRange(tarItems.Select(s => s.ID));
+                            mapControl1.UpdatePosItem(tarItems);
+                            db.PosRes.AddOrUpdate(tarItems);
+                            await db.SaveChangesAsync();
+                        }
                     }
                 }
                 var ds = this.gridHomePosRes.DataSource as List<ModelPosRes>;
@@ -1415,9 +1436,12 @@ namespace XdCxRhDW.App.UserControl
                     var ids = groupItem.Select(m => m.ID).ToList();
                     using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
                     {
-                        var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
-                        UseMirror(array);
-                        await db.SaveChangesAsync();
+                        if (db.DatabaseExist)
+                        {
+                            var array = await db.PosRes.Where(p => ids.Contains(p.ID)).ToArrayAsync();
+                            UseMirror(array);
+                            await db.SaveChangesAsync();
+                        }
                     }
                 }
                 UseMirror(items);
@@ -1450,9 +1474,12 @@ namespace XdCxRhDW.App.UserControl
                     var ids = groupItem.Select(m => m.ID).ToList();
                     using (RHDWPartContext db = RHDWPartContext.GetContext(groupItem.First().SigTime))
                     {
-                        var list = await db.PosRes.Where(p => ids.Contains(p.ID)).ToListAsync();
-                        db.PosRes.RemoveRange(list);
-                        await db.SaveChangesAsync();
+                        if (db.DatabaseExist)
+                        {
+                            var list = await db.PosRes.Where(p => ids.Contains(p.ID)).ToListAsync();
+                            db.PosRes.RemoveRange(list);
+                            await db.SaveChangesAsync();
+                        }
                     }
                 }
                 mapControl1.DelPosItem(items);

+ 18 - 14
XdCxRhDW.App/UserControl/X1D1GDOPParam.cs

@@ -45,20 +45,24 @@ namespace XdCxRhDW.App.UserControl
             PosResType = item.PosResType;
             using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
             {
-                var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
-                var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
-                if (station != null)
+                if (db.DatabaseExist)
                 {
-                    this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
-                    this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
-                    this.txtCXStation.Text = $"{station.CxLon},{station.CxLat}";
-                }
-
-                if (cg != null)
-                {
-                    var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
-                    ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
-
+                    var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
+                    var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
+
+                    if (station != null)
+                    {
+                        this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
+                        this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                        this.txtCXStation.Text = $"{station.CxLon},{station.CxLat}";
+                    }
+
+                    if (cg != null)
+                    {
+                        var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
+                        ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
+
+                    }
                 }
             }
 
@@ -104,7 +108,7 @@ namespace XdCxRhDW.App.UserControl
                 var cdb = new double[] { Model.StationLon, Model.StationLat, 0 };
                 var cx = new double[] { Model.StationLon, Model.StationLat, 0 };
                 var refstation = new double[] { Model.RefLon, Model.RefLat, 0 };
-                var  data = GdopHelper.Gdop1Sat1DByXyz(Model.EphMain, cdb, cx,
+                var data = GdopHelper.Gdop1Sat1DByXyz(Model.EphMain, cdb, cx,
                                  Model.DtousErr, Model.CXErr, Model.SatLocErr, refstation);
                 if (data == null)
                 {

+ 18 - 17
XdCxRhDW.App/UserControl/X2D1GDOPParam.cs

@@ -50,25 +50,26 @@ namespace XdCxRhDW.App.UserControl
           
             using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
             {
-
-                var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
-                var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
-                if (station != null)
+                if (db.DatabaseExist)
                 {
-                    this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
-                    this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
+                    var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
+                    if (station != null)
+                    {
+                        this.txtStationLocation1.Text = $"{station.CdbTxLon},{station.CdbTxLat}";
+                        this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    }
+
+                    if (cg != null)
+                    {
+                        var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
+                        ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
+
+                        var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
+                        ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
+
+                    }
                 }
-
-                if (cg != null)
-                {
-                    var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
-                    ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
-
-                    var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
-                    ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
-
-                }
-
             }
 
         }

+ 18 - 16
XdCxRhDW.App/UserControl/X2DFGDOPParam.cs

@@ -44,24 +44,26 @@ namespace XdCxRhDW.App.UserControl
             PosResType = item.PosResType;
             using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
             {
-                var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
-                var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
-                if (station != null)
+                if (db.DatabaseExist)
                 {
-                    this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
+                    var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
+                    if (station != null)
+                    {
+                        this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    }
+                    if (cg != null)
+                    {
+                        this.txtFu1.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
+                        this.txtFu2.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
+
+                        var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
+                        ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
+
+                        var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
+                        ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
+                    }
                 }
-                if (cg != null)
-                {
-                    this.txtFu1.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
-                    this.txtFu2.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
-
-                    var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
-                    ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
-
-                    var adjaEph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
-                    ucEphXYZAdja.SetParam($"邻星", cg.Adja1Code, adjaEph, Color.Black);
-                }
-
 
             }
 

+ 21 - 19
XdCxRhDW.App/UserControl/X3DFGDOPParam .cs

@@ -43,27 +43,29 @@ namespace XdCxRhDW.App.UserControl
             PosResType = item.PosResType;
             using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
             {
-                var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
-                var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
-                if (station != null)
+                if (db.DatabaseExist)
                 {
-                    this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
+                    var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
+                    if (station != null)
+                    {
+                        this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    }
+                    if (cg != null)
+                    {
+                        this.txtFu1.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
+                        this.txtFu2.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
+
+                        var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
+                        ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
+
+                        var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
+                        ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
+
+                        var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
+                        ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
+                    }
                 }
-                if (cg != null)
-                {
-                    this.txtFu1.EditValue = cg.TarFreqUp.HasValue ? cg.TarFreqUp.Value * 1e-6 : 950;
-                    this.txtFu2.EditValue = cg.RefFreqUp.HasValue ? cg.RefFreqUp.Value * 1e-6 : 950;
-
-                    var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
-                    ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
-
-                    var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
-                    ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
-
-                    var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
-                    ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
-                }
-
 
             }
         }

+ 19 - 16
XdCxRhDW.App/UserControl/X3GDOPParam.cs

@@ -44,23 +44,26 @@ namespace XdCxRhDW.App.UserControl
 
             using (RHDWPartContext db = RHDWPartContext.GetContext(item.SigTime))
             {
-                var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
-                var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
-                if (station != null)
+                if (db.DatabaseExist)
                 {
-                    this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
-                }
-                if (cg != null)
-                {
-
-                    var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
-                    ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
-
-                    var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
-                    ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
-
-                    var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
-                    ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
+                    var cg = db.CgRes.Where(m => m.ID == item.CgResID).FirstOrDefault();
+                    var station = db.StationRes.Where(m => m.ID == item.StationResID).FirstOrDefault();
+                    if (station != null)
+                    {
+                        this.txtRefLocation1.Text = $"{station.RefLon},{station.RefLat}";
+                    }
+                    if (cg != null)
+                    {
+
+                        var mainEph = (cg.MainX, cg.MainY, cg.MainZ, cg.MainVx, cg.MainVy, cg.MainVz);
+                        ucEphXYZMain.SetParam($"主星", cg.MainCode, mainEph, Color.Black);
+
+                        var adja1Eph = (cg.Adja1X, cg.Adja1Y, cg.Adja1Z, cg.Adja1Vx, cg.Adja1Vy, cg.Adja1Vz);
+                        ucEphXYZAdja1.SetParam($"邻星1", cg.Adja1Code, adja1Eph, Color.Black);
+
+                        var adja2Eph = (cg.Adja2X, cg.Adja2Y, cg.Adja2Z, cg.Adja2Vx, cg.Adja2Vy, cg.Adja2Vz);
+                        ucEphXYZAdja2.SetParam($"邻星2", cg.Adja2Code, adja2Eph, Color.Black);
+                    }
                 }
 
             }

+ 158 - 18
XdCxRhDW.Repostory/EFContext/RHDWContext.cs

@@ -1,19 +1,14 @@
-using System;
-using System.Collections.Generic;
+using SQLite.CodeFirst;
+using System;
+using System.Data.Common;
 using System.Data.Entity;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using SQLite.CodeFirst;
-using System.Data.Entity.ModelConfiguration.Conventions;
+using System.Data.Entity.Core.Common;
 using System.Data.Entity.Infrastructure.Interception;
-using System.IO;
-using System.Data.Common;
-using System.Data.Entity.Infrastructure;
-using System.Reflection;
-using System.Data.SQLite.EF6;
+using System.Data.Entity.ModelConfiguration.Conventions;
 using System.Data.SQLite;
-using System.Data.Entity.Core.Common;
+using System.Data.SQLite.EF6;
+using System.IO;
+using System.Text.RegularExpressions;
 using XdCxRhDW.Entity;
 
 namespace XdCxRhDW.Repostory
@@ -35,6 +30,7 @@ namespace XdCxRhDW.Repostory
             {
             };
             modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
+            //modelBuilder.Configurations.Add<RHDWContext>(new EntityTypeConfiguration<RHDWContext>());//new SqliteConfiguration()
             modelBuilder.Configurations.AddFromAssembly(typeof(RHDWContext).Assembly);//自动加载SqliteConfiguration
 
             var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<RHDWContext>(modelBuilder);
@@ -66,18 +62,27 @@ namespace XdCxRhDW.Repostory
     //[DbConfigurationType(typeof(SqliteConfiguration))]
     public class RHDWPartContext : DbContext
     {
+        public bool DatabaseExist = false;
         public static RHDWPartContext GetContext(string dbFile)
         {
             var connectionString = $@"Data Source={dbFile}";
             SQLiteConnection con = new SQLiteConnection(connectionString);
-            return new RHDWPartContext(con);
+            bool databaseExist = File.Exists(dbFile);
+            return new RHDWPartContext(con) { DatabaseExist = databaseExist };
         }
 
-        public static RHDWPartContext GetContext(DateTime partTime, string prefix = "")
+        public static RHDWPartContext GetContext(DateTime partTime, bool isCreateDb = false, string prefix = "")
         {
+            var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart");
+            var dayFile = Path.Combine(dir, $@"{partTime.Year}\{prefix}{partTime:MMdd}.db");
+            bool databaseExist = File.Exists(dayFile);
+            if (isCreateDb)
+            {
+                databaseExist = true;
+            }
             var connectionString = $@"Data Source=|DataDirectory|\DbPart\{partTime.Year}\{prefix}{partTime:MMdd}.db";
             SQLiteConnection con = new SQLiteConnection(connectionString);
-            return new RHDWPartContext(con);
+            return new RHDWPartContext(con) { DatabaseExist = databaseExist };
         }
 
         private RHDWPartContext(DbConnection con)
@@ -91,10 +96,10 @@ namespace XdCxRhDW.Repostory
             this.Database.Log = msg =>
             {
             };
-            
+
             modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
             modelBuilder.Configurations.AddFromAssembly(typeof(RHDWPartContext).Assembly);
-            var sqliteConnectionInitializer = new SqliteDropCreateDatabaseAlways<RHDWPartContext>(modelBuilder);
+            var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<RHDWPartContext>(modelBuilder);
             Database.SetInitializer(sqliteConnectionInitializer);
             DbInterception.Add(new SqliteInterceptor());//拦截器
             base.OnModelCreating(modelBuilder);
@@ -108,7 +113,135 @@ namespace XdCxRhDW.Repostory
         public DbSet<CheckRes> CheckRes { get; set; }
     }
 
+    /// <summary>
+    /// 分区表上下文(id为long)
+    /// </summary>
+    //[DbConfigurationType(typeof(SqliteConfiguration))]
+    public class RHDWPartReadContext : DbContext
+    {
+        public bool DatabaseExist = false;
+        private string dbFile;
+        public static RHDWPartReadContext GetContext(string dbFile)
+        {
+            var connectionString = $@"Data Source={dbFile}";
+            SQLiteConnection con = new SQLiteConnection(connectionString);
+            bool databaseExist = File.Exists(dbFile);
+            return new RHDWPartReadContext(con) { DatabaseExist = databaseExist, dbFile = dbFile };
+        }
 
+        public static RHDWPartReadContext GetContext(DateTime partTime, bool isCreateDb = false, string prefix = "")
+        {
+            var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DbPart");
+            var dayFile = Path.Combine(dir, $@"{partTime.Year}\{prefix}{partTime:MMdd}.db");
+            bool databaseExist = File.Exists(dayFile);
+            if (isCreateDb)
+            {
+                databaseExist = true;
+            }
+            var connectionString = $@"Data Source=|DataDirectory|\DbPart\{partTime.Year}\{prefix}{partTime:MMdd}.db";
+            SQLiteConnection con = new SQLiteConnection(connectionString);
+            return new RHDWPartReadContext(con) { DatabaseExist = databaseExist, dbFile= dayFile };
+        }
+
+        private RHDWPartReadContext(DbConnection con)
+        : base(con, true)
+        {
+        }
+
+
+        protected override void OnModelCreating(DbModelBuilder modelBuilder)
+        {
+            this.Database.Log = msg =>
+            {
+            };
+
+            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
+            modelBuilder.Configurations.AddFromAssembly(typeof(RHDWPartReadContext).Assembly);
+            Database.SetInitializer<RHDWPartReadContext>(null);
+            DbInterception.Add(new PartSqliteInterceptor(this.dbFile));//拦截器
+            base.OnModelCreating(modelBuilder);
+        }
+
+        public DbSet<StationRes> StationRes { get; set; }
+        public DbSet<CxRes> CxRes { get; set; }
+        public DbSet<CgRes> CgRes { get; set; }
+        public DbSet<CgXgfRes> CgXgfRes { get; set; }
+        public DbSet<PosRes> PosRes { get; set; }
+        public DbSet<CheckRes> CheckRes { get; set; }
+    }
+    /// <summary>
+    /// Sqlite拦截器.
+    /// contains或indexOf成的CHARINDEX函数在sqlite里面并不支持,需要拦截转换成LIKE语句
+    /// </summary>
+    public class PartSqliteInterceptor : IDbCommandInterceptor
+    {
+        private readonly string dbFile;
+        public PartSqliteInterceptor(string dbFile)
+        {
+            this.dbFile = dbFile;
+        }
+        private static Regex replaceRegex = new Regex(@"\(CHARINDEX\((.*?),\s?(.*?)\)\)\s*?>\s*?0");
+
+        public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
+        {
+        }
+
+        public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)
+        {
+        }
+
+        public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
+        {
+        }
+
+        public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
+        {
+            if (!File.Exists(dbFile))
+                interceptionContext.Result = null;
+            else
+                ReplaceCharIndexFunc(command);
+        }
+
+        public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
+        {
+        }
+
+        public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
+        {
+            if (!File.Exists(dbFile))
+                interceptionContext.Result = null;
+            else
+                ReplaceCharIndexFunc(command);
+        }
+
+        private void ReplaceCharIndexFunc(DbCommand command)
+        {
+            bool isMatch = false;
+            var text = replaceRegex.Replace(command.CommandText, (match) =>
+            {
+                if (match.Success)
+                {
+                    string paramsKey = match.Groups[1].Value;
+                    string paramsColumnName = match.Groups[2].Value;
+                    //replaceParams
+                    foreach (DbParameter param in command.Parameters)
+                    {
+                        if (param.ParameterName == paramsKey.Substring(1))
+                        {
+                            param.Value = string.Format("%{0}%", param.Value);
+                            break;
+                        }
+                    }
+                    isMatch = true;
+                    return string.Format("{0} LIKE {1}", paramsColumnName, paramsKey);
+                }
+                else
+                    return match.Value;
+            });
+            if (isMatch)
+                command.CommandText = text;
+        }
+    }
     public class SqliteConfiguration : DbConfiguration
     {
         public SqliteConfiguration()
@@ -119,4 +252,11 @@ namespace XdCxRhDW.Repostory
 
         }
     }
+    public class DbPartSqliteConfiguration : DbConfiguration
+    {
+        public DbPartSqliteConfiguration(IDbInterceptor dbInterceptor)
+        {
+            base.AddInterceptor(dbInterceptor);
+        }
+    }
 }