| | |
| | | using DevExpress.Utils; |
| | | using DevExpress.XtraEditors.Controls; |
| | | using HStation.Vmo; |
| | | |
| | | namespace HStation.WinFrmUI.Assets |
| | | { |
| | |
| | | public EditAssetsThreelinkMainDlg() |
| | | { |
| | | InitializeComponent(); |
| | | this.treeList1.InitialMultiColSettings(); |
| | | this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon; |
| | | } |
| | | |
| | | private Vmo.AssetsThreelinkMainVmo _ThreeLinkVmo = null; |
| | | |
| | | private List<Vmo.AssetsThreelinkCoefficientVmo> _AssetsThreelinkCoefficient; |
| | | |
| | | public async void SetBindingData(Vmo.AssetsThreelinkMainVmo ThreeLinkVmo) |
| | | { |
| | | var bll = new BLL.AssetsThreelinkCoefficient(); |
| | | _AssetsThreelinkCoefficient = await bll.GetAll(); |
| | | this.threelinkCoefficientViewModelBindingSource.DataSource = _AssetsThreelinkCoefficient; |
| | | _ThreeLinkVmo = ThreeLinkVmo; |
| | | var allCaliber = await new Yw.BLL.SysDictData().GetByTypeCode("1"); |
| | | if (allCaliber != null) |
| | |
| | | { |
| | | TextEditCaliber.EditValue = _ThreeLinkVmo.Caliber.ToString(); |
| | | } |
| | | if (_ThreeLinkVmo.MaterialName == null) |
| | | if (_ThreeLinkVmo.Material == null) |
| | | { |
| | | TextEditMaterial.EditValue = "默认"; |
| | | } |
| | | else |
| | | { |
| | | TextEditMaterial.EditValue = _ThreeLinkVmo.MaterialName.ToString(); |
| | | TextEditMaterial.EditValue = _ThreeLinkVmo.Material.ToString(); |
| | | } |
| | | this.textEditRunThroughCoefficient.Text = _ThreeLinkVmo.RunThroughMinorLoss.ToString(); |
| | | this.textEditBranchThroughCoefficient.Text = _ThreeLinkVmo.BranchThroughMinorLoss.ToString(); |
| | | this.TextEditName.Text = _ThreeLinkVmo.Name; |
| | | this.DescriptionTextEdit.Text = _ThreeLinkVmo.Description; |
| | | this.TextEditCoefficient.Text = _ThreeLinkVmo.Coefficient.ToString(); |
| | | this.TextEditKeyWorld.Text = _ThreeLinkVmo.KeyWord; |
| | | this.TextEditMinorLoss.Text = _ThreeLinkVmo.MinorLoss.ToString(); |
| | | this.TextEditKeyWord.Text = string.Join(",", _ThreeLinkVmo.KeyWord); |
| | | } |
| | | |
| | | public event Func<Vmo.AssetsThreelinkMainVmo, Task<bool>> ReloadDataEvent = null; |
| | |
| | | return true; |
| | | } |
| | | |
| | | //材料选择变化事件 |
| | | private void TextEditMaterial_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsThreelinkCoefficient == null) |
| | | return; |
| | | |
| | | var select = GetCoefficientByMaterial(TextEditMaterial.Text); |
| | | if (select == null) |
| | | { |
| | | this.TextEditMinorLoss.Text = string.Empty; |
| | | return; |
| | | } |
| | | this.TextEditMinorLoss.Text = select.MinorLoss.ToString(); |
| | | this.textEditRunThroughCoefficient.Text = select.RunThroughMinorLoss.ToString(); |
| | | this.textEditBranchThroughCoefficient.Text = select.BranchThroughMinorLoss.ToString(); |
| | | } |
| | | |
| | | //口径选择变化事件 |
| | | private void TextEditCaliber_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (_AssetsThreelinkCoefficient == null) |
| | | return; |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | foreach (var item in _AssetsThreelinkCoefficient) |
| | | { |
| | | if (item.Caliber.HasValue) |
| | | { |
| | | if (Math.Abs(Convert.ToDouble(item.Caliber) - caliber) < 10) |
| | | { |
| | | this.TextEditMinorLoss.Text = item.MinorLoss.ToString(); |
| | | this.textEditRunThroughCoefficient.Text = item.RunThroughMinorLoss.ToString(); |
| | | this.textEditBranchThroughCoefficient.Text = item.BranchThroughMinorLoss.ToString(); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | //找到最相近的材料 |
| | | private AssetsThreelinkCoefficientVmo GetCoefficientByMaterial(string name) |
| | | { |
| | | AssetsThreelinkCoefficientVmo select = null; |
| | | int maxMatchedChars = 0; |
| | | foreach (var item in _AssetsThreelinkCoefficient) |
| | | { |
| | | 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; |
| | | _ThreeLinkVmo.MaterialName = TextEditMaterial.Text.Trim(); |
| | | _ThreeLinkVmo.Material = TextEditMaterial.Text.Trim(); |
| | | _ThreeLinkVmo.Description = DescriptionTextEdit.Text.Trim(); |
| | | _ThreeLinkVmo.Name = TextEditName.Text.Trim(); |
| | | _ThreeLinkVmo.KeyWord = TextEditKeyWorld.Text.Trim(); |
| | | _ThreeLinkVmo.KeyWord = this.TextEditKeyWord.Text.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); |
| | | if (double.TryParse(TextEditCaliber.Text, out double caliber)) |
| | | { |
| | | _ThreeLinkVmo.Caliber = caliber; |
| | | } |
| | | if (double.TryParse(TextEditCoefficient.Text, out double Coefficient)) |
| | | if (double.TryParse(TextEditMinorLoss.Text, out double MinorLoss)) |
| | | { |
| | | _ThreeLinkVmo.Coefficient = Coefficient; |
| | | _ThreeLinkVmo.MinorLoss = MinorLoss; |
| | | } |
| | | else if (TextEditCaliber.Text == "默认") |
| | | { |
| | | _ThreeLinkVmo.Caliber = null; |
| | | } |
| | | if (double.TryParse(textEditRunThroughCoefficient.Text, out double runThrough)) |
| | | { |
| | | _ThreeLinkVmo.RunThroughMinorLoss = runThrough; |
| | | } |
| | | if (double.TryParse(textEditBranchThroughCoefficient.Text, out double branchThough)) |
| | | { |
| | | _ThreeLinkVmo.BranchThroughMinorLoss = branchThough; |
| | | } |
| | | if (await this.ReloadDataEvent.Invoke(_ThreeLinkVmo)) |
| | | { |
| | |
| | | this.DialogResult = DialogResult.OK; |
| | | this.Close(); |
| | | } |
| | | |
| | | private void treeList1_FocusedNodeChanged(object sender, DevExpress.XtraTreeList.FocusedNodeChangedEventArgs e) |
| | | { |
| | | var vm = this.treeList1.GetCurrentViewModel(_AssetsThreelinkCoefficient); |
| | | if (vm == null) |
| | | return; |
| | | this.TextEditMinorLoss.Text = vm.MinorLoss.ToString(); |
| | | } |
| | | } |
| | | } |