Skip to content

Commit 0b12fac

Browse files
vitaliydavydiakStefH
authored andcommitted
Add Format option to GuidRandomizer (StefH#10)
* Add Format option to GuidRandomizer * Add control to GUI application to define GUID format * ComboBox --> SelectedValueChanged
1 parent a8fb7bc commit 0b12fac

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

src/RandomDataGenerator.Gui/UserControls/BaseUserControl.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System;
1+
using RandomDataGenerator.FieldOptions;
2+
using RandomDataGenerator.Gui.Extensions;
3+
using RandomDataGenerator.Gui.UserControlsFields;
4+
using System;
25
using System.Collections.Generic;
36
using System.Linq;
47
using System.Windows.Forms;
5-
using RandomDataGenerator.FieldOptions;
6-
using RandomDataGenerator.Gui.Extensions;
7-
using RandomDataGenerator.Gui.UserControlsFields;
88

99
namespace RandomDataGenerator.Gui.UserControls
1010
{
@@ -137,6 +137,11 @@ protected void InitEventsForControls()
137137
{
138138
ctrl.ValueChanged += HandleOptionsChangedChanged;
139139
}
140+
141+
foreach (var ctrl in FindControls<ComboBox>())
142+
{
143+
ctrl.SelectedValueChanged += HandleOptionsChangedChanged;
144+
}
140145
}
141146

142147
protected T FindControl<T>() where T : class

src/RandomDataGenerator.Gui/UserControlsFields/UserControlGUID.Designer.cs

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RandomDataGenerator.Gui/UserControlsFields/UserControlGUID.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using RandomDataGenerator.FieldOptions;
1+
using System.Collections.Generic;
2+
using RandomDataGenerator.FieldOptions;
23
using RandomDataGenerator.Gui.UserControls;
34

45
namespace RandomDataGenerator.Gui.UserControlsFields
@@ -10,13 +11,17 @@ public UserControlGuid()
1011
InitializeComponent();
1112

1213
InitEventsForControls();
14+
15+
formatComboBox.DataSource = new List<string> { "N", "D", "B", "P", "X" };
1316
}
1417

1518
public override void SetOptionsAndUpdateControls(FieldOptionsGuid options)
1619
{
1720
base.SetOptionsAndUpdateControls(options);
1821

1922
chkUppercase.Checked = FieldOptions.Uppercase;
23+
24+
formatComboBox.SelectedItem = FieldOptions.Format;
2025
}
2126

2227
public override FieldOptionsGuid GetFieldOptionsT()
@@ -25,6 +30,8 @@ public override FieldOptionsGuid GetFieldOptionsT()
2530

2631
FieldOptions.Uppercase = chkUppercase.Checked;
2732

33+
FieldOptions.Format = formatComboBox.Text;
34+
2835
return FieldOptions;
2936
}
3037
}

src/RandomDataGenerator/FieldOptions/FieldOptionsGuid.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ namespace RandomDataGenerator.FieldOptions
44
public class FieldOptionsGuid : FieldOptionsAbstract, IFieldOptionsGuid
55
{
66
public bool Uppercase { get; set; } = true;
7+
8+
public string Format { get; set; } = "D";
79
}
810
}

src/RandomDataGenerator/Randomizers/RandomizerGuid.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public string GenerateAsString()
2727
return null;
2828
}
2929

30-
return Guid.NewGuid().ToString().ToCasedInvariant(Options.Uppercase);
30+
return Guid.NewGuid().ToString(Options.Format).ToCasedInvariant(Options.Uppercase);
3131
}
3232
}
3333
}

0 commit comments

Comments
 (0)