Monday, 16 September 2013

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;
using System.Collections;
namespace arraylist
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public void showitem()
        {
            listBox1.Items.Clear();
           for(int i=0;i<ar.Count;i++)
           {
               Class1 ob = (Class1)ar[i];
               listBox1.Items.Add(ob.Eid + "    " + ob.Ename + "   " + ob.Esal);
            }
        }

        ArrayList ar = new ArrayList();
        private void button1_Click(object sender, EventArgs e)
        {
            Class1 ob = new Class1();
            ob.Eid = Convert.ToInt32(textBox1.Text);
            ob.Ename = textBox2.Text;
            ob.Esal = Convert.ToInt32(textBox3.Text);
            ar.Add(ob);
            label4.Text = ar.Count.ToString();
            MessageBox.Show("your record is inserted");
            showitem();

        }

        int i;
        private void button2_Click(object sender, EventArgs e)
        {
             i = 0;
            Class1 ob=(Class1)ar[i];
            textBox1.Text = ob.Eid.ToString();
            textBox2.Text = ob.Ename;
            textBox3.Text = ob.Esal.ToString();

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (i < ar.Count - 1)
            {
                i++;
                Class1 ob = (Class1)ar[i];
                textBox1.Text = ob.Eid.ToString();
                textBox2.Text = ob.Ename;
                textBox3.Text = ob.Esal.ToString();
            }
            else
            {
                MessageBox.Show("u r at last");
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (i >0)
            {
                i--;
                Class1 ob = (Class1)ar[i];
                textBox1.Text = ob.Eid.ToString();
                textBox2.Text = ob.Ename;
                textBox3.Text = ob.Esal.ToString();
            }
            else
            {
                MessageBox.Show("u r at first");
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            i = ar.Count - 1;
         
                Class1 ob = (Class1)ar[i];
                textBox1.Text = ob.Eid.ToString();
                textBox2.Text = ob.Ename;
                textBox3.Text = ob.Esal.ToString();
         
           
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
        int x;
        private void button6_Click(object sender, EventArgs e)
        {
            x = 0;
            for (int i = 0; i < ar.Count; i++)
            {
                Class1 ob = (Class1)ar[i];
                if (ob.Eid.ToString() == textBox1.Text)
                {
                    textBox2.Text = ob.Ename;
                    textBox3.Text = ob.Esal.ToString();
                    x = 1;
                    break;
                }
           

            }
            if (x == 0)
            {
                MessageBox.Show("record does not exitst");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }

        }

        private void button7_Click(object sender, EventArgs e)
        {
            x = 0;
            for (int i = 0; i < ar.Count; i++)
            {
                Class1 ob = (Class1)ar[i];
                if (ob.Eid.ToString() == textBox1.Text)
                {
                    ob.Ename = textBox2.Text;
                    ob.Esal = Convert.ToInt32(textBox3.Text);
               
                    x = 1;
                    break;
                }


            }
            if (x == 0)
            {
                MessageBox.Show("record does not exitst");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }
            else if(x==1)
            {
                MessageBox.Show("data is updated");
                showitem();
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            x = 0;
            for (int i = 0; i < ar.Count; i++)
            {
                Class1 ob = (Class1)ar[i];
                if (ob.Eid.ToString() == textBox1.Text)
                {
                    ar.Remove(ob);

                    x = 1;
                    break;
                }


            }
            if (x == 0)
            {
                MessageBox.Show("record does not exitst");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox3.Text = "";
            }
            else if (x == 1)
            {
                MessageBox.Show("data is deleted");
                showitem();
            }
        }
    }
}


Code For Class


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace arraylist
{
    class Class1
    {
        int eid;

        public int Eid
        {
            get { return eid; }
            set { eid = value; }
        }
        string ename;

        public string Ename
        {
            get { return ename; }
            set { ename = value; }
        }
        int esal;

        public int Esal
        {
            get { return esal; }
            set { esal = value; }
        }
    }
}




No comments:

Post a Comment