Files
SourceCode/PROMS/VEPROMS User Interface/dlgSetChangeBarStartDate.cs

137 lines
4.9 KiB
C#

using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
using VEPROMS.CSLA.Library;
using Volian.Controls.Library;
namespace VEPROMS
{
public partial class dlgSetChangeBarStartDate : DevComponents.DotNetBar.Office2007Form
{
public ProcedureConfig MyProcConfig { get; set; } = null;
public ProcedureInfo MyProcInfo { get; set; } = null;
public dlgSetChangeBarStartDate(ProcedureConfig pc, ProcedureInfo pi)
{
InitializeComponent();
MyProcConfig = pc;
MyProcInfo = pi;
}
private void dlgSetChangeBarStartDate_Load(object sender, EventArgs e)
{
string cbdt = MyProcConfig.Print_ChangeBarDate;
string[] tmp = cbdt.Split(' ');
if (tmp[0] == null || tmp[0] == "") // First time date set.
{
cbdt = DateTime.Now.ToString("MM/dd/yyyy") + " " + DateTime.Now.ToString("HH:mm:ss");
dateTimeInput1.Value = DateTime.Parse(cbdt);
return;
}
else
{
DateTime tmpdt = DateTime.Parse(cbdt);
if (tmpdt.Date == DateTime.Today) // Date has before been set.
{
TimeSpan start = TimeSpan.Parse("00:00:00");
var time = tmpdt.TimeOfDay;
if (start < time) // If time is greater than 12:00:00 AM
{
cbdt = DateTime.Now.ToString("MM/dd/yyyy") + " " + tmpdt.TimeOfDay.ToString();
dateTimeInput1.Value = DateTime.Parse(cbdt);
return;
}
else // if time is 12:00:00 AM
{
cbdt = DateTime.Now.ToString("MM/dd/yyyy") + " " + " 00:00:00";
dateTimeInput1.Value = DateTime.Parse(cbdt);
return;
}
}
else
{
cbdt = tmpdt.ToString();
dateTimeInput1.Value = DateTime.Parse(cbdt);
return;
}
}
}
private void btnOK_Click(object sender, EventArgs e)
{
MyProcConfig.Print_ChangeBarDate = dateTimeInput1.Value.ToString("MM/dd/yyyy HH:mm:ss");// ("MM/dd/yyyy HH:mm:ss");
}
private void btnNow_Click(object sender, EventArgs e)
{
dateTimeInput1.Value = DateTime.Now;
}
//C2026-009 Add Option to Reset Change Bar to Last Approved Date/Time
private void btnResetToApproved_Click(object sender, EventArgs e)
{
System.Data.DataTable dt = RevisionData.GetRevisionDataByUnit(MyProcInfo.ItemID);
if (dt.Rows.Count == 0)
{
//no records, remove
if (MessageBox.Show("There are currently no approvals set. Selecting yes will set ChangeBars to show all changes since the creation of the procedure.\r\nAre you sure you wish to reset ChangeBars?", "Reset ChangeBar Date", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MyProcConfig.Print_ChangeBarDate = "";
DialogResult = DialogResult.OK;
Close();
}
}
else if (RevisionData.HasUnits(dt))
{
//any with units
string maxDTS = RevisionData.MaxDTS(dt).ToString("MM/dd/yyyy HH:mm:ss");
//create wording for ChangeBar changes
StringBuilder sb = new StringBuilder();
sb.Append($" The Procedure Viewer Change Bar Date will be set to ({maxDTS}).");
foreach (DataRow r in dt.Rows)
{
sb.Append($"\r\n The Change Bar Date for Unit ({r["UnitName"]}) will be set to ({Convert.ToDateTime(r["DTS"]):MM/dd/yyyy HH:mm:ss}).");
}
sb.Append("\r\n Any Change Bars for Units not listed above will use the Overall/Procedure Viewer Change Bar Date (as these Units have no approvals).");
if (CustomMessageBox.Show($"This will reset ChangeBars to show for changes newer than the last approval.\r\nThis includes the following changes:\r\n{sb.ToString()}\r\n\r\nAre you sure you wish to reset ChangeBars?", "Reset ChangeBar Date", "Yes", "No") == DialogResult.Yes)
{
//Change the overall ChangeBarDate
MyProcConfig.Print_ChangeBarDate = maxDTS;
//Change the ChangeBarDate for each unit
foreach (DataRow r in dt.Rows)
{
MyProcConfig.SelectedSlave = Convert.ToInt32(r["UnitID"]);
MyProcConfig.Print_ChangeBarDate = Convert.ToDateTime(r["DTS"]).ToString("MM / dd / yyyy HH: mm: ss");
}
MyProcConfig.SelectedSlave = 0;
DialogResult = DialogResult.OK;
Close();
}
}
else
{
//no units
string maxDTS = RevisionData.MaxDTS(dt).ToString("MM/dd/yyyy HH:mm:ss");
if (MessageBox.Show($"This will reset ChangeBars to show for changes newer than the last approval ({maxDTS}).\r\nAre you sure you wish to reset ChangeBars?", "Reset ChangeBar Date", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
MyProcConfig.Print_ChangeBarDate = maxDTS;
DialogResult = DialogResult.OK;
Close();
}
}
}
}
}