diff --git a/App.config b/App.config index 3fda9a3..c0e288e 100644 --- a/App.config +++ b/App.config @@ -2,8 +2,8 @@ <configuration> <appSettings> <!-- 切工仪URL --> - <add key="BaseUrl" value="http://192.168.10.111:5000/api/SoC"/> - <!-- <add key="BaseUrl" value="http://192.168.3.100:8080"/> --> + <!-- <add key="BaseUrl" value="http://192.168.10.111:5000/api/SoC"/> --> + <add key="BaseUrl" value="http://192.168.3.100:8080"/> <!-- SOC下载图片目录 --> <add key="ImageFileBasePath" value="D:\diamond_images"/> <!-- 算法失败时,历史图片保存文件夹路径 --> @@ -21,7 +21,7 @@ <!--网络质量检测阈值 Mbps--> <add key="InternetCheckMbps" value="866" /> <!--检测模式 0:json 1:Image Ohter:algorithm --> - <add key="RunModel" value="0" /> + <add key="RunModel" value="10" /> <!-- 客户端版本 --> <!-- <add key="AppVersion" value="Nlsqq/kAPIXFHKk9dFcfqw==" /> --> </appSettings> diff --git a/BrilliantSight.csproj b/BrilliantSight.csproj index cff83cc..6223a3e 100644 --- a/BrilliantSight.csproj +++ b/BrilliantSight.csproj @@ -12,12 +12,14 @@ <Description>晶瞳钻石检测工具</Description> <Copyright>Copyright ©2025 北京跃洋新视科技有限公司</Copyright> <Company>北京跃洋新视科技有限公司</Company> - <AssemblyVersion>1.1.2521</AssemblyVersion> - <FileVersion>1.1.2521</FileVersion> + <AssemblyVersion>1.1.2522</AssemblyVersion> + <FileVersion>1.1.2522</FileVersion> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <AssemblyName>BrilliantSightClient</AssemblyName> <RootNamespace>BrilliantSightClient</RootNamespace> <PackageId>BrilliantSightClient</PackageId> + + </PropertyGroup> <ItemGroup> @@ -79,9 +81,6 @@ <None Remove="Resource\Images\UIResource\round_P8-P8.png" /> <None Remove="Resource\Images\UIResource\round_select.png" /> <None Remove="Resource\Images\ze-add-o 1%403x.png" /> - <Content Include="ffmpeg.exe"> - <CopyToOutputDirectory>Always</CopyToOutputDirectory> - </Content> <None Remove="Resource\Images\homebg.png" /> <Resource Include="Resource\Images\UIResource\Cushion.png" /> <Resource Include="Resource\Images\UIResource\Cushion_select.png" /> @@ -111,7 +110,7 @@ <None Update="log4net.config"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> - <None Update="SparkDB.db"> + <None Update="BrilliantSightED.db"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Remove="Resource\Images\config_3x.png" /> diff --git a/BrilliantSightED.db b/BrilliantSightED.db new file mode 100644 index 0000000..d94effc Binary files /dev/null and b/BrilliantSightED.db differ diff --git a/Model/Entity/ApiEntity/StatusCodes.cs b/Model/Entity/ApiEntity/StatusCodes.cs index 23741e6..9dabf09 100644 --- a/Model/Entity/ApiEntity/StatusCodes.cs +++ b/Model/Entity/ApiEntity/StatusCodes.cs @@ -1,6 +1,6 @@ using System.Reflection; -namespace BrilliantSightClient.Model.Common +namespace BrilliantSightClient.Model.Entity.ApiEntity { /// <summary> /// 存储状态码及其描述信息的常量类。 diff --git a/Model/Entity/JsonEntity.cs b/Model/Entity/JsonEntity.cs index 478c48e..7547711 100644 --- a/Model/Entity/JsonEntity.cs +++ b/Model/Entity/JsonEntity.cs @@ -8,6 +8,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Documents; using System.Windows.Shapes; +using BrilliantSightClient.Model.GradeResult.Entity; namespace BrilliantSightClient.Model.Entity { diff --git a/Model/GradeLevel/Entity/DatabaseEntity/BaseEntity.cs b/Model/GradeLevel/Entity/DatabaseEntity/BaseEntity.cs new file mode 100644 index 0000000..f3584fa --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/BaseEntity.cs @@ -0,0 +1,6 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; + +public class BaseEntity +{ + public string Sign { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelDataSet.cs b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelDataSet.cs new file mode 100644 index 0000000..9876111 --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelDataSet.cs @@ -0,0 +1,16 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; + +/// <summary> +/// 定级数据设定 +/// </summary> +public class GradeLevelDataSet: BaseEntity +{ + public string Mst_Sign { get; set; } = string.Empty; + public string Mst_Name { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; + public string EName { get; set; } = string.Empty; + public string KName { get; set; } = string.Empty; + public string Unit {set; get;} = string.Empty; + public int HasCut { get; set; } = 0; + public int HasSym { get; set; } = 0; +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelMst.cs b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelMst.cs new file mode 100644 index 0000000..f4b1be2 --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelMst.cs @@ -0,0 +1,13 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +/// <summary> +/// 定级设定主表 +/// </summary> +public class GradeLevelMst : BaseEntity +{ + public string Name { get; set; } = string.Empty; + public string EName { get; set; } = string.Empty; + public int RunMode { get; set; } = -1; + public int Shape { get; set; } = 0; + public int Crown { get; set; } = 8; + public int Pavilion { get; set; } = 8; +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelSet.cs b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelSet.cs new file mode 100644 index 0000000..c86f487 --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelSet.cs @@ -0,0 +1,15 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; + +/// <summary> +/// 级别设定表 +/// </summary> +public class GradeLevelSet : BaseEntity +{ + public string Mst_Sign { get; set; } = string.Empty; + public string Mst_Name { get; set; } = string.Empty; + public int Set_Type { get; set; } = 0; + public string Name { get; set; } = string.Empty; + public string EName { get; set; } = string.Empty; + public string AName { get; set; } = string.Empty; + public int Short { get; set; } = 0; +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelSetDtl.cs b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelSetDtl.cs new file mode 100644 index 0000000..e67195b --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelSetDtl.cs @@ -0,0 +1,14 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +/// <summary> +/// 评级设定明细 +/// </summary> +public class GradeLevelSetDtl: BaseEntity +{ + public string Mst_Sign { get; set; } = string.Empty; + public string Mst_Name { get; set; } = string.Empty; + public string Tree_Sign { get; set; } = string.Empty; + public string DataSet_Sign { get; set; } = string.Empty; + public string Level_Sign { get; set; } = string.Empty; + public double Max_Value { get; set; } + public double Min_Value { get; set; } +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelTotalSet.cs b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelTotalSet.cs new file mode 100644 index 0000000..f242356 --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelTotalSet.cs @@ -0,0 +1,14 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; + +/// <summary> +/// 综合评级设定表 +/// </summary> +public class GradeLevelTotalSet: BaseEntity +{ + public string Mst_Sign { get; set; } = string.Empty; + public string Mst_Name { get; set; } = string.Empty; + public int Set_Type { get; set; } = 0; + public int Statistics { get; set; } = 0; + public string DataNames { get; set; } = string.Empty; + public string DataSigns { get; set; } = string.Empty; +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelTreeSet.cs b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelTreeSet.cs new file mode 100644 index 0000000..3f7ac2f --- /dev/null +++ b/Model/GradeLevel/Entity/DatabaseEntity/GradeLevelTreeSet.cs @@ -0,0 +1,29 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +/// <summary> +/// 评级设定树 +/// </summary> +public class GradeLevelTreeSet: BaseEntity +{ + public string Mst_Sign { get; set; } = string.Empty; + public string Mst_Name { get; set; } = string.Empty; + public string Header { get; set; } = string.Empty; + public int NodeType { get; set; } = 0; + public int HasData { get; set; } = 0; + public int IsTop { get; set; } = 0; + public string DimensionValue { get; set; } = string.Empty; + public string DimensionSign { get; set; } = string.Empty; + public string ParentSign { get; set; } = string.Empty; + + private List<GradeLevelSetDtl> _setDtls = new List<GradeLevelSetDtl>(); + + public List<GradeLevelSetDtl> GetLevelSetDtls() + { + return _setDtls; + } + + public void AddSetDtl(GradeLevelSetDtl setDtl) + { + _setDtls.Add(setDtl); + } + +} \ No newline at end of file diff --git a/Model/GradeLevel/Entity/Enum/GradeType.cs b/Model/GradeLevel/Entity/Enum/GradeType.cs new file mode 100644 index 0000000..1f19c6a --- /dev/null +++ b/Model/GradeLevel/Entity/Enum/GradeType.cs @@ -0,0 +1,7 @@ +namespace BrilliantSightClient.Model.GradeLevel.Entity.Enum; + +public enum GradeType +{ + Cut = 0, + Sym = 1, +} \ No newline at end of file diff --git a/Model/GradeLevel/GradeLevelCalculator.cs b/Model/GradeLevel/GradeLevelCalculator.cs new file mode 100644 index 0000000..6126305 --- /dev/null +++ b/Model/GradeLevel/GradeLevelCalculator.cs @@ -0,0 +1,35 @@ +using BrilliantSightClient.Model.Entity.ApiEntity; +using BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +using BrilliantSightClient.Model.GradeResult.Entity; + +namespace BrilliantSightClient.Model.GradeLevel; + +public class GradeLevelCalculator +{ + public GradeLevelCalculator(AlgorithmResultEntity entity) + { + + } + + public GradeLevelSet GetCutGradeLevelSet(double maxVal, double minVal) + { + return null; + } + + public GradeLevelSet GetCutTotalGradeLevelSet(List<DataInfo> dataInfos) + { + return null; + } + + public GradeLevelSet GetSymGradeLevelSet(double devVal) + { + return null; + } + + public GradeLevelSet GetSymTotalGradeLevelSet(List<DataInfo> dataInfos) + { + return null; + } + + +} \ No newline at end of file diff --git a/Model/GradeLevel/Helper/EntityHelper.cs b/Model/GradeLevel/Helper/EntityHelper.cs new file mode 100644 index 0000000..c2578ce --- /dev/null +++ b/Model/GradeLevel/Helper/EntityHelper.cs @@ -0,0 +1,108 @@ +using System.Reflection; +using System.Text; +using BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +using BrilliantSightClient.Model.Helper; + + +namespace BrilliantSightClient.Model.GradeLevel.Helper; + +public static class EntityHelper +{ + public static void GenerateSign(this BaseEntity entity) + { + Type type = entity.GetType(); + PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(p => p.Name != nameof(BaseEntity.Sign) && p.CanRead) + .ToArray(); + Array.Sort(properties, (p1, p2) => string.Compare(p1.Name, p2.Name, StringComparison.Ordinal)); + StringBuilder sourceBuilder = new StringBuilder(); + foreach (PropertyInfo property in properties) + { + object value = property.GetValue(entity); + string valueString = value?.ToString() ?? string.Empty; + sourceBuilder.Append($"{property.Name}={valueString}&"); + } + if (sourceBuilder.Length > 0) + { + sourceBuilder.Length--; + } + string sign = Common.GenerateMd5Hash(sourceBuilder.ToString()); + entity.Sign = sign; + } + + public static string GenerateInsertSql(this BaseEntity entity) + { + Type type = entity.GetType(); + string tableName = ConvertToUpperSnakeCase(type.Name); + PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(p => p.CanRead && p.GetValue(entity) != null) + .ToArray(); + StringBuilder columnsBuilder = new StringBuilder(); + StringBuilder valuesBuilder = new StringBuilder(); + + foreach (PropertyInfo property in properties) + { + string columnName = ConvertToUpperCase(property.Name); + object value = property.GetValue(entity); + string valueString = ProcessValue(value); + columnsBuilder.Append($"{columnName},"); + valuesBuilder.Append($"{valueString},"); + } + if (columnsBuilder.Length > 0) + { + columnsBuilder.Length--; + valuesBuilder.Length--; + } + string insertSql = $"INSERT INTO {tableName} ({columnsBuilder}) VALUES ({valuesBuilder});"; + return insertSql; + } + + // 辅助方法:大驼峰转大写下划线 + private static string ConvertToUpperSnakeCase(string input) + { + return string.Concat(input.Select((c, i) => + i > 0 && char.IsUpper(c) + ? "_" + c + : c.ToString())).ToUpper(); + } + + // 辅助方法:大驼峰+下划线转纯大写 + private static string ConvertToUpperCase(string input) + { + return input.ToUpper(); + } + + // 辅助方法:处理不同类型的值 + private static string ProcessValue(object value) + { + if (value == null) + return "NULL"; + + if (value is string str) + return $"'{str.Replace("'", "''")}'"; + + if (value is DateTime dateTime) + return $"'{dateTime:yyyy-MM-dd HH:mm:ss}'"; + + if (value is bool boolean) + return boolean ? "1" : "0"; + + return value.ToString(); + } + public static int GetValue<TEnum>(this TEnum enumValue) + where TEnum : Enum + { + return Convert.ToInt32(enumValue); + } + + public static int? GetValueFromName<TEnum>(string name, bool ignoreCase = true) + where TEnum : struct, Enum + { + if (Enum.TryParse<TEnum>(name, ignoreCase, out var result)) + { + return Convert.ToInt32(result); + } + return null; // 转换失败返回 null + } + +} \ No newline at end of file diff --git a/Model/GradeLevel/Helper/LevelConfigImportHelper.cs b/Model/GradeLevel/Helper/LevelConfigImportHelper.cs new file mode 100644 index 0000000..6c02560 --- /dev/null +++ b/Model/GradeLevel/Helper/LevelConfigImportHelper.cs @@ -0,0 +1,248 @@ +using System.Data; +using System.Text; +using BrilliantSightClient.Model.Entity.ApiEntity; +using BrilliantSightClient.Model.Extension; +using BrilliantSightClient.Model.GradeLevel.Entity; +using BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +using BrilliantSightClient.Model.GradeLevel.Entity.Enum; +using BrilliantSightClient.Model.GradeResult.Entity; +using BrilliantSightClient.Model.Helper; +using BrilliantSightClient.Views.Dialog; +using BaseEntity = BrilliantSightClient.Model.GradeLevel.Entity.BaseEntity; + +namespace BrilliantSightClient.Model.GradeLevel.Helper; + +/// <summary> +/// 配置文件导入方法 +/// </summary> +public class LevelConfigImportHelper +{ + public static bool ImportLevelConfig(MasterLevelEntity master, List<UseDataSet> useDatasets, BaseEntity baseTree) + { + //主数据做成 + GradeLevelMst mst = new GradeLevelMst() + { + Name = master.Name, + EName = master.EName, + RunMode = master.RunMode.GetValue(), + Shape = master.Shape.GetValue(), + Crown = master.Crown, + Pavilion = master.Pavilion, + }; + mst.GenerateSign(); + //级别设定 + List<GradeLevelSet> gradeLevelSets = new List<GradeLevelSet>(); + foreach (var levelSet in master.CutLevelSet) + { + var temp = new GradeLevelSet() + { + Mst_Name = mst.Name, + Mst_Sign = mst.Sign, + Set_Type = GradeType.Cut.GetValue(), + Name = levelSet.Name, + EName = levelSet.EName, + AName = levelSet.AName, + Short = levelSet.Short, + Sign = levelSet.Sign, + }; + if (temp.Sign.IsNullOrEmpty()) + temp.GenerateSign(); + gradeLevelSets.Add(temp); + } + foreach (var levelSet in master.SymLevelSet) + { + var temp = new GradeLevelSet() + { + Mst_Name = mst.Name, + Mst_Sign = mst.Sign, + Set_Type = GradeType.Sym.GetValue(), + Name = levelSet.Name, + EName = levelSet.EName, + AName = levelSet.AName, + Short = levelSet.Short, + Sign = levelSet.Sign, + }; + if (temp.Sign.IsNullOrEmpty()) + temp.GenerateSign(); + gradeLevelSets.Add(temp); + } + //定级数据配置 + List<GradeLevelDataSet> dataSets = new List<GradeLevelDataSet>(); + List<GradeLevelDataSet> CutDataSets = new List<GradeLevelDataSet>(); + List<GradeLevelDataSet> SymDataSets = new List<GradeLevelDataSet>(); + foreach (var useData in useDatasets) + { + var temp = new GradeLevelDataSet() + { + Mst_Name = mst.Name, + Mst_Sign = mst.Sign, + Name = useData.Name, + EName = useData.EName, + KName = useData.Key, + Unit = useData.Unit, + HasSym = useData.HasSym ? 1 : 0, + HasCut = useData.HasCut ? 1 : 0, + }; + temp.GenerateSign(); + if(master.CutTotalRuleSet.UserDataSets.Exists(e => e.Name == temp.Name) && temp.HasCut == 1) + CutDataSets.Add(temp); + if(master.SymTotalRuleSet.UserDataSets.Exists(e => e.Name == temp.Name) && temp.HasSym == 1) + SymDataSets.Add(temp); + dataSets.Add(temp); + } + #region 综合评级设定 + List<GradeLevelTotalSet> totalSets = new List<GradeLevelTotalSet>(); + if (master.CutTotalRuleSet != null) + { + StringBuilder sbCutDataSigns = new StringBuilder(); + StringBuilder sbCutDataNames = new StringBuilder(); + + CutDataSets.ForEach(e => + { + sbCutDataSigns.Append(e.Sign + ","); + sbCutDataNames.Append(e.Name + ","); + }); + + GradeLevelTotalSet cutTotalSet = new GradeLevelTotalSet() + { + Mst_Name = mst.Name, + Mst_Sign = mst.Sign, + Set_Type = GradeType.Cut.GetValue(), + Statistics = master.CutTotalRuleSet.Type.GetValue(), + DataNames = sbCutDataNames.ToString(0, sbCutDataNames.Length-1), + DataSigns = sbCutDataSigns.ToString(0, sbCutDataSigns.Length-1), + }; + cutTotalSet.GenerateSign(); + totalSets.Add(cutTotalSet); + } + if (master.SymTotalRuleSet != null) + { + StringBuilder sbCutDataSigns = new StringBuilder(); + StringBuilder sbCutDataNames = new StringBuilder(); + + SymDataSets.ForEach(e => + { + sbCutDataSigns.Append(e.Sign + ","); + sbCutDataNames.Append(e.Name + ","); + }); + + GradeLevelTotalSet symTotalSet = new GradeLevelTotalSet() + { + Mst_Name = mst.Name, + Mst_Sign = mst.Sign, + Set_Type = GradeType.Sym.GetValue(), + Statistics = master.SymTotalRuleSet.Type.GetValue(), + DataNames = sbCutDataNames.ToString(0, sbCutDataNames.Length-1), + DataSigns = sbCutDataSigns.ToString(0, sbCutDataSigns.Length-1), + }; + symTotalSet.GenerateSign(); + totalSets.Add(symTotalSet); + } + #endregion + + //评级树和评级 + List<GradeLevelTreeSet> treeSets = ConvertToTreeList(baseTree, mst, dataSets,gradeLevelSets); + List<GradeLevelSetDtl> dtlSets = new List<GradeLevelSetDtl>(); + foreach (var treeSet in treeSets) + { + dtlSets.AddRange(treeSet.GetLevelSetDtls()); + } + + //数据库登入 + + //检查是否存在 ->存在删除 + string checkSql = $"SELECT SIGN FROM GRADE_LEVEL_MST WHERE NAME = '{mst.Name}' AND RUNMODE = '{mst.RunMode}' AND SHAPE = '{mst.Shape}' AND CROWN = '{mst.Crown}' AND PAVILION = '{mst.Pavilion}'"; + DataTable checkResult = DataBaseHelper.ExecuteQuery(checkSql); + if (checkResult.Rows.Count > 0) + { + string Sign = checkResult.Rows[0]["SIGN"].ToString(); + string Where = $"WHERE MST_NAME = '{mst.Name}' AND MST_SIGN = '{Sign}'"; + List<string> deleteSql = new List<string>(); + deleteSql.Add( $"DELETE FROM GRADE_LEVEL_MST WHERE SIGN = '{Sign}'"); + deleteSql.Add( $"DELETE FROM GRADE_LEVEL_SET {Where}"); + deleteSql.Add( $"DELETE FROM GRADE_LEVEL_DATA_SET {Where}"); + deleteSql.Add( $"DELETE FROM GRADE_LEVEL_TOTAL_SET {Where}"); + deleteSql.Add( $"DELETE FROM GRADE_LEVEL_TREE_SET {Where}"); + deleteSql.Add( $"DELETE FROM GRADE_LEVEL_SET_DTL {Where}"); + deleteSql.ForEach(e => DataBaseHelper.ExecuteNonQuery(e)); + } + List<string> insertSql = new List<string>(); + insertSql.Add(mst.GenerateInsertSql()); + gradeLevelSets.ForEach(e => insertSql.Add(e.GenerateInsertSql())); + dataSets.ForEach(e => insertSql.Add(e.GenerateInsertSql())); + totalSets.ForEach(e => insertSql.Add(e.GenerateInsertSql())); + treeSets.ForEach(e => insertSql.Add(e.GenerateInsertSql())); + dtlSets.ForEach(e => insertSql.Add(e.GenerateInsertSql())); + int kakeCount = 0; + foreach (var item in insertSql) + { + kakeCount += DataBaseHelper.ExecuteNonQuery(item); + } + + if (kakeCount >= insertSql.Count) + { + new MessageBox().Show("配置已导入"); + } + + return false; + } + + private static List<GradeLevelTreeSet> ConvertToTreeList(BaseEntity root, GradeLevelMst master, + List<GradeLevelDataSet> useDatasets, List<GradeLevelSet> gradeLevelSets) + { + var result = new List<GradeLevelTreeSet>(); + + void ConvertNode(BaseEntity node, string parentSign) + { + var useData = useDatasets.FirstOrDefault(e => e.KName == node.DimensionKey); + var treeSetNode = new GradeLevelTreeSet + { + Mst_Sign = master.Sign, + Mst_Name = master.Name, + Header = node.Header, + NodeType = node.NodeType, + HasData = node.HasData, + IsTop = node.IsTops ? 1 : 0, // 转换bool为int + DimensionValue = node.DimensionValue, + DimensionSign = useData==null?string.Empty:useData.Sign, + ParentSign = parentSign + }; + treeSetNode.GenerateSign(); + if (node.GradeSet != null && node.GradeSet.Count > 0) + { + foreach (var gradeSet in node.GradeSet) + { + var nowUseData = useDatasets.FirstOrDefault(e => e.KName == gradeSet.DataSet.Key); + gradeSet.NumSets.ForEach(numSet => + { + var levelSet = gradeLevelSets.FirstOrDefault(e => e.Set_Type == node.NodeType-1 && e.Name.Equals(numSet.Name)); + var temp = new GradeLevelSetDtl() + { + Mst_Sign = master.Sign, + Mst_Name = master.Name, + Tree_Sign = treeSetNode.Sign, + DataSet_Sign = nowUseData.Sign, + Level_Sign = levelSet.Sign, + Max_Value = numSet.MaxValue, + Min_Value = numSet.MinValue, + }; + temp.GenerateSign(); + treeSetNode.AddSetDtl(temp); + }); + + } + } + + result.Add(treeSetNode); if (node.Children != null && node.Children.Any()) + { + foreach (var child in node.Children) + { + ConvertNode(child, treeSetNode.Sign); + } + } + } + ConvertNode(root, string.Empty); + return result; + } + +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/CalGradeInfo.cs b/Model/GradeResult/Entity/CalGradeInfo.cs new file mode 100644 index 0000000..3786608 --- /dev/null +++ b/Model/GradeResult/Entity/CalGradeInfo.cs @@ -0,0 +1,9 @@ +namespace BrilliantSightClient.Model.GradeResult.Entity; + +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; } +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/DataInfo.cs b/Model/GradeResult/Entity/DataInfo.cs new file mode 100644 index 0000000..48fb9d6 --- /dev/null +++ b/Model/GradeResult/Entity/DataInfo.cs @@ -0,0 +1,56 @@ +using System.ComponentModel; +using System.Data; + +namespace BrilliantSightClient.Model.GradeResult.Entity; + +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 Dtl1 { get; set; } = string.Empty; + public string Dtl2 { get; set; } = string.Empty; + public string Dtl3 { get; set; } = string.Empty; + public string Dtl4 { get; set; } = string.Empty; + public string Dtl5 { get; set; } = string.Empty; + public string Dtl6 { get; set; } = string.Empty; + public string Dtl7 { get; set; } = string.Empty; + public string Dtl8 { get; set; } = string.Empty; + + public string? CutLevel { get; set; } + private Int64? _symLevel; + //public int? SymLevel { get; set; } + public Int64? 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 + { + return _gradeList; + } + set + { + _gradeList = value; + } + } + public event PropertyChangedEventHandler PropertyChanged; + protected void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/Enums/Accuracy.cs b/Model/GradeResult/Entity/Enums/Accuracy.cs new file mode 100644 index 0000000..f941822 --- /dev/null +++ b/Model/GradeResult/Entity/Enums/Accuracy.cs @@ -0,0 +1,19 @@ +using System.ComponentModel; + +namespace BrilliantSightClient.Model.GradeResult.Entity.Enums; + +public enum Accuracy +{ + [Description("强制保留两位小数,向下取整(ZDZ1)")] + ForceTwoDecimals, + [Description("强制保留一位小数,向下取整(ZD1)")] + ForceOneDecimal, + [Description("将数值舍入到最近的 0.5 倍数(ZD5)")] + HalfStepRounding, + [Description("将数值舍入到最近的 5 的整数倍(Z5)")] + MultipleOfFive, + [Description("将数值舍入到最近的0.2倍数(ZD2)")] + DecimalTwoStepRounding, + [Description("强制向下取整为整数(Floor)")] + IntegerFloor +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/Enums/DiamondShape.cs b/Model/GradeResult/Entity/Enums/DiamondShape.cs new file mode 100644 index 0000000..b667d9d --- /dev/null +++ b/Model/GradeResult/Entity/Enums/DiamondShape.cs @@ -0,0 +1,13 @@ +using System.ComponentModel; + +namespace BrilliantSightClient.Model.GradeResult.Entity.Enums; + +public enum DiamondShape +{ + [Description("强制保留两位小数,向下取整(ZDZ1)")] + Round = 0, + [Description("强制保留一位小数,向下取整(ZD1)")] + Oval = 1, + [Description("将数值舍入到最近的 0.5 倍数(ZD5)")] + Pear = 2, +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/Enums/SaveStatus.cs b/Model/GradeResult/Entity/Enums/SaveStatus.cs new file mode 100644 index 0000000..0b56095 --- /dev/null +++ b/Model/GradeResult/Entity/Enums/SaveStatus.cs @@ -0,0 +1,8 @@ +namespace BrilliantSightClient.Model.GradeResult.Entity.Enums; + +public enum SaveStatus +{ + AutoSave = 0, + Save=1, + SaveAs=2 +} diff --git a/Model/GradeResult/Entity/Name.cs b/Model/GradeResult/Entity/Name.cs new file mode 100644 index 0000000..fcc80f8 --- /dev/null +++ b/Model/GradeResult/Entity/Name.cs @@ -0,0 +1,27 @@ +using System.Data; +using BrilliantSightClient.Model.Attributes; +using BrilliantSightClient.Model.Helper; + +namespace BrilliantSightClient.Model.GradeResult.Entity; + +public class Name +{ + public string Id { get; set; } + public string name { get; set; } + + [Log] + public static string getNameById(string id) + { + string sql = $"SELECT NAME, EN_NAME FROM NAME WHERE ID = '{id}'"; + DataTable data = DataBaseHelper.ExecuteQuery(sql); + string nameType = "zn-ch".Equals(MultilingualHelper.getLangType())?"NAME":MultilingualHelper.getString("NameType"); + if (data.Rows.Count>0) + { + return data.Rows[0][nameType].ToString(); + } + else + { + return ""; + } + } +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/RowDetail.cs b/Model/GradeResult/Entity/RowDetail.cs new file mode 100644 index 0000000..6651b00 --- /dev/null +++ b/Model/GradeResult/Entity/RowDetail.cs @@ -0,0 +1,22 @@ +namespace BrilliantSightClient.Model.GradeResult.Entity; + +public class RowDetail +{ + public string? itemName { get; set; } + public string? Avg { get; set; } + public string? Dev { get; set; } + public string? Min { get; set; } + public string? Max { get; set; } + public string? item1 { get; set; } + public string? item2 { get; set; } + public string? item3 { get; set; } + public string? item4 { get; set; } + public string? item5 { get; set; } + public string? item6 { get; set; } + public string? item7 { get; set; } + public string? item8 { get; set; } + public string? CutLevel { get; set; } + public string? SymLevel { get; set; } + public int? MaxIndex { get; set; } + public int? MinIndex { get; set; } +} \ No newline at end of file diff --git a/Model/GradeResult/Entity/ViewData.cs b/Model/GradeResult/Entity/ViewData.cs new file mode 100644 index 0000000..e9a6908 --- /dev/null +++ b/Model/GradeResult/Entity/ViewData.cs @@ -0,0 +1,24 @@ +namespace BrilliantSightClient.Model.GradeResult.Entity; + +public class ViewData +{ + public string InfoPath { get; set; } = string.Empty; + public string Name { get; set; } = string.Empty; + public string EName { get; set; } = string.Empty; + public string DevKey { get; set; } = string.Empty; + public string DevType { get; set; } = string.Empty; + public string AvgKey { get; set; } = string.Empty; + public string AvgType { get; set; } = string.Empty; + public string MaxKey { get; set; } = string.Empty; + public string MaxType { get; set; } = string.Empty; + public string MinKey { get; set; } = string.Empty; + public string MinType { get; set; } = string.Empty; + public string DtlKey { get; set; } = string.Empty; + public string DtlAttr { get; set; } = string.Empty; + public string DtlCt { get; set; } = string.Empty; + public string DtlType { get; set; } = string.Empty; + public int Shape { get; set; } = 0; // 按枚举或字典为准 + public string Specifications { get; set; } = string.Empty; // 规格(P8-P8、P8-P8-S1) + public int RunMode { get; set; } = -1; // 0实验室、1工厂、-1通用 + +} \ No newline at end of file diff --git a/Model/GradeResult/Helper/DoubleDataFormatHelper.cs b/Model/GradeResult/Helper/DoubleDataFormatHelper.cs new file mode 100644 index 0000000..28e7a00 --- /dev/null +++ b/Model/GradeResult/Helper/DoubleDataFormatHelper.cs @@ -0,0 +1,137 @@ +using BrilliantSightClient.Model.Attributes; +using BrilliantSightClient.Model.GradeResult.Entity.Enums; + +namespace BrilliantSightClient.Model.GradeResult.Helper; +/// <summary> +/// 数据格式化工具类 +/// </summary> +public static class DoubleDataFormatHelper +{ + /// <summary> + /// 格式为小数点后一位 + /// </summary> + public const string DigitsFormat = "f1"; + + /// <summary> + /// 直径的小数格式化 + /// </summary> + /// <param name="value"></param> + /// <returns></returns> + [Log] + public static string FormatDouble_D(double value) + { + // 2025/03/28 维护阶段发现直径切舍为四舍五入,现在改成直接切割 + //return value.ToString("f2"); + return (Math.Floor(value*100)/100).ToString("f2"); + } + /// <summary> + /// 百分比用的小数格式化 + /// </summary> + /// <param name="value"></param> + /// <returns></returns> + [Log] + public static string FormatDouble_P(double value) + { + return (Math.Floor(value*1000)/10).ToString(DigitsFormat); + } + + + [Log] + public static string FormatDouble_P2(double value) + { + return (Math.Floor(value * 10000) / 100).ToString("f2"); + } + + /// <summary> + /// 百分比用的小数格式化 + /// </summary> + /// <param name="value"></param> + /// <returns></returns> + [Log] + public static string FormatDouble_Avg(double value, Accuracy accuracy) + { + string result = ""; + if (Model.Helper.Common.RunMode == 0) + { + switch (accuracy) + { + case Accuracy.ForceTwoDecimals: + result = (Math.Floor(value * 100) / 100).ToString("f2"); + break; + case Accuracy.ForceOneDecimal: + result = (Math.Floor(value * 10) / 10).ToString("f1"); + break; + case Accuracy.HalfStepRounding: + result = (RoundFiveDownSixUp(value * 2) / 2).ToString("f1"); + break; + case Accuracy.MultipleOfFive: + result = (RoundFiveDownSixUp(value / 5) * 5).ToString(); + break; + case Accuracy.DecimalTwoStepRounding: + result = RoundToPointTwo(value).ToString("f1"); // 保留1位小数 + break; + case Accuracy.IntegerFloor: + result = Math.Floor(value).ToString("F1"); // 直接取整 + break; + } + } + else + { + //工厂模式不量化 + switch (accuracy) + { + case Accuracy.ForceTwoDecimals: + result = (Math.Floor(value * 100) / 100).ToString("f2"); + break; + case Accuracy.HalfStepRounding: + case Accuracy.ForceOneDecimal: + case Accuracy.DecimalTwoStepRounding: + case Accuracy.IntegerFloor: + case Accuracy.MultipleOfFive: + result = (Math.Floor(value * 10) / 10).ToString("f1"); + break; + } + } + return result; + } + + + [Log] + public static double RoundFiveDownSixUp(double value) + { + // 提取整数部分 + double integerPart = Math.Truncate(value); + // 提取小数部分 + double fractionalPart = value - integerPart; + + // 判断小数部分是否大于 0.5 + return fractionalPart > 0.5 ? integerPart + 1 : integerPart; + } + public static double RoundToPointTwo(double value) + { + // 转换到10倍精度空间处理 + double scaled = value * 10; + double remainder = scaled % 2; // 求模得到余数 + + // 核心舍入规则:余数>=1.5时进位 + return remainder >= 1.5 ? (scaled - remainder + 2) / 10 : (scaled - remainder) / 10; + } + + /// <summary> + /// 直接值(角度,直径)用的小数格式化 + /// </summary> + /// <param name="value"></param> + /// <returns></returns> + [Log] + public static string FormatDouble_A(double value) + { + return (Math.Floor(value * 10) / 10).ToString(DigitsFormat); + } + [Log] + public static string FormatDouble_A2(double value) + { + return (Math.Floor(value * 100) / 100).ToString("f2"); + } + + +} \ No newline at end of file diff --git a/Model/GradeResult/Helper/ViewDataInfoHelper.cs b/Model/GradeResult/Helper/ViewDataInfoHelper.cs new file mode 100644 index 0000000..2cf286b --- /dev/null +++ b/Model/GradeResult/Helper/ViewDataInfoHelper.cs @@ -0,0 +1,34 @@ +using BrilliantSightClient.Model.Entity.ApiEntity; +using BrilliantSightClient.Model.GradeLevel.Helper; +using BrilliantSightClient.Model.GradeResult.Entity; +using BrilliantSightClient.Model.GradeResult.Entity.Enums; +using BrilliantSightClient.Model.Helper; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace BrilliantSightClient.Model.GradeResult.Helper; + +/// <summary> +/// 视图 DataInfo工具类 +/// </summary> +public class ViewDataInfoHelper +{ + public static List<DataInfo> GenerateDataInfos(AlgorithmResultEntity result) + { + JToken measurements = JToken.Parse(JsonConvert.SerializeObject(result.Measurements)); + List<DataInfo> dataInfos = new List<DataInfo>(); + int shape = EntityHelper.GetValueFromName<DiamondShape>(result.Shape)??-1; + if(shape == -1) throw new Exception("Unsupported shapes"); + string viewDataSql = $"SELECT * FROM ViewData WHERE Shape = {shape} AND Specifications = '{result.PavType}-{result.CrownType}' AND RunMode = {Common.RunMode}"; + List<ViewData> showViewData = DataBaseHelper.ExecuteQuery<ViewData>(viewDataSql); + foreach (var viewData in showViewData) + { + DataInfo dataInfo = new DataInfo(); + + } + + return dataInfos; + } + + +} \ No newline at end of file diff --git a/Model/Helper/AESHelper.cs b/Model/Helper/AESHelper.cs index 3dd59f1..78a2caf 100644 --- a/Model/Helper/AESHelper.cs +++ b/Model/Helper/AESHelper.cs @@ -113,24 +113,54 @@ public class AESHelper } } } - public static string DecryptFile(string inputFile, string password) - { - var aes = Aes.Create(); - var pdb = new Rfc2898DeriveBytes(password, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); - aes.Key = pdb.GetBytes(32); - aes.IV = pdb.GetBytes(16); - StringBuilder sb = new StringBuilder(); - using (var fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) - { - using (var cs = new CryptoStream(fs, aes.CreateDecryptor(), CryptoStreamMode.Read)) - { - StreamReader sr = new StreamReader(cs); - while (!sr.EndOfStream) - { - sb.Append(sr.ReadLine()); - } - } + + /// <summary> + /// 加密字符串并返回二进制数组(指定密钥和IV) + /// </summary> + /// <param name="plainText">明文字符串</param> + /// <param name="key">密钥</param> + /// <param name="iv">初始化向量</param> + /// <returns>加密后的二进制数组</returns> + public static byte[] EncryptToBinary(string plainText, string key = Common.AesKey, string iv = Common.AesIV) { + using (var aes = CreateAes(key, iv)) { + var encryptor = aes.CreateEncryptor(); + var plainBytes = Encoding.UTF8.GetBytes(plainText); // 复用现有编码处理 + return PerformCryptography(plainBytes, encryptor); + } + } + /// <summary> + /// 解密二进制数组并返回字符串(指定密钥和IV) + /// </summary> + /// <param name="cipherBytes">加密的二进制数组</param> + /// <param name="key">密钥</param> + /// <param name="iv">初始化向量</param> + /// <returns>解密后的明文字符串</returns> + public static string DecryptFromBinary(byte[] cipherBytes, string key = Common.AesKey, string iv = Common.AesIV) { + using (var aes = CreateAes(key, iv)) { + var decryptor = aes.CreateDecryptor(); + var plainBytes = PerformCryptography(cipherBytes, decryptor); + return Encoding.UTF8.GetString(plainBytes); // 复用现有编码处理 } - return sb.ToString(); } + + // public static string DecryptFile(string inputFile, string password) + // { + // var aes = Aes.Create(); + // var pdb = new Rfc2898DeriveBytes(password, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); + // aes.Key = pdb.GetBytes(32); + // aes.IV = pdb.GetBytes(16); + // StringBuilder sb = new StringBuilder(); + // using (var fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read)) + // { + // using (var cs = new CryptoStream(fs, aes.CreateDecryptor(), CryptoStreamMode.Read)) + // { + // StreamReader sr = new StreamReader(cs); + // while (!sr.EndOfStream) + // { + // sb.Append(sr.ReadLine()); + // } + // } + // } + // return sb.ToString(); + // } } \ No newline at end of file diff --git a/Model/Helper/Common.cs b/Model/Helper/Common.cs index 232e703..d2d73a2 100644 --- a/Model/Helper/Common.cs +++ b/Model/Helper/Common.cs @@ -8,20 +8,17 @@ namespace BrilliantSightClient.Model.Helper; public class Common { - - public const string DatabasePwd = "DyumL4FvF6wVHWw"; - public const string AesKey = "2AB6AA27B1302AEB747E952D5C5C73B9"; public const string AesIV = "B1302AEB747E952D"; public static readonly string BasePath = AppDomain.CurrentDomain.BaseDirectory; - public const string DataBaseFileName = "SparkDB.db"; - public const string DataBaseTempFileName = "SparkDBtemp.db"; + public const string DataBaseFileName = "BrilliantSightED.db"; + public const string DataBaseTempFileName = "temp.db"; + public const string DataBaseName = "BrilliantSightED"; + public const string DatabasePwd = "DyumL4FvF6wVHWw"; - public const string DataBaseName = "SparkDB"; - public static int RunMode { get; set; } = 0; public static object LastParam = "ROUND P8 P8"; diff --git a/Model/Helper/DataBaseHelper.cs b/Model/Helper/DataBaseHelper.cs index 3314ac3..bf86d4b 100644 --- a/Model/Helper/DataBaseHelper.cs +++ b/Model/Helper/DataBaseHelper.cs @@ -148,7 +148,7 @@ public class DataBaseHelper Logger.Error($"全局异常捕获:{ex.Message}", ex); System.Windows.MessageBox.Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); } - return null; + return new DataTable(); } public static List<T> ExecuteQuery<T>(String sql, SqliteParameter[] sqlParameters = null) where T : new() diff --git a/Model/Services/SOCClientService.cs b/Model/Services/SOCClientService.cs index 2cfea63..55c86e1 100644 --- a/Model/Services/SOCClientService.cs +++ b/Model/Services/SOCClientService.cs @@ -6,7 +6,7 @@ using System.IO; using System.Net.Http; using System.Text; using log4net; -using BrilliantSightClient.Model.Common; +using BrilliantSightClient.Model; using BrilliantSightClient.Model.Entity.ApiEntity; using BrilliantSightClient.Model.Extension; using BrilliantSightClient.Model.Helper; @@ -469,6 +469,12 @@ namespace BrilliantSightClient.Model.Services public async Task<string> OpenPump(bool isOpen) { + string runModel = ConfigurationHelper.ReadConfigValue("RunModel") ?? "10"; + if ("1" == runModel || "0" == runModel) + { + return StatusCodes.Success; + } + // if(GenImage) return StatusCodes.DeviceNotFound; Logger.Info($"气泵开关请求发起{isOpen}"); int param = isOpen ? 1 : 0 ; @@ -480,6 +486,10 @@ namespace BrilliantSightClient.Model.Services if (response.StatusCode == 200) { + if (response.Content.Status != StatusCodes.Success) + { + return await OpenPump(isOpen); + } var result = response.Content; Logger.Debug($"Set Pump : {result.ToSafeAbundantString()} "); return result.Status; @@ -497,7 +507,11 @@ namespace BrilliantSightClient.Model.Services public async Task<GpioStatus> GetGpioStatus() { - // GpioStatus + string runModel = ConfigurationHelper.ReadConfigValue("RunModel") ?? "10"; + if ("1" == runModel || "0" == runModel) + { + return GpioStatus.IsClose(); + } string url = $"{_baseUrl}/gpio_check"; Logger.Info($"舱门状态检查开始:{url}"); try @@ -577,5 +591,14 @@ namespace BrilliantSightClient.Model.Services Value2 = 48 }; } + public static GpioStatus IsClose() + { + return new GpioStatus + { + Status = "S000", + Value1 = 49, + Value2 = 49 + }; + } } } diff --git a/Resource/Images/UIResource/Diamond/oval_p8-p8.png b/Resource/Images/UIResource/Diamond/oval_p8-p8.png index c2f1b5c..cfa3279 100644 Binary files a/Resource/Images/UIResource/Diamond/oval_p8-p8.png and b/Resource/Images/UIResource/Diamond/oval_p8-p8.png differ diff --git a/SparkDB.db b/SparkDB.db deleted file mode 100644 index fc291e6..0000000 Binary files a/SparkDB.db and /dev/null differ diff --git a/ViewModel/Configuration/LevelConfigVM.cs b/ViewModel/Configuration/LevelConfigVM.cs index 61625ab..1b2240b 100644 --- a/ViewModel/Configuration/LevelConfigVM.cs +++ b/ViewModel/Configuration/LevelConfigVM.cs @@ -8,10 +8,18 @@ using System.Data; using System.IO; using System.Windows; using System.Windows.Controls; -using System.Windows.Data; using System.Windows.Input; +using System.Windows.Media.Media3D; using MessageBox = BrilliantSightClient.Views.Dialog.MessageBox; using BrilliantSightClient.Model.Attributes; +using BrilliantSightClient.Model.GradeLevel.Entity; +using BrilliantSightClient.Model.GradeLevel.Entity.DatabaseEntity; +using BrilliantSightClient.Model.GradeLevel.Helper; +using BrilliantSightClient.Model.GradeResult.Entity; +using Microsoft.Win32; +using Binding = System.Windows.Data.Binding; +using HorizontalAlignment = System.Windows.HorizontalAlignment; +using Orientation = System.Windows.Controls.Orientation; namespace BrilliantSightClient.ViewModel.Configuration; @@ -593,115 +601,156 @@ public class LevelConfigVM : BaseViewModel { try { - - Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); - openFileDialog.Filter = "Text files (*.enc)|*.enc|All files (*.*)|*.*"; - jsonEntity = null; - jsonEntity_SYM = null; - if (openFileDialog.ShowDialog() == true) + OpenFileDialog openFileDialog = new OpenFileDialog { - string filename = openFileDialog.FileName; - string content = ""; - if (File.Exists(filename)) - { - try - { - content = AESHelper.DecryptFile(filename, "000000"); - if (filename.EndsWith("_SYM.enc")) - { - jsonEntity_SYM = JsonConvert.DeserializeObject<JsonEntity_SYM>(content); - } - else - { - jsonEntity = JsonConvert.DeserializeObject<JsonEntity>(content); - } - - } - catch (Exception ex) - { - new MessageBox().Show($"{MultilingualHelper.getString("LevelConfigFormatError")}"); - Logger.Error($"全局异常捕获:{ex.Message}", ex); - return; - } - } - } - else - { - //InstitutesEnabled = true; - //ShapesEnabled = true; - //IsUpdateButtonEnabled = false; - //InitData(); - //ChangeShapeModel(""); - return; - } - var initJsonEntity = new JsonEntity(); - - if (jsonEntity != null) { - initJsonEntity = jsonEntity; - } - else - { - initJsonEntity = jsonEntity_SYM; - } - if (initJsonEntity != null) + Title = "选择晶瞳标准配置文件", + Filter = "晶瞳标准配置文件 (*.bstand)|*.bstand", + AddExtension = true, + CheckFileExists = true, + CheckPathExists = true, + InitialDirectory = Environment.CurrentDirectory + }; + bool? result = openFileDialog.ShowDialog(); + if (result == true && !string.IsNullOrEmpty(openFileDialog.FileName)) { - // 形状列表重新生成 - string shapeSql = $"SELECT * FROM SHAPE WHERE SHAPE_ID = '{initJsonEntity.SHAPE_ID}';"; - DataTable shapes = DataBaseHelper.ExecuteQuery(shapeSql); - if (shapes == null || shapes.Rows.Count == 0) + byte[] resultBytes = File.ReadAllBytes(openFileDialog.FileName); + string finalData = AESHelper.DecryptFromBinary(resultBytes); + string[] temp = finalData.Split("|^_^|"); + if (temp.Length < 3) { - var row = Shapes.NewRow(); - row["SHAPE_ID"] = initJsonEntity.SHAPE_ID; - row["SHAPE_NAME"] = initJsonEntity.SHAPE_NAME; - row["SHAPE_EN_NAME"] = initJsonEntity.SHAPE_EN_NAME; - Shapes.Rows.Add(row); - ShapeId = initJsonEntity.SHAPE_ID; - } - else - { - ShapeId = shapes.Rows[0]["SHAPE_ID"].ToString() ?? ""; + throw new Exception("Insufficient or missing configuration information"); } - // 机构列表重新生成 - string instituteSql = $"SELECT * FROM RULE WHERE RULE_ID = '{initJsonEntity.RULE_ID}';"; - DataTable institute = DataBaseHelper.ExecuteQuery(instituteSql); - if (institute == null || institute.Rows.Count == 0) - { - var row = Institutes.NewRow(); - row["RULE_ID"] = initJsonEntity.RULE_ID; - row["RULE_NAME"] = initJsonEntity.RULE_NAME; - row["RULE_EN_NAME"] = initJsonEntity.RULE_EN_NAME; - Institutes.Rows.Add(row); - InstituteId = initJsonEntity.RULE_ID; - } - else + MasterLevelEntity? master = JsonConvert.DeserializeObject<MasterLevelEntity>(temp[0]); + List<UseDataSet>? useDatasets = JsonConvert.DeserializeObject<List<UseDataSet>>(temp[1]); + Model.GradeLevel.Entity.BaseEntity? baseTree = JsonConvert.DeserializeObject<Model.GradeLevel.Entity.BaseEntity>(temp[2]); + + if (master == null || useDatasets == null || useDatasets.Count == 0 || baseTree == null) { - InstituteId = institute.Rows[0]["RULE_ID"].ToString() ?? ""; + throw new Exception("The configuration information is incomplete."); } - // 表格内容重新生成 - string gradeInfosJson = JsonConvert.SerializeObject(initJsonEntity.gradeInfos); - DataTable gradeInfos = Common.JsonToDataTable(gradeInfosJson); - string standardInfosJson = JsonConvert.SerializeObject(initJsonEntity.standardInfos); - DataTable standardInfos = Common.JsonToDataTable(standardInfosJson); - setStandardList(gradeInfos, standardInfos); - InstitutesEnabled = false; - ShapesEnabled = false; - IsUpdateButtonEnabled = true; - } - else - { - new MessageBox().Show($"{MultilingualHelper.getString("LevelConfigFormatError")}"); - InstitutesEnabled = true; - ShapesEnabled = true; - IsUpdateButtonEnabled = false; - return; + LevelConfigImportHelper.ImportLevelConfig(master, useDatasets, baseTree); + + } } catch (Exception ex) { new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); - Logger.Error($"全局异常捕获:{ex.Message}", ex); + Logger.Error($"文件导入&解析异常:{ex.Message}", ex); } + + // try + // { + // + // Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog(); + // openFileDialog.Filter = "Text files (*.bstand)|*.bstand|All files (*.*)|*.*"; + // jsonEntity = null; + // jsonEntity_SYM = null; + // if (openFileDialog.ShowDialog() == true) + // { + // string filename = openFileDialog.FileName; + // string content = ""; + // if (File.Exists(filename)) + // { + // try + // { + // content = AESHelper.DecryptFile(filename, "000000"); + // if (filename.EndsWith("_SYM.enc")) + // { + // jsonEntity_SYM = JsonConvert.DeserializeObject<JsonEntity_SYM>(content); + // } + // else + // { + // jsonEntity = JsonConvert.DeserializeObject<JsonEntity>(content); + // } + // + // } + // catch (Exception ex) + // { + // new MessageBox().Show($"{MultilingualHelper.getString("LevelConfigFormatError")}"); + // Logger.Error($"全局异常捕获:{ex.Message}", ex); + // return; + // } + // } + // } + // else + // { + // //InstitutesEnabled = true; + // //ShapesEnabled = true; + // //IsUpdateButtonEnabled = false; + // //InitData(); + // //ChangeShapeModel(""); + // return; + // } + // var initJsonEntity = new JsonEntity(); + // + // if (jsonEntity != null) { + // initJsonEntity = jsonEntity; + // } + // else + // { + // initJsonEntity = jsonEntity_SYM; + // } + // if (initJsonEntity != null) + // { + // // 形状列表重新生成 + // string shapeSql = $"SELECT * FROM SHAPE WHERE SHAPE_ID = '{initJsonEntity.SHAPE_ID}';"; + // DataTable shapes = DataBaseHelper.ExecuteQuery(shapeSql); + // if (shapes == null || shapes.Rows.Count == 0) + // { + // var row = Shapes.NewRow(); + // row["SHAPE_ID"] = initJsonEntity.SHAPE_ID; + // row["SHAPE_NAME"] = initJsonEntity.SHAPE_NAME; + // row["SHAPE_EN_NAME"] = initJsonEntity.SHAPE_EN_NAME; + // Shapes.Rows.Add(row); + // ShapeId = initJsonEntity.SHAPE_ID; + // } + // else + // { + // ShapeId = shapes.Rows[0]["SHAPE_ID"].ToString() ?? ""; + // } + // + // // 机构列表重新生成 + // string instituteSql = $"SELECT * FROM RULE WHERE RULE_ID = '{initJsonEntity.RULE_ID}';"; + // DataTable institute = DataBaseHelper.ExecuteQuery(instituteSql); + // if (institute == null || institute.Rows.Count == 0) + // { + // var row = Institutes.NewRow(); + // row["RULE_ID"] = initJsonEntity.RULE_ID; + // row["RULE_NAME"] = initJsonEntity.RULE_NAME; + // row["RULE_EN_NAME"] = initJsonEntity.RULE_EN_NAME; + // Institutes.Rows.Add(row); + // InstituteId = initJsonEntity.RULE_ID; + // } + // else + // { + // InstituteId = institute.Rows[0]["RULE_ID"].ToString() ?? ""; + // } + // // 表格内容重新生成 + // string gradeInfosJson = JsonConvert.SerializeObject(initJsonEntity.gradeInfos); + // DataTable gradeInfos = Common.JsonToDataTable(gradeInfosJson); + // string standardInfosJson = JsonConvert.SerializeObject(initJsonEntity.standardInfos); + // DataTable standardInfos = Common.JsonToDataTable(standardInfosJson); + // setStandardList(gradeInfos, standardInfos); + // InstitutesEnabled = false; + // ShapesEnabled = false; + // IsUpdateButtonEnabled = true; + // } + // else + // { + // new MessageBox().Show($"{MultilingualHelper.getString("LevelConfigFormatError")}"); + // InstitutesEnabled = true; + // ShapesEnabled = true; + // IsUpdateButtonEnabled = false; + // return; + // } + // } + // catch (Exception ex) + // { + // new MessageBox().Show($"{MultilingualHelper.getString("ApplicationError")}{ex.Message}"); + // Logger.Error($"全局异常捕获:{ex.Message}", ex); + // } } /// <summary> diff --git a/ViewModel/Grading/DiamondSelectVM.cs b/ViewModel/Grading/DiamondSelectVM.cs index 8b3bfc5..5467b67 100644 --- a/ViewModel/Grading/DiamondSelectVM.cs +++ b/ViewModel/Grading/DiamondSelectVM.cs @@ -229,7 +229,7 @@ public class DiamondSelectVM : BaseViewModel { // TODO 待二级图片作成后替换,以及后续检测处理追加 var bitmap_p8p8 = getBitmap("oval_P8-P8.png"); - buttons.Add(new ButtonViewModel { Text = "Oval Stage 1", ImageSource = bitmap_p8p8, Type = "OVAL S1", Command = StartGradingCommand, IsFocused = true }); + buttons.Add(new ButtonViewModel { Text = "Oval P8-P8", ImageSource = bitmap_p8p8, Type = "OVAL P8 P8", Command = StartGradingCommand, IsFocused = true }); } // 运行模式为工厂模式 else if (Common.RunMode == 1) @@ -281,7 +281,7 @@ public class DiamondSelectVM : BaseViewModel DiamondCode = ""; } - string runModel = ConfigurationHelper.ReadConfigValue("RunModel") ?? "1"; + string runModel = ConfigurationHelper.ReadConfigValue("RunModel") ?? "10"; if ("0".Equals(runModel)) //json模式 diff --git a/ViewModel/Grading/GradingLoadingVM.cs b/ViewModel/Grading/GradingLoadingVM.cs index cd3288b..722a911 100644 --- a/ViewModel/Grading/GradingLoadingVM.cs +++ b/ViewModel/Grading/GradingLoadingVM.cs @@ -11,7 +11,7 @@ using System.Windows.Threading; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using BrilliantSightClient.Model.Attributes; -using BrilliantSightClient.Model.Common; +using BrilliantSightClient.Model; using BrilliantSightClient.Model.Entity.ApiEntity; using BrilliantSightClient.Model.Extension; using BrilliantSightClient.Model.Helper; @@ -553,29 +553,36 @@ public class GradingLoadingVM : BaseViewModel,IDisposable private async Task RunProgressAsync(CancellationToken token) { // var configValue = ConfigurationHelper.ReadConfigValue("ProgressTime"); - int totalDuration = 50000; - int stepTime = totalDuration / 97; - - // 使用 IProgress 实现线程安全的进度报告 - var progress = new Progress<double>(value => + try { - if (!token.IsCancellationRequested) - Progress = value; - }); + int totalDuration = 50000; + int stepTime = totalDuration / 97; - await Task.Run(async () => - { - for (int i = 0; i <= 97; i++) + // 使用 IProgress 实现线程安全的进度报告 + var progress = new Progress<double>(value => { - token.ThrowIfCancellationRequested(); - - // 报告进度 - ((IProgress<double>)progress).Report(i); + if (!token.IsCancellationRequested) + Progress = value; + }); + + await Task.Run(async () => + { + for (int i = 0; i <= 97; i++) + { + token.ThrowIfCancellationRequested(); + + // 报告进度 + ((IProgress<double>)progress).Report(i); + + // 使用可取消的延迟 + await Task.Delay(stepTime, token); + } + }, token); + } + catch (Exception e) + { - // 使用可取消的延迟 - await Task.Delay(stepTime, token); - } - }, token); + } } [Log] diff --git a/ViewModel/Grading/GradingResultVM.cs b/ViewModel/Grading/GradingResultVM.cs index 264941a..95682b1 100644 --- a/ViewModel/Grading/GradingResultVM.cs +++ b/ViewModel/Grading/GradingResultVM.cs @@ -1,4 +1,3 @@ -using System.ComponentModel; using System.Configuration; using System.Data; using System.IO; @@ -21,18 +20,13 @@ using BrilliantSightClient.Views.UserControl.ViewportData.Entity; using BrilliantSightClient.ViewModel.Configuration.SettingsPages; using BrilliantSightClient.Views.UserControl.ViewportData.Helper; using log4net; -using System.Drawing.Printing; -using System.Drawing; -using HandyControl.Controls; -using RectangleF = System.Drawing.RectangleF; -using FontFamily = System.Drawing.FontFamily; -using FontStyle = System.Drawing.FontStyle; using NPOI.SS.Util; -using Brush = System.Drawing.Brush; -using Brushes = System.Drawing.Brushes; using BrilliantSightClient.Model.Attributes; -using BrilliantSightClient.Model.Common; +using BrilliantSightClient.Model; using BrilliantSightClient.Model.Extension; +using BrilliantSightClient.Model.GradeResult.Entity; +using BrilliantSightClient.Model.GradeResult.Entity.Enums; +using BrilliantSightClient.Model.GradeResult.Helper; using SparkDotNetCore.DiamondScanner.Entity.Child; using Exception = System.Exception; @@ -146,10 +140,7 @@ public class GradingResultVM : BaseViewModel /// </summary> public bool IsEnabled { get{ return _isEnabled; } set { _isEnabled = value; OnPropertyChanged(nameof(IsEnabled)); } } - /// <summary> - /// 格式为小数点后一位 - /// </summary> - private readonly static string digitsFormat = "f1"; + /// <summary> /// 切工总等级(辅助计算用) @@ -197,6 +188,7 @@ public class GradingResultVM : BaseViewModel if (result != null) { algorithmResult = result as AlgorithmResultEntity?? new AlgorithmResultEntity(); + // ViewDataInfoHelper.GenerateDataInfos(algorithmResult); InitView(algorithmResult); machine = algorithmResult.DeviceId; username = Settings.SelectValueById("PERMISSIONS"); @@ -215,12 +207,16 @@ public class GradingResultVM : BaseViewModel } DS = ConfigurationManager.AppSettings["DSSet"]; - if (IsEnabled) + + if (shapeId.Equals("ROUND")) { - AutoSave(); + if (IsEnabled) + { + AutoSave(); + } + SaveTestResult(SaveStatus.AutoSave); + SaveToCsv(); } - SaveTestResult(SaveStatus.AutoSave); - SaveToCsv(); }catch(IOException) { throw; @@ -306,17 +302,17 @@ public class GradingResultVM : BaseViewModel string line = $"{DiamondCode}," + $"{Wight}," + - $"{FormatDouble_A2(info.M1)}," + - $"{FormatDouble_A2(info.M2)}," + - $"{FormatDouble_A2(info.M3)}," + - $"{FormatDouble_P2(info.TABLE)}," + - $"{FormatDouble_P2(info.CROWN_HEIGHT)}," + - $"{FormatDouble_P2(info.PAV_DEPTH)}," + - $"{FormatDouble_P2(info.TOTAL_DEPTH)}," + - $"{FormatDouble_A2(info.CROWN_ANGLE)}," + - $"{FormatDouble_A2(info.PAV_ANGLE)}," + - $"{FormatDouble_A2(info.CULET_SIZE)}," + - $"{FormatDouble_P2(info.GIRDLE)}," + + $"{DoubleDataFormatHelper.FormatDouble_A2(info.M1)}," + + $"{DoubleDataFormatHelper.FormatDouble_A2(info.M2)}," + + $"{DoubleDataFormatHelper.FormatDouble_A2(info.M3)}," + + $"{DoubleDataFormatHelper.FormatDouble_P2(info.TABLE)}," + + $"{DoubleDataFormatHelper.FormatDouble_P2(info.CROWN_HEIGHT)}," + + $"{DoubleDataFormatHelper.FormatDouble_P2(info.PAV_DEPTH)}," + + $"{DoubleDataFormatHelper.FormatDouble_P2(info.TOTAL_DEPTH)}," + + $"{DoubleDataFormatHelper.FormatDouble_A2(info.CROWN_ANGLE)}," + + $"{DoubleDataFormatHelper.FormatDouble_A2(info.PAV_ANGLE)}," + + $"{DoubleDataFormatHelper.FormatDouble_A2(info.CULET_SIZE)}," + + $"{DoubleDataFormatHelper.FormatDouble_P2(info.GIRDLE)}," + $"{calGirdleName(info)}," + $"," + $"{GetGradeEnName(GetGradeOrder(SymLevelTotal))}," + @@ -382,25 +378,31 @@ public class GradingResultVM : BaseViewModel PavType = result.PavType; DiamondCode = result.DiamondCode; CalWight(result); - DtResults = new List<DataInfo>(); - var testItemList = GetTestItemList(); - Type type = this.GetType(); - foreach (var testItem in testItemList) + if (shapeId.Equals("ROUND")) { - string methodName = "get" + testItem; - MethodInfo? methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic); - if (methodInfo != null) + ViewDataInfoHelper.GenerateDataInfos(result); + DtResults = new List<DataInfo>(); + var testItemList = GetTestItemList(); + Type type = this.GetType(); + foreach (var testItem in testItemList) { - object[] parameters = new object[] { result }; - DataInfo? dataInfo = methodInfo.Invoke(this, parameters) as DataInfo; - if (dataInfo != null) + string methodName = "get" + testItem; + MethodInfo? methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic); + if (methodInfo != null) { - dataInfo.GradeList = GradeList; - DtResults.Add(dataInfo); + object[] parameters = new object[] { result }; + DataInfo? dataInfo = methodInfo.Invoke(this, parameters) as DataInfo; + if (dataInfo != null) + { + dataInfo.GradeList = GradeList; + DtResults.Add(dataInfo); + } } } + CutLevelTotal = GetGradeName(totalCutGrade); } - CutLevelTotal = GetGradeName(totalCutGrade); + + } catch (Exception ex) { @@ -454,7 +456,7 @@ public class GradingResultVM : BaseViewModel else if (ruleId.StartsWith("GB")) { double ta = algorithmResult.Measurements.TABLE * 100; - ta = (RoundFiveDownSixUp(ta * 2) / 2); + ta = (DoubleDataFormatHelper.RoundFiveDownSixUp(ta * 2) / 2); if (ta < 49) { ruleIdForSelect = ruleId + "_TA_49"; @@ -736,28 +738,30 @@ public class GradingResultVM : BaseViewModel } return (Max - Min) * c; } + + [Log] private DataInfo getDIAMETER(AlgorithmResultEntity result) { DataInfo info = new DataInfo(); info.TestItemId = "DIAMETER"; info.TestItemName = GetName("DIAMETER"); - info.Avg = FormatDouble_D(result.Measurements.DIAMETER); - info.Dev = result.Measurements.DIAMETER_DEV.ToString(digitsFormat); - info.Min = FormatDouble_D(result.Measurements.M1); - info.Max = FormatDouble_D(result.Measurements.M2); + info.Avg = DoubleDataFormatHelper.FormatDouble_D(result.Measurements.DIAMETER); + info.Dev = result.Measurements.DIAMETER_DEV.ToString(DoubleDataFormatHelper.DigitsFormat); + info.Min = DoubleDataFormatHelper.FormatDouble_D(result.Measurements.M1); + info.Max = DoubleDataFormatHelper.FormatDouble_D(result.Measurements.M2); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.DIAMETER_DETAIL != null) { - info.Dtl1 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_1); - info.Dtl2 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_2); - info.Dtl3 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_3); - info.Dtl4 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_4); - info.Dtl5 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_5); - info.Dtl6 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_6); - info.Dtl7 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_7); - info.Dtl8 = FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_D(data.DIAMETER_DETAIL.DIAMETER_8); } info.SymLevel = calGradeSym("DIAMETER", calSymValue(data.M1, data.M2, data.DIAMETER,false)); return info; @@ -768,7 +772,7 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "TOTAL_DEPTH"; info.TestItemName = GetName("TOTAL_DEPTH"); - info.Avg = FormatDouble_Avg(result.Measurements.TOTAL_DEPTH*100,Accuracy.ForceOneDecimal); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.TOTAL_DEPTH*100,Accuracy.ForceOneDecimal); info.CutLevel = calGrade_TOTAL_DEPTH(result.Measurements.TOTAL_DEPTH); info.isEnabled = false; return info; @@ -780,18 +784,18 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "TABLE"; info.TestItemName = GetName("TABLE"); - info.Avg = FormatDouble_Avg(result.Measurements.TABLE*100, Accuracy.IntegerFloor); - info.Min = FormatDouble_P(result.Measurements.TABLE_MIN); - info.Max = FormatDouble_P(result.Measurements.TABLE_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.TABLE*100, Accuracy.IntegerFloor); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.TABLE_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.TABLE_MAX); info.CutLevel = calGrade_TABLE(result.Measurements.TABLE_MIN, result.Measurements.TABLE_MAX); info.isEnabled = false; var data = result.Measurements; if (data.TABLE_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.TABLE_DETAIL.TABLE_1); - info.Dtl2 = FormatDouble_P(data.TABLE_DETAIL.TABLE_2); - info.Dtl3 = FormatDouble_P(data.TABLE_DETAIL.TABLE_3); - info.Dtl4 = FormatDouble_P(data.TABLE_DETAIL.TABLE_4); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.TABLE_DETAIL.TABLE_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.TABLE_DETAIL.TABLE_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.TABLE_DETAIL.TABLE_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.TABLE_DETAIL.TABLE_4); } return info; } @@ -802,23 +806,23 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "CROWN_ANGLE"; info.TestItemName = GetName("CROWN_ANGLE"); - info.Avg = FormatDouble_Avg(result.Measurements.CROWN_ANGLE, Accuracy.DecimalTwoStepRounding); - 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.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.CROWN_ANGLE, Accuracy.DecimalTwoStepRounding); + info.Dev = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.CROWN_ANGLE_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.CROWN_ANGLE_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.CROWN_ANGLE_MAX); info.CutLevel = calGrade_CROWN_ANGLE(result.Measurements.CROWN_ANGLE_MIN, result.Measurements.CROWN_ANGLE_MAX); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.CROWN_ANGLE_DETAIL != null) { - info.Dtl1 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_1); - info.Dtl2 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_2); - info.Dtl3 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_3); - info.Dtl4 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_4); - info.Dtl5 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_5); - info.Dtl6 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_6); - info.Dtl7 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_7); - info.Dtl8 = FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_A(data.CROWN_ANGLE_DETAIL.CROWN_ANGLE_8); } info.SymLevel = calGradeSym(info.TestItemId, calSymValue(data.CROWN_ANGLE_MIN, data.CROWN_ANGLE_MAX, data.CROWN_ANGLE,false)); return info; @@ -830,23 +834,23 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "CROWN_HEIGHT"; info.TestItemName = GetName("CROWN_HEIGHT"); - info.Avg = FormatDouble_Avg(result.Measurements.CROWN_HEIGHT * 100, Accuracy.HalfStepRounding); - 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.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.CROWN_HEIGHT * 100, Accuracy.HalfStepRounding); + info.Dev = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.CROWN_H_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.CROWN_H_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.CROWN_H_MAX); info.CutLevel = calGrade_CROWN_HEIGHT(result.Measurements.CROWN_H_MIN, result.Measurements.CROWN_H_MAX); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.CROWN_HEIGHT_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_1); - info.Dtl2 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_2); - info.Dtl3 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_3); - info.Dtl4 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_4); - info.Dtl5 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_5); - info.Dtl6 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_6); - info.Dtl7 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_7); - info.Dtl8 = FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P(data.CROWN_HEIGHT_DETAIL.CROWN_HEIGHT_8); } info.SymLevel = calGradeSym(info.TestItemId, calSymValue(data.CROWN_H_MIN, data.CROWN_H_MAX, data.CROWN_HEIGHT)); return info; @@ -858,22 +862,22 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "GIRDLE_BEZEL"; info.TestItemName = GetName("GIRDLE_BEZEL"); - info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_BEZEL * 100, Accuracy.ForceOneDecimal); - 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); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.GIRDLE_BEZEL * 100, Accuracy.ForceOneDecimal); + info.Dev = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_BEZEL_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_BEZEL_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_BEZEL_MAX); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.GIRDLE_BEZEL_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_1); - info.Dtl2 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_2); - info.Dtl3 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_3); - info.Dtl4 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_4); - info.Dtl5 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_5); - info.Dtl6 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_6); - info.Dtl7 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_7); - info.Dtl8 = FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BEZEL_DETAIL.GIRDLE_BEZEL_8); } info.SymLevel = calGradeSym(info.TestItemId, calSymValue(data.GIRDLE_BEZEL_MIN, data.GIRDLE_BEZEL_MAX, data.GIRDLE_BEZEL)); return info; @@ -885,21 +889,21 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "GIRDLE_BONE"; info.TestItemName = GetName("GIRDLE_BONE"); - info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_BONE * 100, Accuracy.ForceOneDecimal); - info.Min = FormatDouble_P(result.Measurements.GIRDLE_BONE_MIN); - info.Max = FormatDouble_P(result.Measurements.GIRDLE_BONE_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.GIRDLE_BONE * 100, Accuracy.ForceOneDecimal); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_BONE_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_BONE_MAX); info.isEnabled = false; var data = result.Measurements; if (data.GIRDLE_BONE_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_1); - info.Dtl2 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_2); - info.Dtl3 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_3); - info.Dtl4 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_4); - info.Dtl5 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_5); - info.Dtl6 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_6); - info.Dtl7 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_7); - info.Dtl8 = FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P(data.GIRDLE_BONE_DETAIL.GIRDLE_BONE_8); } @@ -912,10 +916,10 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "GIRDLE"; info.TestItemName = GetName("GIRDLE"); - info.Avg = FormatDouble_Avg(result.Measurements.GIRDLE_VALLEY * 100, Accuracy.HalfStepRounding); - info.Dev = FormatDouble_P(result.Measurements.GIRDLE_VALLEY_DEV); - info.Min = FormatDouble_P(result.Measurements.GIRDLE_VALLEY_MIN); - info.Max = FormatDouble_P(result.Measurements.GIRDLE_VALLEY_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.GIRDLE_VALLEY * 100, Accuracy.HalfStepRounding); + info.Dev = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_VALLEY_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_VALLEY_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.GIRDLE_VALLEY_MAX); info.CutLevel = calGrade_GIRDLE(result.Measurements.GIRDLE, result.Measurements.GIRDLE); info.Dev = calDev(info.Max, info.Min); @@ -942,14 +946,14 @@ public class GradingResultVM : BaseViewModel doubles.Add(girdleValleyDetail.GIRDLE_VALLEY_15); doubles.Add(girdleValleyDetail.GIRDLE_VALLEY_16); doubles.Sort(); - info.Dtl1= FormatDouble_P2(doubles[0]); - info.Dtl2 = FormatDouble_P2(doubles[1]); - info.Dtl3 = FormatDouble_P2(doubles[2]); - info.Dtl4 = FormatDouble_P2(doubles[3]); - info.Dtl5 = FormatDouble_P2(doubles[12]); - info.Dtl6 = FormatDouble_P2(doubles[13]); - info.Dtl7 = FormatDouble_P2(doubles[14]); - info.Dtl8 = FormatDouble_P2(doubles[15]); + info.Dtl1= DoubleDataFormatHelper.FormatDouble_P2(doubles[0]); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P2(doubles[1]); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P2(doubles[2]); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P2(doubles[3]); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P2(doubles[12]); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P2(doubles[13]); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P2(doubles[14]); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P2(doubles[15]); } @@ -963,23 +967,23 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "PAV_ANGLE"; info.TestItemName = GetName("PAV_ANGLE"); - info.Avg = FormatDouble_Avg(result.Measurements.PAV_ANGLE, Accuracy.DecimalTwoStepRounding); - info.Dev = FormatDouble_A(result.Measurements.PAV_ANGLE_DEV); - info.Min = FormatDouble_A(result.Measurements.PAV_ANGLE_MIN); - info.Max = FormatDouble_A(result.Measurements.PAV_ANGLE_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.PAV_ANGLE, Accuracy.DecimalTwoStepRounding); + info.Dev = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.PAV_ANGLE_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.PAV_ANGLE_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.PAV_ANGLE_MAX); info.CutLevel = calGrade_PAV_ANGLE(result.Measurements.PAV_ANGLE_MIN, result.Measurements.PAV_ANGLE_MAX); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.PAV_ANGLE_DETAIL != null) { - info.Dtl1 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_1); - info.Dtl2 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_2); - info.Dtl3 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_3); - info.Dtl4 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_4); - info.Dtl5 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_5); - info.Dtl6 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_6); - info.Dtl7 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_7); - info.Dtl8 = FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_A(data.PAV_ANGLE_DETAIL.PAV_ANGLE_8); } info.SymLevel = calGradeSym(info.TestItemId, calSymValue(data.PAV_ANGLE_MIN, data.PAV_ANGLE_MAX, data.PAV_ANGLE, false)); return info; @@ -991,23 +995,23 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "PAV_DEPTH"; info.TestItemName = GetName("PAV_DEPTH"); - info.Avg = FormatDouble_Avg(result.Measurements.PAV_DEPTH*100, Accuracy.HalfStepRounding); - 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.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.PAV_DEPTH*100, Accuracy.HalfStepRounding); + info.Dev = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.PAV_DEPTH_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.PAV_DEPTH_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.PAV_DEPTH_MAX); info.CutLevel = calGrade_PAV_DEPTH(result.Measurements.PAV_DEPTH_MIN, result.Measurements.PAV_DEPTH_MAX); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.PAV_DEPTH_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_1); - info.Dtl2 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_2); - info.Dtl3 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_3); - info.Dtl4 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_4); - info.Dtl5 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_5); - info.Dtl6 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_6); - info.Dtl7 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_7); - info.Dtl8 = FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P(data.PAV_DEPTH_DETAIL.PAV_DEPTH_8); } info.SymLevel = calGradeSym(info.TestItemId, calSymValue(data.PAV_DEPTH_MIN, data.PAV_DEPTH_MAX, data.PAV_DEPTH)); @@ -1020,22 +1024,22 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "STAR"; info.TestItemName = GetName("STAR"); - info.Avg = FormatDouble_Avg(result.Measurements.STAR*100, Accuracy.MultipleOfFive); - info.Min = FormatDouble_P(result.Measurements.STAR_MIN); - info.Max = FormatDouble_P(result.Measurements.STAR_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.STAR*100, Accuracy.MultipleOfFive); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.STAR_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.STAR_MAX); info.CutLevel = calGrade_STAR(result.Measurements.STAR_MIN, result.Measurements.STAR_MAX); info.isEnabled = false; var data = result.Measurements; if (data.STAR_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.STAR_DETAIL.STAR_1); - info.Dtl2 = FormatDouble_P(data.STAR_DETAIL.STAR_2); - info.Dtl3 = FormatDouble_P(data.STAR_DETAIL.STAR_3); - info.Dtl4 = FormatDouble_P(data.STAR_DETAIL.STAR_4); - info.Dtl5 = FormatDouble_P(data.STAR_DETAIL.STAR_5); - info.Dtl6 = FormatDouble_P(data.STAR_DETAIL.STAR_6); - info.Dtl7 = FormatDouble_P(data.STAR_DETAIL.STAR_7); - info.Dtl8 = FormatDouble_P(data.STAR_DETAIL.STAR_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P(data.STAR_DETAIL.STAR_8); } return info; } @@ -1046,22 +1050,22 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "LOWER_HALVES_RATIO"; info.TestItemName = GetName("LOWER_HALVES_RATIO"); - info.Avg = FormatDouble_Avg(result.Measurements.LOWER_HALVES_RATIO*100, Accuracy.MultipleOfFive); - info.Min = FormatDouble_P(result.Measurements.LOWER_HALVES_RATIO_MIN); - info.Max = FormatDouble_P(result.Measurements.LOWER_HALVES_RATIO_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.LOWER_HALVES_RATIO*100, Accuracy.MultipleOfFive); + info.Min = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.LOWER_HALVES_RATIO_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_P(result.Measurements.LOWER_HALVES_RATIO_MAX); info.CutLevel = calGrade_LOWER_HALVES_RATIO(result.Measurements.LOWER_HALVES_RATIO_MIN, result.Measurements.LOWER_HALVES_RATIO_MAX); info.isEnabled = false; var data = result.Measurements; if (data.LOWER_HALVES_RATIO_DETAIL != null) { - info.Dtl1 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_1); - info.Dtl2 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_2); - info.Dtl3 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_3); - info.Dtl4 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_4); - info.Dtl5 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_5); - info.Dtl6 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_6); - info.Dtl7 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_7); - info.Dtl8 = FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_P(data.LOWER_HALVES_RATIO_DETAIL.LOWER_HALVES_RATIO_8); } return info; } @@ -1072,7 +1076,7 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "CULET"; info.TestItemName = GetName("CULET"); - info.Avg = FormatDouble_Avg(result.Measurements.CULET * 100, Accuracy.ForceOneDecimal); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.CULET * 100, Accuracy.ForceOneDecimal); info.CutLevel = calGrade_CULET(result.Measurements.CULET); info.isEnabled = false; @@ -1085,7 +1089,7 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "TOC"; info.TestItemName = GetName("TOC"); - info.Avg = FormatDouble_Avg(result.Measurements.TOC * 100, Accuracy.ForceOneDecimal); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.TOC * 100, Accuracy.ForceOneDecimal); var data = result.Measurements; info.SymLevel = calGradeSym(info.TestItemId, data.TOC * 100); @@ -1098,7 +1102,7 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "COC"; info.TestItemName = GetName("COC"); - info.Avg = FormatDouble_Avg(result.Measurements.COC*100, Accuracy.ForceOneDecimal); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.COC*100, Accuracy.ForceOneDecimal); var data = result.Measurements; info.SymLevel = calGradeSym(info.TestItemId, data.COC * 100); return info; @@ -1111,22 +1115,22 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "TWIST"; info.TestItemName = GetName("TWIST"); - info.Avg = FormatDouble_Avg(result.Measurements.TWIST, Accuracy.ForceOneDecimal); - info.Dev = FormatDouble_A(result.Measurements.TWIST_DEV); - info.Min = FormatDouble_A(result.Measurements.TWIST_MIN); - info.Max = FormatDouble_A(result.Measurements.TWIST_MAX); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.TWIST, Accuracy.ForceOneDecimal); + info.Dev = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.TWIST_DEV); + info.Min = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.TWIST_MIN); + info.Max = DoubleDataFormatHelper.FormatDouble_A(result.Measurements.TWIST_MAX); info.Dev = calDev(info.Max, info.Min); var data = result.Measurements; if (data.TWIST_DETAIL != null) { - info.Dtl1 = FormatDouble_A(data.TWIST_DETAIL.TWIST_1); - info.Dtl2 = FormatDouble_A(data.TWIST_DETAIL.TWIST_2); - info.Dtl3 = FormatDouble_A(data.TWIST_DETAIL.TWIST_3); - info.Dtl4 = FormatDouble_A(data.TWIST_DETAIL.TWIST_4); - info.Dtl5 = FormatDouble_A(data.TWIST_DETAIL.TWIST_5); - info.Dtl6 = FormatDouble_A(data.TWIST_DETAIL.TWIST_6); - info.Dtl7 = FormatDouble_A(data.TWIST_DETAIL.TWIST_7); - info.Dtl8 = FormatDouble_A(data.TWIST_DETAIL.TWIST_8); + info.Dtl1 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_1); + info.Dtl2 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_2); + info.Dtl3 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_3); + info.Dtl4 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_4); + info.Dtl5 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_5); + info.Dtl6 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_6); + info.Dtl7 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_7); + info.Dtl8 = DoubleDataFormatHelper.FormatDouble_A(data.TWIST_DETAIL.TWIST_8); } info.SymLevel = calGradeSym(info.TestItemId, calSymValue(data.TWIST_MIN, data.TWIST_MAX, data.TWIST)); return info; @@ -1138,7 +1142,7 @@ public class GradingResultVM : BaseViewModel DataInfo info = new DataInfo(); info.TestItemId = "CULET_TO_TABLE"; info.TestItemName = GetName("CULET_TO_TABLE"); - info.Avg = FormatDouble_Avg(result.Measurements.CULET_TO_TABLE*100,Accuracy.ForceOneDecimal); + info.Avg = DoubleDataFormatHelper.FormatDouble_Avg(result.Measurements.CULET_TO_TABLE*100,Accuracy.ForceOneDecimal); var data = result.Measurements; info.SymLevel = calGradeSym(info.TestItemId, data.CULET_TO_TABLE * 100); return info; @@ -1500,17 +1504,17 @@ public class GradingResultVM : BaseViewModel col = 0; dataRow = sheet.CreateRow(row); Measurements info = algorithmResult.Measurements; - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.M1)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.M2)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.M3)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.TABLE)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.CROWN_HEIGHT)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.PAV_DEPTH)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.TOTAL_DEPTH)}%"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.CROWN_ANGLE)}°"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.PAV_ANGLE)}°"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_A2(info.CULET_SIZE)}(mm)"); - dataRow.CreateCell(col++).SetCellValue($"{FormatDouble_P2(info.GIRDLE)}%"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_A2(info.M1)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_A2(info.M2)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_A2(info.M3)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_P2(info.TABLE)}%"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_P2(info.CROWN_HEIGHT)}%"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_P2(info.PAV_DEPTH)}%"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_P2(info.TOTAL_DEPTH)}%"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_A2(info.CROWN_ANGLE)}°"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_A2(info.PAV_ANGLE)}°"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_A2(info.CULET_SIZE)}(mm)"); + dataRow.CreateCell(col++).SetCellValue($"{DoubleDataFormatHelper.FormatDouble_P2(info.GIRDLE)}%"); // 腰部厚度英文 dataRow.CreateCell(col++).SetCellValue($"{calGirdleName(info)}"); dataRow.CreateCell(col++).SetCellValue($""); @@ -1645,123 +1649,7 @@ public class GradingResultVM : BaseViewModel } return girdleName; } - /// <summary> - /// 直径的小数格式化 - /// </summary> - /// <param name="value"></param> - /// <returns></returns> - [Log] - private string FormatDouble_D(double value) - { - // 2025/03/28 维护阶段发现直径切舍为四舍五入,现在改成直接切割 - //return value.ToString("f2"); - return (Math.Floor(value*100)/100).ToString("f2"); - } - /// <summary> - /// 百分比用的小数格式化 - /// </summary> - /// <param name="value"></param> - /// <returns></returns> - [Log] - private string FormatDouble_P(double value) - { - return (Math.Floor(value*1000)/10).ToString(digitsFormat); - } - [Log] - private string FormatDouble_P2(double value) - { - return (Math.Floor(value * 10000) / 100).ToString("f2"); - } - /// <summary> - /// 百分比用的小数格式化 - /// </summary> - /// <param name="value"></param> - /// <returns></returns> - [Log] - private string FormatDouble_Avg(double value, Accuracy accuracy) - { - string result = ""; - if (Common.RunMode == 0) - { - switch (accuracy) - { - case Accuracy.ForceTwoDecimals: - result = (Math.Floor(value * 100) / 100).ToString("f2"); - break; - case Accuracy.ForceOneDecimal: - result = (Math.Floor(value * 10) / 10).ToString("f1"); - break; - case Accuracy.HalfStepRounding: - result = (RoundFiveDownSixUp(value * 2) / 2).ToString("f1"); - break; - case Accuracy.MultipleOfFive: - result = (RoundFiveDownSixUp(value / 5) * 5).ToString(); - break; - case Accuracy.DecimalTwoStepRounding: - result = RoundToPointTwo(value).ToString("f1"); // 保留1位小数 - break; - case Accuracy.IntegerFloor: - result = Math.Floor(value).ToString("F1"); // 直接取整 - break; - } - } - else - { - //工厂模式不量化 - switch (accuracy) - { - case Accuracy.ForceTwoDecimals: - result = (Math.Floor(value * 100) / 100).ToString("f2"); - break; - case Accuracy.HalfStepRounding: - case Accuracy.ForceOneDecimal: - case Accuracy.DecimalTwoStepRounding: - case Accuracy.IntegerFloor: - case Accuracy.MultipleOfFive: - result = (Math.Floor(value * 10) / 10).ToString("f1"); - break; - } - } - - - return result; - } - [Log] - private static double RoundFiveDownSixUp(double value) - { - // 提取整数部分 - double integerPart = Math.Truncate(value); - // 提取小数部分 - double fractionalPart = value - integerPart; - - // 判断小数部分是否大于 0.5 - return fractionalPart > 0.5 ? integerPart + 1 : integerPart; - } - private static double RoundToPointTwo(double value) - { - // 转换到10倍精度空间处理 - double scaled = value * 10; - double remainder = scaled % 2; // 求模得到余数 - - // 核心舍入规则:余数>=1.5时进位 - return remainder >= 1.5 ? (scaled - remainder + 2) / 10 : (scaled - remainder) / 10; - } - /// <summary> - /// 直接值(角度,直径)用的小数格式化 - /// </summary> - /// <param name="value"></param> - /// <returns></returns> - [Log] - private string FormatDouble_A(double value) - { - return (Math.Floor(value * 10) / 10).ToString(digitsFormat); - } - [Log] - private string FormatDouble_A2(double value) - { - return (Math.Floor(value * 100) / 100).ToString("f2"); - } [Log] private async Task DatFile(string filePath) { @@ -2011,108 +1899,108 @@ public class GradingResultVM : BaseViewModel private void setDIAMETER_DETAIL(RowDetail row) { DiameterDetail diameterDetail = algorithmResult.Measurements.DIAMETER_DETAIL; - row.item1 = FormatDouble_D(diameterDetail.DIAMETER_1); - row.item2 = FormatDouble_D(diameterDetail.DIAMETER_2); - row.item3 = FormatDouble_D(diameterDetail.DIAMETER_3); - row.item4 = FormatDouble_D(diameterDetail.DIAMETER_4); - row.item5 = FormatDouble_D(diameterDetail.DIAMETER_5); - row.item6 = FormatDouble_D(diameterDetail.DIAMETER_6); - row.item7 = FormatDouble_D(diameterDetail.DIAMETER_7); - row.item8 = FormatDouble_D(diameterDetail.DIAMETER_8); + row.item1 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_1); + row.item2 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_2); + row.item3 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_3); + row.item4 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_4); + row.item5 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_5); + row.item6 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_6); + row.item7 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_7); + row.item8 = DoubleDataFormatHelper. FormatDouble_D(diameterDetail.DIAMETER_8); calIndex(row); } [Log] private void setTABLE_DETAIL(RowDetail row) { TableDetail diameterDetail = algorithmResult.Measurements.TABLE_DETAIL; - row.item1 = FormatDouble_P(diameterDetail.TABLE_1); - row.item2 = FormatDouble_P(diameterDetail.TABLE_2); - row.item3 = FormatDouble_P(diameterDetail.TABLE_3); - row.item4 = FormatDouble_P(diameterDetail.TABLE_4); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(diameterDetail.TABLE_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(diameterDetail.TABLE_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(diameterDetail.TABLE_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(diameterDetail.TABLE_4); calIndex(row); } [Log] private void setCROWN_HEIGHT_DETAIL(RowDetail row) { CrownHeightDetail crownHeightDetail = algorithmResult.Measurements.CROWN_HEIGHT_DETAIL; - row.item1 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_1); - row.item2 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_2); - row.item3 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_3); - row.item4 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_4); - row.item5 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_5); - row.item6 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_6); - row.item7 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_7); - row.item8 = FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_P(crownHeightDetail.CROWN_HEIGHT_8); calIndex(row); } [Log] private void setCROWN_ANGLE_DETAIL(RowDetail row) { CrownAngleDetail crownAngleDetail = algorithmResult.Measurements.CROWN_ANGLE_DETAIL; - row.item1 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_1); - row.item2 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_2); - row.item3 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_3); - row.item4 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_4); - row.item5 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_5); - row.item6 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_6); - row.item7 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_7); - row.item8 = FormatDouble_A(crownAngleDetail.CROWN_ANGLE_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_A(crownAngleDetail.CROWN_ANGLE_8); calIndex(row); } [Log] private void setPAV_DEPTH_DETAIL(RowDetail row) { PavDepthDetail pavDepthDetail = algorithmResult.Measurements.PAV_DEPTH_DETAIL; - row.item1 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_1); - row.item2 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_2); - row.item3 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_3); - row.item4 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_4); - row.item5 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_5); - row.item6 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_6); - row.item7 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_7); - row.item8 = FormatDouble_P(pavDepthDetail.PAV_DEPTH_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_P(pavDepthDetail.PAV_DEPTH_8); calIndex(row); } [Log] private void setPAV_ANGLE_DETAIL(RowDetail row) { PavAngleDetail pavAngleDetail = algorithmResult.Measurements.PAV_ANGLE_DETAIL; - row.item1 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_1); - row.item2 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_2); - row.item3 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_3); - row.item4 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_4); - row.item5 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_5); - row.item6 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_6); - row.item7 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_7); - row.item8 = FormatDouble_A(pavAngleDetail.PAV_ANGLE_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_A(pavAngleDetail.PAV_ANGLE_8); calIndex(row); } [Log] private void setGIRDLE_BEZEL_DETAIL(RowDetail row) { GirdleBezelDetail girdleBezelDetail = algorithmResult.Measurements.GIRDLE_BEZEL_DETAIL; - row.item1 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_1); - row.item2 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_2); - row.item3 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_3); - row.item4 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_4); - row.item5 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_5); - row.item6 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_6); - row.item7 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_7); - row.item8 = FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_P(girdleBezelDetail.GIRDLE_BEZEL_8); calIndex(row); } [Log] private void setGIRDLE_BONE_DETAIL(RowDetail row) { GirdleBoneDetail girdleBoneDetail = algorithmResult.Measurements.GIRDLE_BONE_DETAIL; - row.item1 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_1); - row.item2 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_2); - row.item3 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_3); - row.item4 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_4); - row.item5 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_5); - row.item6 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_6); - row.item7 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_7); - row.item8 = FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_P(girdleBoneDetail.GIRDLE_BONE_8); calIndex(row); } @@ -2138,56 +2026,56 @@ public class GradingResultVM : BaseViewModel doubles.Add(girdleValleyDetail.GIRDLE_VALLEY_15); doubles.Add(girdleValleyDetail.GIRDLE_VALLEY_16); doubles.Sort(); - row.item1 = FormatDouble_P2(doubles[0]); - row.item2 = FormatDouble_P2(doubles[1]); - row.item3 = FormatDouble_P2(doubles[2]); - row.item4 = FormatDouble_P2(doubles[3]); - row.item5 = FormatDouble_P2(doubles[12]); - row.item6 = FormatDouble_P2(doubles[13]); - row.item7 = FormatDouble_P2(doubles[14]); - row.item8 = FormatDouble_P2(doubles[15]); + row.item1 = DoubleDataFormatHelper.FormatDouble_P2(doubles[0]); + row.item2 = DoubleDataFormatHelper.FormatDouble_P2(doubles[1]); + row.item3 = DoubleDataFormatHelper.FormatDouble_P2(doubles[2]); + row.item4 = DoubleDataFormatHelper.FormatDouble_P2(doubles[3]); + row.item5 = DoubleDataFormatHelper.FormatDouble_P2(doubles[12]); + row.item6 = DoubleDataFormatHelper.FormatDouble_P2(doubles[13]); + row.item7 = DoubleDataFormatHelper.FormatDouble_P2(doubles[14]); + row.item8 = DoubleDataFormatHelper.FormatDouble_P2(doubles[15]); calIndex(row); } [Log] private void setSTAR_DETAIL(RowDetail row) { StarDetail starDetail = algorithmResult.Measurements.STAR_DETAIL; - row.item1 = FormatDouble_P(starDetail.STAR_1); - row.item2 = FormatDouble_P(starDetail.STAR_2); - row.item3 = FormatDouble_P(starDetail.STAR_3); - row.item4 = FormatDouble_P(starDetail.STAR_4); - row.item5 = FormatDouble_P(starDetail.STAR_5); - row.item6 = FormatDouble_P(starDetail.STAR_6); - row.item7 = FormatDouble_P(starDetail.STAR_7); - row.item8 = FormatDouble_P(starDetail.STAR_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_P(starDetail.STAR_8); calIndex(row); } [Log] private void setLOWER_HALVES_RATIO_DETAIL(RowDetail row) { LowerHalvesRatioDetail lowerHalvesRatioDetail = algorithmResult.Measurements.LOWER_HALVES_RATIO_DETAIL; - row.item1 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_1); - row.item2 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_2); - row.item3 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_3); - row.item4 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_4); - row.item5 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_5); - row.item6 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_6); - row.item7 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_7); - row.item8 = FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_P(lowerHalvesRatioDetail.LOWER_HALVES_RATIO_8); calIndex(row); } [Log] private void setTWIST_DETAIL(RowDetail row) { TwistDetail twistDetail = algorithmResult.Measurements.TWIST_DETAIL; - row.item1 = FormatDouble_A(twistDetail.TWIST_1); - row.item2 = FormatDouble_A(twistDetail.TWIST_2); - row.item3 = FormatDouble_A(twistDetail.TWIST_3); - row.item4 = FormatDouble_A(twistDetail.TWIST_4); - row.item5 = FormatDouble_A(twistDetail.TWIST_5); - row.item6 = FormatDouble_A(twistDetail.TWIST_6); - row.item7 = FormatDouble_A(twistDetail.TWIST_7); - row.item8 = FormatDouble_A(twistDetail.TWIST_8); + row.item1 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_1); + row.item2 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_2); + row.item3 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_3); + row.item4 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_4); + row.item5 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_5); + row.item6 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_6); + row.item7 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_7); + row.item8 = DoubleDataFormatHelper.FormatDouble_A(twistDetail.TWIST_8); calIndex(row); } @@ -2380,124 +2268,8 @@ public class GradingResultVM : BaseViewModel cell.SetCellValue(value?.ToString() ?? ""); } } -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 Dtl1 { get; set; } = string.Empty; - public string Dtl2 { get; set; } = string.Empty; - public string Dtl3 { get; set; } = string.Empty; - public string Dtl4 { get; set; } = string.Empty; - public string Dtl5 { get; set; } = string.Empty; - public string Dtl6 { get; set; } = string.Empty; - public string Dtl7 { get; set; } = string.Empty; - public string Dtl8 { get; set; } = string.Empty; - public string? CutLevel { get; set; } - private Int64? _symLevel; - //public int? SymLevel { get; set; } - public Int64? 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 - { - return _gradeList; - } - set - { - _gradeList = value; - } - } - public event PropertyChangedEventHandler PropertyChanged; - protected void OnPropertyChanged(string propertyName) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } -} -public class Name -{ - public string Id { get; set; } - public string name { get; set; } - [Log] - public static string getNameById(string id) - { - string sql = $"SELECT NAME, EN_NAME FROM NAME WHERE ID = '{id}'"; - DataTable data = DataBaseHelper.ExecuteQuery(sql); - string nameType = "zn-ch".Equals(MultilingualHelper.getLangType())?"NAME":MultilingualHelper.getString("NameType"); - if (data.Rows.Count>0) - { - return data.Rows[0][nameType].ToString(); - } - else - { - return ""; - } - } -} -public class RowDetail -{ - public string? itemName { get; set; } - public string? Avg { get; set; } - public string? Dev { get; set; } - public string? Min { get; set; } - public string? Max { get; set; } - public string? item1 { get; set; } - public string? item2 { get; set; } - public string? item3 { get; set; } - public string? item4 { get; set; } - public string? item5 { get; set; } - public string? item6 { get; set; } - public string? item7 { get; set; } - public string? item8 { get; set; } - public string? CutLevel { get; set; } - public string? SymLevel { get; set; } - public int? MaxIndex { get; set; } - public int? MinIndex { get; set; } -} -public enum SaveStatus -{ - AutoSave = 0, - Save=1, - SaveAs=2 -} -public enum Accuracy -{ - [Description("强制保留两位小数,向下取整(ZDZ1)")] - ForceTwoDecimals, - [Description("强制保留一位小数,向下取整(ZD1)")] - ForceOneDecimal, - [Description("将数值舍入到最近的 0.5 倍数(ZD5)")] - HalfStepRounding, - [Description("将数值舍入到最近的 5 的整数倍(Z5)")] - MultipleOfFive, - [Description("将数值舍入到最近的0.2倍数(ZD2)")] - DecimalTwoStepRounding, - [Description("强制向下取整为整数(Floor)")] - IntegerFloor -} \ No newline at end of file + + diff --git a/Views/Grading/GradingResult.xaml.cs b/Views/Grading/GradingResult.xaml.cs index 703f9d9..1cdf63f 100644 --- a/Views/Grading/GradingResult.xaml.cs +++ b/Views/Grading/GradingResult.xaml.cs @@ -1,10 +1,10 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Controls.Primitives; -using System.Windows.Forms.VisualStyles; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; +using BrilliantSightClient.Model.GradeResult.Entity; using GlobalHotKey; using log4net; using BrilliantSightClient.Model.Helper; diff --git a/Views/UserControl/Viewport3D.xaml.cs b/Views/UserControl/Viewport3D.xaml.cs index cb1b4a4..4bada30 100644 --- a/Views/UserControl/Viewport3D.xaml.cs +++ b/Views/UserControl/Viewport3D.xaml.cs @@ -91,6 +91,11 @@ public partial class Viewport3D ContextMenu.Items.Remove(ViewportCutXuanZSeparator); } + if (!ViewportManager.DiamondType.Split(" ").First().Equals("ROUND")) + { + ViewportManager.DoubleClickSelect = false; + } + //工厂模式屏蔽一些东西 string step = ViewportManager.DiamondType.Split(" ").Last(); if (Common.RunMode == 1 && step.StartsWith("S")) diff --git a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs index 24d9477..df8b673 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportHelperPro.cs @@ -1793,7 +1793,7 @@ public class ViewportHelperPro var center = ViewportManager.CenterVector; center.Y = Y; double radius = 5; - if (double.TryParse(ViewportManager.DiamondData["M2"].ToString(), out var v)) + if (double.TryParse(ViewportManager.DiamondData["M2"].ToSafeString(), out var v)) { radius = (v * 0.5); } diff --git a/Views/UserControl/ViewportData/Helper/ViewportManager.cs b/Views/UserControl/ViewportData/Helper/ViewportManager.cs index c6717b3..bb4ccd8 100644 --- a/Views/UserControl/ViewportData/Helper/ViewportManager.cs +++ b/Views/UserControl/ViewportData/Helper/ViewportManager.cs @@ -10,6 +10,7 @@ using BrilliantSightClient.Model.Attributes; using BrilliantSightClient.Views.Dialog; using BrilliantSightClient.Views.UserControl.ViewportData.Entity; using BrilliantSightClient.Views.UserControl.ViewportData.Enum; +using Newtonsoft.Json.Linq; using GeometryModel3D = HelixToolkit.Wpf.SharpDX.GeometryModel3D; namespace BrilliantSightClient.Views.UserControl.ViewportData.Helper; @@ -23,11 +24,12 @@ public class ViewportManager /// </summary> public static List<Viewport3DTriangleEntity> ViewportTriangle = new List<Viewport3DTriangleEntity>(); - public static JsonObject DiamondData = new JsonObject(); + public static JObject DiamondData { get; set; } = new JObject(); public static string DiamondCode = string.Empty; //钻石类型 - public static string DiamondType = string.Empty; + public static string DiamondType { get; set; } = string.Empty; + /// <summary> /// 模型正方向(从模型中心出发的方向) /// </summary> diff --git a/Views/UserControl/ViewportData/ViewportData.cs b/Views/UserControl/ViewportData/ViewportData.cs index eb844e3..b7382a5 100644 --- a/Views/UserControl/ViewportData/ViewportData.cs +++ b/Views/UserControl/ViewportData/ViewportData.cs @@ -8,6 +8,7 @@ using BrilliantSightClient.Model.Helper; using BrilliantSightClient.Views.UserControl.ViewportData.Entity; using BrilliantSightClient.Views.UserControl.ViewportData.Enum; using BrilliantSightClient.Views.UserControl.ViewportData.Helper; +using Newtonsoft.Json.Linq; using SparkDotNetCore.DiamondScanner.Entity; namespace BrilliantSightClient.Views.UserControl.ViewportData; @@ -109,7 +110,8 @@ public class ViewportData ViewportManager.DiamondCode = DiamondCode; ViewportManager.DiamondType = diamondData.ErrorMsg.ToSafeString(); - ViewportManager.DiamondData = JsonObject.Parse(JsonConvert.SerializeObject(diamondData.Measurements)).AsObject(); + if(diamondData.Measurements != null) + ViewportManager.DiamondData = JObject.Parse(JsonConvert.SerializeObject(diamondData.Measurements)); var midZ = facets.SelectMany(e => new[] { e.Point1.X, e.Point2.X, e.Point3.X }).OrderBy(z => Math.Abs(z)) .First(); List<Viewport3DTriangleEntity> facetsFinal = new List<Viewport3DTriangleEntity>(); @@ -160,7 +162,7 @@ public class ViewportData facetsFinal.Add(item); } - if (diamondData.Status.Equals("P021")) + if (diamondData.Status != null && diamondData.Status.Equals("P021")) { ViewportManager.isUglyDiamond = true; } diff --git a/ffmpeg.exe b/ffmpeg.exe deleted file mode 100644 index a364320..0000000 Binary files a/ffmpeg.exe and /dev/null differ