private void Page_Load(object sender, System.EventArgs e)
    {
        if (!Page.IsPostBack)
            Master.DataFromPageLabelControl("Doctor");
        // Load array elements
        cmbArray[0] = cmb8;
        cmbArray[1] = cmb830;
        cmbArray[2] = cmb9;
        cmbArray[3] = cmb930;
        cmbArray[4] = cmb10;
        cmbArray[5] = cmb1030;
        cmbArray[6] = cmb11;
        cmbArray[7] = cmb1130;
        cmbArray[8] = cmb12;
        cmbArray[9] = cmb1230;
        cmbArray[10] = cmb13;
        cmbArray[11] = cmb1330;
        cmbArray[12] = cmb14;
        cmbArray[13] = cmb1430;
        cmbArray[14] = cmb15;
        cmbArray[15] = cmb1530;
        cmbArray[16] = cmb16;
        cmbArray[17] = cmb1630;
        cmbArray[18] = cmb17;
        if (!Page.IsPostBack)
        {

            // MultiView1.ActiveViewIndex = 0;
            System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
            proxy = new WebRef.Service();
            // Proxy must accept and hold cookies
            //   proxy.CookieContainer = new System.Net.CookieContainer();
            proxy.Url = new Uri(proxy.Url).AbsoluteUri;

            //txtHiddenDate.Text = System.DateTime.Now.ToString();
            PostSchedule(System.DateTime.Now);
            //Calendar1.SelectedDate = System.DateTime.Now;
        }
        else
        {
            proxy = new WebRef.Service();

            // Proxy must accept and hold cookies
            //   proxy.CookieContainer = new System.Net.CookieContainer();
            proxy.Url = new Uri(proxy.Url).AbsoluteUri;
            apptTransfer.date = Convert.ToDateTime(this.txtDate.Text);
            apptTransfer.doctorID = Convert.ToInt32(Session["DocID"]);
            aRequest.date = apptTransfer.date;
            aRequest.docID = apptTransfer.doctorID;
            AppointmentResponse aResponse = proxy.GetDocSchedule(aRequest);
            dsSchedule = aResponse.ds;
            dt = adap.GetData(DateTime.Now.Day, DateTime.Now.Month, Convert.ToInt32(Session["DocID"]));
            Session["day"] = dt;
        }
    }
    private void PostSchedule(System.DateTime dateDayToLoad)
    {
        // get selected date's schedule
        if (!string.IsNullOrEmpty(txtDate.Text))
            apptTransfer.date = Convert.ToDateTime(this.txtDate.Text);
        else
        {
            apptTransfer.date = DateTime.Now;
            txtDate.Text = DateTime.Now.ToShortDateString();
        }
        apptTransfer.doctorID = Convert.ToInt32(Session["DocID"]);
        aRequest.date = apptTransfer.date;
        aRequest.docID = apptTransfer.doctorID;
        System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
        proxy = new WebRef.Service();

        // Proxy must accept and hold cookies
        //   proxy.CookieContainer = new System.Net.CookieContainer();
        proxy.Url = new Uri(proxy.Url).AbsoluteUri;
        AppointmentResponse aResponse = proxy.GetDocSchedule(aRequest);
        dsSchedule = aResponse.ds;
        Session["day"] = adap.GetData(DateTime.Now.Day, DateTime.Now.Month, Convert.ToInt32(Session["DocID"]));

        try
        {
            // For each time slot
            for (int x = 0; x < 19; ++x)
            {
                // If value is available, unavailable, or in class.
                if (dsSchedule.Tables[1].Rows[0][x + 8].ToString() == "Yes" || dsSchedule.Tables[1].Rows[0][x + 8].ToString() == "No")
                {
                    cmbArray[x].SelectedValue = dsSchedule.Tables[1].Rows[0][x + 8].ToString();
                }

                // If value is a student appointment
                if (dsSchedule.Tables[1].Rows[0][x + 8].ToString().StartsWith("P"))
                {
                    System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
                    proxy = new WebRef.Service();

                    // Proxy must accept and hold cookies
                    //   proxy.CookieContainer = new System.Net.CookieContainer();
                    proxy.Url = new Uri(proxy.Url).AbsoluteUri;

                    PatientRequest pRequest = new PatientRequest();
                    pRequest.PatientID = Convert.ToInt32(dsSchedule.Tables[1].Rows[0][x + 8].ToString().Substring(3));

                    PatientResponse pResponse = proxy.GetPatient(pRequest);

                    //dsStudent = new DataSet();
                    //// Get student ID
                    //strStudentID = dsSchedule.Tables[0].Rows[0][x+8].ToString().Substring(3);

                    //// Set up SQL query to retrieve student's name
                    //string[] strSelect = new string[2] {"First_Name", "Last_Name"};
                    //string[] strWhere = new string [2] {"PAT", strStudentID};

                    //// Execute query
                    //dsStudent = dbMangler.SelectQuery("SDT", strSelect, strWhere);

                    //// Build student's name
                    //strStudentName = dsStudent.Tables[0].Rows[0][0] + " " + dsStudent.Tables[0].Rows[0][1];

                    //// Add and display student's name to combo box
                    cmbArray[x].Items.Add(new ListItem(pResponse.Name, "PAT" + pRequest.PatientID));
                    cmbArray[x].SelectedValue = "PAT" + pRequest.PatientID;
                }

            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.ToString();
        }

        //btnSubmit.Enabled = true;
        btnFlip.Enabled = true;
    }
    /// <summary>
    /// Gets an instructors schedule
    /// </summary>
    /// <param name="strInsID">A string value with a numeric integer representing 
    /// an instructor.</param>
    /// <remarks>
    /// Pseudocode follows below
    /// <code>
    /// Begin
    ///    Get Day_ID for selected date and instructor
    ///    Get Schedule for selected Day_ID    
    /// End
    /// </code>
    /// </remarks>
    private void GetDocSchedule(string strDocID)
    {
        try
        {
            proxy = new WebRef.Service();

            // Proxy must accept and hold cookies
            //   proxy.CookieContainer = new System.Net.CookieContainer();
            proxy.Url = new Uri(proxy.Url).AbsoluteUri;
            AppointmentRequest aRequest = new AppointmentRequest();
            AppointmentTransferObject aTransferObject = new AppointmentTransferObject();
            aTransferObject.date = Convert.ToDateTime(txtDate.Text);
            aTransferObject.doctorID = Convert.ToInt32(strDocID);
            aRequest.date = aTransferObject.date;
            aRequest.docID = aTransferObject.doctorID;

            AppointmentResponse aResponse = proxy.GetDocSchedule(aRequest);

            dsDay = aResponse.ds.Tables[0];
            dsSchedule = aResponse.ds.Tables[1];

            Session["dsSchedule"] = dsSchedule;

            //  lblDay.Text = dsDay.Rows[0][1].ToString();

            // Get schedule

        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Black;
            lblMessage.BackColor = Color.Red;
            lblMessage.Text = ex.ToString();
        }
    }