using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using TProduct.Model;
namespace TProduct.WinFrmUI.TPump
{
///
/// 性能测试
///
public partial class FeatTestIngMainPage
{
///
/// 赋值
///
///
///
///
///
public void SetBindingData(
TProduct.Model.ProductMainExPump pump,
TProduct.Model.PartBase part,
TProduct.Model.TestProjectItemView item,
TProduct.Model.WorkBenchBase workBench)
{
if (workBench == null)
{
MessageBox.Show("还未设置workBench参数");
return;
}
if (item == null)
{
MessageBox.Show("还未设置item参数");
return;
}
if (pump == null)
{
MessageBox.Show("还未设置pump参数");
return;
}
if (part == null)
{
MessageBox.Show("还未设置part参数");
return;
}
if (string.IsNullOrEmpty(pump.RatedParas))
{
MessageBox.Show("还未设置泵的额定参数");
return;
}
this._workBenchInfo = workBench;
this._testItem = item;
this._currentPump = pump;
this._currentPart = part;
this._ratedParas = TProduct.Model.RatedParas4Pump.ToModel(pump.RatedParas);
if (_currentPump.MotorMainID.HasValue && _currentPump.MotorMainID > 0)
{
_currentMotor = new BLL.ProductMotor().GetExByProductID((long)_currentPump.MotorMainID);
}
this._currentPumpSeries = new BLL.ProductSeries().GetByID(this._currentPump.SeriesID);
if (this._currentPumpSeries == null)
{
MessageBox.Show("当前泵对应系列未找到");
return;
}
if (TProduct.CorpSetting.PumpTest.IsRefreshAdditionInfo)
{
_isRefreshAdditionInfo = true;
}
else
{
_isRefreshAdditionInfo = false;
bbi刷新状态信息.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
}
ribbonPageGroup开停机.Visible = false;
bsiOperateInfo.Caption = "";
this._isInnerMotor = _currentPumpSeries.IsInnerMotor == 1 ? true : false;
//初始化操作提示
InitialNoticeList();
//从数据库中获取以前的测试数据: 里面会初始化 _allMonitorPointList 的值
if (!InitialLink())
{
//MessageBox.Show("初始化测点失败");
return;
}
//从数据库中获取以前的测试数据
List allRecords4Ds =
new BLL.PumpFeatTestRecord().GetByTestItem(item);
this._allRecords = new List();
if (allRecords4Ds != null)
{
foreach (var r in allRecords4Ds)
{
this._allRecords.Add(new TProduct.Model.PumpFeatTestRecordViewModel(r) { MonitorRecordList = new TProduct.Model.MonitorRecord4DsList(r.MonitorRecords) });
}
}
//数据记录辅助类(放在前面)
_monitorValveIngRecordHelper = new MonitorValveIngRecordHelper();
_monitorValveIngRecordHelper.Initial(
TProduct.Model.eProductType.Pump,
this._currentPumpSeries.ID,
this._currentPump.ID,
this._currentPart.ID,
this._testItem,
this._workBenchInfo,
this._allMonitorPointList);
//初始化耐久测试
InitialDurabilityTest();
//
InitialJudgeItem();
//
InitialGuages(_allMonitorPointList);
//
if (!InitialCalcDialog(this._currentPumpSeries, this._currentPump, _currentMotor, workBench, item, _allMonitorPointList))
{
return;
}
//
InitialMonitorGrid(_allMonitorPointList);
//修正点表和实时数据控件
InitialCorrentPtGrid();
//
InitialAutoTestGrid(_allMonitorPointList);
//
IntialMainChart();
//
IntialPartInfoCtrl();
//测试日志
InitialTestLogCtrl();
//记录操控
InitialRecordOperateCtrl();
//三维模型
InitialModel3d();
//工艺流程图
InitialProcessDrawing();
//通讯日志(放在最后)
InitialLinkLogCtrl();
bbiPumpName.Caption = string.Format("泵ID:{0},型号:{1}", pump.ID, pump.Name);
TProduct.LogHelper.Test(string.Format("开始进行性能测试,泵型号:{0}", pump.Name));
}
///
/// 初始化操作注意事项
///
List _allNoticeRecordList = null;
private void InitialNoticeList()
{
bbi注意事项.Enabled = false;
var productStyle = new BLL.ProductStyle().GetByID(this._currentPumpSeries.ProductStyleID);
if (productStyle == null)
return;
var notice_matter = new BLL.TestNoticeMattter().GetDefaultByProductType(productStyle.ID);
if (notice_matter == null)
return;
var details = new BLL.TestNoticeItem().GetListByMatterID(notice_matter.ID);
if (details == null || details.Count == 0)
return;
var records = new BLL.TestNoticeRecord().GetByTestItem(this._testItem);
_allNoticeRecordList = new List();
foreach (Model.TestNoticeItemEx detail in details)
{
var v = new TestNoticeRecordView(detail);
v.TestItemID = this._testItem.ItemID;
if (records != null && records.Count > 0)
{
var r = records.Find(x => x.NoticeItemID == detail.ID);
if (r != null)
{
v.RecordID = r.ID;
v.Value = r.Value;
v.DsValue = r.Value;
v.Note = r.Note;
v.DsNote = r.Note;
}
}
_allNoticeRecordList.Add(v);
}
bbi注意事项.Enabled = true;
}
///
/// 设置测点
///
///
///
private List ResetMonitorPoint(
List list)
{
if (list == null || list.Count() == 0)
{
return null;
}
//this._monitorTotalFlow = list.Find(x => x.MonitorType == Model.eMonitorType.流量);
var instrumentInfo = this._testItem.InstrumentInfo;
if (instrumentInfo != null)
{
#region 出口压力
var out_press_index = list.FindIndex(x => x.MonitorType == Model.eMonitorType.压力
&& x.Property == TProduct.Model.MonitorTypeProperty.出口);
if (out_press_index >= 0)
{
var monitor_outletPress = list[out_press_index];
//设置出口压力表量程
if (instrumentInfo.OutletPressureMeterID > 0)
{
var meter = new BLL.PressureMeter().GetByID(instrumentInfo.OutletPressureMeterID);
if (meter != null)
{
if (monitor_outletPress.AnalogParas == null)
monitor_outletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_outletPress.AnalogParas.RangeMax = meter.RangeMax;
monitor_outletPress.AnalogParas.RangeMin = meter.RangeMin;
list[out_press_index] = monitor_outletPress;
}
}
if (instrumentInfo.OutletPressureMeterPipeDia > 0)
{// 暂时用不到, 都是从测点或者泵上获取的,代码暂时保留
if (monitor_outletPress.AnalogParas == null)
monitor_outletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_outletPress.PipeDia = instrumentInfo.OutletPressureMeterPipeDia;
}
if (instrumentInfo.InletPressureMeterElevation > 0)
{
if (monitor_outletPress.AnalogParas == null)
monitor_outletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_outletPress.Elevation = instrumentInfo.OutletPressureMeterElevation;
}
//1:来源泵口径
if (TProduct.UserSetting.Setting.PumpTest.OutletPressMonitorDiaStatus == 1 && _ratedParas != null)
{
if (this._ratedParas.OutletDia.HasValue && _ratedParas.OutletDia > 0)
{
if (monitor_outletPress.AnalogParas == null)
monitor_outletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_outletPress.PipeDia = this._ratedParas.OutletDia.Value;
}
}
}
#endregion
#region 进口压力
var inlet_press_index = list.FindIndex(x => x.MonitorType == Model.eMonitorType.压力
&& x.Property == TProduct.Model.MonitorTypeProperty.进口);
if (inlet_press_index >= 0)
{
var monitor_inletPress = list[inlet_press_index];
if (instrumentInfo.InletPressureMeterID > 0)
{
var meter = new BLL.PressureMeter().GetByID(instrumentInfo.InletPressureMeterID);
if (meter != null)
{
if (monitor_inletPress.AnalogParas == null)
monitor_inletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_inletPress.AnalogParas.RangeMax = meter.RangeMax;
monitor_inletPress.AnalogParas.RangeMin = meter.RangeMin;
list[inlet_press_index] = monitor_inletPress;
}
}
if (instrumentInfo.InletPressureMeterPipeDia > 0)
{
if (monitor_inletPress.AnalogParas == null)
monitor_inletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_inletPress.PipeDia = instrumentInfo.InletPressureMeterPipeDia;
}
if (instrumentInfo.InletPressureMeterElevation > 0)
{
if (monitor_inletPress.AnalogParas == null)
monitor_inletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_inletPress.Elevation = instrumentInfo.InletPressureMeterElevation;
}
//1:来源泵口径
if (TProduct.UserSetting.Setting.PumpTest.InletPressMonitorDiaStatus == 1 && _ratedParas != null)
{
if (this._ratedParas.InletDia.HasValue && _ratedParas.InletDia > 0)
{
if (monitor_inletPress.AnalogParas == null)
monitor_inletPress.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_inletPress.PipeDia = this._ratedParas.InletDia.Value;
}
}
}
#endregion
#region 流量
if (instrumentInfo.FlowMeterRangeMax > instrumentInfo.FlowMeterRangeMin)
{
var flow_index = list.FindIndex(x => x.MonitorType == Model.eMonitorType.流量);
if (flow_index >= 0)
{
var monitor_flow = list[flow_index];
if (monitor_flow.AnalogParas == null)
monitor_flow.AnalogParas = new Model.AnalogMonitorPointParas();
monitor_flow.AnalogParas.RangeMax = instrumentInfo.FlowMeterRangeMax;
monitor_flow.AnalogParas.RangeMin = instrumentInfo.FlowMeterRangeMin;
}
}
#endregion
}
var testMethod = new Model.WorkBenchMethod4Pump(this._workBenchInfo.TestMethod);
if (testMethod.Power == Model.ePowerTestMethod.扭矩)
{
var monitor扭矩 = list.Find(x => x.MonitorType == Model.eMonitorType.扭矩);
if (monitor扭矩 == null)
{
monitor扭矩 = new Model.WorkBenchMonitorPoint()
{
Name = "扭矩",
MonitorType = Model.eMonitorType.扭矩,
SumCalcCoeff = 1,
ValueCoeffParas = null,
UseStatus = Model.eUseStatus.Enable,
SourceType = Model.eMonitorPointSourceType.数字量,
DigitalParas = null,
DispInPanel = 1,
AnalogParas = null,
BenchID = this._workBenchInfo.ID,
CreateTime = DateTime.Now,
CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
UpdateTime = DateTime.Now,
UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
SortCode = 6
};
monitor扭矩.ID = new BLL.WorkBenchMonitorPoint().Insert(monitor扭矩);
list.Add(monitor扭矩);
}
}
else if (!_isInnerMotor)
{
var monitor电机效率 = list.Find(x => x.MonitorType == Model.eMonitorType.电机效率);
if (monitor电机效率 == null)
{
monitor电机效率 = new Model.WorkBenchMonitorPoint()
{
Name = "电机效率",
MonitorType = Model.eMonitorType.电机效率,
SumCalcCoeff = 1,
ValueCoeffParas = null,
UseStatus = Model.eUseStatus.Enable,
SourceType = Model.eMonitorPointSourceType.计算量,
DigitalParas = null,
DispInPanel = 1,
AnalogParas = null,
BenchID = this._workBenchInfo.ID,
CreateTime = DateTime.Now,
CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
UpdateTime = DateTime.Now,
UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
SortCode = 6
};
monitor电机效率.ID = new BLL.WorkBenchMonitorPoint().Insert(monitor电机效率);
list.Add(monitor电机效率);
}
}
if (this._testItem.ProjectParas != null)
{
var testParas = this._testItem.ProjectParas;
if (testParas.IsTemperatureTrn)
{
var monitor介质温度 = list.Find(x => x.MonitorType == Model.eMonitorType.介质温度);
if (monitor介质温度 == null)
{
monitor介质温度 = new Model.WorkBenchMonitorPoint()
{
Name = "介质温度",
MonitorType = Model.eMonitorType.介质温度,
SumCalcCoeff = 1,
ValueCoeffParas = null,
UseStatus = Model.eUseStatus.Enable,
SourceType = Model.eMonitorPointSourceType.计算量,
DigitalParas = null,
DispInPanel = 1,
AnalogParas = null,
BenchID = this._workBenchInfo.ID,
CreateTime = DateTime.Now,
CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
UpdateTime = DateTime.Now,
UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
SortCode = 11
};
monitor介质温度.ID = new BLL.WorkBenchMonitorPoint().Insert(monitor介质温度);
list.Add(monitor介质温度);
}
}
}
// if(_parallelInfo != null && _parallelInfo.Count > 0)
// {
// var monitor并联参考进口 = list.Find(x =>
// x.MonitorType == Model.eMonitorType.压力 &&
// x.Property == TProduct.Model.MonitorTypeProperty.并联泵进口);
// if (monitor并联参考进口 == null)
// {
// monitor并联参考进口 = new Model.WorkBenchMonitorPoint()
// {
// Name = "并联进口压力",
// MonitorType = Model.eMonitorType.压力,
// ValueCoefficient = 1,
// ValueAdditional = 0,
// UseStatus = Model.eUseStatus.Enable,
// SourceType = Model.eMonitorPointSourceType.未知,
// DigitalParas = null,
// DispInPanel = 1,
// AnalogParas = null,
// BenchID = this._workBenchInfo.ID,
// Tag = TProduct.Model.MonitorTypeProperty.并联泵进口,
// CreateTime = DateTime.Now,
// CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
// UpdateTime = DateTime.Now,
// UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
// SortCode = 12
// };
// monitor并联参考进口.ID = new BLL.WorkBenchMonitorPoint().Insert(monitor并联参考进口);
// list.Add(monitor并联参考进口);
// }
// var monitor并联参考出口 = list.Find(x =>
//x.MonitorType == Model.eMonitorType.压力 &&
//x.Property == TProduct.Model.MonitorTypeProperty.并联泵出口);
// if (monitor并联参考出口 == null)
// {
// monitor并联参考出口 = new Model.WorkBenchMonitorPoint()
// {
// Name = "并联进口出力",
// MonitorType = Model.eMonitorType.压力,
// ValueCoefficient = 1,
// ValueAdditional = 0,
// UseStatus = Model.eUseStatus.Enable,
// SourceType = Model.eMonitorPointSourceType.未知,
// DigitalParas = null,
// DispInPanel = 1,
// AnalogParas = null,
// BenchID = this._workBenchInfo.ID,
// Tag = TProduct.Model.MonitorTypeProperty.并联泵出口,
// CreateTime = DateTime.Now,
// CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
// UpdateTime = DateTime.Now,
// UpdateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID,
// SortCode = 12
// };
// monitor并联参考出口.ID = new BLL.WorkBenchMonitorPoint().Insert(monitor并联参考出口);
// list.Add(monitor并联参考出口);
// }
// }
return list;
}
//初始化Comm链接控件
private bool InitialCommConnectCtrl(List ComPortNameList)
{
if (_commCtrl == null)
{
if (ComPortNameList.Count > 1)
{
var multiComStepCtrl = new TProduct.WinFrmUI.TBase.CommConMultiCtrl();
multiComStepCtrl.Name = "CommConMultiCtrl";
multiComStepCtrl.Dock = DockStyle.Fill;
// 修改了Comm链接
multiComStepCtrl.OnChangeConnectStatus += this.ChangeCommConnectStatus;
panelComm.Controls.Clear();
panelComm.Controls.Add(multiComStepCtrl);
_commCtrl = multiComStepCtrl;
string error_info;
var ret = multiComStepCtrl.InitialData(ComPortNameList, out error_info);
if (!ret)
{
MessageBox.Show(error_info);
}
}
else if (ComPortNameList.Count == 1)
{
var singleComStepCtrl = new TProduct.WinFrmUI.TBase.CommConSingleCtrl();
singleComStepCtrl.Name = "CommConSingleCtrl";
singleComStepCtrl.Dock = DockStyle.Fill;
// 修改了Comm链接
singleComStepCtrl.OnChangeConnectStatus += this.ChangeCommConnectStatus;
panelComm.Controls.Clear();
panelComm.Controls.Add(singleComStepCtrl);
_commCtrl = singleComStepCtrl;
string error_info;
var ret = singleComStepCtrl.InitialData(ComPortNameList.First(), out error_info);
if (!ret)
{
MessageBox.Show(error_info);
}
}
}
return true;
}
//初始化仪表控件
private void InitialGuages(
List allMonitorList)
{
if (allMonitorList == null || allMonitorList.Count == 0)
return;
var sort_allMonitorList = (from x in allMonitorList orderby x.SortCode descending select x).ToList();
_allMonitorGaugeDict = new Dictionary();
this.gaugeDockPanel.Controls.Clear();
for (int i = 0; i < sort_allMonitorList.Count(); i++)
{
var monitor = sort_allMonitorList[i];
if (monitor.DispInPanel == 0)
continue;
var gaugeControl = TProduct.WinFrmUI.TBase.UserGaugeControl.Build(TProduct.UserSetting.Setting.Disp.GaugeStyle);
gaugeControl.SetBindingData(
Model.eProductType.Pump,
this._testItem.TestType,
monitor,
this._testItem.AlarmSetting);
gaugeControl.Size = new Size(153, 80);
gaugeControl.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
//gaugeControl.Margin = new System.Windows.Forms.Padding(10, 0, 0, 10);
//gaugeControl.Height = 90;
//gaugeControl.Width = 165;
gaugeControl.Dock = DockStyle.Left;
if (monitor.MonitorType == Model.eMonitorType.耐久时间)
{
if (_durabilityTestTimeHelper == null)
{
continue;
}
//
_durabilityTestTimeHelper.OnRefreshMintueTime += (mintue) =>
{
gaugeControl.RefreshRecordValue(mintue);
};
var totalMinute = _durabilityTestTimeHelper.GetTotalMintueTime();
gaugeControl.InitialRecordValue(totalMinute);
}
if (monitor.MonitorType == Model.eMonitorType.转速)
{
if (monitor.SourceType == Model.eMonitorPointSourceType.额定参数)
gaugeControl.InitialRecordValue(this._currentPump.Ratedn.Value);
}
this.gaugeDockPanel.Controls.Add(gaugeControl);
//gaugeControl.InitialRecordValue(-1);
//添加到字典中
_allMonitorGaugeDict[monitor.ID] = gaugeControl;
}
//if (allMonitorList.Count > 5)
//{//两排
// splitContainerControlMain.SplitterPosition = 200;
//}
}
List _parallelInfo = null;
///
/// 在SetBindingData之前调用
///
///
internal void SetParallelInfo(List parallelInfo)
{
this._parallelInfo = parallelInfo;
}
private void IntialMainChart()
{
if (_chartMainCtrl == null)
{
_chartMainCtrl = new ChartLxpFeatCurveCtrl();
_chartMainCtrl.Name = "ChartFeatTestCtrl";
_chartMainCtrl.Dock = DockStyle.Fill;
this.tableLayoutPanel1.Controls.Add(this._chartMainCtrl, 0, 1);
this.chartBarCtrl.cmbSetAction += (cmd, tag) =>
{
if (cmd == "显示效率线")
{
this._chartMainCtrl.SetEtaDisp(Convert.ToBoolean(tag));
}
if (cmd == "显示功率线")
{
this._chartMainCtrl.SetPowerDisp(Convert.ToBoolean(tag));
}
if (cmd == "显示判定点")
{
this._chartMainCtrl.SetJudgePointDisp(Convert.ToBoolean(tag));
}
if (cmd == "显示装置曲线")
{
this._chartMainCtrl.SetEquipCurveDisp(Convert.ToBoolean(tag));
}
if (cmd == "查询参数")
{
this._chartMainCtrl.SetQueryLineDisp1(Convert.ToBoolean(tag));
}
if (cmd == "曲线方程")
{
this._chartMainCtrl.ShowCurveEquation( );
}
};
}
_chartMainCtrl.SetEtaDisp(TProduct.UserSetting.Setting.PumpTest.IsDispCurveQE);
_chartMainCtrl.SetPowerDisp(TProduct.UserSetting.Setting.PumpTest.IsDispCurveQP);
_chartMainCtrl.SetRatedParas(this._currentPump, this._ratedParas, this._testJudgeItems);
if (_allRecords == null || _allRecords.Count == 0)
{
_chartMainCtrl.UpdateCoordByRatedParas();
}
else
{
_chartMainCtrl.SetRecordPoint(this._allRecords);
_chartMainCtrl.UpdateChart(true);
}
_chartMainCtrl.SetEtaDisp(TProduct.UserSetting.Setting.PumpTest.IsDispCurveQE);
_chartMainCtrl.SetPowerDisp(TProduct.UserSetting.Setting.PumpTest.IsDispCurveQP);
}
}
}