Пример #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();
        }
    }