| | |
| | | var bll = new BLL.AssetsPressmeterCoefficient(); |
| | | _AssetsPressmeterCoefficient = await bll.GetAll(); |
| | | this.PressmeterCoefficientViewModelBindingSource.DataSource = _AssetsPressmeterCoefficient; |
| | | |
| | | _PressmeterVmo = PressmeterVmo; |
| | | var allCaliber = await new Yw.BLL.SysDictData().GetByTypeCode("1"); |
| | | if (allCaliber != null) |
| | | { |
| | | foreach (var item in allCaliber) |
| | | { |
| | | var imageItem = new ImageComboBoxItem(item.Name, item.Name); |
| | | TextEditCaliber.Properties.Items.Add(imageItem); |
| | | } |
| | | } |
| | | var allMaterial = await new Yw.BLL.SysDictData().GetByTypeCode("3"); |
| | | if (allMaterial != null) |
| | | { |
| | | foreach (var item in allMaterial) |
| | | { |
| | | var imageItem = new ImageComboBoxItem(item.Name, item.Name); |
| | | TextEditMaterial.Properties.Items.Add(imageItem); |
| | | } |
| | | } |
| | | if (_PressmeterVmo.Caliber == null) |
| | | { |
| | | TextEditCaliber.EditValue = "默认"; |
| | | } |
| | | else |
| | | { |
| | | TextEditCaliber.EditValue = _PressmeterVmo.Caliber.ToString(); |
| | | } |
| | | if (_PressmeterVmo.Material == null) |
| | | { |
| | | TextEditMaterial.EditValue = "默认"; |
| | | } |
| | | else |
| | | { |
| | | TextEditMaterial.EditValue = _PressmeterVmo.Material.ToString(); |
| | | } |
| | | this.TextEditName.Text = _PressmeterVmo.Name; |
| | | this.TextEditMinorLoss.Text = _PressmeterVmo.MinorLoss.ToString(); |
| | | this.DescriptionTextEdit.Text = _PressmeterVmo.Description; |
| | |
| | | return true; |
| | | } |
| | | |
| | | //材料选择变化事件 |
| | | private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsPressmeterCoefficient == 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 (_AssetsPressmeterCoefficient == null) |
| | | return; |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | foreach (var item in _AssetsPressmeterCoefficient) |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | if (Math.Abs(Convert.ToDouble(item.Caliber) - caliber) < 10) |
| | | { |
| | | this.TextEditMinorLoss.Text = item.MinorLoss.ToString(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //找到最相近的材料 |
| | | private AssetsPressmeterCoefficientVmo GetCoefficientByMaterial(string name) |
| | | { |
| | | AssetsPressmeterCoefficientVmo select = null; |
| | | int maxMatchedChars = 0; |
| | | foreach (var item in _AssetsPressmeterCoefficient) |
| | | { |
| | | 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) |
| | | { |
| | | if (!(Valid())) |
| | | return; |
| | | _PressmeterVmo.Material = TextEditMaterial.Text.Trim(); |
| | | _PressmeterVmo.Description = DescriptionTextEdit.Text.Trim(); |
| | | _PressmeterVmo.Name = TextEditName.Text.Trim(); |
| | | _PressmeterVmo.KeyWord = TextEditKeyWord.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | _PressmeterVmo.Caliber = caliber; |
| | | } |
| | | if (double.TryParse(TextEditMinorLoss.Text, out double MinorLoss)) |
| | | { |
| | | _PressmeterVmo.MinorLoss = MinorLoss; |