Esempio n. 1
0
        private void displaydrinfo_Load(object sender, EventArgs e)
        {
            try
            {
                FileStream   fs = new FileStream("doctor.txt", FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs);
                drclass      h  = new drclass();
                DataTable    tb = new DataTable();
                tb.Columns.Add("ID", typeof(int));
                tb.Columns.Add("Name", typeof(string));
                tb.Columns.Add("Speciality", typeof(string));

                string[] record, field;
                while (sr.Peek() != -1)
                {
                    record = sr.ReadLine().Split('#');
                    for (int i = 0; i < record.Length - 1; i++)
                    {
                        field  = record[i].Split('*');
                        h.Id   = int.Parse(field[0]);
                        h.nam  = field[1];
                        h.spec = field[2];
                    }
                    tb.Rows.Add(h.Id, h.nam, h.spec);

                    dataGridView1.DataSource = tb;
                }
                sr.Close();
            }
            catch
            { Console.WriteLine("error couldnt find file !"); }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            drclass dr = new drclass();

            //FileStream fs = new FileStream("doctor.txt", FileMode.Append);
            //StreamWriter sw = new StreamWriter(fs);
            dr.id         = txtid.Text.ToString();
            dr.name       = txtname.Text;
            dr.speciality = txtspec.Text;
            dr.Write();
        }