Wireup window with access methods + refaktor structure
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user