You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
952 lines
35 KiB
952 lines
35 KiB
using System.ComponentModel; |
|
using System.Data; |
|
using System.IO; |
|
using System.Reflection; |
|
using System.Windows; |
|
using System.Windows.Forms; |
|
using System.Windows.Input; |
|
using HandyControl.Controls; |
|
using Newtonsoft.Json; |
|
using SparkClient.Model.Entity.ApiEntity; |
|
using SparkClient.Model.Helper; |
|
using SparkClient.Views.UserControl.ViewportData; |
|
using Microsoft.Win32; |
|
using SaveFileDialog = Microsoft.Win32.SaveFileDialog; |
|
using NPOI.SS.UserModel; |
|
using NPOI.XSSF.UserModel; |
|
using SparkClient.Views.Dialog; |
|
using NPOI.HPSF; |
|
namespace SparkClient.ViewModel.Grading; |
|
|
|
public class GradingResultVM : BaseViewModel |
|
{ |
|
private string DiamondCode { get; set; } |
|
private List<DataInfo> _dtResults; |
|
// ViewportData |
|
private DataTable _dsList; |
|
private DataTable _gradeList; |
|
private ViewportData _viewportData; |
|
|
|
private string _standard; |
|
private string _shape; |
|
private string _crownType; |
|
private string _pavType; |
|
private string _wight; |
|
private string _cutLevelTotal; |
|
private string _symLevelTotal; |
|
private string _ds; |
|
public ICommand SaveFileCommand { get; } |
|
public ICommand SaveAsCommand { get; } |
|
public List<DataInfo> DtResults { get { return _dtResults; } set { _dtResults = value; OnPropertyChanged(nameof(DtResults)); } } |
|
public ViewportData ViewportData { get { return _viewportData; } set { _viewportData = value; OnPropertyChanged(nameof(ViewportData)); } } |
|
public string Standard { get { return _standard; } set { _standard = value; OnPropertyChanged(nameof(Standard)); } } |
|
public string Shape { get { return _shape; } set { _shape = value; OnPropertyChanged(nameof(Shape)); } } |
|
public string CrownType { get { return _crownType; } set { _crownType = value; OnPropertyChanged(nameof(CrownType)); } } |
|
public string PavType { get { return _pavType; } set { _pavType = value; OnPropertyChanged(nameof(PavType)); } } |
|
public string Wight { get { return _wight; } set { _wight = value; OnPropertyChanged(nameof(Wight)); } } |
|
public string CutLevelTotal { get { return _cutLevelTotal; } set { _cutLevelTotal = value; OnPropertyChanged(nameof(CutLevelTotal)); } } |
|
public string SymLevelTotal { get { return _symLevelTotal; } set { _symLevelTotal = value; OnPropertyChanged(nameof(SymLevelTotal)); } } |
|
public DataTable DSList { get { return _dsList; } set { _dsList = value; OnPropertyChanged(nameof(DSList)); } } |
|
public string DS { get { return _ds; } set { _ds = value; OnPropertyChanged(nameof(DS)); } } |
|
public DataTable GradeList { get { return _gradeList; } set { _gradeList = value; OnPropertyChanged(nameof(GradeList)); } } |
|
|
|
private readonly static string digitsFormat = "f1"; |
|
|
|
private int totalCutGrade = 0; |
|
private int totalSymGrade = 0; |
|
private AlgorithmResultEntity algorithmResult; |
|
private string username = "Lavanda"; |
|
private string machine = "71953"; |
|
/// <summary> |
|
/// 构造 |
|
/// </summary> |
|
/// <param name="result">检测结果</param> |
|
public GradingResultVM(object result) |
|
{ |
|
SaveAsCommand = new RelayCommand(SaveAs); |
|
SaveFileCommand = new RelayCommand(SaveFile); |
|
if (result != null) |
|
{ |
|
algorithmResult = result as AlgorithmResultEntity?? new AlgorithmResultEntity(); |
|
InitView(algorithmResult); |
|
machine = "71953"; |
|
} |
|
InitCombobox(); |
|
DS = "NA"; |
|
AutoSave(); |
|
} |
|
|
|
#region 画面初始化相关操作 |
|
private void InitCombobox() |
|
{ |
|
// DS下拉列表初始化 |
|
InitDSlist(); |
|
// 等级下拉列表初始化 |
|
InitGradeList(); |
|
} |
|
private void InitDSlist() |
|
{ |
|
DSList = new DataTable(); |
|
DSList.Columns.Add("Key"); |
|
DSList.Columns.Add("Value"); |
|
DSList.Rows.Add("NA", "NA"); |
|
DSList.Rows.Add("pass", "pass"); |
|
DSList.Rows.Add("refer", "refer"); |
|
} |
|
private void InitGradeList() |
|
{ |
|
GradeList = new DataTable(); |
|
GradeList.Columns.Add("Key"); |
|
GradeList.Columns.Add("Value"); |
|
GradeList.Rows.Add("极好", "Exc"); |
|
GradeList.Rows.Add("很好", "VG"); |
|
GradeList.Rows.Add("好", "G"); |
|
GradeList.Rows.Add("一般", "F"); |
|
GradeList.Rows.Add("差", "P"); |
|
} |
|
private void InitView(AlgorithmResultEntity result) |
|
{ |
|
string data = JsonConvert.SerializeObject(result); |
|
ViewportData = new ViewportData(result.DiamondCode, data); |
|
ViewportData.LoadData(); |
|
totalCutGrade = 0; |
|
totalSymGrade = 0; |
|
Standard = result.Standard; |
|
Shape = result.Shape; |
|
CrownType = result.CrownType; |
|
PavType = result.PavType; |
|
DiamondCode = result.DiamondCode; |
|
CalWight(result); |
|
DtResults = new List<DataInfo>(); |
|
var testItemList = GetTestItemList(); |
|
Type type = this.GetType(); |
|
foreach (var testItem in testItemList) |
|
{ |
|
string methodName = "get" + testItem; |
|
MethodInfo? methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic); |
|
if (methodInfo != null) |
|
{ |
|
object[] parameters = new object[] { result }; |
|
DataInfo? dataInfo = methodInfo.Invoke(this, parameters) as DataInfo; |
|
if (dataInfo != null) |
|
{ |
|
DtResults.Add(dataInfo); |
|
} |
|
} |
|
} |
|
CutLevelTotal = GetGradeName(totalCutGrade); |
|
} |
|
#endregion |
|
/// <summary> |
|
/// 参数列表测试内容获取 |
|
/// </summary> |
|
/// <returns></returns> |
|
private List<string> GetTestItemList() |
|
{ |
|
// DB 没关联 |
|
List<string> list = new List<string>(); |
|
list.Add("DIAMETER"); |
|
list.Add("TOTAL_DEPTH"); |
|
list.Add("TABLE"); |
|
list.Add("CROWN_ANGLE"); |
|
list.Add("CROWN_HEIGHT"); |
|
list.Add("GIRDLE_BEZEL"); |
|
list.Add("GIRDLE_BONE"); |
|
list.Add("GIRDLE"); |
|
list.Add("PAV_ANGLE"); |
|
list.Add("PAV_DEPTH"); |
|
list.Add("STAR"); |
|
list.Add("LOWER_HALVES_RATIO"); |
|
list.Add("CULET"); |
|
list.Add("TOC"); |
|
list.Add("COC"); |
|
list.Add("TWIST"); |
|
list.Add("CULET_TO_TABLE"); |
|
return list; |
|
} |
|
#region 定级计算 |
|
private List<CalGradeInfo> GetCalGradeInfos(string item) |
|
{ |
|
// TODO DB要改 |
|
string sql = $"Select GRADE_ID as gradeOrder,STANDARD_MIN Min, STANDARD_MAX Max,IS_MAX_EXIST as isMaxExist,IS_MIN_EXIST as isMinExist from STANDARD where STANDARD_ID = '{item}'"; |
|
List<CalGradeInfo> calGrades = DataBaseHelper.ExecuteQuery<CalGradeInfo>(sql); |
|
return calGrades; |
|
} |
|
private int calGrade(string item ,double value) |
|
{ |
|
int order = 1; |
|
decimal cValue = Convert.ToDecimal(value); |
|
List<CalGradeInfo> calGrades = GetCalGradeInfos(item); |
|
foreach (CalGradeInfo gradeInfo in calGrades) |
|
{ |
|
bool isThisGrade = true; |
|
|
|
if (gradeInfo.Max!= null) { |
|
if ( gradeInfo.isMaxExist == 1 && cValue.CompareTo(gradeInfo.Max)<=0) |
|
{ |
|
}else if(gradeInfo.isMaxExist == 0 && cValue.CompareTo(gradeInfo.Max) < 0) |
|
{ |
|
} |
|
else |
|
{ |
|
isThisGrade = false; |
|
} |
|
} |
|
if (gradeInfo.Min != null) |
|
{ |
|
if (gradeInfo.isMinExist == 1 && cValue.CompareTo(gradeInfo.Min) >= 0) |
|
{ |
|
} |
|
else if (gradeInfo.isMinExist == 0 && cValue.CompareTo(gradeInfo.Min) > 0) |
|
{ |
|
} |
|
else |
|
{ |
|
isThisGrade = false; |
|
} |
|
} |
|
if (isThisGrade) |
|
{ |
|
break; |
|
} |
|
else |
|
{ |
|
order++; |
|
} |
|
} |
|
totalCutGrade = Math.Max(order, totalCutGrade); |
|
return order; |
|
} |
|
private string calGrade_TOTAL_DEPTH(double avg) |
|
{ |
|
string result = ""; |
|
int order = calGrade("TOTAL_DEPTH", avg * 100); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
private string calGrade_TABLE(double min,double max) |
|
{ |
|
string result = ""; |
|
int order1 = calGrade("TABLE", min * 100); |
|
int order2 = calGrade("TABLE", max * 100); |
|
int order = Math.Max(order1, order2); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
private string calGrade_CROWN_ANGLE(double min, double max) |
|
{ |
|
string result = ""; |
|
int order1 = calGrade("CROWN_ANGLE", min); |
|
int order2 = calGrade("CROWN_ANGLE", max); |
|
int order = Math.Max(order1, order2); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
private string calGrade_CROWN_HEIGHT(double min, double max) |
|
{ |
|
string result = ""; |
|
int order1 = calGrade("CROWN_HEIGHT", min * 100); |
|
int order2 = calGrade("CROWN_HEIGHT", max * 100); |
|
int order = Math.Max(order1, order2); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
private string calGrade_GIRDLE(double min, double max) |
|
{ |
|
string result = ""; |
|
int order1 = calGrade("GIRDLE", min * 100); |
|
int order2 = calGrade("GIRDLE", max * 100); |
|
int order = Math.Max(order1, order2); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
private string calGrade_PAV_ANGLE(double min, double max) |
|
{ |
|
string result = ""; |
|
int order1 = calGrade("PAV_ANGLE", min); |
|
int order2 = calGrade("PAV_ANGLE", max); |
|
int order = Math.Max(order1, order2); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
private string calGrade_PAV_DEPTH(double min, double max) |
|
{ |
|
string result = ""; |
|
int order1 = calGrade("PAV_DEPTH", min * 100); |
|
int order2 = calGrade("PAV_DEPTH", max * 100); |
|
int order = Math.Max(order1, order2); |
|
result = GetGradeName(order); |
|
return result; |
|
} |
|
#endregion |
|
#region 参数列表行编辑 |
|
private DataInfo getDIAMETER(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "DIAMETER"; |
|
info.TestItemName = GetName("DIAMETER"); |
|
info.Avg = result.measurements.DIAMETER.ToString(digitsFormat); |
|
info.Dev = result.measurements.DIAMETER_DEV.ToString(digitsFormat); |
|
info.Min = result.measurements.M1.ToString(digitsFormat); |
|
info.Max = result.measurements.M2.ToString(digitsFormat); |
|
return info; |
|
} |
|
private DataInfo getTOTAL_DEPTH(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "TOTAL_DEPTH"; |
|
info.TestItemName = GetName("TOTAL_DEPTH"); |
|
info.Avg = FormatDouble_P(result.measurements.TOTAL_DEPTH); |
|
info.CutLevel = calGrade_TOTAL_DEPTH(result.measurements.TOTAL_DEPTH); |
|
info.isEnabled = false; |
|
return info; |
|
} |
|
|
|
private DataInfo getTABLE(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "TABLE"; |
|
info.TestItemName = GetName("TABLE"); |
|
info.Avg = FormatDouble_P(result.measurements.TABLE); |
|
info.Min = FormatDouble_P(result.measurements.TABLE_MIN); |
|
info.Max = FormatDouble_P(result.measurements.TABLE_MAX); |
|
info.CutLevel = calGrade_TABLE(result.measurements.TABLE_MIN, result.measurements.TABLE_MAX); |
|
info.isEnabled = false; |
|
return info; |
|
} |
|
|
|
private DataInfo getCROWN_ANGLE(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "CROWN_ANGLE"; |
|
info.TestItemName = GetName("CROWN_ANGLE"); |
|
info.Avg = FormatDouble_A(result.measurements.CROWN_ANGLE); |
|
info.Dev = FormatDouble_A(result.measurements.CROWN_ANGLE_DEV); |
|
info.Min = FormatDouble_A(result.measurements.CROWN_ANGLE_MIN); |
|
info.Max = FormatDouble_A(result.measurements.CROWN_ANGLE_MAX); |
|
info.CutLevel = calGrade_CROWN_ANGLE(result.measurements.CROWN_ANGLE_MIN, result.measurements.CROWN_ANGLE_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getCROWN_HEIGHT(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "CROWN_HEIGHT"; |
|
info.TestItemName = GetName("CROWN_HEIGHT"); |
|
info.Avg = FormatDouble_P(result.measurements.CROWN_HEIGHT); |
|
info.Dev = FormatDouble_P(result.measurements.CROWN_H_DEV); |
|
info.Min = FormatDouble_P(result.measurements.CROWN_H_MIN); |
|
info.Max = FormatDouble_P(result.measurements.CROWN_H_MAX); |
|
info.CutLevel = calGrade_CROWN_HEIGHT(result.measurements.CROWN_H_MIN, result.measurements.CROWN_H_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getGIRDLE_BEZEL(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "GIRDLE_BEZEL"; |
|
info.TestItemName = GetName("GIRDLE_BEZEL"); |
|
info.Avg = FormatDouble_P(result.measurements.GIRDLE_BEZEL); |
|
info.Dev = FormatDouble_P(result.measurements.GIRDLE_BEZEL_DEV); |
|
info.Min = FormatDouble_P(result.measurements.GIRDLE_BEZEL_MIN); |
|
info.Max = FormatDouble_P(result.measurements.GIRDLE_BEZEL_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getGIRDLE_BONE(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "GIRDLE_BONE"; |
|
info.TestItemName = GetName("GIRDLE_BONE"); |
|
info.Avg = FormatDouble_P(result.measurements.GIRDLE_BONE); |
|
info.Min = FormatDouble_P(result.measurements.GIRDLE_BONE_MIN); |
|
info.Max = FormatDouble_P(result.measurements.GIRDLE_BONE_MAX); |
|
info.isEnabled = false; |
|
return info; |
|
} |
|
|
|
private DataInfo getGIRDLE(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "GIRDLE"; |
|
info.TestItemName = GetName("GIRDLE"); |
|
info.Avg = FormatDouble_P(result.measurements.GIRDLE); |
|
info.Dev = FormatDouble_P(result.measurements.GIRDLE_DEV); |
|
info.Min = FormatDouble_P(result.measurements.GIRDLE_MIN); |
|
info.Max = FormatDouble_P(result.measurements.GIRDLE_MAX); |
|
info.CutLevel = calGrade_GIRDLE(result.measurements.GIRDLE_MIN, result.measurements.GIRDLE_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getPAV_ANGLE(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "PAV_ANGLE"; |
|
info.TestItemName = GetName("PAV_ANGLE"); |
|
info.Avg = result.measurements.PAV_ANGLE.ToString(digitsFormat); |
|
info.Dev = result.measurements.PAV_ANGLE_DEV.ToString(digitsFormat); |
|
info.Min = result.measurements.PAV_ANGLE_MIN.ToString(digitsFormat); |
|
info.Max = result.measurements.PAV_ANGLE_MAX.ToString(digitsFormat); |
|
info.CutLevel = calGrade_PAV_ANGLE(result.measurements.PAV_ANGLE_MIN, result.measurements.PAV_ANGLE_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getPAV_DEPTH(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "PAV_DEPTH"; |
|
info.TestItemName = GetName("PAV_DEPTH"); |
|
info.Avg = FormatDouble_P(result.measurements.PAV_DEPTH); |
|
info.Dev = FormatDouble_P(result.measurements.PAV_DEPTH_DEV); |
|
info.Min = FormatDouble_P(result.measurements.PAV_DEPTH_MIN); |
|
info.Max = FormatDouble_P(result.measurements.PAV_DEPTH_MAX); |
|
info.CutLevel = calGrade_PAV_DEPTH(result.measurements.PAV_DEPTH_MIN, result.measurements.PAV_DEPTH_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getSTAR(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "STAR"; |
|
info.TestItemName = GetName("STAR"); |
|
info.Avg = FormatDouble_P(result.measurements.STAR); |
|
info.Min = FormatDouble_P(result.measurements.STAR_MIN); |
|
info.Max = FormatDouble_P(result.measurements.STAR_MAX); |
|
info.isEnabled = false; |
|
return info; |
|
} |
|
|
|
private DataInfo getLOWER_HALVES_RATIO(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "LOWER_HALVES_RATIO"; |
|
info.TestItemName = GetName("LOWER_HALVES_RATIO"); |
|
info.Avg = FormatDouble_P(result.measurements.LOWER_HALVES_RATIO); |
|
info.Min = FormatDouble_P(result.measurements.LOWER_HALVES_RATIO_MIN); |
|
info.Max = FormatDouble_P(result.measurements.LOWER_HALVES_RATIO_MAX); |
|
info.isEnabled = false; |
|
return info; |
|
} |
|
|
|
private DataInfo getCULET(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "CULET"; |
|
info.TestItemName = GetName("CULET"); |
|
info.Avg = FormatDouble_P(result.measurements.CULET); |
|
info.isEnabled = false; |
|
return info; |
|
} |
|
|
|
private DataInfo getTOC(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "TOC"; |
|
info.TestItemName = GetName("TOC"); |
|
info.Avg = FormatDouble_P(result.measurements.TOC); |
|
return info; |
|
} |
|
|
|
private DataInfo getCOC(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "COC"; |
|
info.TestItemName = GetName("COC"); |
|
info.Avg = FormatDouble_P(result.measurements.COC); |
|
return info; |
|
} |
|
|
|
private DataInfo getTWIST(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "TWIST"; |
|
info.TestItemName = GetName("TWIST"); |
|
info.Avg = FormatDouble_A(result.measurements.TWIST); |
|
info.Dev = FormatDouble_A(result.measurements.TWIST_DEV); |
|
info.Min = FormatDouble_A(result.measurements.TWIST_MIN); |
|
info.Max = FormatDouble_A(result.measurements.TWIST_MAX); |
|
return info; |
|
} |
|
|
|
private DataInfo getCULET_TO_TABLE(AlgorithmResultEntity result) |
|
{ |
|
DataInfo info = new DataInfo(); |
|
info.TestItemId = "CULET_TO_TABLE"; |
|
info.TestItemName = GetName("CULET_TO_TABLE"); |
|
info.Avg = FormatDouble_P(result.measurements.CULET_TO_TABLE); |
|
return info; |
|
} |
|
#endregion |
|
private double CalWight(AlgorithmResultEntity result) |
|
{ |
|
var M1 = result.measurements.M1; |
|
var M2 = result.measurements.M2; |
|
var M3 = result.measurements.M3; |
|
var wight = Square((M1+M2)/2)*M3*0.0061; |
|
Wight = wight.ToString("f3"); |
|
return wight; |
|
} |
|
|
|
private double Square(double m) |
|
{ |
|
return m*m; |
|
} |
|
private void AutoSave() |
|
{ |
|
if (string.IsNullOrEmpty(DiamondCode)) |
|
{ |
|
return; |
|
} |
|
else |
|
{ |
|
string ts = DateTime.Now.ToString("yyyyMMddHHmmss"); |
|
string fullPath = Path.Combine(getFilePath(), ts + "_" + this.DiamondCode); |
|
ExportFile(fullPath); |
|
} |
|
} |
|
public void SaveFile(object param) |
|
{ |
|
if (string.IsNullOrEmpty(DiamondCode)) |
|
{ |
|
SaveDialog saveDialog = new SaveDialog(); |
|
bool? a = saveDialog.ShowDialog(); |
|
if (saveDialog.DiamondCode.Text.Length > 0) |
|
{ |
|
this.DiamondCode = saveDialog.DiamondCode.Text; |
|
} |
|
else |
|
{ |
|
return; |
|
} |
|
} |
|
string ts = DateTime.Now.ToString("yyyyMMddHHmmss"); |
|
string fullPath = Path.Combine(getFilePath(), ts+ "_" + this.DiamondCode); |
|
ExportFile(fullPath); |
|
} |
|
private string getFilePath() |
|
{ |
|
string defultFilePath = "D://DTest//"; |
|
if( File.Exists(defultFilePath)){ |
|
return defultFilePath; |
|
} |
|
else |
|
{ |
|
Directory.CreateDirectory(defultFilePath); |
|
return defultFilePath; |
|
} |
|
} |
|
#region 文件导出相关 |
|
public void SaveAs(object param) |
|
{ |
|
if (string.IsNullOrEmpty(DiamondCode)) |
|
{ |
|
SaveDialog startDialog = new SaveDialog(); |
|
bool? a = startDialog.ShowDialog(); |
|
|
|
if (startDialog.DiamondCode.Text.Length > 0) |
|
{ |
|
this.DiamondCode = startDialog.DiamondCode.Text; |
|
} |
|
else |
|
{ |
|
return; |
|
} |
|
} |
|
using (var folderBrowserDlg = new FolderBrowserDialog()) |
|
{ |
|
// 创建SaveFileDialog实例 |
|
SaveFileDialog saveFileDialog = new() |
|
{ |
|
Filter = "所有文件 (*.*)|*.*", // 文件类型过滤器 |
|
FileName = this.DiamondCode // 默认文件名 |
|
}; |
|
|
|
// 显示对话框并检查结果 |
|
bool? result = saveFileDialog.ShowDialog(); |
|
if (result == true) |
|
{ |
|
// 获取用户选择的文件路径 |
|
string filePath = saveFileDialog.FileName; |
|
ExportFile(filePath); |
|
} |
|
} |
|
} |
|
private void ExportFile(string filePath) |
|
{ |
|
TxtFile(filePath); |
|
ExcelFile(filePath); |
|
DatFile(filePath); |
|
STLFile(filePath); |
|
} |
|
|
|
private void TxtFile(string filePath) |
|
{ |
|
string fileName = filePath + ".txt"; |
|
using (var file = File.Create(fileName)) |
|
{ |
|
Measurements info = algorithmResult.measurements; |
|
StreamWriter stream = new StreamWriter(file); |
|
stream.WriteLine($"IGI REPORT NUMBER={DiamondCode}"); |
|
stream.WriteLine($"SARIN WEIGHT={Wight}"); |
|
stream.WriteLine($"M1={info.M1}"); |
|
stream.WriteLine($"M2={info.M2}"); |
|
stream.WriteLine($"M3={info.M3}"); |
|
stream.WriteLine($"TABLE={info.TABLE*100}"); |
|
stream.WriteLine($"TABLE MIN={info.TABLE_MIN * 100}"); |
|
stream.WriteLine($"TABLE MAX={info.TABLE_MAX * 100}"); |
|
stream.WriteLine($"CROWN HEIGHT={info.CROWN_HEIGHT * 100}"); |
|
stream.WriteLine($"CROWN H MIN={info.CROWN_H_MIN * 100}"); |
|
stream.WriteLine($"CROWN H MAX={info.CROWN_H_MAX * 100}"); |
|
stream.WriteLine($"CROWN ANGLE={info.CROWN_ANGLE}"); |
|
stream.WriteLine($"CROWN ANGLE MIN={info.CROWN_ANGLE_MIN}"); |
|
stream.WriteLine($"CROWN ANGLE MAX={info.CROWN_ANGLE_MAX}"); |
|
stream.WriteLine($"PAV DEPTH={info.PAV_DEPTH * 100}"); |
|
stream.WriteLine($"PAV DEPTH MIN={info.PAV_DEPTH_MIN * 100}"); |
|
stream.WriteLine($"PAV DEPTH MAX={info.PAV_DEPTH_MAX * 100}"); |
|
stream.WriteLine($"PAV ANGLE={info.PAV_ANGLE}"); |
|
stream.WriteLine($"PAV ANGLE MIN={info.PAV_ANGLE_MIN}"); |
|
stream.WriteLine($"PAV ANGLE MAX={info.PAV_ANGLE_MAX}"); |
|
stream.WriteLine($"GIRDLE={info.GIRDLE * 100}"); |
|
stream.WriteLine($"GIRDLE MIN={info.GIRDLE_MIN * 100}"); |
|
stream.WriteLine($"GIRDLE MAX={info.GIRDLE_MAX * 100}"); |
|
stream.WriteLine($"TOTAL DEPTH={info.TOTAL_DEPTH * 100}"); |
|
stream.WriteLine($"CULET={info.CULET*100}"); |
|
stream.WriteLine($"MACHINE={machine}"); |
|
stream.WriteLine($"CUTGRADE={GetGradeEnName(totalCutGrade)}"); |
|
stream.WriteLine($"LW RATIO={info.LW_RATIO}"); |
|
stream.WriteLine($"DS={DS}"); |
|
stream.WriteLine($"COC={info.COC * 100}"); |
|
stream.WriteLine($"USER={username}"); |
|
string TABLE_GRADE = DtResults.Where(x => "TABLE".Equals(x.TestItemId)).Select(x=>x.CutLevel).First()??""; |
|
stream.WriteLine($"TABLE GRADE={GetGradeEnName(GetGradeOrder(TABLE_GRADE))}"); |
|
string CROWN_H_GRADE = DtResults.Where(x => "CROWN_HEIGHT".Equals(x.TestItemId)).Select(x => x.CutLevel).First() ?? ""; |
|
stream.WriteLine($"CROWN H GRADE={GetGradeEnName(GetGradeOrder(CROWN_H_GRADE))}"); |
|
string CROWN_ANGLE_GRADE = DtResults.Where(x => "CROWN_ANGLE".Equals(x.TestItemId)).Select(x => x.CutLevel).First() ?? ""; |
|
stream.WriteLine($"CROWN ANGLE GRADE={GetGradeEnName(GetGradeOrder(CROWN_ANGLE_GRADE))}"); |
|
string PAV_DEPTH_GRADE = DtResults.Where(x => "PAV_DEPTH".Equals(x.TestItemId)).Select(x => x.CutLevel).First() ?? ""; |
|
stream.WriteLine($"PAV DEPTH GRADE={GetGradeEnName(GetGradeOrder(PAV_DEPTH_GRADE))}"); |
|
string PAV_ANGLE_GRADE = DtResults.Where(x => "PAV_ANGLE".Equals(x.TestItemId)).Select(x => x.CutLevel).First() ?? ""; |
|
stream.WriteLine($"PAV ANGLE GRADE={GetGradeEnName(GetGradeOrder(PAV_ANGLE_GRADE))}"); |
|
string TD_GRADE = DtResults.Where(x => "TOTAL_DEPTH".Equals(x.TestItemId)).Select(x => x.CutLevel).First() ?? ""; |
|
stream.WriteLine($"TD GRADE={GetGradeEnName(GetGradeOrder(TD_GRADE))}"); |
|
stream.WriteLine($"TA={info.TA}"); |
|
stream.WriteLine($"LGF={info.LGF * 100}"); |
|
stream.WriteLine($"STAR={info.STAR * 100}"); |
|
} |
|
} |
|
private void ExcelFile(string filePath) |
|
{ |
|
string fileName = filePath + ".xlsx"; |
|
IWorkbook workbook = new XSSFWorkbook(); |
|
ISheet sheet = workbook.CreateSheet("Sheet1"); |
|
|
|
int col = 0; |
|
int row = 0; |
|
var dataRow = sheet.CreateRow(row); |
|
dataRow.CreateCell(col++).SetCellValue("Measurement1"); |
|
dataRow.CreateCell(col++).SetCellValue("Measurement2"); |
|
dataRow.CreateCell(col++).SetCellValue("Measurement3"); |
|
dataRow.CreateCell(col++).SetCellValue("Table"); |
|
dataRow.CreateCell(col++).SetCellValue("Crown Height"); |
|
dataRow.CreateCell(col++).SetCellValue("Pavilion Depth"); |
|
dataRow.CreateCell(col++).SetCellValue("Total Depth"); |
|
dataRow.CreateCell(col++).SetCellValue("Crown Angle"); |
|
dataRow.CreateCell(col++).SetCellValue("Pavilion Angle"); |
|
dataRow.CreateCell(col++).SetCellValue("Culet Size"); |
|
dataRow.CreateCell(col++).SetCellValue("Girdle Percent"); |
|
dataRow.CreateCell(col++).SetCellValue("Girdle Name"); |
|
dataRow.CreateCell(col++).SetCellValue("POL or Pol/Sym"); |
|
dataRow.CreateCell(col++).SetCellValue("SYM"); |
|
dataRow.CreateCell(col++).SetCellValue("CUT-PROP"); |
|
row++; |
|
col = 0; |
|
dataRow = sheet.CreateRow(row); |
|
Measurements info = algorithmResult.measurements; |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.M1)}(mm)"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.M2)}(mm)"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.M3)}(mm)"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.TABLE)}%"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.CROWN_HEIGHT)}%"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.PAV_DEPTH)}%"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.TOTAL_DEPTH)}%"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.CROWN_ANGLE)}°"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.PAV_ANGLE)}°"); |
|
// TODO 底尖直径 |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A(info.CULET)}(mm)"); |
|
dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P(info.GIRDLE)}%"); |
|
// TODO 腰部厚度英文 |
|
dataRow.CreateCell(col++).SetCellValue($"{calGirdleName(info)}"); |
|
dataRow.CreateCell(col++).SetCellValue($""); |
|
string sysmlevel = ""; |
|
if (!string.IsNullOrEmpty(SymLevelTotal)) |
|
{ |
|
sysmlevel = GetGradeEnName(GetGradeOrder(SymLevelTotal ?? "")); |
|
} |
|
dataRow.CreateCell(col++).SetCellValue($"{sysmlevel}"); |
|
dataRow.CreateCell(col++).SetCellValue($"{GetGradeEnName(GetGradeOrder(CutLevelTotal))}"); |
|
|
|
// 保存Excel文件 |
|
using (FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) |
|
{ |
|
workbook.Write(stream); |
|
} |
|
} |
|
|
|
private string calGirdleName(Measurements info) |
|
{ |
|
string girdleName = ""; |
|
// 有问题 问题1 1.6时为thin to slight thick,那么 thin为什么时刻出现 |
|
// 问题2 假如最小值为very thin,最大值为thick时用哪个 |
|
decimal min = Convert.ToDecimal(info.GIRDLE_MIN * 100); |
|
girdleName += calGirdleName(min,true); |
|
girdleName += " to "; |
|
decimal max = Convert.ToDecimal(info.GIRDLE_MAX * 100); |
|
girdleName += calGirdleName(max,false); |
|
return girdleName; |
|
} |
|
private string calGirdleName(decimal cValue,bool isMin) |
|
{ |
|
string girdleName = ""; |
|
List<CalGradeInfo> calGrades = GetCalGradeInfos("GIRDLE"); |
|
int order = 1; |
|
bool isthin = false; |
|
bool isthick = false; |
|
foreach (CalGradeInfo gradeInfo in calGrades) |
|
{ |
|
bool isThisGrade = true; |
|
|
|
if (gradeInfo.Max != null) |
|
{ |
|
if (gradeInfo.isMaxExist == 1 && cValue.CompareTo(gradeInfo.Max) <= 0) |
|
{ |
|
} |
|
else if (gradeInfo.isMaxExist == 0 && cValue.CompareTo(gradeInfo.Max) < 0) |
|
{ |
|
} |
|
else |
|
{ |
|
isthick = true; |
|
isThisGrade = false; |
|
} |
|
} |
|
if (gradeInfo.Min != null) |
|
{ |
|
if (gradeInfo.isMinExist == 1 && cValue.CompareTo(gradeInfo.Min) >= 0) |
|
{ |
|
} |
|
else if (gradeInfo.isMinExist == 0 && cValue.CompareTo(gradeInfo.Min) > 0) |
|
{ |
|
} |
|
else |
|
{ |
|
isthin = true; |
|
isThisGrade = false; |
|
} |
|
} |
|
if (isThisGrade) |
|
{ |
|
break; |
|
} |
|
else |
|
{ |
|
order++; |
|
} |
|
} |
|
Dictionary<int, string> thinDic = new Dictionary<int, string>(); |
|
thinDic.Add(1, "Thin"); |
|
thinDic.Add(2,"Thin"); |
|
thinDic.Add(3, "Very Thin"); |
|
thinDic.Add(4, "Extremely Thin"); |
|
Dictionary<int, string> thickDic = new Dictionary<int, string>(); |
|
thickDic.Add(1, "Slightly Thick"); |
|
thickDic.Add(2, "Slightly Thick"); |
|
thickDic.Add(3, "Thick"); |
|
thickDic.Add(4, "VeryThick"); |
|
if (order == 1) |
|
{ |
|
if (isMin) |
|
{ |
|
girdleName = thinDic[order]; |
|
} |
|
else |
|
{ |
|
girdleName = thickDic[order]; |
|
} |
|
} |
|
else if (isthin) |
|
{ |
|
girdleName = thinDic[order]; |
|
} |
|
else if (isthick) |
|
{ |
|
girdleName = thickDic[order]; |
|
} |
|
return girdleName; |
|
} |
|
/// <summary> |
|
/// 百分比用的小数格式化 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
/// <returns></returns> |
|
private string FormatDouble_P(double value) |
|
{ |
|
return (Math.Floor(value*1000)/10).ToString(digitsFormat); |
|
} |
|
/// <summary> |
|
/// 直接值(角度,直径)用的小数格式化 |
|
/// </summary> |
|
/// <param name="value"></param> |
|
/// <returns></returns> |
|
private string FormatDouble_A(double value) |
|
{ |
|
return (Math.Floor(value * 10) / 10).ToString(digitsFormat); |
|
} |
|
private void DatFile(string filePath) |
|
{ |
|
File.Create(filePath + ".dat").Close(); |
|
} |
|
private void STLFile(string filePath) |
|
{ |
|
File.Create(filePath + ".stl").Close(); |
|
} |
|
#endregion |
|
|
|
#region 各类名称取得 |
|
private string GetName(string id) |
|
{ |
|
// TODO DB没关联 |
|
Dictionary<string, string> dictionary = new(); |
|
dictionary.Add("DIAMETER", "直径"); |
|
dictionary.Add("TOTAL_DEPTH", "全深比"); |
|
dictionary.Add("TABLE", "台宽比"); |
|
dictionary.Add("CROWN_ANGLE", "冠角"); |
|
dictionary.Add("CROWN_HEIGHT", "冠高比"); |
|
dictionary.Add("GIRDLE_BEZEL", "波峰(风筝面)"); |
|
dictionary.Add("GIRDLE_BONE", "波峰(上腰面)"); |
|
dictionary.Add("GIRDLE", "腰厚比"); |
|
dictionary.Add("PAV_ANGLE", "亭角"); |
|
dictionary.Add("PAV_DEPTH", "亭深比"); |
|
dictionary.Add("STAR", "星刻面长度比"); |
|
dictionary.Add("LOWER_HALVES_RATIO", "下腰比"); |
|
dictionary.Add("CULET", "底尖比"); |
|
dictionary.Add("TOC", "台面偏心比"); |
|
dictionary.Add("COC", "底尖偏心比"); |
|
dictionary.Add("TWIST", "扭曲度"); |
|
dictionary.Add("CULET_TO_TABLE", "底尖到台面偏心比"); |
|
dictionary.Add("round", "圆形"); |
|
return dictionary[id]; |
|
} |
|
private string GetGradeName(int order) |
|
{ |
|
// TODO DB没关联 |
|
Dictionary<int, string> dictionary = new(); |
|
dictionary.Add(1,"极好"); |
|
dictionary.Add(2, "很好"); |
|
dictionary.Add(3, "好"); |
|
dictionary.Add(4, "一般"); |
|
dictionary.Add(5, "差"); |
|
return dictionary[order]; |
|
} |
|
private int GetGradeOrder(string Grade) |
|
{ |
|
// TODO DB没关联 |
|
Dictionary<string, int> dictionary = new(); |
|
dictionary.Add("极好", 1); |
|
dictionary.Add("很好", 2); |
|
dictionary.Add("好", 3); |
|
dictionary.Add("一般", 4); |
|
dictionary.Add("差", 5); |
|
return dictionary[Grade]; |
|
} |
|
private string GetGradeEnName(int order) |
|
{ |
|
// TODO DB没关联 |
|
Dictionary<int, string> dictionary = new(); |
|
dictionary.Add(1, "EXCELLENT-Ideal"); |
|
dictionary.Add(2, "EXCELLENT"); |
|
dictionary.Add(3, "VERY GOOD"); |
|
dictionary.Add(4, "GOOD"); |
|
dictionary.Add(5, "FAIR-POOR"); |
|
return dictionary[order]; |
|
} |
|
#endregion |
|
|
|
/// <summary> |
|
/// 修改对称性等级 |
|
/// </summary> |
|
/// <param name="norm"></param> |
|
public void ChangeSym(object norm) |
|
{ |
|
int? order = this.DtResults.Select(x => x.SymLevel).Max(); |
|
if (order.HasValue) |
|
{ |
|
totalSymGrade = order.Value; |
|
SymLevelTotal = GetGradeName((int)order.Value); |
|
} |
|
else |
|
{ |
|
SymLevelTotal = string.Empty; |
|
} |
|
} |
|
|
|
#region 钻石操作相关 |
|
//暂略 |
|
//部分代码(直接操作控件)需要在xaml.cs里边写 |
|
//涉及到计算部分,这里做一个中转 |
|
#endregion |
|
} |
|
public class CalGradeInfo{ |
|
public int gradeOrder { get; set; } |
|
public decimal? Min { get; set; } |
|
public decimal? Max { get; set; } |
|
public int isMaxExist { get; set; } |
|
public int isMinExist { get; set; } |
|
} |
|
public class DataInfo |
|
{ |
|
public string? TestItemId { get; set; } |
|
public string? TestItemName { get; set; } |
|
public string? Avg { get; set; } |
|
public string? Dev { get; set; } |
|
public string? Min { get; set; } |
|
public string? Max { get; set; } |
|
public string? CutLevel { get; set; } |
|
private int? _symLevel; |
|
//public int? SymLevel { get; set; } |
|
public int? SymLevel |
|
{ |
|
get { return _symLevel; } |
|
set |
|
{ |
|
if (_symLevel != value) |
|
{ |
|
_symLevel = value; |
|
OnPropertyChanged(nameof(SymLevel)); |
|
} |
|
} |
|
} |
|
public bool isEnabled { get; set; } = true; |
|
private DataTable? _gradeList; |
|
public DataTable GradeList { |
|
get |
|
{ |
|
// TODO DB没关联 |
|
if (this._gradeList == null) { |
|
_gradeList = new DataTable(); |
|
_gradeList.Columns.Add("Key"); |
|
_gradeList.Columns.Add("Value"); |
|
_gradeList.Rows.Add("极好", 1); |
|
_gradeList.Rows.Add("很好", 2); |
|
_gradeList.Rows.Add("好", 3); |
|
_gradeList.Rows.Add("一般", 4); |
|
_gradeList.Rows.Add("差", 5); |
|
} |
|
return _gradeList; |
|
} |
|
} |
|
public event PropertyChangedEventHandler PropertyChanged; |
|
protected void OnPropertyChanged(string propertyName) |
|
{ |
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); |
|
} |
|
} |