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 ProjectTileViewCtrl : DevExpress.XtraEditors.XtraUserControl
|
{
|
public ProjectTileViewCtrl()
|
{
|
InitializeComponent();
|
}
|
|
#region 内部视图类
|
|
public class CurrentViewModel
|
{
|
public CurrentViewModel(Model.Project rhs)
|
{
|
this.Id = 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 Id { 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 event Action<Model.Project> ReloadDataEvent;
|
private List<CurrentViewModel> _allBindList = null;//所有绑定列表
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData()
|
{
|
_allBindList = new List<CurrentViewModel>();
|
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);
|
}
|
|
/// <summary>
|
/// 绑定数据
|
/// </summary>
|
public void SetBindingData(List<Model.Project> allProjects)
|
{
|
_allBindList = new List<CurrentViewModel>();
|
if (allProjects != null && allProjects.Count > 0)
|
allProjects.ForEach(x => _allBindList.Add(new CurrentViewModel(x)));
|
_allBindList = _allBindList.OrderBy(t => t.LastSaveTime).ToList();
|
this.bindingSource1.DataSource = _allBindList;
|
this.bindingSource1.ResetBindings(false);
|
}
|
|
/// <summary>
|
/// 获取项目
|
/// </summary>
|
public Model.Project GetProject()
|
{
|
var row = this.tileView1.GetFocusedRow() as CurrentViewModel;
|
if (row == null)
|
{
|
XtraMessageBox.Show("未检索到项目信息!");
|
return default;
|
}
|
if (!File.Exists(row.FileFullName))
|
{
|
XtraMessageBox.Show("项目文件不存在!");
|
return default;
|
}
|
if (row.Model.Id == GlobalParas.ProjectId)
|
{
|
XtraMessageBox.Show("该项目已经打开!");
|
return default;
|
}
|
return row.Model;
|
}
|
|
/// <summary>
|
/// 是否显示边框
|
/// </summary>
|
public bool BorderVisible
|
{
|
get
|
{
|
if (this.tileView1.BorderStyle == BorderStyles.NoBorder)
|
return false;
|
return true;
|
}
|
set
|
{
|
if (value)
|
this.tileView1.BorderStyle = BorderStyles.Simple;
|
else
|
this.tileView1.BorderStyle = BorderStyles.NoBorder;
|
}
|
}
|
|
//显示提示信息
|
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.Id == GlobalParas.ProjectId)
|
{
|
XtraMessageBox.Show("项目已打开,不能移除!");
|
return;
|
}
|
/*//如果不存在直接删除
|
if (!File.Exists(row.FileFullName))
|
{
|
if (!new BLL.Project().DeleteById(row.Id))
|
{
|
XtraMessageBox.Show("项目移除失败!");
|
return;
|
}
|
return;
|
}*/
|
//提示用户是否移除项目
|
if (XtraMessageBox.Show("是否要删除?", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
|
return;
|
if (!new BLL.Project().DeleteById(row.Id,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;
|
this.ReloadDataEvent?.Invoke(row.Model);
|
}
|
|
|
}
|
}
|