Components can be deleted, component ItemNr-s are updated before saving to DB, ver. 2.12.396
This commit is contained in:
parent
1bc3137d20
commit
cec1816f82
@ -33,7 +33,7 @@ namespace TBF
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ComponentsManagerDlg));
|
||||
this.splitContainer = new System.Windows.Forms.SplitContainer();
|
||||
this.listViewEx = new Results.Forms.ListViewEx();
|
||||
this.listViewEx = new Results.Forms.ListViewEx();
|
||||
this.sharedButtons = new TBF.UiControls.SharedButtons();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
|
||||
this.splitContainer.Panel1.SuspendLayout();
|
||||
@ -80,6 +80,7 @@ namespace TBF
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.splitContainer);
|
||||
this.Name = "ComponentsManagerDlg";
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ComponentsManagerDlg_FormClosing);
|
||||
this.Load += new System.EventHandler(this.ComponentsManagerDlg_Load);
|
||||
this.splitContainer.Panel1.ResumeLayout(false);
|
||||
this.splitContainer.Panel2.ResumeLayout(false);
|
||||
|
||||
@ -30,7 +30,7 @@ namespace TBF
|
||||
SelectComponentClassDlg selectComponentTypeDlg; /// Constructed once, the selection is kept between dialog usages
|
||||
|
||||
CfgUpdateFlags flags; /// Or-ed from particular Flags from ComponentParametersDlg
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ListViewEx columns
|
||||
/// </summary>
|
||||
@ -108,9 +108,9 @@ namespace TBF
|
||||
sharedButtons.DisableButtons(UiControls.SharedButtons.Buttons.Remove | UiControls.SharedButtons.Buttons.Edit);
|
||||
|
||||
session = Config.FluentCommon.CreateSession(Config.Entities.DBKind.Config);
|
||||
cmpntEntities = session
|
||||
.CreateQuery("FROM Component ORDER BY ItemNr")
|
||||
.List<Component>();
|
||||
cmpntEntities = session.QueryOver<Component>()
|
||||
.OrderBy(x => x.ItemNr).Asc
|
||||
.List<Component>();
|
||||
|
||||
RedrawAll();
|
||||
}
|
||||
@ -189,34 +189,65 @@ namespace TBF
|
||||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// Save DB changes, return true when DB changes saved OK
|
||||
///
|
||||
bool SaveDBChanges(NHibernate.ISession ses)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var cmpnt in toBeDeletedEntities)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(ses, cmpnt);
|
||||
}
|
||||
|
||||
int itemNr = 1;
|
||||
foreach (var cmpnt in cmpntEntities)
|
||||
{
|
||||
cmpnt.ItemNr = itemNr++;
|
||||
Config.FluentCommon.SaveToDb(ses, cmpnt);
|
||||
}
|
||||
ses.Flush();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the dialog position and ListViewEx column widths
|
||||
/// </summary>
|
||||
void SaveUISettings()
|
||||
{
|
||||
Program.LocalSettings.ComponentsDlgLeft = Location.X;
|
||||
Program.LocalSettings.ComponentsDlgTop = Location.Y;
|
||||
Program.LocalSettings.ComponentsDlgWidth = Size.Width;
|
||||
Program.LocalSettings.ComponentsDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
|
||||
/// Update the column widths
|
||||
Program.LocalSettings.ComponentsColumnWidths = new int[(int)Column.ColumnsCount];
|
||||
for (int i = 0; i < (int)Column.ColumnsCount; i++)
|
||||
{
|
||||
Program.LocalSettings.ComponentsColumnWidths[i] = listViewEx.Columns[i].Width;
|
||||
}
|
||||
Program.LocalSettings.Save();
|
||||
}
|
||||
|
||||
///
|
||||
/// OK
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
///
|
||||
private void okButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
foreach (var cmpnt in toBeDeletedEntities)
|
||||
{
|
||||
Config.FluentCommon.DeleteFromDb(session, cmpnt);
|
||||
}
|
||||
foreach (var cmpnt in cmpntEntities)
|
||||
{
|
||||
Config.FluentCommon.SaveToDb(session, cmpnt);
|
||||
}
|
||||
|
||||
Program.LocalSettings.ComponentsDlgLeft = Location.X;
|
||||
Program.LocalSettings.ComponentsDlgTop = Location.Y;
|
||||
Program.LocalSettings.ComponentsDlgWidth = Size.Width;
|
||||
Program.LocalSettings.ComponentsDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
SaveDBChanges(session);
|
||||
}
|
||||
|
||||
/// Update the column widths
|
||||
Program.LocalSettings.ComponentsColumnWidths = new int[(int)Column.ColumnsCount];
|
||||
for (int i = 0; i < (int)Column.ColumnsCount; i++)
|
||||
{
|
||||
Program.LocalSettings.ComponentsColumnWidths[i] = listViewEx.Columns[i].Width;
|
||||
}
|
||||
Program.LocalSettings.Save();
|
||||
SaveUISettings();
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
@ -226,11 +257,7 @@ namespace TBF
|
||||
/// Cancel
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
Program.LocalSettings.ComponentsDlgLeft = Location.X;
|
||||
Program.LocalSettings.ComponentsDlgTop = Location.Y;
|
||||
Program.LocalSettings.ComponentsDlgWidth = Size.Width;
|
||||
Program.LocalSettings.ComponentsDlgHeight = Size.Height;
|
||||
Program.LocalSettings.Save();
|
||||
SaveUISettings();
|
||||
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
@ -241,6 +268,8 @@ namespace TBF
|
||||
if (dr != DialogResult.Yes) return;
|
||||
}
|
||||
|
||||
flags = CfgUpdateFlags.None; /// Already confirmed abandoning changes
|
||||
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
return;
|
||||
@ -249,21 +278,21 @@ namespace TBF
|
||||
/// Add a new component
|
||||
private void addButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult dr = selectComponentTypeDlg.ShowDialog();
|
||||
if (dr != DialogResult.OK) return;
|
||||
DialogResult dialogRslt = selectComponentTypeDlg.ShowDialog();
|
||||
if (dialogRslt != DialogResult.OK) return;
|
||||
|
||||
IComponentFactory factory = selectComponentTypeDlg.SlctdCmpntFactory;
|
||||
IComponentCfg cfg = factory.DefaultConfig();
|
||||
IComponentCfgCtrl cfgControl = cfg.GetControl();
|
||||
cfgControl.Config = cfg;
|
||||
cfgControl.Config.ItemNr = listViewEx.Items.Count;
|
||||
cfgControl.Config.ItemNr = (cmpntEntities.Count > 0) ? (cmpntEntities[cmpntEntities.Count - 1].ItemNr + 1) : 1;
|
||||
|
||||
ComponentParametersDlg cfgForm = new ComponentParametersDlg();
|
||||
cfgForm.TbfComponents = cmpntEntities;
|
||||
cfgForm.ComponentCfgCtrl = cfgControl;
|
||||
cfgForm.UnlockAfterStart = true;
|
||||
dr = cfgForm.ShowDialog();
|
||||
if (dr != DialogResult.OK) return;
|
||||
dialogRslt = cfgForm.ShowDialog();
|
||||
if (dialogRslt != DialogResult.OK) return;
|
||||
|
||||
flags |= CfgUpdateFlags.RestartRqrd;
|
||||
AddOne(cfgForm.Config.CreateDbEntity());
|
||||
@ -283,8 +312,11 @@ namespace TBF
|
||||
if (ix < 0) return;
|
||||
|
||||
Component selectedCmpnt = (Component)listViewEx.Items[ix].Tag;
|
||||
if (selectedCmpnt.Id != 0) toBeDeletedEntities.Add(selectedCmpnt);
|
||||
listViewEx.Items.RemoveAt(ix);
|
||||
if (selectedCmpnt.Id != 0) toBeDeletedEntities.Add(selectedCmpnt);
|
||||
cmpntEntities.Remove(selectedCmpnt);
|
||||
|
||||
flags |= CfgUpdateFlags.AnyChange;
|
||||
|
||||
RedrawAll();
|
||||
}
|
||||
|
||||
@ -364,5 +396,22 @@ namespace TBF
|
||||
sharedButtons.EnableButtons(SharedButtons.Buttons.Remove | SharedButtons.Buttons.Up | SharedButtons.Buttons.Down);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComponentsManagerDlg_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
SaveUISettings();
|
||||
|
||||
if ((flags & CfgUpdateFlags.AnyChange) != 0 || (flags & CfgUpdateFlags.RestartRqrd) != 0)
|
||||
{
|
||||
DialogResult dr = MessageBox.Show(Strings.Do_you_want_to_save_changes,
|
||||
Strings.Warning,
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Question);
|
||||
if (dr == DialogResult.Yes)
|
||||
{
|
||||
SaveDBChanges(session);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,7 +145,7 @@
|
||||
<value>listViewEx</value>
|
||||
</data>
|
||||
<data name=">>listViewEx.Type" xml:space="preserve">
|
||||
<value>TBF.UiControls.ListViewEx, TBF, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
|
||||
<value>Results.Forms.ListViewEx, Results, Version=2.12.394.0, Culture=neutral, PublicKeyToken=null</value>
|
||||
</data>
|
||||
<data name=">>listViewEx.Parent" xml:space="preserve">
|
||||
<value>splitContainer.Panel1</value>
|
||||
@ -178,7 +178,7 @@
|
||||
<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>
|
||||
<value>TBF.UiControls.SharedButtons, TBF, Version=2.12.395.1, Culture=neutral, PublicKeyToken=null</value>
|
||||
</data>
|
||||
<data name=">>sharedButtons.Parent" xml:space="preserve">
|
||||
<value>splitContainer.Panel2</value>
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.12.395.1")]
|
||||
[assembly: AssemblyFileVersion("2.12.395.1")]
|
||||
[assembly: AssemblyVersion("2.12.396.1")]
|
||||
[assembly: AssemblyFileVersion("2.12.396.1")]
|
||||
|
||||
9
TestBenchFramework/Resources/Strings.Designer.cs
generated
9
TestBenchFramework/Resources/Strings.Designer.cs
generated
@ -1032,6 +1032,15 @@ namespace TBF.Resources {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Do you want to save changes?.
|
||||
/// </summary>
|
||||
internal static string Do_you_want_to_save_changes {
|
||||
get {
|
||||
return ResourceManager.GetString("Do_you_want_to_save_changes", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Do you want to save the procedure?.
|
||||
/// </summary>
|
||||
|
||||
@ -1281,4 +1281,7 @@
|
||||
<data name="PrintBtnText" xml:space="preserve">
|
||||
<value>Vytisknout</value>
|
||||
</data>
|
||||
<data name="Do_you_want_to_save_changes" xml:space="preserve">
|
||||
<value>Chcete uložit změny?</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -1371,4 +1371,7 @@
|
||||
<data name="Starting_the_pump" xml:space="preserve">
|
||||
<value>Pumpe starten</value>
|
||||
</data>
|
||||
<data name="Do_you_want_to_save_changes" xml:space="preserve">
|
||||
<value>Wollen sie die Änderungen speichern?</value>
|
||||
</data>
|
||||
</root>
|
||||
@ -1591,4 +1591,7 @@
|
||||
<data name="Show" xml:space="preserve">
|
||||
<value>Show</value>
|
||||
</data>
|
||||
<data name="Do_you_want_to_save_changes" xml:space="preserve">
|
||||
<value>Do you want to save changes?</value>
|
||||
</data>
|
||||
</root>
|
||||
Loading…
Reference in New Issue
Block a user