Ejemplo n.º 1
0
    //This is the event. When the user clicks submit, it will do the following:
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string        cs  = WebConfigurationManager.ConnectionStrings["localConnection"].ConnectionString;
        SqlConnection con = new SqlConnection(cs);

        //1.check if email exists.
        //2. if it does not, insert data into appointment and account table.

        try
        {
            //check if the email already exist, email must be unique as this is the username
            //retrieving and saving to variables all the information in the form.

            FirstName = FirstName_Form.Text;
            LastName  = LastName_Form.Text;
            Major     = Major_Form.Text;
            Email     = Email_Form.Text;
            Phone     = Phone_Form.Text;
            Reason    = Reason_Form.Text;
            Advisor   = Advisor_Form.Text;
            TimeSlot  = TimeSlots_Form.Text;


            string sql = "select count(*) from customer where email = '" + Email + "'";
            con.Open();

            int count = DBoperations.GetOneInt(sql);

            if (count != 0)
            {//email already exisits
                LblMsg.Text = "The email you entered already exists in the database. Please login to access your account or register with a different email. ";
            }
            else
            {
                DBoperations.CreateAccount(FirstName, LastName, Major, Email, Phone);
                StudentId = 1;//insert CreateAccount outparameter in here so that createappointment can work.
                DBoperations.CreateAppointment(StudentId, Reason, Advisor, Date, TimeSlot, Phone);
            }
        }
        catch (Exception err)
        {
            LblMsg.Text = "Cannot submit information now. Please try again later.";
        }
        finally //must make sure the connection is properly closed
        {       //the finally block will always run whether there is an error or not
            con.Close();
        }
    }
Ejemplo n.º 2
0
    //This is the event. When the user clicks submit, it will do the following:
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        DBoperations DB       = new DBoperations();
        string       username = UserName_Form.Text;
        string       notes    = "Tester";
        int          SID      = DB.GetStudentID(username);
        int          ATID     = Convert.ToInt32(TimeSlots_Form.SelectedValue);

        Boolean       value = DB.CreateAppointment(ATID, SID, notes);
        string        cs    = WebConfigurationManager.ConnectionStrings["localConnection"].ConnectionString;
        SqlConnection con   = new SqlConnection(cs);
        int           APID  = 0;

        try
        {
            string     selectSQL = "Select APID FROM KBS_APPOINTMENTS WHERE ATID=" + ATID + ";";
            SqlCommand com       = new SqlCommand(selectSQL, con);

            string     setNonValid = "UPDATE KBS_ADVISOR_TIMES SET Valid=0 WHERE ATID=" + ATID + ";";
            SqlCommand edit        = new SqlCommand(setNonValid, con);

            con.Open();
            APID = (int)com.ExecuteScalar();
            edit.ExecuteNonQuery();
        }
        catch (Exception err)
        {
            err.ToString();
        }
        finally
        {
            con.Close();
        }

        foreach (ListItem row in Reason_Form.Items)
        {
            if (row.Selected == true)
            {
                int reasons = Convert.ToInt32(row.Value);
                DB.MatchReasonsToAppointment(reasons, APID);
            }
        }


        DB = null;
    }