protected void btnProductAdd_Click(object sender, EventArgs e)
    {
        try
        {
            lblMsg.Text = "";
            string imgNewFileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(FileUpload_Img.FileName).ToLower();
            if (FileUpload_Img.HasFile)
            {
                FileUpload_Img.SaveAs(Server.MapPath("product_img") + "/" + imgNewFileName);
            }
            SqlDataSource_Product.InsertParameters["產品編號"].DefaultValue = txtProductId.Text;
            SqlDataSource_Product.InsertParameters["類別編號"].DefaultValue = ddl_ProductClass.SelectedItem.Value;
            SqlDataSource_Product.InsertParameters["品名"].DefaultValue   = txtProductName.Text;
            SqlDataSource_Product.InsertParameters["單價"].DefaultValue   = txtPrice.Text;
            SqlDataSource_Product.InsertParameters["圖示"].DefaultValue   = imgNewFileName;
            SqlDataSource_Product.Insert();
            // 若目前檔案存在,則將檔案傳送到網站的product_img資料夾下

            lblMsg.ForeColor    = System.Drawing.Color.Blue;
            lblMsg.Text         = "產品資料新增成功!";
            txtProductId.Text   = "";
            txtProductName.Text = "";
            txtPrice.Text       = "";
        }
        catch (Exception ex)
        {
            lblMsg.ForeColor = System.Drawing.Color.Red;
            lblMsg.Text      = ex.Message;
        }
    }
    protected void btn_AccEdit_Click(object sender, EventArgs e)
    {
        conn.Open();
        sqlcommand = new SqlCommand("select M_Name,M_Tel from [Member] WHERE M_num='" + Session["Login"].ToString() + "'", conn);
        dr         = sqlcommand.ExecuteReader();
        dr.Read();
        string Name  = dr["M_Name"].ToString();
        string Phone = dr["M_Tel"].ToString();

        dr.Close();

        sqlcommand = new System.Data.SqlClient.SqlCommand("SELECT MAX(SHPR_num) FROM [SecondHandProductRequire]", conn);//查詢資料個數
        dr         = sqlcommand.ExecuteReader();
        dr.Read();
        string InsertID = "";

        if (dr[0].ToString() == string.Empty) //當商品個數為0 則該筆商品的編號為1
        {
            InsertID = 1.ToString();
        }
        else
        {
            InsertID = (Convert.ToInt32(dr[0]) + 1).ToString();//不為0 該筆商品編號為會員個數+1
        }
        dr.Close();
        conn.Close();

        conn.Open();
        if (FileUpload_Img.HasFile)
        {
            string SaveImg = "SecondHandProductRequireImg/" + FileUpload_Img.FileName;
            FileUpload_Img.SaveAs(Server.MapPath(SaveImg));
            SaveImg    = @"SecondHandProductRequireImg\" + FileUpload_Img.FileName;
            sqlcommand = new SqlCommand("INSERT INTO [SecondHandProductRequire] VALUES('" + //把輸入資料的資料存入資料庫中
                                        InsertID + "','" +
                                        txt_Name.Text + "','" +
                                        txt_Price.Text + "','" +
                                        txt_Info.Text + "','" +
                                        SaveImg + "','" +
                                        Name + "','" +
                                        Phone + "')", conn);
            sqlcommand.ExecuteNonQuery();
        }
        else
        {
            sqlcommand = new SqlCommand("INSERT INTO [SecondHandProductRequire] VALUES('" + //把輸入資料的資料存入資料庫中
                                        InsertID + "','" +
                                        txt_Name.Text + "','" +
                                        txt_Price.Text + "','" +
                                        txt_Info.Text + "'," +
                                        "NULL" + ",'" +
                                        Name + "','" +
                                        Phone + "')", conn);
            sqlcommand.ExecuteNonQuery();
        }

        conn.Close();

        Response.Write("<script>alert('已完成上架申請!');location.href='MyAccount_SHProductRequire.aspx'; </script>");
    }
