ningshuxia
2023-02-07 d027501182b03a0c036af712a2b7f31d55144562
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;
using DevExpress.XtraEditors.Controls;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Tile;
using IStation.Extensions;
 
namespace IStation.WinFormUI.Project
{
    public partial class LatelyProjectOverviewPage : DocumentPage
    {
        public LatelyProjectOverviewPage() 
        {
            InitializeComponent();
            this.PageTitle.Caption = "最近浏览";
 
            this.SurfaceGuid = new SurfaceGuid()
            {
                DockType = eDockType.Tab,
                Modular = eModular.Project,
                Function = "最近浏览"
            };
        }
        public LatelyProjectOverviewPage(SurfaceGuid sguid):this()
        {
            this.SurfaceGuid = sguid;
        }
 
 
        #region 内部视图类
 
        public class CurrentViewModel
        {
            public CurrentViewModel(Model.Project rhs)
            {
                this.ProjectId = rhs.Id;
                this.Name = rhs.Name;
                this.IsExist = true;
                this.LastSaveTime = rhs.UpdateTime;
                if (this.IsExist)
                { 
                    if (this.LastSaveTime > DateTime.Now.Date)
                        this.TimeDescription = " 今天";
                    else if (this.LastSaveTime > DateTime.Now.GetWeekFirst())
                        this.TimeDescription = " 本周";
                    else if (this.LastSaveTime > DateTime.Now.GetMonthFirst())
                        this.TimeDescription = " 本月";
                    else
                        this.TimeDescription = " 历史";
                }
                else
                {
                    this.TimeDescription = " 不存在";
                }
                this.Model = rhs;
            }
 
            /// <summary>
            /// 项目标识
            /// </summary>
            public long ProjectId { get; set; }
 
            /// <summary>
            /// 名称
            /// </summary>
            public string Name { get; set; }
            /// <summary>
            /// 状态
            /// </summary>
            public string Status { get; set; }
            /// <summary>
            /// 文件全路径
            /// </summary>
            public string FileFullName { get; set; }
            /// <summary>
            /// 说明
            /// </summary>
            public string Description { get; set; }
            /// <summary>
            /// 是否存在
            /// </summary>
            public bool IsExist { get; set; }
            /// <summary>
            /// 最后保存时间
            /// </summary>
            public DateTime? LastSaveTime { get; set; }
            /// <summary>
            /// 事件说明
            /// </summary>
            public string TimeDescription { get; set; }
            /// <summary>
            /// Model
            /// </summary>
            public Model.Project Model { get; set; }
 
        }
 
        #endregion
 
        /// <summary>
        /// 初始化数据
        /// </summary>
        public override void InitialDataSource()
        {
            _allBindList = new List<CurrentViewModel>();
            var allProjects = new BLL.Project().QueryAll();
            if (allProjects != null && allProjects.Count > 0)
                allProjects.ForEach(x => _allBindList.Add(new CurrentViewModel(x)));
            _allBindList = _allBindList.OrderByDescending(t => t.LastSaveTime).ToList();
            this.bindingSource1.DataSource = _allBindList;
            this.bindingSource1.ResetBindings(false);
        }
 
        /// <summary>
        /// 刷新数据
        /// </summary>
        public override void RefreshDataSource()
        {
            InitialDataSource();
        }
 
        private List<CurrentViewModel> _allBindList = null;//所有绑定列表
 
        //显示提示信息
        private void toolTipController1_GetActiveObjectInfo(object sender, DevExpress.Utils.ToolTipControllerGetActiveObjectInfoEventArgs e)
        {
            if (e.SelectedControl != this.gridControl1)
                return;
            var view = this.gridControl1.GetViewAt(e.ControlMousePosition) as TileView;
            if (view == null)
                return;
            var hi = view.CalcHitInfo(e.ControlMousePosition);
            ToolTipControlInfo info = null;
            if (hi.InItem)
            {
                var row = view.GetRow(hi.RowHandle) as CurrentViewModel;
                if (row != null)
                {
                    if (row.IsExist)
                    {
                        info = new ToolTipControlInfo(row, row.Description);
                    }
                    else
                    {
                        info = new ToolTipControlInfo(row, "项目不存在");
                    }
                }
            }
            if (info != null)
            {
                e.Info = info;
            }
        }
 
        //关联按钮点击事件
        private void tileView1_ContextButtonClick(object sender, ContextItemClickEventArgs e)
        {
            var tileViewItem = e.DataItem as TileViewItem;
            var row = this.tileView1.GetRow(tileViewItem.RowHandle) as CurrentViewModel;
            if (row == null)
                return;
 
            //判断项目状态
            if (row.ProjectId ==GlobalParas.ProjectId)
            {
                XtraMessageBox.Show("项目已打开,不能移除!");
                return;
            }
            /*//如果不存在直接删除
            if (!File.Exists(row.FileFullName))
            {
                if (!new BLL.Project().DeleteById(row.ProjectId))
                {
                    XtraMessageBox.Show("项目移除失败!");
                    return;
                }
                return;
            }*/
            //提示用户是否移除项目
            if (XtraMessageBox.Show("是否要删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                return;
            if (!new BLL.Project().DeleteById(row.ProjectId,out string msg))
            {
                XtraMessageBox.Show("项目移除失败!");
                return;
            }
            _allBindList.Remove(row);
            this.bindingSource1.ResetBindings(false);
            XtraMessageBox.Show("项目移除成功!");
        }
 
        //双击
        private void tileView1_ItemDoubleClick(object sender, TileViewItemClickEventArgs e)
        {
            var row = this.tileView1.GetRow(e.Item.RowHandle) as CurrentViewModel;
            if (row == null)
                return;
            if (row.ProjectId == GlobalParas.ProjectId)
            {
                XtraMessageBox.Show("无法打开正在使用的项目!");
                return;
            }
            var bol = ProjectHelper.LoadProject(row.ProjectId);
            if (!bol)
            {
                XtraMessageBox.Show("项目加载失败!");
                Application.Exit();
                return;
            }
            this.ResetAllPages();
        }
         
    }
}