ningshuxia
2023-05-06 657c344695223f01bade2776803f719673232f81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Filtering;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;
using DevExpress.XtraGrid.Columns; 
 
namespace IStation.WinFormUI.Project
{
    public partial class LoadProjectOverviewDlg : DevExpress.XtraEditors.XtraForm
    {
        public LoadProjectOverviewDlg()
        {
            InitializeComponent();
            this.IconOptions.Icon = Properties.Resource.app;
            this.layoutControl1.SetupLayoutControl();
            this.projectTileViewCtrl1.ReloadDataEvent += ProjectTileViewListCtrl1_ReloadDataEvent;
        }
 
        public Model.Project Project;
 
        //加载项目
        private void ProjectTileViewListCtrl1_ReloadDataEvent(Model.Project obj)
        {
            if (GlobalParas.ProjectId == obj.Id)
            {
                XtraMessageBox.Show("项目正在使用,无法加载!");
                return;
            }
            var result = ProjectHelper.LoadProject(obj.Id);
            if (!result)
                return;
            Project = new BLL.Project().GetById(obj.Id);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        /// <summary>
        /// 绑定数据
        /// </summary>
        public void SetBindingData()
        {
            var allPrj = new BLL.Project().GetAll();
            if (allPrj == null)
                allPrj = new List<Model.Project>();
            this.projectTileViewCtrl1.SetBindingData(allPrj);
        }
 
        //打开项目
        private void tileOpenPrj_ItemClick(object sender, TileItemEventArgs e)
        {
            var filePath = ProjectHelper.GetOpenProjectPath();
            if (string.IsNullOrEmpty(filePath))
                return;
            var projecId = ProjectHelper.ImportProject(filePath);
            if (projecId<1)
                return;
            GlobalParas.ProjectId=projecId;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
 
        //创建项目
        private void tileCreatePrj_ItemClick(object sender, TileItemEventArgs e)
        {
            this.Visible = false;
            var dlg = new CreateProjectDlg();
            dlg.SetBindingData();
            dlg.ReloadDataEvent += (projectId) =>
             {
                 var result = ProjectHelper.LoadProject(projectId);
                 if (!result)
                     return;
                 this.DialogResult = DialogResult.OK;
                 this.Close();
             };
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                this.Visible = true;
            }
        }
 
 
    }
}