|
@@ -5,15 +5,24 @@ using System.Data;
|
|
|
using System.Linq;
|
|
|
using System.Threading.Tasks;
|
|
|
using System.Windows.Forms;
|
|
|
+using DevExpress.XtraBars.Customization;
|
|
|
using DW5S.App.EditForms;
|
|
|
using DW5S.Entity;
|
|
|
using DW5S.Repostory;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
|
|
|
namespace DW5S.App.UserControl
|
|
|
{
|
|
|
public partial class CtrlFixedStation : DevExpress.XtraEditors.XtraUserControl
|
|
|
{
|
|
|
+ [Autowired]
|
|
|
+ private readonly ILogger logger;
|
|
|
+
|
|
|
+ [Autowired]
|
|
|
+ private readonly UnitOfWork unitOfWork;
|
|
|
+
|
|
|
readonly List<FixedStation> list = new List<FixedStation>();
|
|
|
+
|
|
|
public CtrlFixedStation()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -26,15 +35,13 @@ namespace DW5S.App.UserControl
|
|
|
.UseAddAsync(Add)
|
|
|
.UseEditAsync<FixedStation>(Edit)
|
|
|
.UseDeleteAsync<FixedStation>(Delete).SetDisplayText(nameof(FixedStation.Value), val => $"{val}秒");
|
|
|
- using (var db = new RHDWContext())
|
|
|
- {
|
|
|
- var items = await db.FixedStation.OrderBy(p => p.StationName).ToListAsync();
|
|
|
- list.AddRange(items);
|
|
|
- }
|
|
|
+ var repsFix = unitOfWork.Of<FixedStation>();
|
|
|
+ var items = await repsFix.GetAllAsync(p => p.StationName);
|
|
|
+ list.AddRange(items);
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- DW5S.Framework.LogHelper.Error("查询固定站信息异常", ex);
|
|
|
+ logger.LogError(ex, "查询固定站信息异常");
|
|
|
DxHelper.MsgBoxHelper.ShowError("查询固定站信息异常");
|
|
|
}
|
|
|
}
|
|
@@ -46,16 +53,14 @@ namespace DW5S.App.UserControl
|
|
|
FixedStationEditor frm = new FixedStationEditor();
|
|
|
if (frm.ShowDialog() != DialogResult.OK) return null;
|
|
|
var addItem = frm.info;
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- db.FixedStation.Add(addItem);
|
|
|
- await db.SaveChangesAsync();
|
|
|
- }
|
|
|
+ var repsFix = unitOfWork.Of<FixedStation>();
|
|
|
+ await repsFix.AddOrUpdateAsync(addItem);
|
|
|
+ await unitOfWork.SaveAsync();
|
|
|
return addItem;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- DW5S.Framework.LogHelper.Error("添加卫星信息异常", ex);
|
|
|
+ logger.LogError(ex,"添加卫星信息异常");
|
|
|
DxHelper.MsgBoxHelper.ShowError("添加卫星信息异常");
|
|
|
return null;
|
|
|
}
|
|
@@ -68,23 +73,23 @@ namespace DW5S.App.UserControl
|
|
|
FixedStationEditor frm = new FixedStationEditor(editItem);
|
|
|
if (frm.ShowDialog() != DialogResult.OK) return null;
|
|
|
editItem = frm.info;
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- var find = await db.FixedStation.Where(p => p.ID == editItem.ID).FirstOrDefaultAsync();
|
|
|
- find.StationName = editItem.StationName;
|
|
|
- find.FreqUpHz = editItem.FreqUpHz;
|
|
|
- find.Lon = editItem.Lon;
|
|
|
- find.Lat = editItem.Lat;
|
|
|
- find.Value = editItem.Value;
|
|
|
- find.Enable = editItem.Enable;
|
|
|
- find.UpdateTime = DateTime.Now;
|
|
|
- await db.SaveChangesAsync();
|
|
|
- }
|
|
|
+ var repsFix = unitOfWork.Of<FixedStation>();
|
|
|
+
|
|
|
+ var find = (await repsFix.FirstOrDefaultAsync(p => p.Id == editItem.Id));
|
|
|
+ find.StationName = editItem.StationName;
|
|
|
+ find.FreqUpHz = editItem.FreqUpHz;
|
|
|
+ find.Lon = editItem.Lon;
|
|
|
+ find.Lat = editItem.Lat;
|
|
|
+ find.Value = editItem.Value;
|
|
|
+ find.Enable = editItem.Enable;
|
|
|
+ find.UpdateTime = DateTime.Now;
|
|
|
+ await repsFix.AddOrUpdateAsync(find);
|
|
|
+ await unitOfWork.SaveAsync();
|
|
|
return editItem;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- DW5S.Framework.LogHelper.Error("保存固定站信息异常", ex);
|
|
|
+ logger.LogError(ex,"保存固定站信息异常");
|
|
|
DxHelper.MsgBoxHelper.ShowError("保存固定站信息异常");
|
|
|
return null;
|
|
|
}
|
|
@@ -94,18 +99,15 @@ namespace DW5S.App.UserControl
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
- var ids = list.Select(p => p.ID);
|
|
|
- using (RHDWContext db = new RHDWContext())
|
|
|
- {
|
|
|
- var delItems = await db.SatInfos.Where(p => ids.Contains(p.ID)).ToListAsync();
|
|
|
- db.SatInfos.RemoveRange(delItems);
|
|
|
- await db.SaveChangesAsync();
|
|
|
- }
|
|
|
+ var ids = list.Select(p => p.Id);
|
|
|
+ var repsSat = unitOfWork.Of<SatInfo>();
|
|
|
+ await repsSat.DeleteAsync(p => ids.Contains(p.Id));
|
|
|
+ await unitOfWork.SaveAsync();
|
|
|
return true;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
- DW5S.Framework.LogHelper.Error("删除卫星信息异常", ex);
|
|
|
+ logger.LogError(ex,"删除卫星信息异常");
|
|
|
DxHelper.MsgBoxHelper.ShowError("删除卫星信息异常");
|
|
|
return false;
|
|
|
}
|