| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using HStation.Assets; |
| | | using HStation.Vmo; |
| | | |
| | | namespace HStation.WinFrmUI.Assets |
| | | { |
| | | public partial class EditElbowMainDlg : DevExpress.XtraEditors.XtraForm |
| | | public partial class EditAssetsElbowMainDlg : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | public EditElbowMainDlg() |
| | | public EditAssetsElbowMainDlg() |
| | | { |
| | | InitializeComponent(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | } |
| | | |
| | | private Vmo.ElbowMainVmo _ElbowVmo = null; |
| | | private Vmo.AssetsElbowMainVmo _ElbowVmo = null; |
| | | |
| | | public async void SetBindingData(Vmo.ElbowMainVmo ElbowVmo) |
| | | private List<Vmo.AssetsElbowCoefficientVmo> _AssetsElbowCoefficient; |
| | | |
| | | public async void SetBindingData(Vmo.AssetsElbowMainVmo ElbowVmo) |
| | | { |
| | | var bll = new BLL.AssetsElbowCoefficient(); |
| | | _AssetsElbowCoefficient = await bll.GetAll(); |
| | | this.elbowCoefficientViewModelBindingSource.DataSource = _AssetsElbowCoefficient; |
| | | _ElbowVmo = ElbowVmo; |
| | | var allCaliber = await new Yw.BLL.SysDictData().GetByTypeCode("1"); |
| | | if (allCaliber != null) |
| | |
| | | { |
| | | TextEditCaliber.EditValue = _ElbowVmo.Caliber.ToString(); |
| | | } |
| | | if (_ElbowVmo.MaterialName == null) |
| | | if (_ElbowVmo.Material == null) |
| | | { |
| | | TextEditMaterial.EditValue = "默认"; |
| | | } |
| | | else |
| | | { |
| | | TextEditMaterial.EditValue = _ElbowVmo.MaterialName.ToString(); |
| | | TextEditMaterial.EditValue = _ElbowVmo.Material.ToString(); |
| | | } |
| | | this.imageComboBoxEditConnectlenght.Properties.AddEnum(typeof(eLengthType)); |
| | | this.imageComboBoxEditConnectlenght.EditValue = _ElbowVmo.ElbowLengthType; |
| | | this.textEditAngle.Text = _ElbowVmo.Angle.ToString(); |
| | | this.TextEditName.Text = _ElbowVmo.Name; |
| | | this.TextEditCoefficient.Text = _ElbowVmo.Coefficient.ToString(); |
| | | this.TextEditCoefficient.Text = _ElbowVmo.MinorLoss.ToString(); |
| | | this.DescriptionTextEdit.Text = _ElbowVmo.Description; |
| | | this.TextEditKeyWorld.Text = _ElbowVmo.KeyWord; |
| | | this.TextEditKeyWorld.Text = string.Join(",", _ElbowVmo.KeyWord); |
| | | } |
| | | |
| | | public event Func<Vmo.ElbowMainVmo, Task<bool>> ReloadDataEvent = null; |
| | | public event Func<Vmo.AssetsElbowMainVmo, Task<bool>> ReloadDataEvent = null; |
| | | |
| | | //数据验证 |
| | | private bool Valid() |
| | |
| | | return true; |
| | | } |
| | | |
| | | //材料选择变化事件 |
| | | private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsElbowCoefficient == 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 (_AssetsElbowCoefficient == null) |
| | | return; |
| | | |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | foreach (var item in _AssetsElbowCoefficient) |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | if (Math.Abs(Convert.ToDouble(item.Caliber) - caliber) < 10) |
| | | { |
| | | this.TextEditCoefficient.Text = item.MinorLoss.ToString(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //找到最相近的材料 |
| | | private AssetsElbowCoefficientVmo GetCoefficientByMaterial(string name) |
| | | { |
| | | AssetsElbowCoefficientVmo select = null; |
| | | int maxMatchedChars = 0; |
| | | foreach (var item in _AssetsElbowCoefficient) |
| | | { |
| | | 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) |
| | | { |
| | |
| | | return; |
| | | _ElbowVmo.Description = DescriptionTextEdit.Text.Trim(); |
| | | _ElbowVmo.Name = TextEditName.Text.Trim(); |
| | | _ElbowVmo.KeyWord = TextEditKeyWorld.Text.Trim(); |
| | | _ElbowVmo.MaterialName = TextEditMaterial.Text.Trim(); |
| | | _ElbowVmo.KeyWord = this.TextEditKeyWorld.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | _ElbowVmo.Material = TextEditMaterial.Text.Trim(); |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | _ElbowVmo.Caliber = caliber; |
| | | } |
| | | if (double.TryParse(TextEditCoefficient.Text, out double Coefficient)) |
| | | { |
| | | _ElbowVmo.Coefficient = Coefficient; |
| | | _ElbowVmo.MinorLoss = Coefficient; |
| | | } |
| | | if (int.TryParse(textEditAngle.Text, out int angle)) |
| | | { |
| | | _ElbowVmo.Angle = angle; |
| | | } |
| | | _ElbowVmo.ElbowLengthType = (eLengthType)this.imageComboBoxEditConnectlenght.EditValue; |
| | | if (await this.ReloadDataEvent.Invoke(_ElbowVmo)) |
| | | { |
| | | TipFormHelper.ShowSucceed("修改成功!"); |