Beispiel #3
0
    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        if (txt_Name.Text != string.Empty || txt_Email.Text != string.Empty || txt_Content.Text != string.Empty)
        {
            string ID = DateTime.Now.ToString("yyyyMMddHHmmss");//以日期時間(年月日時分秒)作為ID儲存

            conn.Open();
            if (FileUpload_Img.HasFile)                                                                    //若有包含圖片
            {
                String fileExtension     = System.IO.Path.GetExtension(FileUpload_Img.FileName).ToLower(); //得到檔的尾碼
                String allowedExtensions = ".jpg";                                                         //允許檔的尾碼

                //看包含的檔是否是被允許的檔的尾碼
                if (fileExtension == allowedExtensions)//若為允許的尾碼(.jpg),則上傳
                {
                    FileUpload_Img.SaveAs(Server.MapPath("ContactUsImg/" + ID + ".jpg"));

                    sqlcommand = new SqlCommand("INSERT INTO [ContactUs] VALUES('" +
                                                ID + "','" +
                                                txt_Name.Text + "','" +
                                                txt_Email.Text + "','" +
                                                txt_Content.Text + "','" +
                                                "ContactUsImg/" + ID + ".jpg" + "')", conn);
                    sqlcommand.ExecuteNonQuery();
                }
                else//若為非允許的尾碼(.jpg),則拒絕上傳
                {
                    Response.Write("<script>alert('只能上傳jpg圖像檔喔!');</script>");
                    conn.Close();
                    return;
                }
            }
            else//若無包含圖片
            {
                sqlcommand = new SqlCommand("INSERT INTO [ContactUs] VALUES('" +
                                            ID + "','" +
                                            txt_Name.Text + "','" +
                                            txt_Email.Text + "','" +
                                            txt_Content.Text + "',NULL)", conn);
                sqlcommand.ExecuteNonQuery();
            }

            conn.Close();
            //提醒用戶訊息以傳送成功,並導向回首頁
            Response.Write("<script>alert('您的訊息以傳送成功囉!\\n我們將會盡快回復您。');location.href='index.aspx'; </script>");
        }
        else
        {
            Response.Write("<script>alert('錯誤\\n下方姓名,Email,內容等皆須填寫不可空白喔!');</script>");
        }
    }
    protected void button_create_user_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand    cmd  = new SqlCommand();

        cmd.Connection = conn;

        cmd.CommandText = @"INSERT INTO Users (User_email, User_name, User_password, User_description, User_img) VALUES (@Email, @Name, @Password, @Description, @Img)";
        cmd.Parameters.AddWithValue("@Email", TextBox_Email_Create.Text);
        cmd.Parameters.AddWithValue("@Name", TextBox_Username_Create.Text);
        cmd.Parameters.AddWithValue("@Password", TextBox_Password_Create1.Text);
        cmd.Parameters.AddWithValue("@Description", TextBox_Description.Text);

        string bill_sti = "intetbillede.jpg";

        #region image1
        if (FileUpload_Img.HasFile)
        {
            //NewGuid danner uniq navn for billeder
            bill_sti = Guid.NewGuid() + Path.GetExtension(FileUpload_Img.FileName);
            // Opret
            String UploadeMappe = Server.MapPath("~/Images/ProfilePicture/");
            String Filnavn      = DateTime.Now.ToFileTime() + FileUpload_Img.FileName;
            bill_sti = Filnavn;

            //Gem det orginale Billede
            FileUpload_Img.SaveAs(UploadeMappe + Filnavn);
        }
        // Tildel parameter-værdierne, fra input felterne.
        cmd.Parameters.AddWithValue("@Img", bill_sti);
        #endregion

        conn.Open();
        object user_id = cmd.ExecuteScalar();
        conn.Close();
        Response.Redirect("Default.aspx");
    }