protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
    {
        try
        {
            ppm = rt.palm_pateint_masters.Single(palm_pateint_master => palm_pateint_master.pateint_code == Session["pateint_code"].ToString());
            String memo = Convert.ToString(GridView1.SelectedRow.Cells[0].Text);
            Session["memo"] = memo;
            Panel16.Visible = false;
            Panel17.Visible = true;
            Label112.Text   = Label126.Text = ppm.pateient_title + " " + ppm.pateient_first_name + " " + ppm.pateient_last_name;
            //Label115.Text = d.Text;
            pop = rt.palm_opd_pathlogies.Single(palm_opd_pathlogy => palm_opd_pathlogy.patient_code == Session["pateint_code"].ToString());

            String ref_doctor = pop.ref_by;
        }
        catch (NullReferenceException rtt)
        {
            Response.Redirect("~/login.aspx");
        }
        palm_doctor_employee pdd = new palm_doctor_employee();

        try
        {
            pdd           = rt.palm_doctor_employees.Single(palm_doctor_employee => palm_doctor_employee.emp_code == pop.ref_by);
            Label113.Text = pdd.doctor_name;
        }
        catch (Exception er)
        { Label113.Text = pop.ref_by; }
        pob           = rt.palm_opd_pathlogy_billms.Single(palm_opd_pathlogy_billm => palm_opd_pathlogy_billm.memo == Session["memo"].ToString());
        Label114.Text = pob.memo;
        Label122.Text = pob.memo;
        Label126.Text = ppm.pateient_title + " " + ppm.pateient_first_name + " " + ppm.pateient_last_name;

        Label128.Text = pdd.doctor_name;
        Label124.Text = Convert.ToString(pob.inserted_on);
        TextBox2.Text = Convert.ToString(pob.advanced);
        TextBox3.Text = Convert.ToString(pob.balence);

        BindData1();

        /*  }
         * catch (InvalidOperationException ioe)
         * {Label134.Text="No Record Found";
         * }*/
        DataClassesDataContext df          = new DataClassesDataContext();
        palm_opd_Bill_master   bill_master = new palm_opd_Bill_master();
        palm_opd_Bill_slave    bill_slave  = new palm_opd_Bill_slave();
        palm_doctor_employee   pde         = new palm_doctor_employee();

        try
        {
            bill_master  = df.palm_opd_Bill_masters.Single(palm_opd_Bill_master => palm_opd_Bill_master.pateint_code == TextBox1.Text);
            Label00.Text = Convert.ToString(bill_master.cash_memo);
            palm_pateints_profile ppp = new palm_pateints_profile();
            Label81.Text = bill_master.opd_code;
            pde          = rt.palm_doctor_employees.Single(palm_doctor_employee => palm_doctor_employee.emp_code == bill_master.emp_id);
            palm_department pd = new palm_department();
            pd            = df.palm_departments.Single(palm_department => palm_department.department_code == pde.department);
            Label02.Text  = pde.doctor_name;
            label9.Text   = pd.department_desc;
            ppm           = df.palm_pateint_masters.Single(palm_pateint_master => palm_pateint_master.pateint_code == bill_master.pateint_code);
            Label01.Text  = ppm.pateient_title + " ." + ppm.pateient_last_name + " " + ppm.pateient_first_name + " " + ppm.pateient_middle_name;
            Label84.Text  = ppm.gender;
            ppp           = df.palm_pateints_profiles.Single(palm_pateints_profile => palm_pateints_profile.pateint_code == bill_master.pateint_code);
            Label80.Text  = ppp.ref_doc;
            Label83.Text  = ppp.age;
            Label82.Text  = Convert.ToString(bill_master.inserted_on);
            bill_slave    = df.palm_opd_Bill_slaves.Single(palm_opd_Bill_slave => palm_opd_Bill_slave.opd_bill_id == bill_master.cash_memo);
            Label86.Text  = Convert.ToString(bill_slave.amount);
            Label001.Text = Convert.ToString(bill_slave.amount);
            Label90.Text  = Convert.ToString(bill_slave.amount);
            Label91.Text  = Convert.ToString(bill_slave.amount);
        }
        catch (Exception rt1) { }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        objp.built            = TextBox2.Text;
        objp.pulse            = TextBox26.Text;
        objp.bp               = TextBox5.Text;
        objp.rr               = TextBox3.Text;
        objp.pallor           = TextBox27.Text;
        objp.cyanosis         = TextBox2.Text;
        objp.clubing          = TextBox4.Text;
        objp.peripheral_pulse = TextBox28.Text;
        objp.jvp              = TextBox2.Text;
        objp.hjr              = TextBox29.Text;
        objp.oedema           = TextBox32.Text;
        objp.adenopathy       = TextBox2.Text;
        objp.icterus          = TextBox30.Text;
        objp.erruptions       = TextBox33.Text;
        objp.other            = TextBox47.Text;
        objp.cvs              = TextBox36.Text;
        objp.r_s              = TextBox42.Text;
        objp.p_a              = TextBox43.Text;
        objp.cns              = TextBox44.Text;
        objp.ps_pv            = TextBox45.Text;
        objp.opd_code         = Session["opd_code"].ToString();;
        objp.ref_doctor       = TextBox25.Text;
        objp.department       = DropDownList5.SelectedValue;
        objp.doctor_id        = DropDownList3.SelectedValue;

        objp.con_doctor = DropDownList3.SelectedItem.Text;


        objp.pateint_code = Session["pateint_code"].ToString();
        objp.emp_code     = Session["emp_code"].ToString();
        objp.is_check_in  = "1";

        obj.opdreg(objp);


        int cashmemo = obj.getcashmemo();

        por = df.palm_opd_registrations.Single(palm_opd_registration => palm_opd_registration.opd_code == TextBox21.Text);
        bill_master.cash_memo    = cashmemo;
        bill_master.pateint_code = por.pateint_code;
        bill_master.opd_code     = TextBox21.Text;
        bill_master.cash_memo    = cashmemo;
        bill_master.emp_id       = por.emp_code;
        bill_master.inserted_by  = Session["emp_code"].ToString();
        bill_master.inserted_on  = DateTime.Now;
        df.palm_opd_Bill_masters.InsertOnSubmit(bill_master);
        df.SubmitChanges();

        bill_master            = df.palm_opd_Bill_masters.Single(palm_opd_Bill_master => palm_opd_Bill_master.cash_memo == cashmemo);
        pde                    = df.palm_doctor_employees.Single(palm_doctor_employee => palm_doctor_employee.emp_code == bill_master.emp_id);
        bill_slave.opd_bill_id = bill_master.cash_memo;
        bill_slave.charge_name = "Consulting";
        bill_slave.description = "Consulting";
        bill_slave.units       = 1;
        bill_slave.amount      = pde.consulting_fees;
        df.palm_opd_Bill_slaves.InsertOnSubmit(bill_slave);
        df.SubmitChanges();


        Label00.Text = Convert.ToString(bill_master.cash_memo);
        Label81.Text = bill_master.opd_code;
        palm_department pd = new palm_department();

        pd            = df.palm_departments.Single(palm_department => palm_department.department_code == pde.department);
        Label02.Text  = pde.doctor_name;
        Label006.Text = pd.department_desc;
        ppm           = df.palm_pateint_masters.Single(palm_pateint_master => palm_pateint_master.pateint_code == bill_master.pateint_code);
        Label01.Text  = ppm.pateient_title + " ." + ppm.pateient_last_name + " " + ppm.pateient_first_name + " " + ppm.pateient_middle_name;
        Label84.Text  = ppm.gender;
        ppp           = df.palm_pateints_profiles.Single(palm_pateints_profile => palm_pateints_profile.pateint_code == bill_master.pateint_code);
        Label80.Text  = ppp.ref_doc;
        Label83.Text  = ppp.age;
        Label82.Text  = Convert.ToString(bill_master.inserted_on);
        bill_slave    = df.palm_opd_Bill_slaves.Single(palm_opd_Bill_slave => palm_opd_Bill_slave.opd_bill_id == bill_master.cash_memo);
        Label86.Text  = Convert.ToString(bill_slave.amount);
        Label001.Text = Convert.ToString(bill_slave.amount);
        Label90.Text  = Convert.ToString(bill_slave.amount);
        Label91.Text  = Convert.ToString(bill_slave.amount);

        MultiView1.ActiveViewIndex = 3;
    }