tbf/TBF/UI/ResultsMI/PreviousResultCtrl.cs

147 lines
4.7 KiB
C#

///
/// Copyright (c) 2016-2022 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Common;
using TBF.Resources;
namespace TBF.UI.ResultsMI
{
public partial class PreviousResultCtrl : UserControl
{
readonly PreviousResultsDlg parent;
readonly PreviousResultsMode mode;
readonly bool sendBtnIsPrint;
public int BatchNr;
public DateTime StarTime;
public DateTime EndTime;
public string Ver;
public string ProcedureName;
public string PurchaseOrder;
public int PassedCount;
public int FailedCount;
public bool Sent;
public IList<string> SerialNrs;
PreviousResultCtrl()
{
InitializeComponent();
}
public PreviousResultCtrl(PreviousResultsDlg parent, int bnr, DateTime s, DateTime e,
string ver, string proc, string pOrd, int passCnt, int failCnt,
bool sent, PreviousResultsMode mode, IList<string> serialNrs = null)
: this()
{
this.parent = parent;
BatchNr = bnr;
StarTime = s;
EndTime = e;
Ver = ver;
ProcedureName = proc;
PurchaseOrder = pOrd;
PassedCount = passCnt;
FailedCount = failCnt;
Sent = sent;
this.mode = mode;
SerialNrs = serialNrs;
batchNrLabel.Text = BatchNr.ToString();
startTimeLabel.Text = StarTime.ToString(Constants.DateTimeFormat);
endTimeLabel.Text = EndTime.ToString(Constants.DateTimeFormat);
swVerLabel.Text = Ver;
int nr = 0;
procedureLabel.Text = TBF.UI.MainWnd.ProcedureNrs.TryGetValue(proc, out nr) ? string.Format("{0} {1}", nr, proc) : proc;
purchaseOrderLabel.Text = PurchaseOrder;
passedCountLabel.Text = string.Format("{0}: {1}", Strings.Passed, PassedCount);
failedCountLabel.Text = string.Format("{0}: {1}", Strings.Failed, FailedCount);
/// 'Sent' check box
#if ORACLE_DB
sentCheckBox.Visible = (mode == PreviousResultsMode.Show);
sentCheckBox.Text = Strings.Sent;
sentCheckBox.Checked = Sent;
#endif
/// 'Send again'/'Print' button
sendBtnIsPrint = false;
switch (mode)
{
case PreviousResultsMode.Show:
#if ORACLE_DB
sendReloadButton.Enabled = !Sent;
sendReloadButton.Text = Strings.Save_again;
#else
sendReloadButton.Enabled = true; /// 'Print' function always available
sendReloadButton.Text = Strings.Print;
sendBtnIsPrint = true;
#endif
break;
case PreviousResultsMode.Reload:
sendReloadButton.Enabled = true;
sendReloadButton.Text = Strings.Restore;
break;
case PreviousResultsMode.Fix:
sendReloadButton.Enabled = true;
sendReloadButton.Text = Strings.Fix;
break;
}
/// 'Show' button
showButton.Text = Strings.Show;
}
public void UpdateSentState(bool sent)
{
this.Sent = sent;
#if MUNICH
sentCheckBox.Checked = sent;
sendReloadButton.Enabled = true;
#elif ORACLE_DB
sentCheckBox.Checked = sent;
sendReloadButton.Enabled = !sent;
#endif
}
private void showButton_Click(object sender, EventArgs e)
{
parent.OnShowResults(this, new PreviousResultIdEventArgs(BatchNr, SerialNrs));
}
private void sendReloadButton_MouseClick(object sender, MouseEventArgs e)
{
if (sendBtnIsPrint)
{
parent.OnPrint(this, new PreviousResultIdEventArgs(BatchNr, SerialNrs));
}
else if (mode == PreviousResultsMode.Show)
{
parent.OnSendAgain(this, new PreviousResultIdEventArgs(BatchNr, SerialNrs));
}
else if (mode == PreviousResultsMode.Reload)
{
parent.OnReload(this, new PreviousResultIdEventArgs(BatchNr, SerialNrs));
}
#if TURA_IPERL || TURA_IPERL_NEW || TURA_SPECIAL
else if (mode == PreviousResultsMode.Fix)
{
/// Access only to thise who manage production tracing
GID[] rqrdGroupMembership = new GID[] { GID.TraceabilityManagement };
if ((new Users.Forms.LoginDlg(TBF.DB.UserSessionFactories, Users.CurrentUser.UserName(), rqrdGroupMembership, parent)).ShowDialog() != DialogResult.OK)
{
return;
}
Program.MainWnd.UpdateUser();
parent.OnReloadAndFix(this, new PreviousResultIdEventArgs(BatchNr, SerialNrs));
}
#endif
}
}
}