| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using HStation.Vmo; |
| | | |
| | | namespace HStation.WinFrmUI.Assets |
| | | { |
| | | public partial class EditFourLinkMainDlg : DevExpress.XtraEditors.XtraForm |
| | | public partial class EditAssetsFourlinkMainDlg : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | public EditFourLinkMainDlg() |
| | | public EditAssetsFourlinkMainDlg() |
| | | { |
| | | InitializeComponent(); |
| | | this.treeList1.InitialMultiColSettings(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | } |
| | | |
| | | private Vmo.FourLinkMainVmo _FourLinkVmo = null; |
| | | private Vmo.AssetsFourlinkMainVmo _FourLinkVmo = null; |
| | | |
| | | public async void SetBindingData(Vmo.FourLinkMainVmo FourLinkVmo) |
| | | private List<Vmo.AssetsFourlinkCoefficientVmo> _AssetsFourlinkCoefficient; |
| | | |
| | | public async void SetBindingData(Vmo.AssetsFourlinkMainVmo FourLinkVmo) |
| | | { |
| | | var bll = new BLL.AssetsFourlinkCoefficient(); |
| | | _AssetsFourlinkCoefficient = await bll.GetAll(); |
| | | this.fourlinkCoefficientViewModelBindingSource.DataSource = _AssetsFourlinkCoefficient; |
| | | _FourLinkVmo = FourLinkVmo; |
| | | var allCaliber = await new Yw.BLL.SysDictData().GetByTypeCode("1"); |
| | | if (allCaliber != null) |
| | |
| | | { |
| | | TextEditCaliber.EditValue = _FourLinkVmo.Caliber.ToString(); |
| | | } |
| | | if (_FourLinkVmo.MaterialName == null) |
| | | if (_FourLinkVmo.Material == null) |
| | | { |
| | | TextEditMaterial.EditValue = "默认"; |
| | | } |
| | | else |
| | | { |
| | | TextEditMaterial.EditValue = _FourLinkVmo.MaterialName.ToString(); |
| | | TextEditMaterial.EditValue = _FourLinkVmo.Material.ToString(); |
| | | } |
| | | this.TextEditName.Text = _FourLinkVmo.Name; |
| | | this.TextEditCoefficient.Text = _FourLinkVmo.Coefficient.ToString(); |
| | | this.TextEditCoefficient.Text = _FourLinkVmo.MinorLoss.ToString(); |
| | | this.DescriptionTextEdit.Text = _FourLinkVmo.Description; |
| | | this.TextEditKeyWorld.Text = _FourLinkVmo.KeyWord; |
| | | this.TextEditKeyWorld.Text = string.Join(",", _FourLinkVmo.KeyWord); |
| | | } |
| | | |
| | | public event Func<Vmo.FourLinkMainVmo, Task<bool>> ReloadDataEvent = null; |
| | | public event Func<Vmo.AssetsFourlinkMainVmo, Task<bool>> ReloadDataEvent = null; |
| | | |
| | | //数据验证 |
| | | private bool Valid() |
| | |
| | | return true; |
| | | } |
| | | |
| | | //材料选择变化事件 |
| | | private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | 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 (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | foreach (var item in _AssetsFourlinkCoefficient) |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | if (Math.Abs(Convert.ToDouble(item.Caliber) - caliber) < 10) |
| | | { |
| | | this.TextEditCoefficient.Text = item.MinorLoss.ToString(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //找到最相近的材料 |
| | | private AssetsFourlinkCoefficientVmo GetCoefficientByMaterial(string name) |
| | | { |
| | | AssetsFourlinkCoefficientVmo select = null; |
| | | int maxMatchedChars = 0; |
| | | foreach (var item in _AssetsFourlinkCoefficient) |
| | | { |
| | | 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; |
| | | _FourLinkVmo.MaterialName = TextEditMaterial.Text.Trim(); |
| | | _FourLinkVmo.Material = TextEditMaterial.Text.Trim(); |
| | | _FourLinkVmo.Description = DescriptionTextEdit.Text.Trim(); |
| | | _FourLinkVmo.Name = TextEditName.Text.Trim(); |
| | | _FourLinkVmo.KeyWord = TextEditKeyWorld.Text.Trim(); |
| | | _FourLinkVmo.KeyWord = this.TextEditKeyWorld.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | _FourLinkVmo.Caliber = caliber; |
| | | } |
| | | if (double.TryParse(TextEditCoefficient.Text, out double Coefficient)) |
| | | { |
| | | _FourLinkVmo.Coefficient = Coefficient; |
| | | _FourLinkVmo.MinorLoss = Coefficient; |
| | | } |
| | | if (await this.ReloadDataEvent.Invoke(_FourLinkVmo)) |
| | | { |
| | |
| | | this.DialogResult = DialogResult.OK; |
| | | this.Close(); |
| | | } |
| | | |
| | | private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_AssetsFourlinkCoefficient); |
| | | if (vm == null) |
| | | return; |
| | | this.TextEditCoefficient.Text = vm.MinorLoss.ToString(); |
| | | } |
| | | } |
| | | } |