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 bFrom = session.QueryOver().Where(x => (x.BatchNr == batchFrom)).List(); IList bTo = session.QueryOver().Where(x => (x.BatchNr == batchTo)).List(); if (bFrom.Count != 1) throw new Exception("No start batch"); if (bTo.Count != 1) throw new Exception("No end batch"); IList testResults = session.QueryOver() .WhereRestrictionOn(x => x.StartTime) .IsBetween(bFrom[0].StartTime) .And(bTo[0].EndTime) .List(); 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); } } } }