using DevExpress.XtraEditors;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Windows.Forms;
|
|
namespace TProduct.WinFrmUI.TValve
|
{
|
//
|
internal partial class CalcFeatTestData1Dlg : CalcFeatTestBaseDlg
|
{
|
public CalcFeatTestData1Dlg()
|
{
|
InitializeComponent();
|
|
btnOK.Enabled = false;
|
this.gridViewMain.OptionsDetail.ShowDetailTabs = false;//不显示TAB名
|
this.gridViewMain.OptionsView.ShowGroupPanel = false;//隐藏最上面的GroupPanel
|
this.gridViewMain.OptionsSelection.MultiSelect = false;//单选
|
//this.gridViewMain.OptionsBehavior.Editable = false;//只读
|
this.gridViewMain.BestFitColumns();
|
this.gridViewMain.IndicatorWidth = 2;
|
this.gridViewMain.RowHeight = 25;
|
|
flow_unit = TProduct.UserSetting.Setting.ValveTest.UnitFlow;
|
press_unit = TProduct.UserSetting.Setting.ValveTest.UnitPress;
|
|
lblCorrectQ.Text = string.Format("流量({0})", Eventech.Common.UnitQHelper.GetEnUnitName(flow_unit));
|
labelYaCha.Text = string.Format("压差({0})", Eventech.Common.UnitHHelper.GetEnUnitName(press_unit));
|
|
this.btnCorrect.SetCalcButtonColor();
|
this.btnOK.SetConfirmButtonColor();
|
this.btnCancel.SetCancelButtonColor();
|
}
|
|
private void CalcTestData1Dlg_Load(object sender, EventArgs e)
|
{
|
|
}
|
public class CurrentViewModel
|
{
|
public CurrentViewModel() { }
|
public TProduct.Model.WorkBenchMonitorPoint Entity { get; set; }
|
public long ID { get; set; }
|
public string MonitorName { get; set; }
|
public string UnitName { get; set; }//单位
|
public double? DispValue { get; set; }
|
public DateTime Time { get; set; }
|
}
|
//
|
List<CurrentViewModel> _bindingData = null;
|
public override void InitialMonitorInfo(List<TProduct.Model.WorkBenchMonitorPoint> allMonitorList)
|
{
|
this._allMonitorList = allMonitorList;
|
|
this._bindingData = new List<CurrentViewModel>();
|
foreach (var monitor in allMonitorList)
|
{
|
CurrentViewModel v = new CurrentViewModel();
|
v.Entity = monitor;
|
v.ID = monitor.ID;
|
v.MonitorName = monitor.Name;
|
v.UnitName = GetUnitName(monitor);
|
v.DispValue = null;
|
|
_bindingData.Add(v);
|
}
|
}
|
|
//
|
private TProduct.Model.ValveFeatTestRecordViewModel _currentRecord = null;
|
public override void NewTestRecord(List<TProduct.Model.MonitorPointValuePure> valueList)
|
{
|
if (_bindingData == null)
|
return;
|
if (valueList == null || valueList.Count() == 0)
|
{
|
foreach (var bd in _bindingData)
|
{
|
if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.计算量)
|
continue;
|
if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度)
|
continue;
|
bd.DispValue = null;
|
}
|
}
|
else
|
{
|
foreach (var bd in _bindingData)
|
{
|
var f = valueList.Find(x => x.ID == bd.ID);
|
if (f == null || f.Value == null)
|
{
|
if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.计算量)
|
continue;
|
if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度)
|
continue;
|
bd.DispValue = null;
|
continue;
|
}
|
|
double rMeasureValue = f.Value.Value;
|
if (bd.Entity.MonitorType == Model.eMonitorType.功率)
|
{
|
rMeasureValue = Eventech.Common.UnitPHelper.fromKW(
|
power_unit, rMeasureValue);
|
}
|
else if (bd.Entity.MonitorType == Model.eMonitorType.流量)
|
{
|
rMeasureValue = Eventech.Common.UnitQHelper.fromM3H(
|
flow_unit, rMeasureValue);
|
}
|
else if (bd.Entity.MonitorType == Model.eMonitorType.压力)
|
{
|
rMeasureValue = Eventech.Common.UnitHHelper.fromMPa(
|
press_unit, rMeasureValue);
|
}
|
|
bd.DispValue = rMeasureValue;
|
bd.Time = f.Time;
|
|
}
|
}
|
|
bindingSource1.DataSource = _bindingData;
|
bindingSource1.ResetBindings(false);
|
btnOK.Enabled = false;
|
|
_currentRecord = new TProduct.Model.ValveFeatTestRecordViewModel();
|
_currentRecord.TestItemID = this._testItemID;
|
_currentRecord.Time = DateTime.Now;
|
_currentRecord.RecordType = this._recordType;
|
}
|
|
public override void EditTestRecord(TProduct.Model.ValveFeatTestRecordViewModel record)
|
{
|
if (record == null)
|
return;
|
foreach (var bd in _bindingData)
|
{
|
var f = record.MonitorRecordList.Find(x => x.ID == bd.ID);
|
if (f == null || string.IsNullOrEmpty(f.Value))
|
{
|
if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.计算量)
|
continue;
|
if (bd.Entity.SourceType == TProduct.Model.eMonitorPointSourceType.额定参数)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.电机效率)
|
continue;
|
if (bd.Entity.MonitorType == TProduct.Model.eMonitorType.介质温度)
|
continue;
|
bd.DispValue = null;
|
}
|
|
double rMeasureValue = Convert.ToDouble(f.Value);
|
if (bd.Entity.MonitorType == Model.eMonitorType.功率)
|
{
|
rMeasureValue = Eventech.Common.UnitPHelper.fromKW(
|
power_unit, rMeasureValue);
|
}
|
else if (bd.Entity.MonitorType == Model.eMonitorType.流量)
|
{
|
rMeasureValue = Eventech.Common.UnitQHelper.fromM3H(
|
flow_unit, rMeasureValue);
|
}
|
else if (bd.Entity.MonitorType == Model.eMonitorType.压力)
|
{
|
rMeasureValue = Eventech.Common.UnitHHelper.fromMPa(
|
press_unit, rMeasureValue);
|
}
|
|
bd.DispValue = rMeasureValue;
|
bd.Time = record.Time;
|
}
|
this._currentRecord = record;
|
|
txt流量.Text = record.Flow.ToString();
|
textBoxP1.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P1)).ToString();
|
textBoxP2.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P2)).ToString();
|
textBoxP3.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, record.P3)).ToString();
|
|
|
textBox压差.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, record.DeltaP)).ToString(); //Math.Round(record.DeltaP, 4).ToString();
|
textBox流量系数.Text = Math.Round(record.Kv, 2).ToString();
|
textBox流阻系数.Text = Math.Round(record.Rc, 4).ToString();
|
textBox流速.Text = Math.Round(record.V, 3).ToString();
|
|
|
bindingSource1.DataSource = _bindingData;
|
bindingSource1.ResetBindings(false);
|
btnOK.Enabled = false;
|
}
|
|
//参数 都是标准单位
|
private double Degree;//开度
|
protected double Density;//密度
|
private double Viscosity;
|
private double Flow;//流量
|
private double P1, P2, P3;
|
private double Re;//雷诺数
|
private double V;//流速
|
private double DeltaP;//压差
|
private double Kv;//流量系数
|
private double Rc;//流阻系数
|
|
//计算
|
private void btnCorrect_Click(object sender, EventArgs e)
|
{
|
btnOK.Enabled = false;
|
|
try
|
{
|
if (!CalcMeasurePara())
|
return;
|
|
//计算测试修正值
|
if (!CalculePara())
|
return;
|
|
|
txt流量.Text = TProduct.Common.RoundHelper.GetDispValueFlow(
|
Eventech.Common.UnitQHelper.fromM3H(flow_unit, Flow)).ToString();
|
textBoxP1.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, P1)).ToString();
|
textBoxP2.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, P2)).ToString();
|
textBoxP3.Text = TProduct.Common.RoundHelper.GetDispValuePress(
|
Eventech.Common.UnitHHelper.fromMPa(press_unit, P3)).ToString();
|
|
this.textBox雷诺数.Text = Math.Round(Re, 5).ToString();
|
this.textBox压差.Text = Math.Round(DeltaP * 1000, 1).ToString();//DeltaP * 1000;//换算成KPa
|
this.textBox流量系数.Text = Math.Round(Kv, 4).ToString();
|
this.textBox流阻系数.Text = Math.Round(Rc, 5).ToString();
|
this.textBox流速.Text = Math.Round(this.V, 3).ToString();
|
}
|
catch (Exception ex)
|
{
|
XtraMessageBox.Show(ex.Message, "Error:169");
|
return;
|
}
|
|
btnOK.Enabled = true;
|
}
|
//
|
private bool CalcMeasurePara()
|
{
|
#region P1
|
var moinitor_p1_list = this._bindingData.Where(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.压力 &&
|
x.Entity.Property == TProduct.Model.MonitorTypeProperty.P1);
|
if (moinitor_p1_list == null || moinitor_p1_list.Count() == 0)
|
{
|
XtraMessageBox.Show("请输入P1?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
List<Double> p1_list = new List<double>();
|
foreach (var m in moinitor_p1_list)
|
{
|
if (m.DispValue.HasValue)
|
{
|
p1_list.Add(
|
Eventech.Common.UnitHHelper.toMPa(press_unit, m.DispValue.Value) +
|
Eventech.Common.UnitHHelper.toMPa(Eventech.Model.UnitH.M, m.Entity.GetElevationValve()));
|
}
|
}
|
if (p1_list.Count == 0)
|
{
|
XtraMessageBox.Show("请输入P1?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
else if (p1_list.Count == 1)
|
{
|
this.P1 = p1_list.First();
|
}
|
else
|
{
|
this.P1 = p1_list.Average();
|
}
|
|
|
#endregion
|
|
|
#region P2
|
var moinitor_p2_list = this._bindingData.Where(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.压力 &&
|
x.Entity.Property == TProduct.Model.MonitorTypeProperty.P2);
|
if (moinitor_p2_list == null || moinitor_p2_list.Count() == 0)
|
{
|
XtraMessageBox.Show("请输入P2?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
List<Double> p2_list = new List<double>();
|
foreach (var m in moinitor_p2_list)
|
{
|
if (m.DispValue.HasValue)
|
{
|
p2_list.Add(
|
Eventech.Common.UnitHHelper.toMPa(press_unit, m.DispValue.Value) +
|
Eventech.Common.UnitHHelper.toMPa(Eventech.Model.UnitH.M, m.Entity.GetElevationValve()));
|
}
|
}
|
if (p2_list.Count == 0)
|
{
|
XtraMessageBox.Show("请输入P2?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
else if (p2_list.Count == 1)
|
{
|
this.P2 = p2_list.First();
|
}
|
else
|
{
|
this.P2 = p2_list.Average();
|
}
|
|
#endregion
|
|
|
#region P3
|
var moinitor_p3_list = this._bindingData.Where(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.压力 &&
|
x.Entity.Property == TProduct.Model.MonitorTypeProperty.P3);
|
if (moinitor_p3_list == null || moinitor_p3_list.Count() == 0)
|
{
|
XtraMessageBox.Show("请输入P2?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
List<Double> p3_list = new List<double>();
|
foreach (var m in moinitor_p3_list)
|
{
|
if (m.DispValue.HasValue)
|
{
|
p3_list.Add(
|
Eventech.Common.UnitHHelper.toMPa(press_unit, m.DispValue.Value) +
|
Eventech.Common.UnitHHelper.toMPa(Eventech.Model.UnitH.M, m.Entity.GetElevationValve()));
|
}
|
}
|
if (p3_list.Count == 0)
|
{
|
XtraMessageBox.Show("请输入P3?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
else if (p3_list.Count == 1)
|
{
|
this.P3 = p3_list.First();
|
}
|
else
|
{
|
this.P3 = p3_list.Average();
|
}
|
|
#endregion
|
|
|
#region 流量
|
//测量流量
|
var moinitor_flow = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.流量);
|
if (moinitor_flow == null || moinitor_flow.DispValue == null)
|
{
|
XtraMessageBox.Show("请输入流量?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
this.Flow = Eventech.Common.UnitQHelper.toM3H(flow_unit, moinitor_flow.DispValue.Value);
|
|
#endregion
|
|
|
|
#region 开度
|
//测量流量
|
var moinitor_开度 = this._bindingData.Find(x => x.Entity.MonitorType == TProduct.Model.eMonitorType.阀门开度);
|
if (moinitor_开度 == null || moinitor_开度.DispValue == null)
|
{
|
XtraMessageBox.Show("请输入开度?", "问题确认",
|
MessageBoxButtons.OK, MessageBoxIcon.Question);
|
return false;
|
}
|
this.Degree = moinitor_开度.DispValue.Value;
|
#endregion
|
|
|
|
return true;
|
}
|
|
//根据测试参数,计算测试修正值
|
public bool CalculePara()
|
{
|
try
|
{
|
var dia_m = this._dia / 1000;//口径(m)
|
var flow_m3s = this.Flow / 3600;//流量 m3/s
|
this.V = Math.Round(4 * flow_m3s / (Math.PI * dia_m * dia_m), 4);//流速
|
|
this.Viscosity = 1;//水的运动黏度 单位m2/s 实际和温度也有关系 暂时固定
|
this.Density = TProduct.ConstantParas.WaterDensity;//测试时水密度 实际和温度也有关系 暂时固定
|
|
this.Re = this.V * dia_m / this.Viscosity;//雷诺数
|
|
double deta_p1 = this.P2 - this.P3;//阀门前后取压点压差(MPa)
|
double deta_pt = this.P1 - this.P2;//阀门前管道差压(MPa)
|
|
this.DeltaP = deta_p1 - deta_pt;//MPa
|
if (this.DeltaP < 0.0001)
|
{
|
MessageBox.Show("压差值不合理,请问是否是数据正常");
|
return false;
|
}
|
|
|
|
double midu_15度 = TProduct.ConstantParas.WaterDensity;// 15度时的水密度
|
double kpa_DeltaP = DeltaP * 1000;//换算成KPa
|
|
this.Kv = 10 * this.Flow * Math.Sqrt(this.Density / (midu_15度 * kpa_DeltaP));
|
this.Rc = 2000 * kpa_DeltaP / (this.Density * this.V * this.V);
|
}
|
catch (Exception ex)
|
{
|
XtraMessageBox.Show(ex.ToString());
|
return false;
|
}
|
return true;
|
}
|
|
|
//
|
private void btnOK_Click(object sender, EventArgs e)
|
{
|
if (_bindingData == null)
|
return;
|
|
if (_currentRecord == null)
|
return;
|
try
|
{
|
_currentRecord.Time = DateTime.Now;
|
_currentRecord.Degree = this.Degree;
|
|
_currentRecord.Density = this.Density;
|
_currentRecord.Viscosity = this.Viscosity;
|
_currentRecord.Flow = TProduct.Common.RoundHelper.GetDispValueFlow(this.Flow);
|
_currentRecord.P1 = TProduct.Common.RoundHelper.GetDispValuePress(this.P1);
|
_currentRecord.P2 = TProduct.Common.RoundHelper.GetDispValuePress(this.P2);
|
_currentRecord.P3 = TProduct.Common.RoundHelper.GetDispValuePress(this.P3);
|
_currentRecord.V = Math.Round(this.V, 2);
|
_currentRecord.Re = Math.Round(this.Re, 5);
|
_currentRecord.DeltaP = TProduct.Common.RoundHelper.GetDispValuePress(this.DeltaP);
|
_currentRecord.Kv = Math.Round(this.Kv, 2);
|
_currentRecord.Rc = Math.Round(this.Rc, 4);
|
|
|
TProduct.Model.MonitorRecord4DsList monitorRecord4Ds = new TProduct.Model.MonitorRecord4DsList();
|
foreach (var bd in _bindingData)
|
{
|
double rMeasureValue = bd.DispValue.Value;
|
if (bd.Entity.MonitorType == Model.eMonitorType.功率)
|
{
|
rMeasureValue = Eventech.Common.UnitPHelper.toKW(
|
power_unit, rMeasureValue);
|
}
|
else if (bd.Entity.MonitorType == Model.eMonitorType.流量)
|
{
|
rMeasureValue = Eventech.Common.UnitQHelper.toM3H(
|
flow_unit, rMeasureValue);
|
}
|
else if (bd.Entity.MonitorType == Model.eMonitorType.压力)
|
{
|
rMeasureValue = Eventech.Common.UnitHHelper.toMPa(
|
press_unit, rMeasureValue);
|
}
|
monitorRecord4Ds.Add(new TProduct.Model.MonitorRecord4Ds(bd.ID, rMeasureValue.ToString()));
|
}
|
_currentRecord.MonitorRecordList = monitorRecord4Ds;
|
_currentRecord.MonitorRecords = monitorRecord4Ds.ToDsString();
|
|
if (this.OnSaveRecord == null)
|
return;
|
var bll = new BLL.ValveFeatTestRecord();
|
// operateType表示操作类型 1 表示添加 2 表示更新 3表示删除
|
if (_currentRecord.ID == 0)
|
{
|
_currentRecord.ID = bll.Add(this._testItem, _currentRecord);
|
OnSaveRecord(_currentRecord, 1);
|
}
|
else
|
{
|
bll.Update(this._testItem, _currentRecord);
|
OnSaveRecord(_currentRecord, 2);
|
}
|
}
|
catch (Exception ex)
|
{
|
XtraMessageBox.Show(ex.Message, "Error:184");
|
return;
|
}
|
if (isAutoClose)
|
{
|
this.DialogResult = System.Windows.Forms.DialogResult.OK;
|
this.Close();
|
}
|
else
|
{//注意:此对话框不会关闭,只是隐藏,如果要关闭需要外部关闭
|
txt流量.Text = "";
|
|
|
this.Hide();//不要关闭可能要再次打开
|
}
|
}
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
{
|
if (isAutoClose)
|
{
|
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
|
this.Close();
|
}
|
else
|
{//注意:此对话框不会关闭,只是隐藏,如果要关闭需要外部关闭
|
this.Hide();
|
}
|
}
|
|
|
private void gridView1_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
|
{
|
//DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo group = e.Info as DevExpress.XtraGrid.Views.Grid.ViewInfo.GridGroupRowInfo;
|
//if (Convert.ToBoolean(group.EditValue))
|
//{
|
// group.GroupText = "仪表获取";
|
//}
|
//else
|
//{
|
// group.GroupText = "手动输入";
|
//}
|
}
|
|
private void GridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
|
{
|
//if (e.Column == colUnitName)
|
//{
|
// e.Value = "";
|
// var mv = e.Row as TProduct.Model.MonitorPointValue;
|
// if (mv == null)
|
// return;
|
// e.Value = TProduct.Common.MonitorTypeHelper.GetUnitName(mv.MonitorType);
|
//}
|
}
|
|
|
|
|
|
|
|
|
}
|
}
|