Refactorization: TBF.UI namespace, no change of function, ver. 2.18.1314
This commit is contained in:
@@ -0,0 +1,518 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Slovensko a.s.
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
using Results.Forms;
|
||||
using TBF.BenchControl;
|
||||
using TBF.BenchControl.GenericDevices;
|
||||
using TBF.Resources;
|
||||
using TBF.UI.Shared;
|
||||
|
||||
namespace TBF.UI.Bench.Transitions
|
||||
{
|
||||
public partial class TransitionStepsCtrl : BaseWithListViewEx<TransitionStep>, ITabWithListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(TransitionStepsCtrl));
|
||||
|
||||
/// <summary>
|
||||
/// Fixed ListViewEx columns
|
||||
/// </summary>
|
||||
enum Column
|
||||
{
|
||||
Duration,
|
||||
Message,
|
||||
Condition,
|
||||
FixedColumnsCount,
|
||||
}
|
||||
readonly int fixedCount = (int)Column.FixedColumnsCount;
|
||||
|
||||
TransitionSequence sequence;
|
||||
|
||||
TransitionsDlg parent;
|
||||
Control parentControl;
|
||||
Control[] editors;
|
||||
|
||||
int fmPumpCount; /// Number of pumps with FM control
|
||||
int regvCount; /// Number of regulating valves
|
||||
int vCount; /// Number of valves
|
||||
|
||||
IList<string> conditionNames;
|
||||
IList<string> conditionComponents;
|
||||
IList<int> conditionIDs;
|
||||
|
||||
|
||||
public TransitionStepsCtrl()
|
||||
: base()
|
||||
{
|
||||
conditionNames = new List<string>();
|
||||
conditionComponents = new List<string>();
|
||||
conditionIDs = new List<int>();
|
||||
}
|
||||
|
||||
public void Initialize(TransitionSequence sequence, TBF.UI.Bench.Transitions.TransitionsDlg parent, Control parentControl)
|
||||
{
|
||||
this.sequence = sequence;
|
||||
this.parent = parent;
|
||||
this.parentControl = parentControl;
|
||||
Name = sequence.Name;
|
||||
MyItems = sequence.TransitionSteps;
|
||||
|
||||
SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
|
||||
SubItemRightClicked += new SubItemEventHandler(listViewEx_SubItemRightClicked);
|
||||
SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
||||
|
||||
vCount = 0;
|
||||
fmPumpCount = 0;
|
||||
regvCount = parent.RegulValves.Count;
|
||||
|
||||
///
|
||||
/// ListViewEx columns
|
||||
///
|
||||
Columns.Add(Strings.Duration_s, 70 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.Message, 100 * parent.Dpi / Constants.Dpi100pct);
|
||||
Columns.Add(Strings.End_Condition, 80 * parent.Dpi / Constants.Dpi100pct);
|
||||
foreach (var vlv in parent.Valves)
|
||||
{
|
||||
if (vlv is BenchControl.GenericDevices.IPumpFM)
|
||||
{
|
||||
Columns.Add(vlv.Cfg.Name + " [%]", 45 * parent.Dpi / Constants.Dpi100pct);
|
||||
fmPumpCount++;
|
||||
}
|
||||
}
|
||||
foreach (var rvlv in parent.RegulValves)
|
||||
{
|
||||
Columns.Add(rvlv.Cfg.Name + " [%]", 55 * parent.Dpi / Constants.Dpi100pct);
|
||||
}
|
||||
foreach (var vlv in parent.Valves)
|
||||
{
|
||||
if (!(vlv is BenchControl.GenericDevices.IPumpFM))
|
||||
{
|
||||
Columns.Add(vlv.Cfg.Name, 40 * parent.Dpi / Constants.Dpi100pct);
|
||||
vCount++;
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Prepare valve combo-boxes
|
||||
///
|
||||
TextBox tb;
|
||||
ComboBox cb;
|
||||
editors = new Control[fixedCount + fmPumpCount + regvCount + vCount];
|
||||
|
||||
/// Duration
|
||||
editors[(int)Column.Duration] = tb = new TextBox();
|
||||
tb.Visible = false;
|
||||
parent.Controls.Add(tb);
|
||||
|
||||
/// Message
|
||||
editors[(int)Column.Message] = tb = new TextBox();
|
||||
tb.Visible = false;
|
||||
parent.Controls.Add(tb);
|
||||
|
||||
|
||||
/// End condition
|
||||
editors[(int)Column.Condition] = cb = new ComboBox();
|
||||
cb.Visible = false;
|
||||
cb.Items.Add("---");
|
||||
///for (int i = 1; i < (int)StepCondition.Count; i++) cb.Items.Add(((StepCondition)i).ToString());
|
||||
foreach (var cmpnt in parent.TbfComponents)
|
||||
{
|
||||
if (cmpnt is ISequenceCondition)
|
||||
{
|
||||
ISequenceCondition c = cmpnt as ISequenceCondition;
|
||||
for (int i = 0; i < c.ConditionsCount; i++)
|
||||
{
|
||||
cb.Items.Add(c.ConditionName(i));
|
||||
conditionNames.Add(c.ConditionName(i));
|
||||
conditionComponents.Add(cmpnt.Name);
|
||||
conditionIDs.Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
parent.Controls.Add(cb);
|
||||
|
||||
|
||||
/// FM controlled pumps
|
||||
for (int i = fixedCount; i < fixedCount + fmPumpCount; i++)
|
||||
{
|
||||
editors[i] = cb = new ComboBox();
|
||||
cb.Visible = false;
|
||||
cb.Items.Add("---");
|
||||
cb.Items.Add(Strings.dflt);
|
||||
cb.Items.Add("0");
|
||||
cb.Items.Add("30");
|
||||
cb.Items.Add("40");
|
||||
cb.Items.Add("50");
|
||||
cb.Items.Add("60");
|
||||
cb.Items.Add("70");
|
||||
cb.Items.Add("75");
|
||||
cb.Items.Add("80");
|
||||
cb.Items.Add("85");
|
||||
cb.Items.Add("90");
|
||||
cb.Items.Add("92");
|
||||
cb.Items.Add("94");
|
||||
cb.Items.Add("96");
|
||||
cb.Items.Add("98");
|
||||
cb.Items.Add("100");
|
||||
parent.Controls.Add(cb);
|
||||
}
|
||||
|
||||
/// Regulation valves
|
||||
for (int i = fixedCount + fmPumpCount; i < fixedCount + fmPumpCount + regvCount; i++)
|
||||
{
|
||||
editors[i] = cb = new ComboBox();
|
||||
cb.Visible = false;
|
||||
cb.Items.Add("---");
|
||||
cb.Items.Add("0");
|
||||
cb.Items.Add("25");
|
||||
cb.Items.Add("50");
|
||||
cb.Items.Add("75");
|
||||
cb.Items.Add("100");
|
||||
parent.Controls.Add(cb);
|
||||
}
|
||||
|
||||
/// Valves
|
||||
for (int i = fixedCount + fmPumpCount + regvCount; i < fixedCount + fmPumpCount + regvCount + vCount; i++)
|
||||
{
|
||||
editors[i] = cb = new ComboBox();
|
||||
cb.Visible = false;
|
||||
cb.Items.Add("---");
|
||||
cb.Items.Add(Strings.open);
|
||||
cb.Items.Add(Strings.close);
|
||||
parent.Controls.Add(cb);
|
||||
}
|
||||
|
||||
base.RedrawAll();
|
||||
}
|
||||
|
||||
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (!Unlocked || e.SubItem >= editors.Length) return;
|
||||
StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
||||
}
|
||||
|
||||
void listViewEx_SubItemRightClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (!Unlocked || e.SubItem >= editors.Length) return;
|
||||
|
||||
if (DialogResult.Yes == MessageBox.Show(Strings.Do_you_want_to_copy_this_value_to_all_cells_below_this_cell,
|
||||
Strings.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
|
||||
{
|
||||
int columnNr = e.SubItem;
|
||||
string value = null;
|
||||
System.Drawing.Color backColor = System.Drawing.Color.White;
|
||||
foreach (ListViewItem item in Items)
|
||||
{
|
||||
if (value != null && item.SubItems.Count > columnNr)
|
||||
{
|
||||
item.SubItems[columnNr].Text = value;
|
||||
item.SubItems[columnNr].BackColor = backColor;
|
||||
}
|
||||
else if (item == e.Item)
|
||||
{
|
||||
value = item.SubItems[columnNr].Text;
|
||||
backColor = item.SubItems[columnNr].BackColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
||||
{
|
||||
if (e.SubItem == (int)Column.Duration)
|
||||
{
|
||||
int duration;
|
||||
if (!int.TryParse(e.DisplayText, out duration) || duration <= 0)
|
||||
{
|
||||
e.DisplayText = e.Item.Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if (e.SubItem == (int)Column.Message)
|
||||
{
|
||||
if (e.DisplayText.Length >= 255)
|
||||
{
|
||||
// Message too long
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if (e.SubItem == (int)Column.Condition)
|
||||
{
|
||||
if (!((ComboBox)editors[(int)Column.Condition]).Items.Contains(e.DisplayText))
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if ((e.SubItem >= fixedCount) && (e.SubItem < fixedCount + fmPumpCount))
|
||||
{
|
||||
float pct;
|
||||
if (!e.DisplayText.Equals("---") &&
|
||||
!e.DisplayText.Equals(Strings.dflt) &&
|
||||
!(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if ((e.SubItem >= fixedCount + fmPumpCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount))
|
||||
{
|
||||
float pct;
|
||||
if (!e.DisplayText.Equals("---") &&
|
||||
!(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
else if ((e.SubItem >= fixedCount + fmPumpCount + regvCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount + vCount))
|
||||
{
|
||||
if ((e.DisplayText != Strings.open) && (e.DisplayText != Strings.close) && (e.DisplayText != "---"))
|
||||
{
|
||||
e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Item.SubItems[e.SubItem].BackColor = e.DisplayText == Strings.open ? Color.LightGray : Color.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawOne(object myItem)
|
||||
{
|
||||
TransitionStep step = (TransitionStep)myItem;
|
||||
|
||||
IList<IValve> valvesOpen = new List<IValve>();
|
||||
if (step.ValvesOpen != null)
|
||||
{
|
||||
string[] vOpen = step.ValvesOpen.Split(new char[] { ';' });
|
||||
foreach (var vName in vOpen) valvesOpen.Add((IValve)TbfComponents.FindComponent(vName, parent.TbfComponents));
|
||||
}
|
||||
|
||||
IList<IValve> valvesClose = new List<IValve>();
|
||||
if (step.ValvesClose != null)
|
||||
{
|
||||
string[] vClose = step.ValvesClose.Split(new char[] { ';' });
|
||||
foreach (var vName in vClose) valvesClose.Add((IValve)TbfComponents.FindComponent(vName, parent.TbfComponents));
|
||||
}
|
||||
|
||||
ListViewItem lvi = new ListViewItem(step.Duration.ToString());
|
||||
lvi.UseItemStyleForSubItems = false;
|
||||
|
||||
lvi.SubItems.Add(string.IsNullOrEmpty(step.Message) ? string.Empty : step.Message);
|
||||
|
||||
if (step.EndCondition == "None")
|
||||
{
|
||||
lvi.SubItems.Add("---");
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] fields = step.EndCondition.Split( new char[] { '~' } );
|
||||
if (fields.Length == 2)
|
||||
{
|
||||
ISequenceCondition cmpnt = TbfComponents.FindComponent(fields[0], parent.TbfComponents) as ISequenceCondition;
|
||||
int id;
|
||||
if (cmpnt != null && int.TryParse(fields[1], out id) && id >= 0 && id < cmpnt.ConditionsCount)
|
||||
{
|
||||
lvi.SubItems.Add(cmpnt.ConditionName(id));
|
||||
}
|
||||
else
|
||||
{
|
||||
lvi.SubItems.Add("---");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
lvi.SubItems.Add("---");
|
||||
}
|
||||
}
|
||||
|
||||
string[] fmPumpsStr = (step.PumpWithFMPcts != null) ? step.PumpWithFMPcts.Split(new char[] { ';' })
|
||||
: new string[0];
|
||||
for (int i = 0; i < fmPumpCount; i++)
|
||||
{
|
||||
lvi.SubItems.Add((i < fmPumpsStr.Length) ? fmPumpsStr[i] : "---");
|
||||
}
|
||||
|
||||
string[] rvPosStr = (step.RegulValvesPct != null) ? step.RegulValvesPct.Split(new char[] { ';' })
|
||||
: new string[0];
|
||||
for (int i = 0; i < regvCount; i++)
|
||||
{
|
||||
lvi.SubItems.Add((i < rvPosStr.Length) ? rvPosStr[i] : "---");
|
||||
}
|
||||
|
||||
foreach (var valve in parent.Valves)
|
||||
{
|
||||
if (!(valve is BenchControl.GenericDevices.IPumpFM))
|
||||
{
|
||||
if (valvesOpen != null && valvesOpen.Contains(valve))
|
||||
{
|
||||
lvi.SubItems.Add(Strings.open);
|
||||
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.LightGray;
|
||||
}
|
||||
else if (valvesClose != null && valvesClose.Contains(valve))
|
||||
{
|
||||
lvi.SubItems.Add(Strings.close);
|
||||
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.White;
|
||||
}
|
||||
else
|
||||
{
|
||||
lvi.SubItems.Add("---");
|
||||
lvi.SubItems[lvi.SubItems.Count - 1].BackColor = Color.White;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lvi.Tag = step;
|
||||
|
||||
Items.Add(lvi);
|
||||
}
|
||||
|
||||
public override void UpdateOne(ListViewItem lvi, object myItem)
|
||||
{
|
||||
TransitionStep step = (TransitionStep)myItem;
|
||||
|
||||
///
|
||||
/// Duration
|
||||
///
|
||||
int duration;
|
||||
if (int.TryParse(lvi.Text, out duration) && duration > 0)
|
||||
step.Duration = duration;
|
||||
else
|
||||
lvi.Text = step.Duration.ToString();
|
||||
|
||||
///
|
||||
/// Message
|
||||
///
|
||||
if (lvi.SubItems[(int)Column.Message].Text.Length == 0)
|
||||
step.Message = string.Empty;
|
||||
else
|
||||
step.Message = lvi.SubItems[(int)Column.Message].Text;
|
||||
|
||||
///
|
||||
/// Condition
|
||||
///
|
||||
step.EndCondition = "None"; /// When item text is "---" or a wrong value
|
||||
for (int cix = 0; cix < conditionNames.Count; cix++)
|
||||
{
|
||||
if (lvi.SubItems[(int)Column.Condition].Text.Equals(conditionNames[cix]))
|
||||
{
|
||||
step.EndCondition = string.Format("{0}~{1}", conditionComponents[cix], conditionIDs[cix]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// Required for pumps with FM and valves
|
||||
string valvesOpen = string.Empty;
|
||||
string valvesClose = string.Empty;
|
||||
|
||||
///
|
||||
/// Pumps with FM control
|
||||
///
|
||||
string fmPumpsPcts = string.Empty;
|
||||
int i = 0;
|
||||
foreach (var valve in parent.Valves)
|
||||
{
|
||||
if (valve is BenchControl.GenericDevices.IPumpFM)
|
||||
{
|
||||
string lviSubitText = lvi.SubItems[fixedCount + i++].Text;
|
||||
if (fmPumpsPcts.Length > 0) fmPumpsPcts += ";";
|
||||
float fdummy;
|
||||
if (lviSubitText.Equals("---"))
|
||||
{
|
||||
fmPumpsPcts += lviSubitText;
|
||||
}
|
||||
else if (lviSubitText.Equals(Strings.dflt))
|
||||
{
|
||||
fmPumpsPcts += lviSubitText;
|
||||
if (valvesOpen != string.Empty) valvesOpen += ";";
|
||||
valvesOpen += valve.Cfg.Name;
|
||||
}
|
||||
else if (Utils.TryParseUFloat(lviSubitText, out fdummy) && (fdummy >= 0) && (fdummy <= 100.0f))
|
||||
{
|
||||
fmPumpsPcts += lviSubitText;
|
||||
if (fdummy > 0)
|
||||
{
|
||||
if (valvesOpen != string.Empty) valvesOpen += ";";
|
||||
valvesOpen += valve.Cfg.Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (valvesClose != string.Empty) valvesClose += ";";
|
||||
valvesClose += valve.Cfg.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
step.PumpWithFMPcts = fmPumpsPcts;
|
||||
|
||||
///
|
||||
/// Regulation valves
|
||||
///
|
||||
string regulValvesPct = string.Empty;
|
||||
for (int k = fixedCount + fmPumpCount; k < fixedCount + fmPumpCount + regvCount; k++)
|
||||
{
|
||||
if (regulValvesPct.Length > 0) regulValvesPct += ";";
|
||||
float fdummy;
|
||||
if (lvi.SubItems[k].Text.Equals("---") ||
|
||||
(Utils.TryParseUFloat(lvi.SubItems[k].Text, out fdummy) && (fdummy >= 0) && (fdummy <= 100.0f)))
|
||||
{
|
||||
regulValvesPct += lvi.SubItems[k].Text;
|
||||
}
|
||||
}
|
||||
step.RegulValvesPct = regulValvesPct;
|
||||
|
||||
///
|
||||
/// Valves
|
||||
///
|
||||
for (int j = 0, k = 0; j < parent.Valves.Count; j++)
|
||||
{
|
||||
if (!(parent.Valves[j] is BenchControl.GenericDevices.IPumpFM))
|
||||
{
|
||||
string lviSubitText = lvi.SubItems[fixedCount + fmPumpCount + regvCount + k++].Text;
|
||||
if (lviSubitText.Equals(Strings.open))
|
||||
{
|
||||
if (valvesOpen != string.Empty) valvesOpen += ";";
|
||||
valvesOpen += parent.Valves[j].Cfg.Name;
|
||||
}
|
||||
if (lviSubitText.Equals(Strings.close))
|
||||
{
|
||||
if (valvesClose != string.Empty) valvesClose += ";";
|
||||
valvesClose += parent.Valves[j].Cfg.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
step.ValvesOpen = valvesOpen;
|
||||
step.ValvesClose = valvesClose;
|
||||
}
|
||||
|
||||
public void AddOne()
|
||||
{
|
||||
base.AddOne(new TransitionStep(MyItems.Count, sequence));
|
||||
}
|
||||
|
||||
public new void RemoveSelected()
|
||||
{
|
||||
bool lastItemRemoved = base.RemoveSelected();
|
||||
if (lastItemRemoved && parent != null)
|
||||
{
|
||||
parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetWarningsBeforeSaving(ref Dictionary<string, string> renmInfo)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+91
@@ -0,0 +1,91 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
||||
///
|
||||
namespace TBF.UI.Bench.Transitions
|
||||
{
|
||||
partial class TransitionsDlg
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TransitionsDlg));
|
||||
this.mainSplitContainer = new System.Windows.Forms.SplitContainer();
|
||||
this.tabControl = new System.Windows.Forms.TabControl();
|
||||
this.sharedButtons = new TBF.UI.Shared.SharedButtons();
|
||||
((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).BeginInit();
|
||||
this.mainSplitContainer.Panel1.SuspendLayout();
|
||||
this.mainSplitContainer.Panel2.SuspendLayout();
|
||||
this.mainSplitContainer.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// mainSplitContainer
|
||||
//
|
||||
resources.ApplyResources(this.mainSplitContainer, "mainSplitContainer");
|
||||
this.mainSplitContainer.FixedPanel = System.Windows.Forms.FixedPanel.Panel2;
|
||||
this.mainSplitContainer.Name = "mainSplitContainer";
|
||||
//
|
||||
// mainSplitContainer.Panel1
|
||||
//
|
||||
this.mainSplitContainer.Panel1.Controls.Add(this.tabControl);
|
||||
//
|
||||
// mainSplitContainer.Panel2
|
||||
//
|
||||
this.mainSplitContainer.Panel2.Controls.Add(this.sharedButtons);
|
||||
//
|
||||
// tabControl
|
||||
//
|
||||
resources.ApplyResources(this.tabControl, "tabControl");
|
||||
this.tabControl.Name = "tabControl";
|
||||
this.tabControl.SelectedIndex = 0;
|
||||
this.tabControl.SelectedIndexChanged += new System.EventHandler(this.tabControl_SelectedIndexChanged);
|
||||
//
|
||||
// sharedButtons
|
||||
//
|
||||
resources.ApplyResources(this.sharedButtons, "sharedButtons");
|
||||
this.sharedButtons.Name = "sharedButtons";
|
||||
//
|
||||
// TransitionsDlg
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.mainSplitContainer);
|
||||
this.Name = "TransitionsDlg";
|
||||
this.Load += new System.EventHandler(this.TransitionsDlg_Load);
|
||||
this.mainSplitContainer.Panel1.ResumeLayout(false);
|
||||
this.mainSplitContainer.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.mainSplitContainer)).EndInit();
|
||||
this.mainSplitContainer.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.SplitContainer mainSplitContainer;
|
||||
private System.Windows.Forms.TabControl tabControl;
|
||||
private TBF.UI.Shared.SharedButtons sharedButtons;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2017 Sensus Metering Systems
|
||||
///
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using NHibernate;
|
||||
using Config.Entities;
|
||||
using Results.Forms;
|
||||
using TBF.BenchControl.Generic;
|
||||
using TBF.BenchControl.GenericDevices;
|
||||
using TBF.Resources;
|
||||
using TBF.UI.Shared;
|
||||
|
||||
namespace TBF.UI.Bench.Transitions
|
||||
{
|
||||
public partial class TransitionsDlg : Form, IParentOfListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(TransitionsDlg));
|
||||
|
||||
/// Used when re-scaling the dialog: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi
|
||||
public readonly int Dpi;
|
||||
public const int Dpi100pct = 96;
|
||||
|
||||
/// <summary>
|
||||
/// Fluent-NHibernate database session
|
||||
/// </summary>
|
||||
public ISession Session;
|
||||
|
||||
IList<Procedure> procedures;
|
||||
IList<Test> tests;
|
||||
|
||||
Dictionary<string, string> renameInfo; /// Pairs original name / new name
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Transition sequences to be updated by this dialog.
|
||||
/// Set by the constructor or updated by the parent after creation and before loading.
|
||||
/// </summary>
|
||||
public IList<TransitionSequence> TransitionSequences;
|
||||
public IList<TransitionSequence> RemovedTransitionSequences;
|
||||
|
||||
/// <summary>
|
||||
/// Virtual bench sequences to be updated by this dialog.
|
||||
/// Set by the constructor or updated by the parent after creation and before loading.
|
||||
/// </summary>
|
||||
public IList<VirtualBenchSequence> VirtualBenchSequences;
|
||||
public IList<VirtualBenchSequence> RemovedVirtualBenchSequences;
|
||||
|
||||
|
||||
/// Auxiliary public lists used also by user controls in tab pages
|
||||
public IList<BenchControl.Generic.IComponent> TbfComponents;
|
||||
public IList<IValve> Valves;
|
||||
public IList<IRegulValve> RegulValves;
|
||||
|
||||
|
||||
IList<ITabWithListViewEx> seqStepsCtrls;
|
||||
|
||||
|
||||
public TransitionsDlg()
|
||||
{
|
||||
/// Detect display setting: 100% = 96dpi, 125% = 120dpi, 150% = 144dpi.
|
||||
Dpi = (int)this.CreateGraphics().DpiX;
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
/// SharedDlgButtons configuration
|
||||
sharedButtons.RequiredGroupMembership = new Users.Grp.GID[] { Users.Grp.GID.Metrologists };
|
||||
sharedButtons.OptionalButtons = SharedButtons.Buttons.Add | SharedButtons.Buttons.Remove |
|
||||
SharedButtons.Buttons.Up | SharedButtons.Buttons.Down |
|
||||
SharedButtons.Buttons.Export | SharedButtons.Buttons.Import |
|
||||
SharedButtons.Buttons.Compare | SharedButtons.Buttons.NewTab |
|
||||
SharedButtons.Buttons.RenameTab | SharedButtons.Buttons.RemoveTab;
|
||||
sharedButtons.Unlocked += Unlocked;
|
||||
sharedButtons.OKClicked += okButton_Click;
|
||||
sharedButtons.CancelClicked += cancelButton_Click;
|
||||
sharedButtons.AddClicked += addButton_Click;
|
||||
sharedButtons.RemoveClicked += removeButton_Click;
|
||||
sharedButtons.UpClicked += upButton_Click;
|
||||
sharedButtons.DownClicked += downButton_Click;
|
||||
sharedButtons.ExportClicked += exportButton_Click;
|
||||
sharedButtons.ImportClicked += importButton_Click;
|
||||
sharedButtons.CompareClicked += compareButton_Click;
|
||||
sharedButtons.NewTabClicked += newTabButton_Click;
|
||||
sharedButtons.RenameTabClicked += renameTabButton_Click;
|
||||
sharedButtons.RemoveTabClicked += removeTabButton_Click;
|
||||
|
||||
seqStepsCtrls = new List<ITabWithListViewEx>();
|
||||
|
||||
/// Open the database
|
||||
Session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
|
||||
/// Prepare a list of components and a list of all valves in the test bench
|
||||
TbfComponents = BenchControl.TbfComponents.LoadComponentsFromDB(Session);
|
||||
Valves = BenchControl.GenericDevices.ValveBase.MasterValves(TbfComponents);
|
||||
RegulValves = new List<IRegulValve>();
|
||||
foreach (var cmpnt in TbfComponents)
|
||||
{
|
||||
if ((cmpnt is IRegulValve) && !(cmpnt is BenchControl.Elde.RegulValveTandem.RegulValveTandem))
|
||||
{
|
||||
RegulValves.Add(cmpnt as IRegulValve);
|
||||
}
|
||||
}
|
||||
|
||||
/// Load the sequences
|
||||
/// Note: Each sequence (in both sequences together) has a unique ItemNr (0 .. N-1)
|
||||
TransitionSequences = Session.QueryOver<TransitionSequence>().OrderBy(x => x.ItemNr).Asc.List();
|
||||
VirtualBenchSequences = Session.QueryOver<VirtualBenchSequence>().OrderBy(x => x.ItemNr).Asc.List();
|
||||
procedures = Session.QueryOver<Procedure>().List();
|
||||
tests = Session.QueryOver<Test>().List();
|
||||
|
||||
RemovedTransitionSequences = new List<TransitionSequence>();
|
||||
RemovedVirtualBenchSequences = new List<VirtualBenchSequence>();
|
||||
|
||||
/// Create a tab with sequence steps for each sequence ordered by ItemNr.
|
||||
foreach (var transSeq in TransitionSequences)
|
||||
{
|
||||
transSeq.OriName = transSeq.Name;
|
||||
AddTransitionSeqTab(transSeq);
|
||||
}
|
||||
|
||||
foreach (var vBenchSeq in VirtualBenchSequences)
|
||||
{
|
||||
vBenchSeq.OriName = vBenchSeq.Name;
|
||||
AddVirtualBenchSeqTab(vBenchSeq);
|
||||
}
|
||||
}
|
||||
|
||||
void AddTransitionSeqTab(TransitionSequence sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage(sequence.Name);
|
||||
nwTab.Tag = sequence;
|
||||
TransitionStepsCtrl newCtrl = new TransitionStepsCtrl();
|
||||
seqStepsCtrls.Add(newCtrl);
|
||||
nwTab.Controls.Add(newCtrl);
|
||||
tabControl.TabPages.Add(nwTab);
|
||||
newCtrl.Initialize(sequence, this, tabControl.TabPages[tabControl.TabPages.Count - 1]);
|
||||
newCtrl.SelectedIndexChanged += new System.EventHandler(SelectedIndexChanged);
|
||||
}
|
||||
|
||||
void AddVirtualBenchSeqTab(VirtualBenchSequence sequence)
|
||||
{
|
||||
TabPage nwTab = new TabPage(sequence.Name);
|
||||
nwTab.Tag = sequence;
|
||||
VirtualBenchStepsCtrl newCtrl = new VirtualBenchStepsCtrl();
|
||||
seqStepsCtrls.Add(newCtrl);
|
||||
nwTab.Controls.Add(newCtrl);
|
||||
tabControl.TabPages.Add(nwTab);
|
||||
newCtrl.Initialize(sequence, this, tabControl.TabPages[tabControl.TabPages.Count - 1]);
|
||||
newCtrl.SelectedIndexChanged += new System.EventHandler(SelectedIndexChanged);
|
||||
}
|
||||
|
||||
private void TransitionsDlg_Load(object sender, EventArgs e)
|
||||
{
|
||||
Localize();
|
||||
LoadUISettings();
|
||||
|
||||
/// Now refresh the content of the dialog
|
||||
RefreshAllTabs();
|
||||
}
|
||||
|
||||
void Localize()
|
||||
{
|
||||
Text = Strings.Transitions;
|
||||
}
|
||||
|
||||
void RefreshAllTabs()
|
||||
{
|
||||
foreach (var ctrl in seqStepsCtrls) (ctrl as ListViewEx).Refresh();
|
||||
}
|
||||
|
||||
private void Unlocked(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var ctrl in seqStepsCtrls) ctrl.Unlock();
|
||||
}
|
||||
|
||||
|
||||
private void newTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabNameDlg dlg;
|
||||
bool nameUsed;
|
||||
int tabId = TransitionSequences.Count + VirtualBenchSequences.Count;
|
||||
|
||||
do
|
||||
{
|
||||
/// Find an unused procedure name
|
||||
string newName;
|
||||
for (int nameId = 1; true; nameId++)
|
||||
{
|
||||
newName = "Tr" + nameId.ToString();
|
||||
nameUsed = false;
|
||||
foreach (var seq in TransitionSequences) if (seq.Name.Equals(newName)) nameUsed = true;
|
||||
if (!nameUsed) break;
|
||||
}
|
||||
|
||||
dlg = new TabNameDlg();
|
||||
dlg.TabNameLabel = Strings.New_transition_name;
|
||||
dlg.TabName = newName;
|
||||
|
||||
if (DialogResult.OK != dlg.ShowDialog()) return;
|
||||
|
||||
foreach (var seq in TransitionSequences) if (seq.Name.Equals(dlg.TabName)) nameUsed = true;
|
||||
if (nameUsed) MessageBox.Show(Strings.Please_choose_another_transition_sequence_name,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
while (nameUsed);
|
||||
|
||||
if (dlg.IsVirtualBenchSeq)
|
||||
{
|
||||
VirtualBenchSequence sequence = new VirtualBenchSequence(dlg.TabName, tabId);
|
||||
VirtualBenchSequences.Add(sequence);
|
||||
AddVirtualBenchSeqTab(sequence);
|
||||
seqStepsCtrls[tabId].Unlock();
|
||||
}
|
||||
else
|
||||
{
|
||||
TransitionSequence sequence = new TransitionSequence(dlg.TabName, tabId);
|
||||
TransitionSequences.Add(sequence);
|
||||
AddTransitionSeqTab(sequence);
|
||||
seqStepsCtrls[tabId].Unlock();
|
||||
}
|
||||
tabControl.SelectTab(tabId);
|
||||
}
|
||||
|
||||
private void renameTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabPage tabPage = tabControl.SelectedTab;
|
||||
TransitionSequence transitionSeq = tabPage.Tag as TransitionSequence;
|
||||
VirtualBenchSequence virtualBenchSeq = tabPage.Tag as VirtualBenchSequence;
|
||||
|
||||
TabNameDlg dlg = new TabNameDlg(true);
|
||||
dlg.TabNameLabel = Strings.New_transition_name;
|
||||
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
bool nameUsed = false;
|
||||
foreach (var seq in TransitionSequences) if (seq != transitionSeq && seq.Name == dlg.TabName) nameUsed = true;
|
||||
foreach (var seq in VirtualBenchSequences) if (seq != virtualBenchSeq && seq.Name == dlg.TabName) nameUsed = true;
|
||||
|
||||
if (nameUsed)
|
||||
{
|
||||
MessageBox.Show(Strings.Please_choose_another_transition_sequence_name,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Information);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (transitionSeq != null)
|
||||
{
|
||||
transitionSeq.Name = dlg.TabName;
|
||||
tabPage.Text = dlg.TabName;
|
||||
}
|
||||
else if (virtualBenchSeq != null)
|
||||
{
|
||||
virtualBenchSeq.Name = dlg.TabName;
|
||||
tabPage.Text = dlg.TabName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeTabButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabPage tabPage = tabControl.SelectedTab;
|
||||
TransitionSequence transitionSeq = tabPage.Tag as TransitionSequence;
|
||||
VirtualBenchSequence virtualBenchSeq = tabPage.Tag as VirtualBenchSequence;
|
||||
|
||||
if (DialogResult.Yes == MessageBox.Show(string.Format(Strings.Do_you_really_want_to_delete_sequence_0, tabPage.Text),
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question))
|
||||
{
|
||||
if (transitionSeq != null)
|
||||
{
|
||||
RemovedTransitionSequences.Add(transitionSeq);
|
||||
TransitionSequences.Remove(transitionSeq);
|
||||
tabControl.TabPages.Remove(tabPage);
|
||||
}
|
||||
else if (virtualBenchSeq != null)
|
||||
{
|
||||
RemovedVirtualBenchSequences.Add(virtualBenchSeq);
|
||||
VirtualBenchSequences.Remove(virtualBenchSeq);
|
||||
tabControl.TabPages.Remove(tabPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RetrieveData()
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].OkBtnClicked();
|
||||
}
|
||||
|
||||
string GetWarningsBeforeSaving(ref Dictionary<string, string> renmInfo)
|
||||
{
|
||||
string warnings = string.Empty;
|
||||
renmInfo = new Dictionary<string, string>();
|
||||
|
||||
foreach (var seq in RemovedTransitionSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName))
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Deleting transition sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var seq in RemovedVirtualBenchSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName))
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Deleting virtual bench sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, string.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var seq in TransitionSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName) && seq.OriName != seq.Name)
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Renaming transition sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, seq.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach (var seq in VirtualBenchSequences)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(seq.OriName) && seq.OriName != seq.Name)
|
||||
{
|
||||
int occurances = 0;
|
||||
foreach (var test in tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(test.RelTransBefore) && test.RelTransBefore == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(test.TransitionAfter) && test.TransitionAfter == seq.OriName) occurances++;
|
||||
}
|
||||
foreach (var proc in procedures)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(proc.TransitionStart) && proc.TransitionStart == seq.OriName) occurances++;
|
||||
if (!string.IsNullOrEmpty(proc.TransitionEnd) && proc.TransitionEnd == seq.OriName) occurances++;
|
||||
}
|
||||
if (occurances > 0)
|
||||
{
|
||||
warnings += string.Format("Renaming virtual bench sequence {0} used in {1} tests and procedures{2}", seq.OriName, occurances, Environment.NewLine);
|
||||
renmInfo.Add(seq.OriName, seq.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
RetrieveData();
|
||||
|
||||
string warnings = GetWarningsBeforeSaving(ref renameInfo);
|
||||
|
||||
bool updateRelatedItems = false;
|
||||
if (!string.IsNullOrEmpty(warnings))
|
||||
{
|
||||
string message = string.Format("{0}{1}{2}", warnings, Environment.NewLine,
|
||||
Strings.Do_you_want_to_update_related_tests_and_procedures);
|
||||
DialogResult dr = MessageBox.Show(message, Strings.Warning, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
|
||||
if (dr == DialogResult.Cancel)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
return;
|
||||
}
|
||||
else if (dr == DialogResult.Yes)
|
||||
{
|
||||
updateRelatedItems = true;
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
using (var transaction = Session.BeginTransaction())
|
||||
{
|
||||
try
|
||||
{
|
||||
if (updateRelatedItems)
|
||||
{
|
||||
foreach (var ri in renameInfo)
|
||||
{
|
||||
var tests = Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.RelTransBefore == ri.Key))
|
||||
.List();
|
||||
foreach (var t in tests)
|
||||
{
|
||||
t.RelTransBefore = ri.Value;
|
||||
Session.Update(t);
|
||||
}
|
||||
|
||||
tests = Session.QueryOver<Config.Entities.Test>()
|
||||
.Where(x => (x.TransitionAfter == ri.Key))
|
||||
.List();
|
||||
foreach (var t in tests)
|
||||
{
|
||||
t.TransitionAfter = ri.Value;
|
||||
Session.Update(t);
|
||||
}
|
||||
|
||||
var procedures = Session.QueryOver<Config.Entities.Procedure>()
|
||||
.Where(x => (x.TransitionStart == ri.Key))
|
||||
.List();
|
||||
foreach (var p in procedures)
|
||||
{
|
||||
p.TransitionStart = ri.Value;
|
||||
Session.Update(p);
|
||||
}
|
||||
|
||||
procedures = Session.QueryOver<Config.Entities.Procedure>()
|
||||
.Where(x => (x.TransitionEnd == ri.Key))
|
||||
.List();
|
||||
foreach (var p in procedures)
|
||||
{
|
||||
p.TransitionEnd = ri.Value;
|
||||
Session.Update(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var transSeq in RemovedTransitionSequences)
|
||||
{
|
||||
foreach (var step in transSeq.TransitionSteps) Session.Delete(step);
|
||||
Session.Delete(transSeq);
|
||||
}
|
||||
foreach (var vBnchSeq in RemovedVirtualBenchSequences)
|
||||
{
|
||||
foreach (var step in vBnchSeq.VirtualBenchSteps) Session.Delete(step);
|
||||
Session.Delete(vBnchSeq);
|
||||
}
|
||||
|
||||
int itemNr = 0;
|
||||
foreach (var transSeq in TransitionSequences)
|
||||
{
|
||||
transSeq.ItemNr = itemNr++;
|
||||
Session.SaveOrUpdate(transSeq);
|
||||
}
|
||||
itemNr = 0;
|
||||
foreach (var vBnchSeq in VirtualBenchSequences)
|
||||
{
|
||||
vBnchSeq.ItemNr = itemNr++;
|
||||
Session.SaveOrUpdate(vBnchSeq);
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch (Exception e2)
|
||||
{
|
||||
transaction.Rollback();
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
MessageBox.Show(Strings.Cannot_save_changes, Strings.Error, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
||||
log.ErrorFormat("Update of sequences in the database failed: {0}", e2.Message);
|
||||
}
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
|
||||
SaveUISettings();
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
SaveUISettings();
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
return;
|
||||
}
|
||||
|
||||
private void SaveUISettings()
|
||||
{
|
||||
/// Obtain TransitionsDlg dimensions, etc.
|
||||
bool isMaximized = (WindowState == FormWindowState.Maximized);
|
||||
int left = (WindowState == FormWindowState.Normal) ? Location.X : RestoreBounds.Left;
|
||||
int top = (WindowState == FormWindowState.Normal) ? Location.Y : RestoreBounds.Top;
|
||||
int width = (WindowState == FormWindowState.Normal) ? Size.Width : RestoreBounds.Width;
|
||||
int height = (WindowState == FormWindowState.Normal) ? Size.Height : RestoreBounds.Height;
|
||||
|
||||
LocalSettings ls = Program.LocalSettings;
|
||||
|
||||
if (ls != null && (ls.TransitionsDlgMaximized != isMaximized ||
|
||||
ls.TransitionsDlgLeft != left ||
|
||||
ls.TransitionsDlgTop != top ||
|
||||
ls.TransitionsDlgWidth != width ||
|
||||
ls.TransitionsDlgHeight != height))
|
||||
{
|
||||
/// At least one TransitionsDlg dimension differs => Update local settings and save them
|
||||
ls.TransitionsDlgMaximized = isMaximized;
|
||||
ls.TransitionsDlgLeft = left;
|
||||
ls.TransitionsDlgTop = top;
|
||||
ls.TransitionsDlgWidth = width;
|
||||
ls.TransitionsDlgHeight = height;
|
||||
ls.Save();
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadUISettings()
|
||||
{
|
||||
TBF.LocalSettings ls = Program.LocalSettings;
|
||||
WindowState = (ls.TransitionsDlgMaximized ? FormWindowState.Maximized : FormWindowState.Normal);
|
||||
Width = (ls.TransitionsDlgWidth > 0) ? ls.TransitionsDlgWidth : 1050;
|
||||
Height = (ls.TransitionsDlgHeight > 0) ? ls.TransitionsDlgHeight : 650;
|
||||
Left = (ls.TransitionsDlgLeft != 0) ? ls.TransitionsDlgLeft : 100;
|
||||
Top = (ls.TransitionsDlgTop != 0) ? ls.TransitionsDlgTop : 100;
|
||||
}
|
||||
|
||||
|
||||
int slctdTab;
|
||||
|
||||
private void tabControl_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab)
|
||||
{
|
||||
seqStepsCtrls[slctdTab].OkBtnClicked();
|
||||
}
|
||||
slctdTab = tabControl.SelectedIndex;
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Add);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove);
|
||||
RefreshAllTabs();
|
||||
}
|
||||
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].AddOne();
|
||||
}
|
||||
|
||||
private void removeButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].RemoveSelected();
|
||||
}
|
||||
|
||||
private void upButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].MoveUpSelected();
|
||||
}
|
||||
|
||||
private void downButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (seqStepsCtrls.Count > slctdTab) seqStepsCtrls[slctdTab].MoveDownSelected();
|
||||
}
|
||||
|
||||
public void UpdateButtonStates(SharedButtons.SelectedItemPos selectedItemPos)
|
||||
{
|
||||
if (selectedItemPos == SharedButtons.SelectedItemPos.None)
|
||||
{
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.First)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Down);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Up);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.Last)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Down);
|
||||
}
|
||||
else if (selectedItemPos == SharedButtons.SelectedItemPos.FirstAndLast)
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove);
|
||||
sharedButtons.DisableButtons(SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
else
|
||||
{
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Common part for three xxxListViewEx_SelectedIndexChanged event handlers
|
||||
/// </summary>
|
||||
/// <param name="listViewEx"></param>
|
||||
void SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
ListViewEx listViewEx = sender as ListViewEx;
|
||||
if (listViewEx.SelectedItems.Count != 1)
|
||||
{
|
||||
UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
||||
}
|
||||
else if (listViewEx.Items.Count == 1)
|
||||
{
|
||||
UpdateButtonStates(SharedButtons.SelectedItemPos.FirstAndLast);
|
||||
}
|
||||
else if (listViewEx.SelectedIndices[0] == 0)
|
||||
{
|
||||
UpdateButtonStates(SharedButtons.SelectedItemPos.First);
|
||||
}
|
||||
else if (listViewEx.SelectedIndices[0] == (listViewEx.Items.Count - 1))
|
||||
{
|
||||
UpdateButtonStates(SharedButtons.SelectedItemPos.Last);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateButtonStates(SharedButtons.SelectedItemPos.Middle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void exportButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
TabPage tabPage = tabControl.SelectedTab;
|
||||
TransitionSequence transitionSeq = tabPage.Tag as TransitionSequence;
|
||||
VirtualBenchSequence virtualBenchSeq = tabPage.Tag as VirtualBenchSequence;
|
||||
|
||||
SaveFileDialog dlg = new SaveFileDialog();
|
||||
if (dlg.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
if (transitionSeq != null)
|
||||
{
|
||||
/// export transition sequence
|
||||
transitionSeq.Export(new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8));
|
||||
}
|
||||
else if (virtualBenchSeq != null)
|
||||
{
|
||||
/// export virtual sequence
|
||||
virtualBenchSeq.Export(new StreamWriter(dlg.FileName, false, System.Text.Encoding.UTF8));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void importButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
OpenFileDialog dlg = new OpenFileDialog();
|
||||
|
||||
if (dlg.ShowDialog() != DialogResult.OK) return;
|
||||
|
||||
/// Import a procedure from a file
|
||||
int tabId = TransitionSequences.Count + VirtualBenchSequences.Count;
|
||||
TransitionSequence newSequence = TransitionSequence.Import(new StreamReader(dlg.FileName, System.Text.Encoding.UTF8));
|
||||
newSequence.ItemNr = tabId;
|
||||
|
||||
/// Find an unused procedure name
|
||||
string newName;
|
||||
bool nameUsed;
|
||||
for (int nameId = 1; true; nameId++)
|
||||
{
|
||||
newName = string.Format("{0} imported{1}", newSequence.Name, (nameId == 1) ? string.Empty : string.Format("({0})", nameId));
|
||||
nameUsed = false;
|
||||
foreach (var seq in TransitionSequences) if (seq.Name.Equals(newName)) nameUsed = true;
|
||||
if (!nameUsed) break;
|
||||
}
|
||||
newSequence.Name = newName;
|
||||
|
||||
TransitionSequences.Add(newSequence);
|
||||
AddTransitionSeqTab(newSequence);
|
||||
seqStepsCtrls[tabId].Unlock();
|
||||
tabControl.SelectTab(tabId);
|
||||
}
|
||||
|
||||
private void compareButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("Comparing sequences in not implemented yet");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="mainSplitContainer.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
|
||||
<value>Fill</value>
|
||||
</data>
|
||||
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
|
||||
<data name="mainSplitContainer.IsSplitterFixed" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
|
||||
<data name="mainSplitContainer.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>0, 0</value>
|
||||
</data>
|
||||
<data name="tabControl.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
|
||||
<value>Fill</value>
|
||||
</data>
|
||||
<data name="tabControl.ItemSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>58, 30</value>
|
||||
</data>
|
||||
<data name="tabControl.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>0, 0</value>
|
||||
</data>
|
||||
<data name="tabControl.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>760, 366</value>
|
||||
</data>
|
||||
<data name="tabControl.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>tabControl.Name" xml:space="preserve">
|
||||
<value>tabControl</value>
|
||||
</data>
|
||||
<data name=">>tabControl.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.TabControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>tabControl.Parent" xml:space="preserve">
|
||||
<value>mainSplitContainer.Panel1</value>
|
||||
</data>
|
||||
<data name=">>tabControl.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel1.Name" xml:space="preserve">
|
||||
<value>mainSplitContainer.Panel1</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel1.Parent" xml:space="preserve">
|
||||
<value>mainSplitContainer</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel1.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="sharedButtons.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>-1, 0</value>
|
||||
</data>
|
||||
<data name="sharedButtons.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>100, 636</value>
|
||||
</data>
|
||||
<data name="sharedButtons.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>sharedButtons.Name" xml:space="preserve">
|
||||
<value>sharedButtons</value>
|
||||
</data>
|
||||
<data name=">>sharedButtons.Type" xml:space="preserve">
|
||||
<value>TBF.UiControls.SharedButtons, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
|
||||
</data>
|
||||
<data name=">>sharedButtons.Parent" xml:space="preserve">
|
||||
<value>mainSplitContainer.Panel2</value>
|
||||
</data>
|
||||
<data name=">>sharedButtons.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel2.Name" xml:space="preserve">
|
||||
<value>mainSplitContainer.Panel2</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel2.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.SplitterPanel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel2.Parent" xml:space="preserve">
|
||||
<value>mainSplitContainer</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Panel2.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="mainSplitContainer.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>863, 366</value>
|
||||
</data>
|
||||
<data name="mainSplitContainer.SplitterDistance" type="System.Int32, mscorlib">
|
||||
<value>760</value>
|
||||
</data>
|
||||
<data name="mainSplitContainer.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Name" xml:space="preserve">
|
||||
<value>mainSplitContainer</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.SplitContainer, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>mainSplitContainer.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
|
||||
<value>6, 13</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>863, 366</value>
|
||||
</data>
|
||||
<data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
|
||||
<value>CenterParent</value>
|
||||
</data>
|
||||
<data name="$this.Text" xml:space="preserve">
|
||||
<value>Transitions</value>
|
||||
</data>
|
||||
<data name=">>$this.Name" xml:space="preserve">
|
||||
<value>TransitionsDlg</value>
|
||||
</data>
|
||||
<data name=">>$this.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -0,0 +1,271 @@
|
||||
///
|
||||
/// Copyright (c) 2013-2015 Sensus Slovensko a.s.
|
||||
///
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using log4net;
|
||||
using Config.Entities;
|
||||
using Results.Forms;
|
||||
using TBF.Resources;
|
||||
using TBF.UI.Shared;
|
||||
|
||||
namespace TBF.UI.Bench.Transitions
|
||||
{
|
||||
public partial class VirtualBenchStepsCtrl : BaseWithListViewEx<VirtualBenchStep>, ITabWithListViewEx
|
||||
{
|
||||
static readonly ILog log = LogManager.GetLogger(typeof(VirtualBenchStepsCtrl));
|
||||
|
||||
/// <summary>
|
||||
/// Fixed ListViewEx columns
|
||||
/// </summary>
|
||||
enum Column
|
||||
{
|
||||
Duration,
|
||||
FixedColumnsCount,
|
||||
}
|
||||
readonly int fixedCount = (int)Column.FixedColumnsCount;
|
||||
|
||||
VirtualBenchSequence sequence;
|
||||
|
||||
TransitionsDlg parent;
|
||||
Control parentControl;
|
||||
Control[] editors;
|
||||
|
||||
int fmPumpCount; /// Number of pumps with FM control
|
||||
int regvCount; /// Number of regulating valves
|
||||
int vCount; /// Number of valves
|
||||
|
||||
public VirtualBenchStepsCtrl()
|
||||
: base()
|
||||
{
|
||||
}
|
||||
|
||||
public void Initialize(VirtualBenchSequence sequence, TransitionsDlg parent, Control parentControl)
|
||||
{
|
||||
this.sequence = sequence;
|
||||
this.parent = parent;
|
||||
this.parentControl = parentControl;
|
||||
Name = sequence.Name;
|
||||
MyItems = sequence.VirtualBenchSteps;
|
||||
|
||||
SubItemClicked += new SubItemEventHandler(listViewEx_SubItemClicked);
|
||||
SubItemRightClicked += new SubItemEventHandler(listViewEx_SubItemRightClicked);
|
||||
SubItemEndEditing += new SubItemEndEditingEventHandler(listViewEx_SubItemEndEditing);
|
||||
|
||||
vCount = 0;
|
||||
fmPumpCount = 0;
|
||||
regvCount = 0;
|
||||
|
||||
///
|
||||
/// ListViewEx columns
|
||||
///
|
||||
Columns.Add(Strings.Duration_s, 70 * parent.Dpi / Constants.Dpi100pct);
|
||||
//foreach (var vlv in parent.Valves)
|
||||
//{
|
||||
// if (vlv is BenchControl.GenericDevices.IPumpFM)
|
||||
// {
|
||||
// Columns.Add(vlv.Cfg.Name + " [%]", 45 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
// fmPumpCount++;
|
||||
// }
|
||||
//}
|
||||
//foreach (var rvlv in parent.RegulValves)
|
||||
//{
|
||||
// Columns.Add(rvlv.Cfg.Name + " [%]", 55 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
//}
|
||||
//foreach (var vlv in parent.Valves)
|
||||
//{
|
||||
// if (!(vlv is BenchControl.GenericDevices.IPumpFM))
|
||||
// {
|
||||
// Columns.Add(vlv.Cfg.Name, 40 * parent.Dpi / PathsDlg.Dpi100pct);
|
||||
// vCount++;
|
||||
// }
|
||||
//}
|
||||
|
||||
///
|
||||
/// Prepare valve combo-boxes
|
||||
///
|
||||
editors = new Control[fixedCount + vCount + fmPumpCount + regvCount];
|
||||
|
||||
editors[0] = new TextBox(); /// Duration
|
||||
editors[0].Visible = false;
|
||||
parent.Controls.Add(editors[0]);
|
||||
|
||||
//for (int i = fixedCount; i < fixedCount + fmPumpCount; i++)
|
||||
//{
|
||||
// ComboBox cb = new ComboBox();
|
||||
// cb.Items.Add("---");
|
||||
// cb.Items.Add(Strings.dflt);
|
||||
// cb.Items.Add("0");
|
||||
// cb.Items.Add("25");
|
||||
// cb.Items.Add("50");
|
||||
// cb.Items.Add("75");
|
||||
// cb.Items.Add("100");
|
||||
// editors[i] = cb;
|
||||
// parent.Controls.Add(editors[i]);
|
||||
//}
|
||||
|
||||
//for (int i = fixedCount + fmPumpCount; i < fixedCount + fmPumpCount + regvCount; i++)
|
||||
//{
|
||||
// ComboBox cb = new ComboBox();
|
||||
// cb.Items.Add("---");
|
||||
// cb.Items.Add("0");
|
||||
// cb.Items.Add("25");
|
||||
// cb.Items.Add("50");
|
||||
// cb.Items.Add("75");
|
||||
// cb.Items.Add("100");
|
||||
// editors[i] = cb;
|
||||
// parent.Controls.Add(editors[i]);
|
||||
//}
|
||||
|
||||
//for (int i = fixedCount + fmPumpCount + regvCount; i < fixedCount + fmPumpCount + regvCount + vCount; i++)
|
||||
//{
|
||||
// ComboBox cb = new ComboBox();
|
||||
// cb.Items.Add("---");
|
||||
// cb.Items.Add(Strings.open);
|
||||
// cb.Items.Add(Strings.close);
|
||||
// editors[i] = cb;
|
||||
// parent.Controls.Add(cb);
|
||||
//}
|
||||
|
||||
base.RedrawAll();
|
||||
}
|
||||
|
||||
void listViewEx_SubItemClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (!Unlocked || e.SubItem >= editors.Length) return;
|
||||
StartEditing(editors[e.SubItem], e.Item, e.SubItem);
|
||||
}
|
||||
|
||||
void listViewEx_SubItemRightClicked(object sender, SubItemEventArgs e)
|
||||
{
|
||||
if (!Unlocked || e.SubItem >= editors.Length) return;
|
||||
|
||||
if (DialogResult.Yes == MessageBox.Show(Strings.Do_you_want_to_copy_this_value_to_all_cells_below_this_cell,
|
||||
Strings.Confirmation, MessageBoxButtons.YesNo, MessageBoxIcon.Question))
|
||||
{
|
||||
int columnNr = e.SubItem;
|
||||
string value = null;
|
||||
System.Drawing.Color backColor = System.Drawing.Color.White;
|
||||
foreach (ListViewItem item in Items)
|
||||
{
|
||||
if (value != null && item.SubItems.Count > columnNr)
|
||||
{
|
||||
item.SubItems[columnNr].Text = value;
|
||||
item.SubItems[columnNr].BackColor = backColor;
|
||||
}
|
||||
else if (item == e.Item)
|
||||
{
|
||||
value = item.SubItems[columnNr].Text;
|
||||
backColor = item.SubItems[columnNr].BackColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void listViewEx_SubItemEndEditing(object sender, SubItemEndEditingEventArgs e)
|
||||
{
|
||||
if (e.SubItem == (int)Column.Duration)
|
||||
{
|
||||
int duration;
|
||||
if (!int.TryParse(e.DisplayText, out duration) || duration <= 0)
|
||||
{
|
||||
e.DisplayText = e.Item.Text;
|
||||
e.Cancel = true;
|
||||
}
|
||||
}
|
||||
//else if ((e.SubItem >= fixedCount) && (e.SubItem < fixedCount + fmPumpCount))
|
||||
//{
|
||||
// float pct;
|
||||
// if (!e.DisplayText.Equals("---") &&
|
||||
// !e.DisplayText.Equals(Strings.dflt) &&
|
||||
// !(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
||||
// {
|
||||
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
//}
|
||||
//else if ((e.SubItem >= fixedCount + fmPumpCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount))
|
||||
//{
|
||||
// float pct;
|
||||
// if (!e.DisplayText.Equals("---") &&
|
||||
// !(Utils.TryParseUFloat(e.DisplayText, out pct) && (pct >= 0) && (pct <= 100.0f)))
|
||||
// {
|
||||
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
//}
|
||||
//else if ((e.SubItem >= fixedCount + fmPumpCount + regvCount) && (e.SubItem < fixedCount + fmPumpCount + regvCount + vCount))
|
||||
//{
|
||||
// if ((e.DisplayText != Strings.open) && (e.DisplayText != Strings.close) && (e.DisplayText != "---"))
|
||||
// {
|
||||
// e.DisplayText = e.Item.SubItems[e.SubItem].Text;
|
||||
// e.Cancel = true;
|
||||
// }
|
||||
//}
|
||||
|
||||
if (e.SubItem >= fixedCount)
|
||||
{
|
||||
e.Item.SubItems[e.SubItem].BackColor = e.DisplayText == Strings.open ? Color.LightGray : Color.White;
|
||||
}
|
||||
}
|
||||
|
||||
public override void DrawOne(object myItem)
|
||||
{
|
||||
VirtualBenchStep step = (VirtualBenchStep)myItem;
|
||||
|
||||
ListViewItem lvi = new ListViewItem(step.Duration.ToString());
|
||||
|
||||
/// TODO: All the rest
|
||||
|
||||
lvi.Tag = step;
|
||||
|
||||
Items.Add(lvi);
|
||||
}
|
||||
|
||||
public override void UpdateOne(ListViewItem lvi, object myItem)
|
||||
{
|
||||
VirtualBenchStep step = (VirtualBenchStep)myItem;
|
||||
|
||||
/// Duration
|
||||
int duration;
|
||||
if (int.TryParse(lvi.Text, out duration) && duration > 0)
|
||||
{
|
||||
step.Duration = duration;
|
||||
}
|
||||
else
|
||||
{
|
||||
lvi.Text = step.Duration.ToString();
|
||||
}
|
||||
|
||||
// TODO: Replace the following:
|
||||
//step.PumpWithFMPcts = fmPumpsPcts;
|
||||
//step.RegulValvesPct = regulValvesPct;
|
||||
//step.ValvesOpen = valvesOpen;
|
||||
//step.ValvesClose = valvesClose;
|
||||
}
|
||||
|
||||
public void AddOne()
|
||||
{
|
||||
base.AddOne(new VirtualBenchStep(MyItems.Count, sequence));
|
||||
}
|
||||
|
||||
public new void RemoveSelected()
|
||||
{
|
||||
bool lastItemRemoved = base.RemoveSelected();
|
||||
if (lastItemRemoved && parent != null)
|
||||
{
|
||||
parent.UpdateButtonStates(SharedButtons.SelectedItemPos.None);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetWarningsBeforeSaving(ref Dictionary<string, string> renmInfo)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public void UpdateRelatedItems(Dictionary<string, string> renameInfo)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user