114 lines
3.9 KiB
C#
114 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using NHibernate;
|
|
using Config.Entities;
|
|
|
|
namespace ResultsBrowser
|
|
{
|
|
public partial class MainWnd : Form
|
|
{
|
|
public MainWnd()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void MainWnd_Load(object sender, EventArgs e)
|
|
{
|
|
PreparePurchaseOrderCombo(purchaseOrderComboBox);
|
|
}
|
|
|
|
private void MainWnd_FormClosing(object sender, FormClosingEventArgs e)
|
|
{
|
|
Program.LocalSettings.UpdateHistory(purchaseOrderComboBox.Text, ref Program.LocalSettings.PurchaseOrderHistory);
|
|
Program.LocalSettings.Save();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Load Purchase order combo box items from the LocalSettings PurchaseOrderHistory array
|
|
/// </summary>
|
|
/// <param name="comboBox">Puchase order ComboBox</param>
|
|
void PreparePurchaseOrderCombo(ComboBox comboBox)
|
|
{
|
|
for (int i = 0; i < Program.LocalSettings.PurchaseOrderHistoryCount; i++)
|
|
{
|
|
comboBox.Items.Add(Program.LocalSettings.PurchaseOrderHistory[i]);
|
|
}
|
|
if (comboBox.Items.Count > 0) comboBox.Text = comboBox.Items[0].ToString();
|
|
}
|
|
|
|
private void filterDateCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
fromDateTimePicker.Enabled = toDateTimePicker.Enabled = filterDateCheckBox.Checked;
|
|
}
|
|
|
|
private void purchaseOrderCheckBox_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
purchaseOrderComboBox.Enabled = purchaseOrderCheckBox.Checked;
|
|
}
|
|
|
|
private void queryButton_Click(object sender, EventArgs e)
|
|
{
|
|
if (!purchaseOrderCheckBox.Checked && !filterDateCheckBox.Checked) return;
|
|
try
|
|
{
|
|
ISession session = Config.FluentCommon.CreateSession(Config.Database.Procedures);
|
|
|
|
IList<TestResult> testResults;
|
|
|
|
if (!purchaseOrderCheckBox.Checked)
|
|
{
|
|
testResults = session.QueryOver<TestResult>()
|
|
.WhereRestrictionOn(x => x.TimeStart)
|
|
.IsBetween(fromDateTimePicker.MinDate)
|
|
.And(toDateTimePicker.MaxDate)
|
|
.OrderBy(x => x.BatchNr).Desc
|
|
.List<TestResult>();
|
|
}
|
|
else if (!filterDateCheckBox.Checked)
|
|
{
|
|
testResults = session.QueryOver<TestResult>()
|
|
.Where(x => (x.PurchaseOrder == purchaseOrderComboBox.Text))
|
|
.OrderBy(x => x.BatchNr).Desc
|
|
.List<TestResult>();
|
|
}
|
|
else
|
|
{
|
|
testResults = session.QueryOver<TestResult>()
|
|
.WhereRestrictionOn(x => x.TimeStart)
|
|
.IsBetween(fromDateTimePicker.MinDate)
|
|
.And(toDateTimePicker.MaxDate)
|
|
.Where(x => (x.PurchaseOrder == purchaseOrderComboBox.Text))
|
|
.OrderBy(x => x.BatchNr).Desc
|
|
.List<TestResult>();
|
|
}
|
|
|
|
IList<int> batchNrs = new List<int>();
|
|
|
|
foreach (var tr in testResults)
|
|
{
|
|
if (!batchNrs.Contains(tr.BatchNr))
|
|
{
|
|
batchNrs.Insert(0, tr.BatchNr);
|
|
outputTextBox.Text += string.Format("Batch {0}\r\n", tr.BatchNr);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception exc)
|
|
{
|
|
MessageBox.Show(exc.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void clearButton_Click(object sender, EventArgs e)
|
|
{
|
|
outputTextBox.Text = string.Empty;
|
|
}
|
|
}
|
|
}
|