using DevExpress.XtraEditors;
|
using IStation.Unit;
|
using System;
|
using System.Windows.Forms;
|
|
namespace IStation.WinFrmUI
|
{
|
/// <summary>
|
/// 设置一天小时段
|
/// </summary>
|
public partial class NumericFormatParasCtrl : UserControl, IFormatParas
|
{
|
public NumericFormatParasCtrl()
|
{
|
InitializeComponent();
|
}
|
|
|
private Model.SignalType.NumericFormatParas _model = null;
|
|
|
private bool _isNON = false;//0
|
private bool _isCustomer = false;//999
|
|
|
//初始化数据
|
public void Set(string paras)
|
{
|
|
this.UnitTypeImageComboBoxEdit.Properties.AddEnum(typeof(Unit.eUnitType), false);
|
_model = Model.SignalType.NumericFormatParas.ToModel(paras);
|
if (_model == null)
|
{
|
_model = new Model.SignalType.NumericFormatParas();
|
this.UnitTypeImageComboBoxEdit.SelectedIndex = 0;
|
}
|
else
|
{
|
this.UnitTypeImageComboBoxEdit.EditValue = _model.UnitType;
|
}
|
|
this.DecimalPlacesTextEdit.EditValue = _model.DecimalPlaces;
|
}
|
|
|
//单位类型变换
|
private void UnitTypeImageComboBoxEdit_EditValueChanged(object sender, EventArgs e)
|
{
|
var code = (Unit.eUnitType)this.UnitTypeImageComboBoxEdit.EditValue;
|
SetUnitValueComboBoxEdit(code);
|
}
|
|
private void SetUnitValueComboBoxEdit(Unit.eUnitType unitType)
|
{
|
_isNON = false;
|
this.UnitValueComboBoxEdit.Text = string.Empty;
|
this.UnitValueComboBoxEdit.Properties.Items.Clear();
|
this.UnitValueComboBoxEdit.Enabled = true;
|
this.UnitValueComboBoxEdit.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
|
|
var unitValueDict = UnitHelper.GetEnUnitDict(unitType);
|
if (unitValueDict == null || unitValueDict.Count < 1)
|
return;
|
foreach (var item in unitValueDict)
|
{
|
var keyIntValue = new KeyIntValue(item.Value, item.Key);
|
this.UnitValueComboBoxEdit.Properties.Items.Add(keyIntValue);
|
}
|
|
this.UnitValueComboBoxEdit.SelectedIndex = 0;
|
if (unitType == _model.UnitType)
|
{
|
if (int.TryParse(_model.UnitValue, out int value))
|
{
|
this.UnitValueComboBoxEdit.SelectedIndex = value;
|
}
|
}
|
|
|
}
|
|
|
//验证
|
public bool Valid()
|
{
|
if (this.UnitTypeImageComboBoxEdit.EditValue == null)
|
{
|
XtraMessageBox.Show("请选择单位类型!");
|
return false;
|
}
|
if (!_isNON)
|
{
|
if (string.IsNullOrEmpty(this.UnitValueComboBoxEdit.Text))
|
{
|
XtraMessageBox.Show("请选择/录入单位值!");
|
return false;
|
}
|
}
|
|
return true;
|
}
|
|
|
//获取时间
|
public string Get()
|
{
|
if (!Valid())
|
return default;
|
_model.UnitType = (Unit.eUnitType)this.UnitTypeImageComboBoxEdit.EditValue;
|
if (_isNON)
|
{
|
_model.UnitValue = string.Empty;
|
}
|
else if (_isCustomer)
|
{
|
_model.UnitValue = this.UnitValueComboBoxEdit.Text.TrimEnd();
|
}
|
else
|
{
|
var keyIntValue = (this.UnitValueComboBoxEdit.SelectedItem as KeyIntValue);
|
_model.UnitValue = keyIntValue?.Value.ToString() ?? string.Empty;
|
}
|
|
var decimalPlaces = this.DecimalPlacesTextEdit.Text.Trim();
|
if (!string.IsNullOrEmpty(decimalPlaces))
|
_model.DecimalPlaces = int.Parse(decimalPlaces);
|
else
|
_model.DecimalPlaces = null;
|
|
return _model.ToJson();
|
}
|
|
|
}
|
}
|