| | |
| | | using DevExpress.XtraEditors.Controls; |
| | | using HStation.Assets; |
| | | using HStation.Vmo; |
| | | |
| | | namespace HStation.WinFrmUI.Assets |
| | | { |
| | |
| | | { |
| | | InitializeComponent(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | this.treeList1.InitialMultiColSettings(); |
| | | } |
| | | |
| | | private Vmo.AssetsValveMainVmo _AssetsValveMain = null; //阀门型号 |
| | | |
| | | public async void SetBindingData(long SeriesID, HStation.Assets.eAssetsValveSeriesType type) |
| | | private List<Vmo.AssetsValveCoefficientVmo> _AssetsValveCoefficient; |
| | | |
| | | public async void SetBindingData(long SeriesID) |
| | | { |
| | | var bll = new BLL.AssetsValveCoefficient(); |
| | | _AssetsValveCoefficient = await bll.GetAll(); |
| | | this.valveCoefficientViewModelBindingSource.DataSource = _AssetsValveCoefficient; |
| | | _AssetsValveMain = new Vmo.AssetsValveMainVmo(); |
| | | _AssetsValveMain.SeriesID = SeriesID; |
| | | _AssetsValveMain.SeriesType = type; |
| | | TextEditType.Properties.AddEnum(typeof(HStation.Assets.eValveType)); |
| | | var allCaliber = await new Yw.BLL.SysDictData().GetByTypeCode("1"); |
| | | if (allCaliber != null) |
| | | { |
| | |
| | | TextEditMaterial.Properties.Items.Add(imageItem); |
| | | } |
| | | } |
| | | imageComboBoxEditValveType.Properties.AddEnum(typeof(eValveOpenStatus)); |
| | | TextEditCaliber.SelectedIndex = 0; |
| | | TextEditMaterial.SelectedIndex = 0; |
| | | } |
| | |
| | | _AssetsValveMain.Name = TextEditName.Text.Trim(); |
| | | if (double.TryParse(TextEditCoefficient.Text, out double coefficient)) |
| | | { |
| | | _AssetsValveMain.Coefficient = coefficient; |
| | | _AssetsValveMain.MinorLoss = coefficient; |
| | | } |
| | | if (TextEditMaterial.Text != "默认") |
| | | { |
| | | _AssetsValveMain.MaterialName = TextEditMaterial.Text.Trim(); |
| | | _AssetsValveMain.Material = TextEditMaterial.Text.Trim(); |
| | | } |
| | | _AssetsValveMain.Description = TextEditDescription.Text.Trim(); |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | _AssetsValveMain.Caliber = caliber; |
| | | } |
| | | _AssetsValveMain.OpenStatus = (eValveOpenStatus)this.imageComboBoxEditValveType.EditValue; |
| | | if (Enum.TryParse(Convert.ToString(TextEditType.EditValue), true, out HStation.Assets.eValveType valvetype)) |
| | | { |
| | | _AssetsValveMain.ValveType = valvetype; |
| | | } |
| | | _AssetsValveMain.KeyWord = this.TextEditKeyWord.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | _AssetsValveMain.ValveSetting = this.TextEditValveSetting.Text.Trim(); |
| | | if (await this.ReloadDataEvent.Invoke(_AssetsValveMain)) |
| | | { |
| | | TipFormHelper.ShowSucceed("添加成功!"); |
| | |
| | | this.DialogResult = DialogResult.OK; |
| | | this.Close(); |
| | | } |
| | | |
| | | //材料选择变化事件 |
| | | private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsValveCoefficient == null) |
| | | return; |
| | | var select = GetCoefficientByMaterial(TextEditMaterial.Text); |
| | | if (select == null) |
| | | { |
| | | this.TextEditCoefficient.Text = string.Empty; |
| | | return; |
| | | } |
| | | this.TextEditCoefficient.Text = select.MinorLoss.ToString(); |
| | | } |
| | | |
| | | //口径选择变化事件 |
| | | private void TextEditCaliber_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsValveCoefficient == null) |
| | | return; |
| | | |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | foreach (var item in _AssetsValveCoefficient) |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | if (Math.Abs(Convert.ToDouble(item.Caliber) - caliber) < 10) |
| | | { |
| | | this.TextEditCoefficient.Text = item.MinorLoss.ToString(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //找到最相近的材料 |
| | | private AssetsValveCoefficientVmo GetCoefficientByMaterial(string name) |
| | | { |
| | | AssetsValveCoefficientVmo select = null; |
| | | int maxMatchedChars = 0; |
| | | foreach (var item in _AssetsValveCoefficient) |
| | | { |
| | | int matchedChars = GetIntersect(item.Material, name); |
| | | if (matchedChars > maxMatchedChars) |
| | | { |
| | | maxMatchedChars = matchedChars; |
| | | select = item; |
| | | return select; |
| | | } |
| | | } |
| | | return select; |
| | | } |
| | | |
| | | private int GetIntersect(string str1, string str2) |
| | | { |
| | | if (str1 == null || str2 == null) return 0; |
| | | return string.Join("", str1.Intersect(str2)).Count(); |
| | | } |
| | | |
| | | private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_AssetsValveCoefficient); |
| | | if (vm == null) |
| | | return; |
| | | this.TextEditCoefficient.Text = vm.MinorLoss.ToString(); |
| | | } |
| | | |
| | | private void TextEditType_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (Enum.TryParse(Convert.ToString(TextEditType.EditValue), true, out HStation.Assets.eValveType valvetype)) |
| | | { |
| | | if (valvetype == eValveType.GPV || valvetype == eValveType.TCV) |
| | | { |
| | | TextEditValveSetting.Enabled = false; |
| | | } |
| | | else |
| | | { |
| | | TextEditValveSetting.Enabled = true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |