Wireup window with access methods + refaktor structure

This commit is contained in:
2020-03-22 21:52:02 +01:00
parent b1e62e829e
commit 88bd9b894a
16 changed files with 230 additions and 39 deletions

View File

@ -59,7 +59,7 @@
this.placeNumberValue.Location = new System.Drawing.Point(183, 83);
this.placeNumberValue.Name = "placeNumberValue";
this.placeNumberValue.Size = new System.Drawing.Size(234, 35);
this.placeNumberValue.TabIndex = 14;
this.placeNumberValue.TabIndex = 1;
//
// placeNumberLabel
//
@ -78,7 +78,8 @@
this.prizePercentageValue.Location = new System.Drawing.Point(183, 296);
this.prizePercentageValue.Name = "prizePercentageValue";
this.prizePercentageValue.Size = new System.Drawing.Size(234, 35);
this.prizePercentageValue.TabIndex = 16;
this.prizePercentageValue.TabIndex = 4;
this.prizePercentageValue.Text = "0";
//
// prizePercentageLabel
//
@ -97,7 +98,8 @@
this.prizeAmountValue.Location = new System.Drawing.Point(183, 185);
this.prizeAmountValue.Name = "prizeAmountValue";
this.prizeAmountValue.Size = new System.Drawing.Size(234, 35);
this.prizeAmountValue.TabIndex = 18;
this.prizeAmountValue.TabIndex = 3;
this.prizeAmountValue.Text = "0";
//
// prizeAmountLabel
//
@ -116,7 +118,7 @@
this.placeNameValue.Location = new System.Drawing.Point(183, 134);
this.placeNameValue.Name = "placeNameValue";
this.placeNameValue.Size = new System.Drawing.Size(234, 35);
this.placeNameValue.TabIndex = 20;
this.placeNameValue.TabIndex = 2;
//
// placeNameLabel
//
@ -154,6 +156,7 @@
this.createPrizeButton.TabIndex = 24;
this.createPrizeButton.Text = "Create Prize";
this.createPrizeButton.UseVisualStyleBackColor = true;
this.createPrizeButton.Click += new System.EventHandler(this.createPrizeButton_Click);
//
// CreatePrizeForm
//

View File

@ -7,6 +7,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TrackerLibrary;
using TrackerLibrary.Models;
namespace TrackerUI
{
@ -16,5 +18,77 @@ namespace TrackerUI
{
InitializeComponent();
}
private void createPrizeButton_Click(object sender, EventArgs e)
{
if (ValidateForm())
{
PrizeModel model = new PrizeModel(
placeNameValue.Text,
placeNumberValue.Text,
prizeAmountValue.Text,
prizePercentageValue.Text);
foreach (var db in GlobalConfig.Connections)
{
db.CreatePrize(model);
}
placeNameValue.Text = "";
placeNumberValue.Text = "";
prizeAmountValue.Text = "0";
prizePercentageValue.Text = "0";
}
else
{
MessageBox.Show("This form has invalid information. Please check it and try again.");
}
}
private bool ValidateForm()
{
bool output = true;
int placeNumber = 0;
bool placeNumberValidator = int.TryParse(placeNumberValue.Text, out placeNumber);
if (!placeNumberValidator)
{
output = false;
}
if (placeNumber < 1)
{
output = false;
}
if (placeNameValue.Text.Length == 0)
{
output = false;
}
decimal prizeAmount = 0;
int prizePercentage = 0;
bool prizeAmountValid = decimal.TryParse(prizeAmountValue.Text, out prizeAmount);
bool prizePercentageValid = int.TryParse(prizeAmountValue.Text, out prizePercentage);
if (prizePercentageValid == false || prizeAmountValid == false)
{
output = false;
}
if (prizeAmount <= 0 && prizePercentage <= 0)
{
output = false;
}
if (prizePercentage < 0 || prizePercentage > 100)
{
output = false;
}
return output;
}
}
}

View File

@ -16,7 +16,12 @@ namespace TrackerUI
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TournamentViewerForm());
// Initialize the database connections
TrackerLibrary.GlobalConfig.InitializeConnections(true, true);
Application.Run(new CreatePrizeForm());
//Application.Run(new TournamentDashboardForm());
}
}
}

View File

@ -115,5 +115,11 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TrackerLibrary\TrackerLibrary.csproj">
<Project>{b4ffd708-5d53-4d58-b5a6-5691020ef6dc}</Project>
<Name>TrackerLibrary</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>