Esempio n. 1
0
    public static int Insert_Category(User_Property_Tbl_Category u)
    {
        SqlCommand cmd = new SqlCommand();

        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "insert_tbl_category_sp";

        cmd.Parameters.Add(Create_Parameter.Convert_String("@cat_name", u.cat_name));
        cmd.Parameters.Add(Create_Parameter.Convert_String("@cat_photo", u.cat_photo));

        return(Create_Command.Execute_Non_Query(cmd));
    }
Esempio n. 2
0
    protected void btn_ok_Click(object sender, EventArgs e)
    {
        User_Property_Tbl_Category u = new User_Property_Tbl_Category();

        u.cat_name = txt_category_name.Text;


        if (fl_category_photo.FileName != "")
        {
            if (fl_category_photo.PostedFile.ContentLength <= 512000)
            {
                string ext = Path.GetExtension(fl_category_photo.FileName).ToLower();

                if (ext == ".jpg" || ext == ".png" || ext == ".gif")
                {
                    Random r = new Random();

                    string f_nm = Path.GetFileNameWithoutExtension(fl_category_photo.FileName);

                    f_nm = f_nm + "_" + r.Next() + ext;

                    fl_category_photo.SaveAs(Server.MapPath("~/Upload/" + f_nm));
                    u.cat_photo = "~/Upload/" + f_nm;
                }
                else
                {
                    lbl_photo_msg.Text    = "Invalid Photo Type";
                    lbl_photo_msg.Visible = true;
                    return;
                }
            }
            else
            {
                lbl_photo_msg.Text    = "Photo Size is To Big";
                lbl_photo_msg.Visible = true;
                return;
            }
        }
        else
        {
            u.cat_photo = "";
        }

        //used when insertion of data
        if (btn_ok.Text == "Add")
        {
            int i = Insert_Logic.Insert_Category(u);
            clear();

            if (i == 1)
            {
                {
                    lbl_msg.Text      = "Successfully Inserted Data";
                    lbl_msg.ForeColor = System.Drawing.Color.Green;
                }
            }
            else
            {
                lbl_msg.Text      = "Data Insertion Failed";
                lbl_msg.ForeColor = System.Drawing.Color.Red;
            }
            mpe.Show();
        }


        //used when update the category data

        else
        {
            u.cat_id = id;

            int ii = Update_Logic.Update_Category(u);
            if (ii == 1)
            {
                Response.Redirect("manage_category.aspx");
            }
            else
            {
                lbl_msg.Text = "error";
                mpe.Show();
            }
        }
    }