コード例 #1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Name.Text != null && Price.Text != null && Selling.Text != null && Brand.SelectedItem.Value != null && Category.SelectedItem.Value != null && Sub.SelectedItem.Value != null && Gender.SelectedItem.Value != null && Description.Text != null && MetCare.Text != null && Productdtl.Text != null)
        {
            string path1 = "";
            path1 = "~/Img/" + FileUpload1.FileName;
            FileUpload1.SaveAs(Server.MapPath(path1));

            string path2 = "";
            path2 = "~/Img/" + FileUpload2.FileName;
            FileUpload2.SaveAs(Server.MapPath(path2));

            string path3 = "";
            path3 = "~/Img/" + FileUpload3.FileName;
            FileUpload3.SaveAs(Server.MapPath(path3));

            string path4 = "";
            path4 = "~/Img/" + FileUpload4.FileName;
            FileUpload4.SaveAs(Server.MapPath(path4));

            string path5 = "";
            path5 = "~/Img/" + FileUpload5.FileName;
            FileUpload5.SaveAs(Server.MapPath(path5));

            SqlCommand cmd = new SqlCommand("sp_Project", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@PName", Name.Text);
            cmd.Parameters.AddWithValue("@PPrice", Price.Text);
            cmd.Parameters.AddWithValue("@PSellPrice", Selling.Text);
            cmd.Parameters.AddWithValue("@PBrand", Brand.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@PCatId", Category.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@SubCatId", Sub.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@PGender", Gender.SelectedItem.Value);
            cmd.Parameters.AddWithValue("@PDesc", Description.Text);
            cmd.Parameters.AddWithValue("@PDetail", Productdtl.Text);
            cmd.Parameters.AddWithValue("@PMet", MetCare.Text);
            cmd.Parameters.AddWithValue("@P1", path1);
            cmd.Parameters.AddWithValue("@P2", path2);
            cmd.Parameters.AddWithValue("@P3", path3);
            cmd.Parameters.AddWithValue("@P4", path4);
            cmd.Parameters.AddWithValue("@P5", path5);

            if (free.Checked == true)
            {
                cmd.Parameters.AddWithValue("@free", 1.ToString());
            }
            else
            {
                cmd.Parameters.AddWithValue("@free", 0.ToString());
            }

            if (txtcod.Checked == true)
            {
                cmd.Parameters.AddWithValue("@COD", 1.ToString());
            }
            else
            {
                cmd.Parameters.AddWithValue("@COD", 0.ToString());
            }
            if (txt30.Checked == true)
            {
                cmd.Parameters.AddWithValue("@replace", 1.ToString());
            }
            else
            {
                cmd.Parameters.AddWithValue("@replace", 0.ToString());
            }
            con.Open();
            int k = (int)cmd.ExecuteNonQuery();

            if (k == 1)
            {
                Response.Write("<Script>alert('Data recorded');/<Script>");
            }
            else
            {
                Response.Write("<Script>alert('Data not recorded');/<Script>");
            }

            con.Close();


            Name.Text    = string.Empty;
            Price.Text   = string.Empty;
            Selling.Text = string.Empty;
            Brand.ClearSelection();
            Category.ClearSelection();
            Sub.ClearSelection();
            Gender.ClearSelection();
            Description.Text = string.Empty;
            MetCare.Text     = string.Empty;
            Productdtl.Text  = string.Empty;
        }
        else
        {
            Response.Write("<Script>alert('Product Cannot be Added');</Script>");
        }
    }