tbf/TestBenchFramework/Forms/UpgradeSelectionDlg.cs

96 lines
3.3 KiB
C#
Raw Normal View History

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 Results.Entities;
using NHibernate;
namespace TBF.Forms
{
public partial class UpgradeSelectionDlg : Form
{
int batchFrom;
int batchTo;
public UpgradeSelectionDlg()
{
InitializeComponent();
batchFrom = 1;
batchTo = Program.LocalSettings.BatchNr - 1;
textBox1.Text = batchFrom.ToString();
textBox2.Text = batchTo.ToString();
}
private void pressureRepresentationButton_Click(object sender, EventArgs e)
{
try
{
batchFrom = int.Parse(textBox1.Text);
batchTo = int.Parse(textBox2.Text);
if (batchFrom < 1 || batchFrom > batchTo) throw new Exception();
}
catch
{
MessageBox.Show("Wrong 'From batch #' or 'To batch #'", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
if (MessageBox.Show("Are you sure ?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) return;
try
{
ISession session = Results.DB.CreateSession();
IList<Batch> bFrom = session.QueryOver<Batch>().Where(x => (x.BatchNr == batchFrom)).List<Batch>();
IList<Batch> bTo = session.QueryOver<Batch>().Where(x => (x.BatchNr == batchTo)).List<Batch>();
if (bFrom.Count != 1) throw new Exception("No start batch");
if (bTo.Count != 1) throw new Exception("No end batch");
IList<TestRslt> testResults = session.QueryOver<TestRslt>()
.WhereRestrictionOn(x => x.StartTime)
.IsBetween(bFrom[0].StartTime)
.And(bTo[0].EndTime)
.List<TestRslt>();
foreach (var tr in testResults)
{
Text = string.Format("Batch # = {0}", tr.Batch.BatchNr);
float factor1 = 0.01f;
tr.PressUpMean *= factor1;
tr.PressUpStart *= factor1;
tr.PressUpEnd *= factor1;
tr.PressUpMin *= factor1;
tr.PressUpMax *= factor1;
tr.PressDownMean *= factor1;
tr.PressDownStart *= factor1;
tr.PressDownEnd *= factor1;
tr.PressDownMin *= factor1;
tr.PressDownMax *= factor1;
tr.AmbPressMean *= 0.001f;
session.SaveOrUpdate(tr);
}
session.Flush();
MessageBox.Show("Upgrade completed", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception exc)
{
MessageBox.Show(string.Format("Upgrade failed:\r\n{0}", exc.Message),
"Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}