hiya folks, im trying to do a program whereby i read in file records and provide valid and invalid data reports....i have done it with an arraylist and the use of the errorprovider tooltip.. but how do i show invalid entries to a report if invalid entry is added by the user?..
would it be better to use a txt file maybe?..heres the code ive created so far..thank you..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WinUseOfArrays
{
public partial class Form3 : Form
{
// Arrays -- Parallel Structure
// Global Data Declaration
int[] videoNo = new int[96];
string[] title = new string[500];
string[] category = new string[500];
double[] hireCharge = new double[500];
int size;
int index;
private void btnDisplay_Click(object sender, EventArgs e)
{
//Local Variables
int x;
String s;
txtVideoDetails.Text =
txtVideoDetails.Text = "**** Staff ID **** **** Staff Name **** **** Campus Name **** **** Salary ****\n****************************************************************************************** ";
for (x = 0; x < size; x++)
{
// \r\n Carrage Return Character into text to force a new Line
s = String.Format("\r\n\n{0,10}\t{1,30}{2,20}{3,15:c}", videoNo[x], title[x], category[x], hireCharge[x]);
txtVideoDetails.Text = txtVideoDetails.Text + s;
}
}
if (String.IsNullOrEmpty(txtVideoNo.Text))
{
ok = false;
errP.SetError(txtVideoNo, "Must Enter Staff ID: ");
}
else
{
try
{
no = int.Parse(txtVideoNo.Text);
if (no < 1 || no > 96)
{
ok = false;
errP.SetError(txtVideoNo, "Staff ID must be between 1 and 96");
}
else
errP.SetError(txtVideoNo, "");
}
catch (Exception ex)
{
ok = false;
errP.SetError(txtVideoNo, "Staff ID is Not Numeric");
}
}
//validation of the staff name
if (String.IsNullOrEmpty(txtTitle.Text))
{
ok = false;
errP.SetError(txtTitle, "Must Enter Staff Name: ");
}
//validation of the category selection
if (lstCategory.SelectedIndex < 0)
{
ok = false;
errP.SetError(lstCategory, "Must Select a Category");
}
else
errP.SetError(lstCategory, "");
if (String.IsNullOrEmpty(txtHireCharge.Text))
{
ok = false;
errP.SetError(txtHireCharge, "Must Enter Salary: ");
}
else
{
try
{
no = int.Parse(txtHireCharge.Text);
if (no < 0)
{
ok = false;
errP.SetError(txtHireCharge, "Salary must be greater than 0");
}
else
errP.SetError(txtHireCharge, "");
}
catch (Exception ex)
{
ok = false;
errP.SetError(txtHireCharge, "Salary is Not Numeric");
}
}
//set of if statements which displays a messagebox if input is not entered into all textboxes
}
private void btnFind_Click(object sender, EventArgs e)
{
int no;
bool ok = false;
int x;
no = int.Parse(txtSearchVideoNo.Text);
for (x = 0; x < size; x++)
{
if (no == videoNo[x])
{
ok = true;
txtSrVideoTitle.Text = title[x];
textCampus.Text = category[x];
txtSrHireCharge.Text = hireCharge[x].ToString();
panVideoDetails.Visible = true;
}
}
if (ok == false)
{
panVideoDetails.Visible = false;
MessageBox.Show("Invalid Video No", "Video Details", MessageBoxButtons.OK);
}
//code to ensure that only numeric data is allowed to be entered into the textbox by the user
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.') { e.Handled = true; }
private void txtTitle_TextChanged(object sender, EventArgs e)
{
//code to ensure that the textbox max length is set to 24 characters
txtTitle.MaxLength = 24;
}
private void txtHireCharge_TextChanged(object sender, EventArgs e)
{
//code to ensure that the textbox max length is set to 6
txtHireCharge.MaxLength = 6;
Bookmarks