Procedure settings conversion code (to be completed).
This commit is contained in:
parent
66a31fc1e9
commit
6d47789708
@ -2,6 +2,7 @@
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using TBF.Resources;
|
||||
@ -116,6 +117,11 @@ namespace TBF
|
||||
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (DialogResult.Yes == MessageBox.Show("Chcete naplnit 'Publish' a 'Evaluate' vsetkych testov?", "Otazka", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
|
||||
{
|
||||
UpgradeAllTests();
|
||||
return;
|
||||
}
|
||||
proceduresCtrl.MoveDownSelected();
|
||||
}
|
||||
|
||||
@ -168,5 +174,83 @@ namespace TBF
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpgradeAllTests()
|
||||
{
|
||||
NHibernate.ISession session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
|
||||
IList<Config.Entities.Procedure> procedures = session.CreateQuery("FROM Procedure ORDER BY ItemNr")
|
||||
.List<Config.Entities.Procedure>();
|
||||
|
||||
///IList<TBF.BenchControl.Generic.IComponent> components = TBF.BenchControl.TbfComponents.LoadComponentsFromDB(session);
|
||||
///
|
||||
int successful = 0;
|
||||
int failed = 0;
|
||||
string lastMsg = string.Empty;
|
||||
|
||||
int N = procedures.Count;
|
||||
for (int i = 0; i < N; i++)
|
||||
{
|
||||
Config.Entities.Procedure proc = procedures[i];
|
||||
Text = string.Format("{0} ({1}/{2})", proc.Name, i, N);
|
||||
|
||||
NHibernate.ITransaction transaction = session.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
//IList<Config.Entities.Test> tests = session.CreateQuery("FROM Test WHERE Procedure = ORDER BY ItemNr")
|
||||
// .List<Config.Entities.Test>();
|
||||
IList<Config.Entities.Test> tests = session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.Procedure == proc))
|
||||
.OrderBy(x => x.ItemNr).Desc
|
||||
.List<Config.Entities.Test>();
|
||||
|
||||
foreach (var test in tests)
|
||||
{
|
||||
bool publish;
|
||||
bool evaluate;
|
||||
|
||||
if (test.Name.ToLower().Equals("rfid") ||
|
||||
test.Name.ToLower().Equals("q1") ||
|
||||
test.Name.ToLower().Equals("q2") ||
|
||||
test.Name.ToLower().Equals("q3"))
|
||||
{
|
||||
publish = true;
|
||||
evaluate = true;
|
||||
}
|
||||
else if (test.Name.ToLower().Equals("adjustment") ||
|
||||
test.Name.ToLower().Equals("q2adj"))
|
||||
{
|
||||
publish = true;
|
||||
evaluate = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
publish = false;
|
||||
evaluate = false;
|
||||
}
|
||||
|
||||
bool testChanged = false;
|
||||
if (test.Publish != publish) { test.Publish = publish; testChanged = true; }
|
||||
if (test.Evaluate != evaluate) { test.Evaluate = evaluate; testChanged = true; }
|
||||
|
||||
if (testChanged) Config.FluentCommon.SaveToDb(session, test);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
|
||||
successful++;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
transaction.Rollback();
|
||||
lastMsg = exc.Message;
|
||||
failed++;
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show(string.Format("Successful: {0}, Failed: {1}\r\nMessage: {2}", successful, failed, lastMsg), "Result",
|
||||
MessageBoxButtons.OK, (failed > 0) ? MessageBoxIcon.Error : MessageBoxIcon.Information);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user