using DevExpress.Mvvm.Native;
|
using DevExpress.XtraEditors;
|
using DevExpress.XtraEditors.Controls;
|
using DevExpress.XtraTreeList;
|
using System.Windows.Forms;
|
using Yw;
|
|
namespace PBS.WinFrmUI
|
{
|
public partial class FacilitiesCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public FacilitiesCtrl()
|
{
|
InitializeComponent();
|
}
|
|
//基础验证
|
public bool Valid()
|
{
|
bool isExist = true;
|
this.dxErrorProvider1.ClearErrors();
|
if (string.IsNullOrEmpty(this.txtName.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtName, "必填项");
|
isExist = false;
|
}
|
if (string.IsNullOrEmpty(this.txtFloor.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtFloor, "必填项");
|
isExist = false;
|
}
|
if (string.IsNullOrEmpty(this.txtFloorHeight.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtFloorHeight, "必填项");
|
isExist = false;
|
}
|
if (string.IsNullOrEmpty(this.txtFloorHouseHolds.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtFloorHouseHolds, "必填项");
|
isExist = false;
|
}
|
if (string.IsNullOrEmpty(this.txtConstantP.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtConstantP, "必填项");
|
isExist = false;
|
}
|
if (this.textEditWaterModel.EditValue == null)
|
{
|
this.dxErrorProvider1.SetError(this.textEditWaterModel, "必填项");
|
isExist = false;
|
}
|
if (this.comboBoxWaterSupply.Text == "请选择")
|
{
|
this.dxErrorProvider1.SetError(this.comboBoxWaterSupply, "必填项");
|
isExist = false;
|
}
|
if (string.IsNullOrEmpty(this.txtMaxWaterDemand.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtMaxWaterDemand, "必填项");
|
return false;
|
}
|
if (string.IsNullOrEmpty(this.txtWaterPressure.Text.Trim()))
|
{
|
this.dxErrorProvider1.SetError(this.txtWaterPressure, "必填项");
|
return false;
|
}
|
return isExist;
|
}
|
|
private Vmo.FacilityVmo _facilityVmo = new Vmo.FacilityVmo();
|
|
public async Task SetBindingData()
|
{
|
this.textEditWaterModel.Properties.AddEnum(typeof(PBS.eSupplyMode));
|
/* textEditWaterModel.Properties.LargeImages = imageCollection1;
|
foreach (PBS.eSupplyMode mode in Enum.GetValues(typeof(PBS.eSupplyMode)))
|
{
|
int imageIndex = (int)mode; // 假设图片索引和枚举值顺序一致
|
textEditWaterModel.Properties.Items.Add(new DevExpress.XtraEditors.Controls.ImageComboBoxItem(mode.ToString(), mode, imageIndex));
|
}*/
|
this.comboBoxWaterSupply.Properties.AddEnum(typeof(PBS.eWaterSupply));
|
var allPackages = await new HStation.BLL.AssetsPackageMain().GetAll();
|
foreach (var item in allPackages)
|
{
|
var imageItem = new ImageComboBoxItem(item.Name, item.ID);
|
this.comboBoxPackages.Properties.Items.Add(imageItem);
|
}
|
var list = await new PBS.BLL.Place().GetAll();
|
var model = list.Select(x => new PlaceSelectViewModel(x)).ToList();
|
var regionIdList = model.GroupBy(x => x.ParentID).Select(y => y.Key).ToList();
|
if (regionIdList != null && regionIdList.Count > 0)
|
{
|
var placeList = await new Yw.BLL.Division().GetByIds(regionIdList);
|
foreach (var item in placeList)
|
{
|
model.Add(new PlaceSelectViewModel
|
{
|
ID = item.ID,
|
Name = item.Name
|
});
|
}
|
}
|
this.treeListLookUpEdit1TreeList.DataSource = model;
|
this.imageComboBoxConnectionType.Properties.AddEnum(typeof(PBS.eConnectionType));
|
this.imageComboBoxConnectionType.SelectedIndex = 1;
|
}
|
|
public async void SetData(Vmo.FacilityVmo model)
|
{
|
_facilityVmo = model;
|
this.txtName.EditValue = model.Name;
|
this.txtFloor.EditValue = model.Floor;
|
this.txtFloorHouseHolds.EditValue = model.Households;
|
this.txtFloorHeight.EditValue = model.FloorHeight;
|
this.txtMaxWaterDemand.EditValue = model.MaxWaterDemand;
|
this.txtWaterPressure.EditValue = model.TerminalPressure;
|
this.comboBoxWaterSupply.EditValue = model.WaterSupply;
|
this.txtConstantP.EditValue = model.ConstantPressure;
|
this.textEditWaterModel.EditValue = model.SupplyMode;
|
this.txtEditPlace.EditValue = model.PlaceID;
|
this.comboBoxPackages.EditValue = model.PackageID;
|
this.imageComboBoxConnectionType.EditValue = model.ConnectionType;
|
this.textEditConnectionAddress.EditValue = model.ConnectionAddress;
|
this.textEditMaxHeight.EditValue = model.MaxHeight;
|
this.txtDescription.EditValue = model.Description;
|
var flags = await BLLFactory<Yw.BLL.SysFlag>.Instance.GetBySysType(HStation.Assets.DataType.FourlinkMain);
|
this.setFlagsEditCtrl1.SetBindingData(flags?.Select(x => x.Name).ToList(), model.Flags);
|
this.txtTagName.EditValue = model.TagName;
|
}
|
|
//获取文本信息
|
public Vmo.FacilityVmo GetData()
|
{
|
if (!Valid())
|
return null;
|
_facilityVmo.Floor = int.Parse(txtFloor.Text);
|
_facilityVmo.Name = txtName.Text;
|
if (this.textEditWaterModel.EditValue != null)
|
{
|
_facilityVmo.SupplyMode = (PBS.eSupplyMode)this.textEditWaterModel.EditValue;
|
}
|
_facilityVmo.UseStatus = Yw.Vmo.eUseStatus.Enable;
|
_facilityVmo.FloorHeight = double.Parse(txtFloorHeight.Text);
|
_facilityVmo.Households = int.Parse(txtFloorHouseHolds.Text);
|
_facilityVmo.ConstantPressure = double.Parse(txtConstantP.Text);
|
_facilityVmo.MaxWaterDemand = Convert.ToDouble(txtMaxWaterDemand.EditValue);
|
_facilityVmo.TerminalPressure = Convert.ToDouble(txtWaterPressure.EditValue);
|
if (this.comboBoxPackages.EditValue != null)
|
{
|
_facilityVmo.PackageID = (long)this.comboBoxPackages.EditValue;
|
}
|
if (this.txtEditPlace.EditValue != null)
|
{
|
_facilityVmo.PlaceID = Convert.ToInt64(this.txtEditPlace.EditValue);
|
}
|
if (comboBoxWaterSupply.EditValue != null)
|
{
|
_facilityVmo.WaterSupply = (PBS.eWaterSupply)comboBoxWaterSupply.EditValue;
|
}
|
if (this.imageComboBoxConnectionType.EditValue != null)
|
{
|
_facilityVmo.ConnectionType = (PBS.eConnectionType)this.imageComboBoxConnectionType.EditValue;
|
}
|
_facilityVmo.ConnectionAddress = this.textEditConnectionAddress.Text;
|
if (this.textEditMaxHeight.EditValue != null)
|
{
|
double.TryParse(this.textEditMaxHeight.Text, out double maxHeight);
|
_facilityVmo.MaxHeight = maxHeight;
|
}
|
_facilityVmo.TagName = txtTagName.Text.Trim();
|
_facilityVmo.Flags = this.setFlagsEditCtrl1.SelectedFlagList;
|
_facilityVmo.Description = txtDescription.Text;
|
return _facilityVmo;
|
}
|
|
private void treeListLookUpEdit1TreeList_BeforeFocusNode(object sender, BeforeFocusNodeEventArgs e)
|
{
|
TreeList treeList = sender as TreeList;
|
if (treeList != null)
|
{
|
// 检查当前焦点节点是否为父节点
|
if (e.Node.HasChildren)
|
{
|
e.CanFocus = false;
|
}
|
}
|
}
|
}
|
}
|