@ -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>