| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using HStation.Vmo; |
| | | |
| | | namespace HStation.WinFrmUI.Assets |
| | | { |
| | |
| | | |
| | | private Vmo.AssetsCompressorMainVmo _CompressorVmo = null; |
| | | |
| | | private List<Vmo.AssetsCompressorCoefficientVmo> _AssetsCompressorCoefficient; |
| | | |
| | | public async void SetBindingData(Vmo.AssetsCompressorMainVmo CompressorVmo) |
| | | { |
| | | var bll = new BLL.AssetsCompressorCoefficient(); |
| | | _AssetsCompressorCoefficient = await bll.GetAll(); |
| | | this.compressorCoefficientViewModelBindingSource.DataSource = _AssetsCompressorCoefficient; |
| | | _CompressorVmo = CompressorVmo; |
| | | |
| | | var allMaterial = await new Yw.BLL.SysDictData().GetByTypeCode("3"); |
| | | if (allMaterial != null) |
| | | { |
| | |
| | | { |
| | | TextEditMaterial.EditValue = _CompressorVmo.Material.ToString(); |
| | | } |
| | | var allCaliber = await new Yw.BLL.SysDictData().GetByTypeCode("1"); |
| | | if (allCaliber != null) |
| | | { |
| | | foreach (var item in allCaliber) |
| | | { |
| | | var imageItem = new ImageComboBoxItem(item.Name, item.ID); |
| | | TextEditCaliber.Properties.Items.Add(imageItem); |
| | | } |
| | | } |
| | | TextEditMaterial.SelectedIndex = 0; |
| | | TextEditCaliber.SelectedIndex = 0; |
| | | |
| | | this.TextEditName.Text = _CompressorVmo.Name; |
| | | this.TextEditMinorLoss.Text = _CompressorVmo.MinorLoss.ToString(); |
| | | this.DescriptionTextEdit.Text = _CompressorVmo.Description; |
| | |
| | | return true; |
| | | } |
| | | |
| | | //材料选择变化事件 |
| | | private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsCompressorCoefficient == null) |
| | | return; |
| | | |
| | | var select = GetCoefficientByMaterial(TextEditMaterial.Text); |
| | | if (select == null) |
| | | { |
| | | this.TextEditMinorLoss.Text = string.Empty; |
| | | return; |
| | | } |
| | | this.TextEditMinorLoss.Text = select.MinorLoss.ToString(); |
| | | } |
| | | |
| | | //口径选择变化事件 |
| | | private void TextEditCaliber_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsCompressorCoefficient == null) |
| | | return; |
| | | |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | foreach (var item in _AssetsCompressorCoefficient) |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | if (Math.Abs(Convert.ToDouble(item.Caliber) - caliber) < 10) |
| | | { |
| | | this.TextEditMinorLoss.Text = item.MinorLoss.ToString(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //找到最相近的材料 |
| | | private AssetsCompressorCoefficientVmo GetCoefficientByMaterial(string name) |
| | | { |
| | | AssetsCompressorCoefficientVmo select = null; |
| | | int maxMatchedChars = 0; |
| | | foreach (var item in _AssetsCompressorCoefficient) |
| | | { |
| | | 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 async void BtnOk_ClickAsync(object sender, EventArgs e) |
| | | { |