不幸的是,当我启动程序时,没有输入数据并按下“创建奖品”按钮,我没有收到消息“此表格包含错误信息。请检查并重试。”我在做什么错了?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TrackerLibrary;
namespace TrackerUI
{
public partial class CreatePrizeForm : Form
{
public CreatePrizeForm()
{
InitializeComponent();
}
private void CreatePrizeButton_Click(object sender, EventArgs e)
{
if (ValidateForm())
{
PrizeModel model = new PrizeModel(
placeNameValue.Text,
placeNumberValue.Text,
prizeAmountValue.Text,
prizePercentageValue.Text);
foreach (IDataConnection db in GlobalConfig.Connections)
{
db.CreatePrize(model);
}
}
else
{
MessageBox.Show("Ten formularz zawiera błędne informacje. Proszę sprawdzić i spróbować ponownie.");
}
}
private bool ValidateForm()
{
bool output = true;
int placeNumber = 0;
bool placeNumberValidNumber = int.TryParse(placeNumberValue.Text, out placeNumber);
if (placeNumberValidNumber == false)
{
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(prizePercentageValue.Text, out prizePercentage);
if (prizeAmountValid == false || prizePercentageValid == false)
{
output = false;
}
if (prizeAmount <= 0 && prizePercentage <= 0)
{
output = false;
}
if (prizePercentage < 0 || prizePercentage > 100)
{
output = false;
}
return output;
}
}
}
嗨
不幸的是,当我启动程序时,没有输入数据并按下“创建奖品”按钮,我没有收到消息“此表格包含错误信息。请检查并重试。”我在做什么错了?