duheng
2024-07-05 5aba1bf12cd27faa797e7f3d15e0f960bdc2a4b2
WinFrmUI/HStation.WinFrmUI.Xhs.Project/01-project/XhsProjectListPage.cs
@@ -1,21 +1,214 @@
using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HStation.Dto;
using HStation.WinFrmUI.Xhs;
using HStation.WinFrmUI.Xhs.Project;
using ISupply.WinFrmUI;
namespace HStation.WinFrmUI
{
    public partial class XhsProjectListPage : DevExpress.XtraEditors.XtraForm
    public partial class XhsProjectListPage : DocumentPage
    {
        public XhsProjectListPage()
        {
            InitializeComponent();
            this.PageTitle.Caption = "项目管理";
            this.gridView1.SetNormalView();
            this.gridView1.RegistCustomDrawRowIndicator();
        }
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            SetBindingData();
        }
        private new BLL.XhsProject _bll = new BLL.XhsProject();
        private List<ProjectViewModel> _allBindingList = new List<ProjectViewModel>();
        private ProjectViewModel _prjviewmodel = new ProjectViewModel();
        /// <summary>
        /// 初始化数据
        /// </summary>
        private async void SetBindingData()
        {
            _allBindingList.Clear();
            var alllist = await _bll.GetAll();
            if (alllist != null)
            {
                foreach (var item in alllist)
                {
                    var model = new ProjectViewModel(item);
                    _allBindingList.Add(await _prjviewmodel.SetUploadStatusAsync(model));
                }
                this.projectViewModelBindingSource.DataSource = _allBindingList;
                this.projectViewModelBindingSource.ResetBindings(false);
            }
        }
        //添加
        private void BtnAdd_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var dlg = new AddProjectDlg();
            dlg.ReloadEvent += async (pro, item, model, map) =>
            {
                var id = await _bll.InsertEx(pro, item, model, map);
                if (id > 0)
                {
                    var vmmodel = await _bll.GetByID(id);
                    _allBindingList.Add(await new ProjectViewModel().SetUploadStatusAsync(vmmodel));
                    this.projectViewModelBindingSource.ResetBindings(false);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
        //修改
        private void BtnEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowError("请选择数据行!");
                return;
            }
            var dlg = new EditProjectDlg();
            dlg.SetBindingData(vm.ID);
            dlg.ReloadEvent += async (prj, item) =>
            {
                if (await _bll.UpdateEx(prj, item))
                {
                    vm.Reset(prj);
                    this.projectViewModelBindingSource.ResetBindings(false);
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
        //删除
        private async void BtnDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowError("请选择数据行!");
                return;
            }
            if (MessageBoxHelper.IsClickOk($"确认删除数据行?", "提示", MessageBoxButtons.OKCancel))
                return;
            var result = await _bll.DeleteEx(vm.ID);
            if (!result)
            {
                MessageBoxHelper.ShowError($"删除失败!", "警告");
                return;
            }
            MessageBoxHelper.ShowSuccess($"删除成功!");
            _allBindingList.Remove(vm);
            this.projectViewModelBindingSource.ResetBindings(false);
        }
        //使用状态
        private void BtnUpdateUseStatus_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            var dlg = new SetUseStatusDlg();
            dlg.SetBindingData(vm.UseStatus);
            dlg.ReloadDataEvent += async (useStatus) =>
            {
                var result = await _bll.UpdateUseStatus(vm.ID, (int)useStatus);
                if (result)
                {
                    vm.UseStatus = useStatus;
                    vm.Reset(vm);
                    this.projectViewModelBindingSource.ResetBindings(false);
                }
                return result;
            };
            dlg.ShowDialog();
        }
        //刷新
        private void BtnRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            this.SetBindingData();
        }
        //历史模型
        private void BtnModelEdit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            var dlg = new ModelEdit();
            dlg.SetBiningData(vm.ID);
            dlg.ShowDialog();
        }
        //模型编辑
        private void BtnEditModel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
            {
                MessageBoxHelper.ShowWarning("请选择数据行!");
                return;
            }
            var dlg = new SetModelEditDlg();
            dlg.SetBindingData(vm.ID);
            dlg.ReloadDataEvent += async (rhs) =>
            {
                var bll = new BLL.XhsProjectItemModel();
                if (await bll.Update(rhs))
                {
                    return true;
                }
                return false;
            };
            dlg.ShowDialog();
        }
        private async void gridView1_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            if (_allBindingList == null || _allBindingList.Count < 1)
                return;
            var vm = this.gridView1.GetCurrentViewModel(_allBindingList);
            if (vm == null)
                return;
            if (e.Column == this.colModelManage)
            {
                var guid = new SurfaceGuid()
                {
                    Function = "模型管理",
                    Modular = eModular.Basic
                };
                if (!IsExistPage(guid, true))
                {
                    var bll = new BLL.XhsProjectItemModel();
                    var result = await bll.GetByPrjID(vm.ID);
                    var select = result.Where(x => x.UseStatus == 1).FirstOrDefault();
                    if (select != null)
                    {
                        var page = new PumpCurveCtrl(select);
                        page.PageTitle.Caption = guid.Function;
                        page.SurfaceGuid = guid;
                        CreatePage(page, guid);
                    }
                }
            }
        }
    }
}