Exemplo n.º 1
0
 protected void ImageButton_login_Click(object sender, ImageClickEventArgs e)
 {
     if (!TextBox_name.Equals("") && !TextBox_password.Equals(""))
     {
         SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings["connectionstring"].ToString());
         con.Open();
         SqlCommand com = new SqlCommand();
         com.Connection = con;
         string Tsql = "select User_Name from Web_User where User_Name=@name and User_Password=@password";
         com.CommandText = Tsql;
         com.Parameters.AddWithValue("name", TextBox_name.Text.Trim());
         com.Parameters.AddWithValue("password", TextBox_password.Text.Trim());
         SqlDataReader dr = com.ExecuteReader();
         if (dr.Read())
         {
             Session["User_Name"] = dr["User_Name"].ToString();
             Response.Redirect("Main.aspx");
         }
         else
         {
             Response.Write("<script>alert('登录失败! 1.用户名不存在 2.用户密码错误');</script>");
         }
     }
     else
     {
         Response.Write("<script>alert('用户名或密码不能为空!');</script>");
     }
 }
 private void clear()
 {
     TextBox_ID.Clear();
     TextBox_Name.Clear();
     TextBox_age.Clear();
     TextBox_Phone.Clear();
     TextBox_password.Clear();
 }
        protected void Btn_Save_Click(object sender, EventArgs e)
        {
            //Insert Logic

            //SqlConnection conn = new SqlConnection("Data Source = MONPC-PC; Initial Catalog = Burger2Home; Integrated Security = True; MultipleActiveResultSets = True; Application Name = EntityFramework");
            SqlConnection conn = new SqlConnection("Data Source = EPHREM-PC; Initial Catalog = Burger2Home; Integrated Security = True");

            conn.Open();
            var requete = " ";
            int ok      = 1;

            if (!(TextBox_email.Text.Equals(TextBox_Confirm_Email.Text)))
            {
                ok = 0;
                Label_Email_Distinct.Visible = true;
                TextBox_Confirm_Email.Focus();
            }
            else
            {
                if (!(TextBox_password.Text.Equals(TextBox_Password_Confirm.Text)))
                {
                    ok = 0;
                    Label_Password_Distinct.Visible = true;
                    TextBox_Password_Confirm.Focus();
                }
                else
                {
                    if (TextBox_email.Text.Equals(""))
                    {
                        ok = 0;
                        Label_mail_exist.Text = "Ce champs ne doit pas être vide!";
                        Label_mail_exist.Focus();
                    }
                    else
                    {
                        if (TextBox_password.Text.Equals(""))
                        {
                            ok = 0;
                            Label_password_vide.Visible = true;
                            TextBox_password.Focus();
                        }
                    }
                }
            }

            if (IfEmailExist(conn, TextBox_email.Text))
            {
                ok = 0;
                Label_mail_exist.Visible = true;
                TextBox_email.Focus();
            }

            if (ok == 1)
            {
                //string EncryptedPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(TextBox_password.Text, "SHA1");
                //requete = @"INSERT INTO[dbo].[Customer] ([firstname],[lastname],[email],[password],[address]) VALUES('" + TextBox_firstname.Text + "', '" + TextBox_lastname.Text + "', '" + TextBox_email.Text + "','" + EncryptedPassword + "','" + TextBox_address.Text + "')";
                requete = @"INSERT INTO[dbo].[Customer] ([firstname],[lastname],[email],[password],[address]) VALUES('" + TextBox_firstname.Text + "', '" + TextBox_lastname.Text + "', '" + TextBox_email.Text + "','" + TextBox_password.Text + "','" + TextBox_address.Text + "')";
            }
            int insert = ok;

            SqlCommand cmd = new SqlCommand(requete, conn);

            cmd.ExecuteNonQuery();
            Session["newCustomer"] = TextBox_firstname.Text + " " + TextBox_lastname.Text;
            conn.Close();
            Response.Redirect("toConnect.aspx");
        }