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

AD曲线界面 加载默认曲线

parent c6017f7e
......@@ -14,7 +14,7 @@
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Page.Resources>
<Grid Background="{StaticResource Brushes.NoAct}">
<Grid Background="{StaticResource Brushes.Card.Background}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="90*" />
<ColumnDefinition Width="500*" />
......
......@@ -27,6 +27,7 @@ using System.Data;
using System.IO;
using Microsoft.Win32;
using System.Threading.Tasks;
using FLY.Thick.Base.Server;
namespace FLY.Thick.Base.UI
{
......@@ -136,7 +137,7 @@ namespace FLY.Thick.Base.UI
#endregion
#region Command
public RelayCommand ApplyCmd { get;}
public RelayCommand ApplyCmd { get; }
public RelayCommand AdScaleCmd { get; }
public RelayCommand ValueScaleCmd { get; }
public RelayCommand SetRevisedCmd { get; }
......@@ -171,7 +172,8 @@ namespace FLY.Thick.Base.UI
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.Curves), ()=> {
Misc.BindingOperations.SetBinding(mCurveService, nameof(mCurveService.Curves), () =>
{
update_curves();
});
......@@ -315,11 +317,21 @@ namespace FLY.Thick.Base.UI
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();
sfd.Filter = "xlsx files (*.xlsx)|*.xlsx";
sfd.InitialDirectory = strDesktopPath;
sfd.InitialDirectory = dirPath;
if (sfd.ShowDialog() == true)
{
......@@ -516,7 +528,7 @@ namespace FLY.Thick.Base.UI
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) });
dataTable.Columns.Add(new DataColumn() { ColumnName = "校正方式", DataType = typeof(string) });
{
var dataRow = dataTable.NewRow();
......@@ -567,7 +579,8 @@ namespace FLY.Thick.Base.UI
private void SetRevised()
{
if (mCurveService.Curves != null) {
if (mCurveService.Curves != null)
{
Curves.CollectionChanged -= Curves_CollectionChanged;
Curves.Clear();
......@@ -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