Esempio n. 1
0
        private void addnewdoc_Click(object sender, EventArgs e)
        {
            if (ID_Textbox.Text.Length == 0 || Name_TextBox.Text.Length == 0 || Speciality_TextBox.Text.Length == 0)
            {
                MessageBox.Show("Wrong Entry");
            }
            else
            {
                dc doctor = new dc();
                doctor.id        = ID_Textbox.Text;
                doctor.name      = Name_TextBox.Text;
                doctor.specialty = Speciality_TextBox.Text;
                string record = "";
                int    rec_len;
                byte[] record_b;
                record  += doctor.id + "*" + doctor.name + "*" + doctor.specialty;
                rec_len  = record.Length;
                record_b = new byte[rec_len];
                FileStream Doctor_File = new FileStream("doctor.txt", FileMode.Append);
                for (int i = 0; i < rec_len; i++)
                {
                    record_b[i] = (byte)record[i];
                }
                Doctor_File.WriteByte((byte)rec_len);
                Doctor_File.Write(record_b, 0, rec_len);
                Doctor_File.Close();

                ID_Textbox.Text         = "";
                Name_TextBox.Text       = "";
                Speciality_TextBox.Text = "";
                MessageBox.Show("done");
            }
        }
Esempio n. 2
0
        private void searchbyname_Click(object sender, EventArgs e)
        {
            string record;
            bool   Doctor_Exist = false;
            string doctorid     = "";
            int    rec_len;

            byte[] record_b;
            //open file
            FileStream Doctor_File = new FileStream("doctor.txt", FileMode.Open);

            string[] fields;
            //search by doctor name
            while (Doctor_File.Position != Doctor_File.Length)
            {
                dc doc = new dc();
                rec_len  = Doctor_File.ReadByte();
                record_b = new byte[rec_len];
                record   = "";
                Doctor_File.Read(record_b, 0, rec_len);
                for (int i = 0; i < rec_len; i++)
                {
                    record += (char)record_b[i];
                }
                fields        = record.Split('*');
                doc.id        = fields[0];
                doc.name      = fields[1];
                doc.specialty = fields[2];
                if (doc.name == Doctor_TextBox.Text)
                {
                    doctorid     = doc.id;
                    Doctor_Exist = true;
                    break;
                }
            }
            if (!Doctor_Exist)
            {
                MessageBox.Show("Doctor not Found");
            }

            Doctor_File.Close();
            //making table
            DataTable Table = new DataTable();

            Table.Columns.Add("ID", typeof(string));
            Table.Columns.Add("Patient Name", typeof(string));
            Table.Columns.Add("Disease", typeof(string));
            Table.Columns.Add("Doctor's ID", typeof(string));
            Table.Columns.Add("Appointment Date", typeof(string));

            //open file patient
            FileStream Patient_File = new FileStream("Patient.txt", FileMode.Open);

            string[] pat_field;
            //display patient by doctor name
            while (Patient_File.Position != Patient_File.Length)
            {
                patient patien = new patient();
                rec_len  = Patient_File.ReadByte();
                record_b = new byte[rec_len];
                record   = "";
                Patient_File.Read(record_b, 0, rec_len);
                for (int i = 0; i < rec_len; i++)
                {
                    record += (char)record_b[i];
                }
                pat_field               = record.Split('@');
                patien.id               = pat_field[0];
                patien.name             = pat_field[1];
                patien.disease          = pat_field[2];
                patien.doctor_id        = pat_field[3];
                patien.appointment_date = pat_field[4];
                if (patien.doctor_id == doctorid)
                {
                    Table.Rows.Add(patien.id, patien.name, patien.disease, patien.doctor_id, patien.appointment_date);
                }
            }
            data_findbyname.DataSource = Table;
            Patient_File.Close();
        }