DeviceManager/DeviceRepairAndOptimization/Pages/Common/XtraCalendarShow.cs
2024-07-17 10:32:45 +08:00

159 lines
5.5 KiB
C#

using DevExpress.Utils;
using DevExpress.XtraEditors.Controls;
using DeviceRepair.Models;
using DeviceRepair.Models.Plan;
using DeviceRepairAndOptimization.Biz;
using DeviceRepairAndOptimization.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace DeviceRepairAndOptimization.Pages.Common
{
public partial class XtraCalendarShow : DevExpress.XtraEditors.XtraForm
{
int PlanAutoID = 0;
List<DailyPlanCompleteStatus> Datas;
DateTime ServerDate = DateTime.MaxValue;
public DateTime Value
{
get
{
return DateTime.Parse(calendarControl1.EditValue + "");
}
}
public XtraCalendarShow() : this(0, DateTime.Now)
{
InitializeComponent();
}
public XtraCalendarShow(int m_PlanAutoID, DateTime dateTime)
{
InitializeComponent();
PlanAutoID = m_PlanAutoID;
calendarControl1.EditValue = dateTime;
}
/// <summary>
/// 窗体加载完成
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void XtraCalendarShow_Load(object sender, EventArgs e)
{
try
{
if (PlanAutoID == 0)
throw new Exception($"传入的计划主键编号不能为0!");
ServerDate = Convert.ToDateTime(ApiHelper.Instance.GetServiceTime());
APIResponseData apiResponseData = Biz.AM.PlanManager.Instance.GetDailyPlanCompleteStatus(PlanAutoID);
if (!apiResponseData.IsSuccess)
throw new Exception(apiResponseData.Message);
Datas = apiResponseData.ToDeserializeObject<List<DailyPlanCompleteStatus>>();
this.calendarControl1.CellStyleProvider = new SFCStyleProvider() { Datas = Datas, ServerDate = ServerDate };
}
catch (Exception ex)
{
XtraMessageBoxHelper.Error(ex.Message);
this.DialogResult = DialogResult.Cancel;
}
}
private void btnSubmit_Click(object sender, EventArgs e)
{
try
{
if (DateTime.Parse(calendarControl1.EditValue + "") > ServerDate)
{
throw new Exception($"不允许超前保养!");
}
if ((Datas.First(x => x.MaintenanceDay.Date == calendarControl1.DateTime.Date)?.IsComplete ?? 0) == 1)
{
throw new Exception($"当日保养已全部完成,无法继续!");
}
this.DialogResult = DialogResult.OK;
}
catch (Exception ex)
{
XtraMessageBoxHelper.Error(ex.Message);
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void calendarControl1_ContextButtonCustomize(object sender, CalendarContextButtonCustomizeEventArgs e)
{
e.Item.AllowGlyphSkinning = DefaultBoolean.True;
e.Item.ImageOptions.SvgImage = Properties.Resources.ok;
}
}
public class SFCStyleProvider : ICalendarCellStyleProvider
{
public List<DailyPlanCompleteStatus> Datas;
public DateTime ServerDate = DateTime.MaxValue;
public void UpdateAppearance(CalendarCellStyle cell)
{
if (Datas != null)
{
DailyPlanCompleteStatus item = Datas.FirstOrDefault(x => x.MaintenanceDay == cell.Date);
if (item != null)
{
if (item.MaintenanceDay > ServerDate)
{
return;
}
if (item.IsComplete == 0)
{
if (cell.Date == ServerDate.Date)
{
return;
}
// 未完成
cell.Image = DevExpress.Images.ImageResourceCache.Default.GetImageById(DevExpress.Images.DXImages.Cancel, DevExpress.Utils.Design.ImageSize.Size16x16, DevExpress.Utils.Design.ImageType.Colored);
}
else if (item.IsComplete == 1)
{
// 已完成
cell.Image = DevExpress.Images.ImageResourceCache.Default.GetImageById(DevExpress.Images.DXImages.Apply, DevExpress.Utils.Design.ImageSize.Size16x16, DevExpress.Utils.Design.ImageType.Colored);
}
cell.ImageAlignment = DevExpress.Utils.Drawing.ImageAlignmentMode.TopRight;
}
}
//if (cell.Date.Day % 4 == 0)
//{
// cell.Image = DevExpress.Images.ImageResourceCache.Default.GetImageById(DevExpress.Images.DXImages.Apply, DevExpress.Utils.Design.ImageSize.Size16x16, DevExpress.Utils.Design.ImageType.Colored);
// cell.ImageAlignment = DevExpress.Utils.Drawing.ImageAlignmentMode.TopRight;
// //cell.Appearance.BackColor = Color.FromArgb(192, 255, 192);
//}
//else if (cell.Date.Day % 7 == 0)
//{
// cell.Appearance.BackColor = Color.FromArgb(255, 126, 126);
//}
//else
//{
// cell.Appearance.BackColor = Color.FromArgb(255, 255, 129);
//}
}
}
}