duheng
2024-12-10 26917739c47252ecdc3b8f43eca6ebaf9cba6ac4
WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/06-prop/EditPackagePartPropDlg.cs
ÎļþÃû´Ó WinFrmUI/HStation.WinFrmUI.Assets.Core/10-exchanger/06-prop/EditExchangerPartPropDlg.cs ÐÞ¸Ä
@@ -1,4 +1,6 @@
namespace HStation.WinFrmUI.Assets
using HStation.WinFrmUI.Assets;
namespace HStation.WinFrmUI
{
    public partial class EditExchangerPartPropDlg : DevExpress.XtraEditors.XtraForm
    {
@@ -7,55 +9,66 @@
            InitializeComponent();
            this.gridView1.Columns["PropGroupName"].Group();
            this.IconOptions.Icon = Yw.WinFrmUI.GlobalParas.AppIcon;
            this.ExchangerProductListBox1.MouseUp += ExchangerProductListBox1_MouseUp;
            this.exchangerProductListBox1.MouseUp += exchangerProductListBox1_MouseUp;
        }
        private BLL.AssetsExchangerPartMain _bll = null;
        private List<PropGroupChoiceViewModel> _proplist = null;
        #region Private
        private List<CurrentPartMainViewModel> _allBindingList = new List<CurrentPartMainViewModel>();
        private BLL.AssetsExchangerPartMain _bll;
        private List<HStation.WinFrmUI.Assets.ExchangerPropChoiceViewModel> _propList;
        private Vmo.AssetsExchangerMainAndPartMapVmo _partmap = null;
        private Vmo.AssetsExchangerMainAndPartMappingVmo _partMapping;
        private Vmo.AssetsExchangerPartMainVmo _ExchangerPart = null;
        private Vmo.AssetsExchangerMainVmo _ExchangerMain;
        private Vmo.AssetsExchangerPartMainVmo _ExchangerPart;
        private long _catalogID;  //分类ID
        private long _seriesID;  //系列ID
        private Vmo.AssetsExchangerSeriesVmo _series;  //系列ID
        private List<Vmo.AssetsExchangerPropContentVmo> _allPropList = null;
        private List<Vmo.AssetsExchangerPropContentVmo> _allPropList;
        private Yw.BLL.SysPropMapping _sysPropMapping;
        #endregion Private
        //回调事件
        public event Func<Vmo.AssetsExchangerPartMainVmo, List<Vmo.AssetsExchangerPropContentVmo>, Vmo.AssetsExchangerMainAndPartMapVmo, Task<bool>> ReloadEvent;
        public event Func<Vmo.AssetsExchangerPartMainVmo, List<Vmo.AssetsExchangerPropContentVmo>, Vmo.AssetsExchangerMainAndPartMappingVmo, Task<bool>> ReloadEvent;
        //数据绑定
        public async void SetBindingData(Vmo.AssetsExchangerMainVmo AssetsExchangerMain)
        {
            this.ExchangerProductListBox1.SetBindingData(AssetsExchangerMain);
            this.ExchangerProductListBox1.SelectReloadEvent += () =>
            this.exchangerProductListBox1.SetBindingData(AssetsExchangerMain);
            _ExchangerMain = AssetsExchangerMain;
            this.exchangerProductListBox1.SelectReloadEvent += () =>
            {
                ListBoxPart_SelectedIndexChanged();
            };
            this.ExchangerProductListBox1.AddReloadEvent += () =>
            this.exchangerProductListBox1.AddReloadEvent += () =>
            {
                BarBtnAddExchangerPart_ItemClick();
            };
            this.exchangerProductListBox1.DeleteReloadEvent += () =>
            {
                BarBtnDeletePart_ItemClick();
            };
            _bll = new BLL.AssetsExchangerPartMain();
            var allpartlist = await _bll.GetByExchangerMainID(AssetsExchangerMain.ID);   //获取所有产品
            /*   var series = await new BLL.AssetsExchangerSeries().GetByID(AssetsExchangerMain.ExchangerSeriesID);  //获取系列
               _ExchangerPart = new Vmo.AssetsExchangerPartMainVmo();
               _series = series.ID;
               _ExchangerPart.SeriesID = _series;
               _catalogID = series.CatalogID;
               _propList = new List<PropGroupChoiceViewModel>();
               _partMapping = new Vmo.AssetsExchangerMainAndPartMapVmo();
               _partMapping.ExchangerID = AssetsExchangerMain.ID;
               _partMapping.SeriesID = _series;*/
            this.propGroupChoiceViewModelBindingSource.DataSource = _proplist;
            var series = await new BLL.AssetsExchangerSeries().GetByID(AssetsExchangerMain.SeriesID);  //获取系列
            _ExchangerPart = new Vmo.AssetsExchangerPartMainVmo();
            _series = series;
            _ExchangerPart.SeriesID = _series.ID;
            _catalogID = _series.CatalogID;
            _propList = new List<HStation.WinFrmUI.Assets.ExchangerPropChoiceViewModel>();
            _partMapping = new Vmo.AssetsExchangerMainAndPartMappingVmo();
            _partMapping.MainID = AssetsExchangerMain.ID;
            _partMapping.SeriesID = _series.ID;
            this.propGroupChoiceViewModelBindingSource.DataSource = _propList;
            this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
        }
        //分类选择变换
        //选择变换
        private async void SetPropSelectedValue(ExchangerPartViewModel partmain)
        {
            layoutControAddPart.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
@@ -64,7 +77,7 @@
            this.TextEditNo.Text = partmain.NO.Trim();
            this.TextEditProductCode.Text = partmain.Code.Trim();
            this.TextEditProductName.Text = partmain.Name.Trim();
            _proplist.Clear();
            _propList.Clear();
            var bll = new Yw.BLL.SysPropStruct();
            var catlog = await bll.GetByCatalogID(_catalogID);
            if (catlog == null)
@@ -72,20 +85,25 @@
                this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
                return;
            }
            _proplist.Clear();
            _propList.Clear();
            foreach (var item in catlog)
            {
                foreach (var prop in item.PropList)
                {
                    _proplist.Add(new PropGroupChoiceViewModel() { PropGroupName = item.Name, PropName = prop.Name, ID = prop.ID });
                    _propList.Add(new ExchangerPropChoiceViewModel()
                    {
                        PropGroupName = item.Name,
                        PropName = prop.Name,
                        ID = prop.ID,
                        TagName = prop.Code
                    });
                }
            }
            var propbll = new BLL.AssetsExchangerPartPropContent();
            var alllist = await propbll.GetByExchangerPartID(model.ID);
            _allPropList = alllist;
            foreach (var item in alllist)
            _allPropList = await propbll.GetByExchangerPartID(model.ID);
            foreach (var item in _allPropList)
            {
                var selectProp = _proplist.Find(x => x.ID == item.PropID);
                var selectProp = _propList.Find(x => x.ID == item.PropID);
                if (selectProp != null)
                {
                    selectProp.Value = item.PropValue;
@@ -98,7 +116,7 @@
        //产品列表聚焦改变
        private void ListBoxPart_SelectedIndexChanged()
        {
            var vm = this.ExchangerProductListBox1.GetCurrentVm();
            var vm = this.exchangerProductListBox1.GetCurrentVm();
            if (vm == null)
                return;
            SetPropSelectedValue(vm);
@@ -107,7 +125,7 @@
        //确认编辑
        private async void BtnOk_Click(object sender, EventArgs e)
        {
            var vm = this.ExchangerProductListBox1.GetCurrentVm();
            var vm = this.exchangerProductListBox1.GetCurrentVm();
            if (vm == null)
                return;
            var updatepart = new Vmo.AssetsExchangerPartMainVmo();
@@ -115,9 +133,8 @@
            updatepart.Name = TextEditProductName.Text;
            updatepart.NO = TextEditNo.Text;
            updatepart.Code = TextEditProductCode.Text;
            updatepart.SeriesID = _seriesID;
            var updateproplist = new List<UpdateAssetsExchangerPropContentInput>();
            foreach (var item in _proplist)
            updatepart.SeriesID = _series.ID;
            foreach (var item in _propList)
            {
                if (_allPropList != null)
                {
@@ -130,14 +147,23 @@
                    }
                    else
                    {
                        _allPropList.Add(new Vmo.AssetsExchangerPropContentVmo() { SeriesID = _allPropList.First().SeriesID, PartID = _allPropList.First().PartID, PropID = item.ID, PropValue = item.Value });
                        _allPropList.Add(new Vmo.AssetsExchangerPropContentVmo()
                        {
                            SeriesID = _allPropList.First().SeriesID,
                            PartID = _allPropList.First().PartID,
                            PropID = item.ID,
                            PropValue = item.Value,
                            TagName = item.TagName
                        });
                    }
                }
            }
            var ExchangerMainBll = new BLL.AssetsExchangerMain();
            await ExchangerMainBll.Update(_ExchangerMain);
            if (await _bll.UpdateEx(updatepart, _allPropList))
            {
                vm.Reset(updatepart);
                this.ExchangerProductListBox1.Refresh();
                this.exchangerProductListBox1.Refresh();
                TipFormHelper.ShowSucceed("修改成功!");
            }
            else
@@ -149,15 +175,16 @@
        }
        //左侧树右击菜单事件
        private void ExchangerProductListBox1_MouseUp(object sender, MouseEventArgs e)
        private void exchangerProductListBox1_MouseUp(object sender, MouseEventArgs e)
        {
            /*   if (e.Button == MouseButtons.Right)
               {
                   Point screenPoint = Cursor.Position;
                   popupExchangerPartMenu.ShowPopup(screenPoint);
               }*/
            if (e.Button == MouseButtons.Right)
            {
                Point screenPoint = Cursor.Position;
                popupExchangerPartMenu.ShowPopup(screenPoint);
            }
        }
        //数据验证
        private bool Vaild()
        {
            this.dxErrorProvider1.ClearErrors();
@@ -178,16 +205,22 @@
            _ExchangerPart.NO = TextEditNo.Text;
            _ExchangerPart.Code = TextEditProductCode.Text;
            var AssetsExchangerPropContent = new List<Vmo.AssetsExchangerPropContentVmo>();
            foreach (var item in _proplist)
            foreach (var item in _propList)
            {
                AssetsExchangerPropContent.Add(new Vmo.AssetsExchangerPropContentVmo { PropID = item.ID, PropValue = item.Value, SeriesID = _ExchangerPart.SeriesID });
                AssetsExchangerPropContent.Add(new Vmo.AssetsExchangerPropContentVmo
                {
                    PropID = item.ID,
                    PropValue = item.Value,
                    SeriesID = _ExchangerPart.SeriesID,
                    TagName = item.TagName
                });
            }
            var id = await _bll.InsertEx(_ExchangerPart, AssetsExchangerPropContent, _partmap);
            var id = await _bll.InsertEx(_ExchangerPart, AssetsExchangerPropContent, _partMapping);
            if (id > 0)
            {
                var Exchangerpart = await _bll.GetByID(id);
                this.ExchangerProductListBox1._allBindingList.Add(new ExchangerPartViewModel(Exchangerpart));
                this.ExchangerProductListBox1.Refresh();
                this.exchangerProductListBox1._allBindingList.Add(new ExchangerPartViewModel(Exchangerpart));
                this.exchangerProductListBox1.Refresh();
                TipFormHelper.ShowSucceed("添加成功!");
            }
            else
@@ -204,9 +237,9 @@
        private async void BarBtnAddExchangerPart_ItemClick()
        {
            layoutControAddPart.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
            TextEditProductName.Text = string.Empty;
            TextEditNo.Text = string.Empty;
            TextEditProductCode.Text = string.Empty;
            this.TextEditProductName.Text = string.Empty;
            this.TextEditNo.Text = string.Empty;
            this.TextEditProductCode.Text = string.Empty;
            var bll = new Yw.BLL.SysPropStruct();
            try
            {
@@ -216,12 +249,19 @@
                    this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
                    return;
                }
                _proplist.Clear();
                _propList.Clear();
                foreach (var item in catlog)
                {
                    foreach (var prop in item.PropList)
                    {
                        _proplist.Add(new PropGroupChoiceViewModel() { PropGroupName = item.Name, PropName = prop.Name, ID = prop.ID, Value = prop.DefaultValue });
                        _propList.Add(new ExchangerPropChoiceViewModel()
                        {
                            PropGroupName = item.Name,
                            PropName = prop.Name,
                            ID = prop.ID,
                            Value = prop.DefaultValue,
                            TagName = prop.Code
                        });
                    }
                }
                this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
@@ -233,23 +273,27 @@
            // å°è¯•改变焦点以触发控件更新
            this.TextEditProductName.Focus();
            //  this.TextEditProductName.SelectAll();
            this.TextEditNo.Properties.NullText = "在此输入产品编号";
            this.TextEditProductCode.Properties.NullText = "在此输入产品图号";
        }
        //  åˆ é™¤äº§å“
        private async void BarBtnDeletePart_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        private async void BarBtnDeletePart_ItemClick()
        {
            var vm = this.ExchangerProductListBox1.GetCurrentVm();
            var vm = this.exchangerProductListBox1.GetCurrentVm();
            if (vm == null)
                return;
            if (!MessageBoxHelper.IsClickOk("确定删除数据行"))
            {
                if (await _bll.DeleteEx(vm.ID))
                {
                    this.ExchangerProductListBox1._allBindingList.Remove(vm);
                    this.ExchangerProductListBox1.Refresh();
                    this.exchangerProductListBox1._allBindingList.Remove(vm);
                    this.exchangerProductListBox1.Refresh();
                    this._propList.Clear();
                    this.propGroupChoiceViewModelBindingSource.ResetBindings(false);
                    this.TextEditProductName.Text = string.Empty;
                    this.TextEditNo.Text = string.Empty;
                    this.TextEditProductCode.Text = string.Empty;
                    MessageBoxHelper.ShowSuccess("删除成功!");
                }
                else