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; } /// /// 项目标识 /// public long ProjectId { get; set; } /// /// 名称 /// public string Name { get; set; } /// /// 状态 /// public string Status { get; set; } /// /// 文件全路径 /// public string FileFullName { get; set; } /// /// 说明 /// public string Description { get; set; } /// /// 是否存在 /// public bool IsExist { get; set; } /// /// 最后保存时间 /// public DateTime? LastSaveTime { get; set; } /// /// 事件说明 /// public string TimeDescription { get; set; } /// /// Model /// public Model.Project Model { get; set; } } #endregion /// /// 初始化数据 /// public override void InitialDataSource() { _allBindList = new List(); var allProjects = new BLL.Project().GetAll(); 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); } /// /// 刷新数据 /// public override void RefreshDataSource() { InitialDataSource(); } private List _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(); } } }