using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace TProduct.WinFrmUI.TestBench
{
public partial class SetSingleBenchMonitorPointInoCtrl : DevExpress.XtraEditors.XtraUserControl
{
public SetSingleBenchMonitorPointInoCtrl()
{
InitializeComponent();
this.imgComMonitorType.Properties.Items.AddEnum(typeof(Model.eMonitorType), false);
this.imgComUserStatus.Properties.Items.AddEnum(typeof(Model.eUseStatus), false);
}
private Model.WorkBenchMonitorPoint _model = null;
private string _oldName = string.Empty;
///
/// 添加
///
public void SetBindingData(long benchID)
{
_model = new Model.WorkBenchMonitorPoint();
_model.CreateTime = DateTime.Now;
_model.CreateUserID = TProduct.WinFrmUI.GlobeParas.CurrentLoginUser.ID;
_model.UpdateTime = DateTime.Now;
_model.BenchID = benchID;
_model.UseStatus = Model.eUseStatus.Enable;
var sortCode = new BLL.WorkBenchMonitorPoint().GetMaxSortCode(benchID);
this.txtSortCode.EditValue = ++sortCode;
this.imgComUserStatus.EditValue = Model.eUseStatus.Enable;
this.checkEditDispInPanel.Checked = true;
}
public void SetBindingData(Model.WorkBenchMonitorPoint model)
{
if (model == null)
return;
_model = model;
_oldName = _model.Name;
this.txtName.EditValue = _model.Name;
this.textEditTag.Text = _model.Tag;
this.txtPipeDia.EditValue = _model.PipeDia;
this.imgComMonitorType.EditValue = _model.MonitorType;
this.txtElevation.EditValue = _model.Elevation;
this.txtSortCode.EditValue = _model.SortCode;
this.imgComUserStatus.EditValue = _model.UseStatus;
this.checkEditDispInPanel.Checked = model.DispInPanel == 0 ? false : true;
this.check在实时曲线界面中显示.Checked = model.DispInRealChart == 0 ? false : true;
this.comboBoxSource.EditValue = (int)model.SourceType;
this.textEditIStationID.Text = _model.IStationID;
var list_propte = Model.MonitorTypeProperty.GetPropertyList(_model.MonitorType);
this.txtProperty.Properties.Items.Clear();
list_propte?.ForEach(x => this.txtProperty.Properties.Items.Add(x));
this.txtProperty.Text = _model.Property;
spinEditSumCalcCoeff.Text = model.SumCalcCoeff.ToString();
if (model.ValueCoeffParas != null)
{
simpleLabelItem数据修正.Text = "数据已设置修正";
}
if (model.PointParas != null)
{
checkEdit是否可以出现负值.Checked = model.PointParas.IsHaveNavigateValue;
}
if (model.SourceType == Model.eMonitorPointSourceType.数字量)
{
if (model.DigitalParas != null)
{
textEditRegisterAddress.Text = model.DigitalParas.RegisterAddress.ToString();
spinEditDataLength.Text = model.DigitalParas.DataLength.ToString();
spinEditDecimalPointPosition.Text = model.DigitalParas.DecimalPointPosition.ToString();
if (model.DigitalParas.ValueType == 0)
{
imageComboBoxDtype.SelectedIndex = 0;
layoutControlGroup模拟量.Enabled = false;
}
else if (model.DigitalParas.ValueType == 1)
{
imageComboBoxDtype.SelectedIndex = 1;
layoutControlGroup模拟量.Enabled = true;
if (model.AnalogParas != null)
{
spinEditRangeMax.Text = model.AnalogParas.RangeMax.ToString();
spinEditRangeMin.Text = model.AnalogParas.RangeMin.ToString();
}
}
}
}
else if (model.SourceType == Model.eMonitorPointSourceType.模拟量)
{
if (model.AnalogParas != null)
{
spinEditRangeMax.Text = model.AnalogParas.RangeMax.ToString();
spinEditRangeMin.Text = model.AnalogParas.RangeMin.ToString();
}
}
}
///
/// 获取数据
///
///
public Model.WorkBenchMonitorPoint GetData()
{
if (_model == null)
return null;
if (!Verify())
return null;
_model.Name = this.txtName.Text.Trim();
_model.Property = this.txtProperty.Text.Trim();
_model.Tag = this.textEditTag.Text;
_model.MonitorType = (Model.eMonitorType)this.imgComMonitorType.EditValue;
if (!string.IsNullOrEmpty(this.txtPipeDia.Text))
_model.PipeDia = double.Parse(this.txtPipeDia.Text.Trim());
else
_model.PipeDia = null;
if (!string.IsNullOrEmpty(this.txtElevation.Text))
_model.Elevation = double.Parse(this.txtElevation.Text.Trim());
else
_model.Elevation = null;
//if (!string.IsNullOrEmpty(this.txtValueCoefficient.Text))
// _model.ValueCoefficient = double.Parse(this.txtValueCoefficient.Text.Trim());
//if (!string.IsNullOrEmpty(this.txtValueAdditional.Text))
// _model.ValueAdditional = double.Parse(this.txtValueAdditional.Text.Trim());
if (!string.IsNullOrEmpty(this.txtSortCode.Text))
_model.SortCode = int.Parse(this.txtSortCode.Text.Trim());
_model.SumCalcCoeff = Convert.ToDouble(spinEditSumCalcCoeff.Text);
if (_model.PointParas == null)
_model.PointParas = new Model.MonitorPointParas();
_model.PointParas.IsHaveNavigateValue = checkEdit是否可以出现负值.Checked;
_model.IStationID = this.textEditIStationID.Text;
if (this.comboBoxSource.SelectedIndex == 0)
{
_model.DigitalParas = null;
_model.AnalogParas = null;
_model.SourceType = Model.eMonitorPointSourceType.未知;
}
else if (this.comboBoxSource.SelectedIndex == 1)
{
_model.DigitalParas = null;
_model.SourceType = Model.eMonitorPointSourceType.模拟量;
_model.AnalogParas = new Model.AnalogMonitorPointParas();
_model.AnalogParas.RangeMax = Convert.ToDouble(spinEditRangeMax.Text);
_model.AnalogParas.RangeMin = Convert.ToDouble(spinEditRangeMin.Text);
}
else if (this.comboBoxSource.SelectedIndex == 2)
{
_model.SourceType = Model.eMonitorPointSourceType.数字量;
_model.DigitalParas = new Model.DigitalMonitorPointParas();
if (string.IsNullOrEmpty(textEditRegisterAddress.Text))
{
_model.DigitalParas.RegisterAddress = 0;
}
else if (textEditRegisterAddress.Text.ToLower().Contains("0x"))
{
_model.DigitalParas.RegisterAddress = Convert.ToByte(textEditRegisterAddress.Text, 16);
}
else
{
_model.DigitalParas.RegisterAddress = Convert.ToInt32(textEditRegisterAddress.Text);
}
_model.DigitalParas.DataLength = Convert.ToInt32(spinEditDataLength.Text);
_model.DigitalParas.DecimalPointPosition = Convert.ToInt32(spinEditDecimalPointPosition.Text);
_model.DigitalParas.ValueType = Convert.ToInt32(imageComboBoxDtype.EditValue);
if (_model.DigitalParas.ValueType == 0)
{
_model.AnalogParas = null;
}
else
{
_model.AnalogParas = new Model.AnalogMonitorPointParas();
_model.AnalogParas.RangeMax = Convert.ToDouble(spinEditRangeMax.Text);
_model.AnalogParas.RangeMin = Convert.ToDouble(spinEditRangeMin.Text);
}
}
else if (this.comboBoxSource.SelectedIndex == 3)
{
_model.SourceType = Model.eMonitorPointSourceType.额定参数;
}
_model.DispInPanel = this.checkEditDispInPanel.Checked ? 1 : 0;
_model.DispInRealChart = this.check在实时曲线界面中显示.Checked ? 1 : 0;
return _model;
}
private bool Verify()
{
this.dxErrorProvider1.ClearErrors();
if (string.IsNullOrEmpty(this.txtName.Text))
{
this.dxErrorProvider1.SetError(this.txtName, "必填项!");
return false;
}
if (string.IsNullOrEmpty(_oldName) || _oldName != this.txtName.Text.Trim())
{
if (new BLL.WorkBenchMonitorPoint().IsExistName(this._model.ID, this.txtName.Text.Trim()))
{
this.dxErrorProvider1.SetError(this.txtName, "该名称已存在!");
return false;
}
}
//if (string.IsNullOrEmpty(this.txtTag.Text))
//{
// this.dxErrorProvider1.SetError(this.txtTag, "必填项!");
// return false;
//}
if (string.IsNullOrEmpty(this.imgComMonitorType.Text))
{
this.dxErrorProvider1.SetError(this.imgComMonitorType, "必选项!");
return false;
}
//if (string.IsNullOrEmpty(this.txtValueCoefficient.Text))
//{
// this.dxErrorProvider1.SetError(this.txtValueCoefficient, "必选项!");
// return false;
//}
//if (string.IsNullOrEmpty(this.txtValueAdditional.Text))
//{
// this.dxErrorProvider1.SetError(this.txtValueAdditional, "必选项!");
// return false;
//}
return true;
}
private void imgComMonitorType_SelectedValueChanged(object sender, EventArgs e)
{
if (this.imgComMonitorType.EditValue == null)
return;
this.txtProperty.Properties.Items.Clear();
this.txtProperty.Text = null;
var monitorType = (Model.eMonitorType)this.imgComMonitorType.EditValue;
List list = null;
int default_index = -1;
if (monitorType == Model.eMonitorType.水位)
{
list = new List()
{
Model.MonitorTypeProperty.进口, Model.MonitorTypeProperty.出口
};
default_index = 0;
}
else if (monitorType == Model.eMonitorType.压力)
{
if (TProduct.UserSetting.Setting.PumpTest.IsHaveParappelTest)
{
list = new List()
{
Model.MonitorTypeProperty.进口,
Model.MonitorTypeProperty.出口,
Model.MonitorTypeProperty.并联泵进口,
Model.MonitorTypeProperty.并联泵出口
};
}
else
{
list = new List()
{
Model.MonitorTypeProperty.进口, Model.MonitorTypeProperty.出口
};
}
}
else if (monitorType == Model.eMonitorType.功率)
{
if (TProduct.UserSetting.Setting.PumpTest.IsHaveParappelTest)
{
list = new List()
{
Model.MonitorTypeProperty.总,
Model.MonitorTypeProperty.A,
Model.MonitorTypeProperty.B,
Model.MonitorTypeProperty.C,
//Model.MonitorTypeProperty.并联泵总功率,//暂时不行,需要指定仪器时,分区对应哪台泵,暂时没发区分
};
}
else
{
list = new List()
{
Model.MonitorTypeProperty.总,
Model.MonitorTypeProperty.A,
Model.MonitorTypeProperty.B,
Model.MonitorTypeProperty.C,
};
}
default_index = 0;
}
else
{
list = Model.MonitorTypeProperty.GetPropertyList(monitorType);
}
if (list != null && list.Count > 0)
{
list.ForEach(x => this.txtProperty.Properties.Items.Add(x));
if (default_index >= 0)
{
this.txtProperty.SelectedIndex = default_index;
}
}
}
private void comboBoxSource_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBoxSource.SelectedIndex == 0)
{
layoutControlGroup模拟量.Enabled = false;
layoutControlGroup数字量.Enabled = false;
}
if (comboBoxSource.SelectedIndex == 1)
{
layoutControlGroup模拟量.Enabled = true;
layoutControlGroup数字量.Enabled = false;
}
if (comboBoxSource.SelectedIndex == 2)
{
layoutControlGroup数字量.Enabled = true;
if (Convert.ToInt32(imageComboBoxDtype.EditValue) == 0)
{
layoutControlGroup模拟量.Enabled = false;
}
else
{
layoutControlGroup模拟量.Enabled = true;
}
}
}
private void imageComboBoxDtype_SelectedIndexChanged(object sender, EventArgs e)
{
if (Convert.ToInt32(imageComboBoxDtype.EditValue) == 0)
{
layoutControlGroup模拟量.Enabled = false;
}
else
{
layoutControlGroup模拟量.Enabled = true;
}
}
private void simpleLabelItem数据修正_Click(object sender, EventArgs e)
{
if (_model == null)
return;
SethMonitorPointValueCoeffParasDlg frm = new SethMonitorPointValueCoeffParasDlg();
frm.SetBindingData(_model.ValueCoeffParas);
if (frm.ShowDialog() == DialogResult.OK)
{
_model.ValueCoeffParas = frm.GetBindingData();
if (_model.ValueCoeffParas != null)
{
simpleLabelItem数据修正.Text = "数据已设置修正";
}
else
{
simpleLabelItem数据修正.Text = "数据无需修正";
}
}
}
}
}