CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2011
    Posts
    10

    file handling with arraylist

    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;

    public Form3()
    {
    InitializeComponent();
    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
    this.Close();
    }

    private void Form1_Load(object sender, EventArgs e)
    {








    //Intialise Arrays + set size
    videoNo[0] = 0001; title[0] = "Jim Simpson"; category[0] = "Strand Road"; hireCharge[0] = 25000;
    videoNo[1] = 0002; title[1] = "Laura O'Reilly"; category[1] = "City Factory"; hireCharge[1] = 18000;
    videoNo[2] = 0003; title[2] = "Sally Stevens"; category[2] = "Glendermott Road"; hireCharge[2] = 19500;
    videoNo[3] = 0004; title[3] = "Brian O'Hara"; category[3] = "Northside"; hireCharge[3] = 23500;
    videoNo[4] = 0005; title[4] = "Kevin Mc Laughlin "; category[4] = "Strand Road"; hireCharge[4] = 19500;
    videoNo[5] = 0010; title[5] = "Mary Hegarty"; category[5] = "City Factory"; hireCharge[5] = 27500;
    videoNo[6] = 0015; title[6] = "Joe Mc Dermot "; category[6] = "Strabane"; hireCharge[6] = 26500;
    videoNo[7] = 0020; title[7] = "Peter Hampson"; category[7] = "Strabane"; hireCharge[7] = 19500;
    videoNo[8] = 0025; title[8] = "Patrick Smith"; category[8] = "City Factory"; hireCharge[8] = 28000;
    videoNo[9] = 0030; title[9] = "James Mc Daid "; category[9] = "Glendermott"; hireCharge[9] = 18000;
    videoNo[10] = 0040; title[10] = "Kim Ferguson"; category[10] = "Strand Road"; hireCharge[10] = 34000;
    videoNo[11] = 0045; title[11] = "Jill Simms"; category[11] = "Star Factory"; hireCharge[11] = 35000;
    videoNo[12] = 0050; title[12] = "Paddy Doherty"; category[12] = "Strabane"; hireCharge[12] = 23000;
    videoNo[13] = 0070; title[13] = "Patsy Wheeler"; category[13] = "Limavady"; hireCharge[13] = 22500;
    videoNo[14] = 0080; title[14] = "John Quigg"; category[14] = "Strand Road"; hireCharge[14] = 25000;


    size = 15;


    //Paging Controls
    btnFirst.Enabled = true;
    btnNext.Enabled = false;
    btnPrevious.Enabled = false;
    btnLast.Enabled = false;
    index = 0;

    panVideoDetails.Visible = true;




    }

    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;
    }
    }

    private void btnClear_Click(object sender, EventArgs e)
    {
    txtVideoDetails.Clear();
    }

    private void btnFirst_Click(object sender, EventArgs e)
    {
    btnFirst.Enabled = false;
    btnNext.Enabled = true;
    btnPrevious.Enabled = false;
    btnLast.Enabled = true;

    index = 0;

    lblVideoNo.Text = videoNo[index].ToString();
    lblTitle.Text = title[index];
    lblCategory.Text = category[index];
    lblHireCharge.Text = hireCharge[index].ToString();

    }

    private void btnNext_Click(object sender, EventArgs e)
    {
    btnFirst.Enabled = false;
    btnNext.Enabled = true;
    btnPrevious.Enabled = true;
    btnLast.Enabled = true;

    index++;

    lblVideoNo.Text = videoNo[index].ToString();
    lblTitle.Text = title[index];
    lblCategory.Text = category[index];
    lblHireCharge.Text = hireCharge[index].ToString();

    if (index == size - 1)
    {
    btnNext.Enabled = false;
    btnLast.Enabled = false;
    }
    }

    private void btnPrevious_Click(object sender, EventArgs e)
    {
    btnFirst.Enabled = false;
    btnNext.Enabled = true;
    btnPrevious.Enabled = true;
    btnLast.Enabled = true;

    index--;

    lblVideoNo.Text = videoNo[index].ToString();
    lblTitle.Text = title[index];
    lblCategory.Text = category[index];
    lblHireCharge.Text = hireCharge[index].ToString();

    if (index == 0)
    {
    btnPrevious.Enabled = false;
    }

    }

    private void btnLast_Click(object sender, EventArgs e)
    {
    btnFirst.Enabled = true;
    btnNext.Enabled = false;
    btnPrevious.Enabled = true;
    btnLast.Enabled = false;

    index = size - 1;


    lblVideoNo.Text = videoNo[index].ToString();
    lblTitle.Text = title[index];
    lblCategory.Text = category[index];
    lblHireCharge.Text = hireCharge[index].ToString();

    }

    private void label6_Click(object sender, EventArgs e)
    {

    }

    private void btnAdd_Click(object sender, EventArgs e)
    {


    // validation of the staff id

    Boolean ok = true;
    int no;

    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 (ok == true)
    {
    videoNo[size] = int.Parse(txtVideoNo.Text);
    category[size] = lstCategory.SelectedItem.ToString();
    title[size] = txtTitle.Text;
    hireCharge[size] = int.Parse(txtHireCharge.Text);



    //Array
    size++;

    txtVideoNo.Clear();
    lstCategory.ClearSelected();
    txtTitle.Clear();
    txtHireCharge.Clear();

    txtVideoNo.Focus();

    }


    //salary validation

    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);
    }




    }

    private void btnClear2_Click(object sender, EventArgs e)
    {
    txtSearchVideoNo.Clear();
    txtSrVideoTitle.Clear();
    textCampus.Clear();
    txtSrHireCharge.Clear();

    }

    private void txtVideoDetails_TextChanged(object sender, EventArgs e)
    {

    }

    private void txtVideoNo_TextChanged(object sender, EventArgs e)
    {



    //videoNo[size] = int.Parse(txtVideoNo.Text);




    }

    private void btnAdd_KeyPress(object sender, KeyPressEventArgs e)
    {

    }


    private void txtVideoNo_KeyPress(object sender, KeyPressEventArgs e)
    {



    txtVideoNo.MaxLength = 4;







    //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 menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
    {

    }

    private void tabPage3_Click(object sender, EventArgs e)
    {

    }

    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;

    }

    private void pictureBox1_Click(object sender, EventArgs e)
    {




    }

    private void menuStrip1_ItemClicked_1(object sender, ToolStripItemClickedEventArgs e)
    {

    }

    private void toolStripMenuItem1_Click(object sender, EventArgs e)
    {
    Form2 frm2 = new Form2();
    frm2.Show();
    this.Hide();
    }

    private void backToLoginScreenToolStripMenuItem_Click(object sender, EventArgs e)
    {

    }



    }
    }

  2. #2
    Join Date
    Apr 2011
    Posts
    10

    Re: file handling with arraylist

    how could i do this?.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured