using DevExpress.XtraEditors;
|
using DevExpress.XtraGrid.Columns;
|
using System.Data;
|
|
namespace IStation.Win
|
{
|
public partial class ModelValidView : XtraUserControl
|
{
|
public ModelValidView()
|
{
|
InitializeComponent();
|
this.treeList1.InitialMultiColSettings();
|
this.treeList1.OptionsBehavior.AllowRecursiveNodeChecking = true;//获取或设置父节点时是否自动检查/取消检查子节点
|
this.treeList1.OptionsView.CheckBoxStyle = DevExpress.XtraTreeList.DefaultNodeCheckBoxStyle.Check;//设置勾选框样式
|
this.treeList1.OptionsBehavior.AllowIndeterminateCheckState = false;
|
|
this.gridView1.SetNormalView();
|
this.gridView2.SetNormalView();
|
this.gridView2.OptionsView.ColumnAutoWidth = false;
|
|
//this.dateEditStart.SetOnlyShowYearMonth();
|
//this.dateEditEnd.SetOnlyShowYearMonth();
|
|
var year = 2024;
|
var month = 1;
|
this.dateEditStart.DateTime = new DateTime(year, month, 1);
|
this.dateEditEnd.DateTime = new DateTime(year, month, DateTime.DaysInMonth(year, month));
|
InitTreeList();
|
}
|
|
|
private void InitTreeList()
|
{
|
var list=new List<ModelValidModelMappingViewModel>();
|
var config = new IStation.Service.HydraulicModelValidationConfig().Get();
|
var flow_id_mapping_dict = config.FlowIdMappingDict;
|
foreach (var item in flow_id_mapping_dict)
|
{
|
var vm=new ModelValidModelMappingViewModel();
|
vm.ModelId=item.Key;
|
vm.ScadaId=item.Value;
|
vm.IsChecked = false;
|
list.Add(vm);
|
}
|
|
var pressure_id_mapping_dict = config.PressureIdMappingDict;
|
foreach (var item in pressure_id_mapping_dict)
|
{
|
var vm = new ModelValidModelMappingViewModel();
|
vm.ModelId = item.Key;
|
vm.ScadaId = item.Value;
|
vm.IsChecked = false;
|
list.Add(vm);
|
}
|
|
this.treeList1.DataSource = list;
|
this.treeList1.RefreshDataSource();
|
}
|
|
|
private List<Model.HydraulicModelRecord> _hydraulic_model_record_list = null;
|
private DataTable _data_table = null;
|
private bool _init = false;
|
private void Init()
|
{
|
if (_init)
|
return;
|
_data_table = new DataTable();
|
|
var data_table_col_time = new DataColumn("Time");
|
_data_table.Columns.Add(data_table_col_time);
|
_data_table.PrimaryKey = new DataColumn[] { data_table_col_time };
|
|
var col_time = new GridColumn();
|
col_time.FieldName = "Time";
|
col_time.Caption = "时间";
|
this.gridView2.Columns.Add(col_time);
|
|
var config = new IStation.Service.HydraulicModelValidationConfig().Get();
|
foreach (var item in config.FlowIdMappingDict)
|
{
|
var col_key = new GridColumn();
|
col_key.FieldName = item.Key;
|
col_key.Caption = item.Key;
|
col_key.Visible = true;
|
this.gridView2.Columns.Add(col_key);
|
|
var col_value = new GridColumn();
|
col_value.FieldName = item.Value;
|
col_value.Caption = item.Value;
|
col_value.Visible = true;
|
this.gridView2.Columns.Add(col_value);
|
|
var col_key_value = new GridColumn();
|
col_key_value.FieldName = GetTempId(item.Key, item.Value);
|
col_key_value.Caption = GetTempId(item.Key, item.Value);
|
col_key_value.Visible = true;
|
this.gridView2.Columns.Add(col_key_value);
|
|
|
|
_data_table.Columns.Add(item.Key, typeof(string));
|
_data_table.Columns.Add(item.Value, typeof(string));
|
_data_table.Columns.Add(GetTempId(item.Key, item.Value), typeof(string));
|
}
|
|
foreach (var item in config.PressureIdMappingDict)
|
{
|
var col_key = new GridColumn();
|
col_key.FieldName = item.Key;
|
col_key.Caption = item.Key;
|
col_key.Visible = true;
|
this.gridView2.Columns.Add(col_key);
|
|
var col_value = new GridColumn();
|
col_value.FieldName = item.Value;
|
col_value.Caption = item.Value;
|
col_value.Visible = true;
|
this.gridView2.Columns.Add(col_value);
|
|
var col_key_value = new GridColumn();
|
col_key_value.FieldName = GetTempId(item.Key, item.Value);
|
col_key_value.Caption = GetTempId(item.Key, item.Value);
|
col_key_value.Visible = true;
|
this.gridView2.Columns.Add(col_key_value);
|
|
_data_table.Columns.Add(item.Key, typeof(string));
|
_data_table.Columns.Add(item.Value, typeof(string));
|
_data_table.Columns.Add(GetTempId(item.Key, item.Value), typeof(string));
|
}
|
|
_init = true;
|
}
|
|
private string GetTempId(string key,string value)
|
{
|
return $"{key}_{value}_diff";
|
}
|
|
//加载
|
private void barBtnLoad_Click(object sender, EventArgs e)
|
{
|
WaitHelper.ShowWaitForm();
|
|
Init();
|
|
var start_time = this.dateEditStart.DateTime;
|
var end_time = this.dateEditEnd.DateTime;
|
|
_hydraulic_model_record_list = new IStation.Service.HydraulicModelRecord().GetByDate(start_time, end_time);
|
if (_hydraulic_model_record_list == null || !_hydraulic_model_record_list.Any())
|
{
|
WaitHelper.HideWaitForm();
|
XtraMessageBox.Show("无数据!");
|
return;
|
}
|
SetGridView1(_hydraulic_model_record_list);
|
//SetGridView2(_hydraulic_model_record_list);
|
WaitHelper.HideWaitForm();
|
}
|
|
|
|
private void SetGridView1(List<Model.HydraulicModelRecord> hydraulic_model_record_list)
|
{
|
var model_valid_vm_list = new List<ModelValidViewModel>();
|
if (hydraulic_model_record_list != null && hydraulic_model_record_list.Any())
|
{
|
foreach (var hydraulic_model_record in hydraulic_model_record_list)
|
{
|
var model_valid_vm = new ModelValidViewModel();
|
model_valid_vm.Time = hydraulic_model_record.Time;
|
model_valid_vm.ValueType = hydraulic_model_record.ValueType;
|
model_valid_vm.ModelId = hydraulic_model_record.ModelId;
|
model_valid_vm.ScadaId = hydraulic_model_record.ScadaId;
|
model_valid_vm.ModeValue = hydraulic_model_record.ModeValue;
|
model_valid_vm.ScadaValue = hydraulic_model_record.ScadaValue;
|
model_valid_vm.DifferenceValue = hydraulic_model_record.DifferenceValue;
|
model_valid_vm.Round();
|
model_valid_vm_list.Add(model_valid_vm);
|
}
|
}
|
this.modelValidViewModelBindingSource.DataSource = model_valid_vm_list;
|
this.modelValidViewModelBindingSource.ResetBindings(false);
|
}
|
|
private void SetGridView2(List<Model.HydraulicModelRecord> hydraulic_model_record_list)
|
{
|
_data_table.Rows.Clear();
|
if (hydraulic_model_record_list != null && hydraulic_model_record_list.Any())
|
{
|
foreach (var hydraulic_model_record in hydraulic_model_record_list)
|
{
|
var time = hydraulic_model_record.Time.ToString("G");
|
var model_id = hydraulic_model_record.ModelId;
|
var scada_id = hydraulic_model_record.ScadaId;
|
var model_scada_id = GetTempId(model_id, scada_id);
|
|
DataRow dr = _data_table.Rows.Find(time);
|
if (dr == null)
|
{
|
dr = _data_table.NewRow();
|
dr["Time"] = time;
|
dr[model_id] = hydraulic_model_record.ModeValue;
|
dr[scada_id] = hydraulic_model_record.ScadaValue;
|
dr[model_scada_id] = hydraulic_model_record.DifferenceValue;
|
_data_table.Rows.Add(dr);
|
}
|
else
|
{
|
dr[model_id] = hydraulic_model_record.ModeValue;
|
dr[scada_id] = hydraulic_model_record.ScadaValue;
|
dr[model_scada_id] = hydraulic_model_record.DifferenceValue;
|
}
|
}
|
}
|
this.gridControl2.DataSource = _data_table;
|
this.gridControl2.RefreshDataSource();
|
this.gridView2.BestFitColumns();
|
}
|
|
}
|
}
|