Commit c3b5e30a authored by 潘栩锋's avatar 潘栩锋 🚴

AD曲线界面 加载默认曲线

parent c6017f7e
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
</Page.Resources> </Page.Resources>
<Grid Background="{StaticResource Brushes.NoAct}"> <Grid Background="{StaticResource Brushes.Card.Background}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="90*" /> <ColumnDefinition Width="90*" />
<ColumnDefinition Width="500*" /> <ColumnDefinition Width="500*" />
......
...@@ -27,6 +27,7 @@ using System.Data; ...@@ -27,6 +27,7 @@ using System.Data;
using System.IO; using System.IO;
using Microsoft.Win32; using Microsoft.Win32;
using System.Threading.Tasks; using System.Threading.Tasks;
using FLY.Thick.Base.Server;
namespace FLY.Thick.Base.UI namespace FLY.Thick.Base.UI
{ {
...@@ -47,7 +48,7 @@ namespace FLY.Thick.Base.UI ...@@ -47,7 +48,7 @@ namespace FLY.Thick.Base.UI
System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea();
System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend();
System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series();
chart1.Name = "chart1"; chart1.Name = "chart1";
// //
// chart1 // chart1
...@@ -79,7 +80,7 @@ namespace FLY.Thick.Base.UI ...@@ -79,7 +80,7 @@ namespace FLY.Thick.Base.UI
legend1.Enabled = false; legend1.Enabled = false;
legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold); legend1.Font = new System.Drawing.Font("Trebuchet MS", 8.25F, System.Drawing.FontStyle.Bold);
legend1.IsTextAutoFit = false; legend1.IsTextAutoFit = false;
this.chart1.Legends.Add(legend1); this.chart1.Legends.Add(legend1);
//this.chart1.Location = new System.Drawing.Point(16, 32); //this.chart1.Location = new System.Drawing.Point(16, 32);
...@@ -92,12 +93,12 @@ namespace FLY.Thick.Base.UI ...@@ -92,12 +93,12 @@ namespace FLY.Thick.Base.UI
series1.Legend = "Default"; series1.Legend = "Default";
series1.MarkerSize = 8; series1.MarkerSize = 8;
series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle; series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle;
series1.ShadowColor = System.Drawing.Color.Black; series1.ShadowColor = System.Drawing.Color.Black;
series1.ShadowOffset = 2; series1.ShadowOffset = 2;
series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double; series1.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Double;
series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32; series1.YValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Int32;
this.chart1.Series.Add(series1); this.chart1.Series.Add(series1);
...@@ -107,7 +108,7 @@ namespace FLY.Thick.Base.UI ...@@ -107,7 +108,7 @@ namespace FLY.Thick.Base.UI
[InjectionMethod] [InjectionMethod]
public void Init(ICurveService curveService) public void Init(ICurveService curveService)
{ {
viewModel = new PgCurveVm(); viewModel = new PgCurveVm();
viewModel.Init(curveService, chart1, this); viewModel.Init(curveService, chart1, this);
...@@ -120,7 +121,7 @@ namespace FLY.Thick.Base.UI ...@@ -120,7 +121,7 @@ namespace FLY.Thick.Base.UI
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
#region 参数 #region 参数
/// <summary> /// <summary>
/// AD曲线校正方式 /// AD曲线校正方式
...@@ -136,7 +137,7 @@ namespace FLY.Thick.Base.UI ...@@ -136,7 +137,7 @@ namespace FLY.Thick.Base.UI
#endregion #endregion
#region Command #region Command
public RelayCommand ApplyCmd { get;} public RelayCommand ApplyCmd { get; }
public RelayCommand AdScaleCmd { get; } public RelayCommand AdScaleCmd { get; }
public RelayCommand ValueScaleCmd { get; } public RelayCommand ValueScaleCmd { get; }
public RelayCommand SetRevisedCmd { get; } public RelayCommand SetRevisedCmd { get; }
...@@ -148,7 +149,7 @@ namespace FLY.Thick.Base.UI ...@@ -148,7 +149,7 @@ namespace FLY.Thick.Base.UI
ICurveService mCurveService; ICurveService mCurveService;
System.Windows.Forms.DataVisualization.Charting.Chart chart1; System.Windows.Forms.DataVisualization.Charting.Chart chart1;
Page page; Page page;
public PgCurveVm() public PgCurveVm()
{ {
ApplyCmd = new RelayCommand(Apply); ApplyCmd = new RelayCommand(Apply);
AdScaleCmd = new RelayCommand(AdScale); AdScaleCmd = new RelayCommand(AdScale);
...@@ -171,8 +172,9 @@ namespace FLY.Thick.Base.UI ...@@ -171,8 +172,9 @@ namespace FLY.Thick.Base.UI
Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.CorrectWay), this, nameof(CorrectWay)); Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.CorrectWay), this, nameof(CorrectWay));
Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.Flag), this, nameof(Flag)); Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.Flag), this, nameof(Flag));
Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.Curves), ()=> { Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.Curves), () =>
update_curves(); {
update_curves();
}); });
this.PropertyChanged += PgCurveVm_PropertyChanged; this.PropertyChanged += PgCurveVm_PropertyChanged;
...@@ -180,14 +182,14 @@ namespace FLY.Thick.Base.UI ...@@ -180,14 +182,14 @@ namespace FLY.Thick.Base.UI
private void PgCurveVm_PropertyChanged(object sender, PropertyChangedEventArgs e) private void PgCurveVm_PropertyChanged(object sender, PropertyChangedEventArgs e)
{ {
if (e.PropertyName == nameof(Flag)) if (e.PropertyName == nameof(Flag))
{ {
DataBindAll(); DataBindAll();
} }
} }
void update_curves() void update_curves()
{ {
Curves.CollectionChanged -= Curves_CollectionChanged; Curves.CollectionChanged -= Curves_CollectionChanged;
Curves.Clear(); Curves.Clear();
...@@ -284,7 +286,7 @@ namespace FLY.Thick.Base.UI ...@@ -284,7 +286,7 @@ namespace FLY.Thick.Base.UI
FLY.ControlLibrary.Window_Tip.Show("应用成功", FLY.ControlLibrary.Window_Tip.Show("应用成功",
null, null,
TimeSpan.FromSeconds(2)); TimeSpan.FromSeconds(2));
} }
private void AdScale() private void AdScale()
{ {
...@@ -315,11 +317,21 @@ namespace FLY.Thick.Base.UI ...@@ -315,11 +317,21 @@ namespace FLY.Thick.Base.UI
private async void LoadXlsx() private async void LoadXlsx()
{ {
//加载数据 //加载数据
string strDesktopPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
//检查是否存在默认曲线,没有就新建
CreateDefaultCurve();
string dirPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "adcurve");
if (!Directory.Exists(dirPath))
{
//上面创建失败了。。。
dirPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
}
OpenFileDialog sfd = new OpenFileDialog(); OpenFileDialog sfd = new OpenFileDialog();
sfd.Filter = "xlsx files (*.xlsx)|*.xlsx"; sfd.Filter = "xlsx files (*.xlsx)|*.xlsx";
sfd.InitialDirectory = strDesktopPath; sfd.InitialDirectory = dirPath;
if (sfd.ShowDialog() == true) if (sfd.ShowDialog() == true)
{ {
...@@ -372,7 +384,7 @@ namespace FLY.Thick.Base.UI ...@@ -372,7 +384,7 @@ namespace FLY.Thick.Base.UI
} }
page.Dispatcher.Invoke(() => page.Dispatcher.Invoke(() =>
{ {
Curves.CollectionChanged -= Curves_CollectionChanged; Curves.CollectionChanged -= Curves_CollectionChanged;
...@@ -478,7 +490,7 @@ namespace FLY.Thick.Base.UI ...@@ -478,7 +490,7 @@ namespace FLY.Thick.Base.UI
{ {
SaveToXlsx(filename); SaveToXlsx(filename);
}); });
FLY.ControlLibrary.Window_Tip.Show("成功", $"导出到{filename}", TimeSpan.FromSeconds(2)); FLY.ControlLibrary.Window_Tip.Show("成功", $"导出到{filename}", TimeSpan.FromSeconds(2));
} }
} }
...@@ -516,7 +528,7 @@ namespace FLY.Thick.Base.UI ...@@ -516,7 +528,7 @@ namespace FLY.Thick.Base.UI
sheet = p.Workbook.Worksheets.Add("辅助信息"); sheet = p.Workbook.Worksheets.Add("辅助信息");
dataTable = new DataTable("table_info"); dataTable = new DataTable("table_info");
dataTable.Columns.Add(new DataColumn() { ColumnName = "曲线类型", DataType = typeof(string)}); dataTable.Columns.Add(new DataColumn() { ColumnName = "曲线类型", DataType = typeof(string) });
dataTable.Columns.Add(new DataColumn() { ColumnName = "校正方式", DataType = typeof(string) }); dataTable.Columns.Add(new DataColumn() { ColumnName = "校正方式", DataType = typeof(string) });
{ {
var dataRow = dataTable.NewRow(); var dataRow = dataTable.NewRow();
...@@ -567,7 +579,8 @@ namespace FLY.Thick.Base.UI ...@@ -567,7 +579,8 @@ namespace FLY.Thick.Base.UI
private void SetRevised() private void SetRevised()
{ {
if (mCurveService.Curves != null) { if (mCurveService.Curves != null)
{
Curves.CollectionChanged -= Curves_CollectionChanged; Curves.CollectionChanged -= Curves_CollectionChanged;
Curves.Clear(); Curves.Clear();
...@@ -609,5 +622,169 @@ namespace FLY.Thick.Base.UI ...@@ -609,5 +622,169 @@ namespace FLY.Thick.Base.UI
} }
} }
} }
CurveCollectionJsonDb curve_k85 = new CurveCollectionJsonDb()
{
Curves = new CurveCell2[] {
new CurveCell2() { AD = 58790, Value = 0 },
new CurveCell2() { AD = 39460, Value = 238.38 },
new CurveCell2() { AD = 39070, Value = 244.88 },
new CurveCell2() { AD = 38450, Value = 255.48 },
new CurveCell2() { AD = 37920, Value = 263.08 },
new CurveCell2() { AD = 37436, Value = 270.68 },
new CurveCell2() { AD = 36990, Value = 281.98 },
new CurveCell2() { AD = 36527, Value = 287.08 },
new CurveCell2() { AD = 35892, Value = 296.28 },
new CurveCell2() { AD = 35622, Value = 305.88 },
new CurveCell2() { AD = 35222, Value = 311.58 },
new CurveCell2() { AD = 34552, Value = 321.58 },
new CurveCell2() { AD = 35655, Value = 300.58 },
new CurveCell2() { AD = 34812, Value = 316.78 },
new CurveCell2() { AD = 33700, Value = 335.18 },
new CurveCell2() { AD = 32824, Value = 351.38 },
new CurveCell2() { AD = 31785, Value = 370.78 },
new CurveCell2() { AD = 30896, Value = 386.58 },
new CurveCell2() { AD = 30130, Value = 403.88 },
new CurveCell2() { AD = 29022, Value = 422.48 },
new CurveCell2() { AD = 28520, Value = 433.18 },
new CurveCell2() { AD = 27696, Value = 455.58 }
},
CorrectWay = CurveCorrectWay.OnePointIsScale,
Flag = CurveType.E
};
CurveCollectionJsonDb curve_4k = new CurveCollectionJsonDb()
{
Curves = new CurveCell2[] {
new CurveCell2() { AD = 50300 , Value = 0 },
new CurveCell2() { AD = 46505 , Value = 19 },
new CurveCell2() { AD = 42999 , Value = 38 },
new CurveCell2() { AD = 39698 , Value = 58 },
new CurveCell2() { AD = 36646 , Value = 78 },
new CurveCell2() { AD = 33894 , Value = 98 },
new CurveCell2() { AD = 31229 , Value = 118 },
new CurveCell2() { AD = 28934 , Value = 137 },
new CurveCell2() { AD = 26818 , Value = 156 },
new CurveCell2() { AD = 24908 , Value = 175 },
new CurveCell2() { AD = 23220 , Value = 194 },
new CurveCell2() { AD = 21558 , Value = 213 },
new CurveCell2() { AD = 20057 , Value = 232 },
new CurveCell2() { AD = 18606 , Value = 251 },
new CurveCell2() { AD = 17283 , Value = 271 },
new CurveCell2() { AD = 16035 , Value = 290 }
},
CorrectWay = CurveCorrectWay.OnePointIsScale,
Flag = CurveType.E
};
CurveCollectionJsonDb curve_20k = new CurveCollectionJsonDb()
{
Curves = new CurveCell2[] {
new CurveCell2() { AD = 59297 , Value = 0 },
new CurveCell2() { AD = 22988 , Value = 153.52 },
new CurveCell2() { AD = 22032 , Value = 160.32 },
new CurveCell2() { AD = 20822 , Value = 167.92 },
new CurveCell2() { AD = 19570 , Value = 177.62 },
new CurveCell2() { AD = 17811 , Value = 192.72 },
new CurveCell2() { AD = 16857 , Value = 202.42 },
new CurveCell2() { AD = 16193 , Value = 209.62 },
new CurveCell2() { AD = 15120 , Value = 218.52 },
new CurveCell2() { AD = 14609 , Value = 227.32 },
new CurveCell2() { AD = 13917 , Value = 233.62 },
new CurveCell2() { AD = 11142 , Value = 275.62 },
new CurveCell2() { AD = 10284 , Value = 291.52 },
new CurveCell2() { AD = 9196 , Value = 308.12 },
new CurveCell2() { AD = 8690 , Value = 319.92 },
new CurveCell2() { AD = 8007 , Value = 334.72 },
new CurveCell2() { AD = 7291 , Value = 353.02 },
new CurveCell2() { AD = 6743 , Value = 368.32 },
new CurveCell2() { AD = 6224 , Value = 386.32 },
new CurveCell2() { AD = 5616 , Value = 402.72 },
new CurveCell2() { AD = 5331 , Value = 417.02 },
new CurveCell2() { AD = 4982 , Value = 433.12 }
},
CorrectWay = CurveCorrectWay.OnePointIsScale,
Flag = CurveType.E
};
CurveCollectionJsonDb curve_laser = new CurveCollectionJsonDb()
{
Curves = new CurveCell2[] {
new CurveCell2() { AD = 22130 , Value = 186.00 },
new CurveCell2() { AD = 36774 , Value = 672.00 }
},
CorrectWay = CurveCorrectWay.OnePointIsOffset,
Flag = CurveType.Line
};
private void SaveToXlsx(string filepath, CurveCollectionJsonDb curve)
{
if (File.Exists(filepath))
{
File.Delete(filepath);
}
using (ExcelPackage p = new ExcelPackage(new FileInfo(filepath)))
{
ExcelWorksheet sheet = p.Workbook.Worksheets.Add("AD曲线");
DataTable dataTable = new DataTable("table_curve");
dataTable.Columns.Add(new DataColumn() { ColumnName = "AD", DataType = typeof(double), Caption = "0" });
dataTable.Columns.Add(new DataColumn() { ColumnName = "VALUE", DataType = typeof(double), Caption = "0.00" });
for (int i = 0; i < curve.Curves.Count(); i++)
{
try
{
var dataRow = dataTable.NewRow();
dataRow["AD"] = curve.Curves[i].AD;
dataRow["VALUE"] = curve.Curves[i].Value;
dataTable.Rows.Add(dataRow);
}
catch
{
break;
}
}
ToSheet(sheet, dataTable);
sheet = p.Workbook.Worksheets.Add("辅助信息");
dataTable = new DataTable("table_info");
dataTable.Columns.Add(new DataColumn() { ColumnName = "曲线类型", DataType = typeof(string) });
dataTable.Columns.Add(new DataColumn() { ColumnName = "校正方式", DataType = typeof(string) });
{
var dataRow = dataTable.NewRow();
dataRow["曲线类型"] = curve.Flag.ToString();
dataRow["校正方式"] = curve.CorrectWay.ToString();
dataTable.Rows.Add(dataRow);
}
ToSheet(sheet, dataTable);
p.Save();
}
}
private void CreateDefaultCurve()
{
Dictionary<string, CurveCollectionJsonDb> defaultCurve = new Dictionary<string, CurveCollectionJsonDb>();
string dirPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "adcurve");
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
defaultCurve.Add(System.IO.Path.Combine(dirPath, "K85.xlsx"), curve_k85);
defaultCurve.Add(System.IO.Path.Combine(dirPath, "X光4K.xlsx"), curve_4k);
defaultCurve.Add(System.IO.Path.Combine(dirPath, "X光20K.xlsx"), curve_20k);
defaultCurve.Add(System.IO.Path.Combine(dirPath, "激光.xlsx"), curve_laser);
foreach (var kv in defaultCurve) {
string filepath = kv.Key;
if(!File.Exists(filepath))
SaveToXlsx(filepath, defaultCurve[filepath]);
}
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment