Ejemplo n.º 1
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = File.ReadAllText(HttpContext.Current.Server.MapPath("/sys/YachtsUpdate.sql"));

            string get = System.Web.Configuration.WebConfigurationManager
                         .ConnectionStrings["ProjectConnection"].ConnectionString;
            SqlConnection getConnection = new SqlConnection(get);
            SqlCommand    command       = new SqlCommand(sql, getConnection);

            string fileName = "";

            if (DownLoadFileUpload1.HasFile)
            {
                //取得副檔名
                string Extension = DownLoadFileUpload1.FileName.Split('.')[DownLoadFileUpload1.FileName.Split('.').Length - 1];
                //新檔案名稱
                fileName = String.Format("{0:yyyyMMddhhmmsss}.{1}", DateTime.Now, Extension);
                //上傳目錄為/upload/Images/
                DownLoadFileUpload1.SaveAs(Server.MapPath(String.Format("~/sys/uploadfile/Yachts_DownLoad/{0}", fileName)));
            }
            else


            {
                if (DownLoadHiddenField2.Value != "")
                {
                    fileName = DownLoadHiddenField2.Value;
                }
                //else
                //{
                //    DownLoadMessage.Text = "沒有上傳檔案";
                //    return;
                //}
            }

            command.Parameters.Add("@id", SqlDbType.Int);
            command.Parameters["@id"].Value = Request.QueryString["id"];
            command.Parameters.Add("@YachtsType", SqlDbType.NVarChar);
            command.Parameters["@YachtsType"].Value = UpdateName.Text;
            command.Parameters.Add("@Overview", SqlDbType.NVarChar);
            command.Parameters["@Overview"].Value = UpdateOverview.Value;

            command.Parameters.Add("@Dimensions", SqlDbType.NVarChar);
            command.Parameters["@Dimensions"].Value = UpdateDimensions.Value;

            command.Parameters.Add("@Specifications", SqlDbType.NVarChar);
            command.Parameters["@Specifications"].Value = UpdateSpecification.Value;
            command.Parameters.Add("@Downloads", SqlDbType.NVarChar);
            command.Parameters["@Downloads"].Value = fileName;

            getConnection.Open();
            command.ExecuteNonQuery();
            getConnection.Close();
            Response.Redirect("YachtsInformation.aspx?page=" + Request.QueryString["Page"]);
        }
Ejemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string sql = File.ReadAllText(HttpContext.Current.Server.MapPath("/sys/UpdateDealers.sql"));

            string get = System.Web.Configuration.WebConfigurationManager
                         .ConnectionStrings["ProjectConnection"].ConnectionString;
            SqlConnection getConnection = new SqlConnection(get);
            SqlCommand    command       = new SqlCommand(sql, getConnection);

            string fileName;

            if (DownLoadFileUpload1.HasFile)
            {
                //取得副檔名
                string Extension = DownLoadFileUpload1.FileName.Split('.')[DownLoadFileUpload1.FileName.Split('.').Length - 1];
                //新檔案名稱
                fileName = String.Format("{0:yyyyMMddhhmmsss}.{1}", DateTime.Now, Extension);
                //上傳目錄為/upload/Images/
                DownLoadFileUpload1.SaveAs(Server.MapPath(String.Format("~/sys/uploadfile/dealers_photo/{0}", fileName)));
            }
            else


            {
                if (DownLoadHiddenField2.Value != "")
                {
                    fileName = DownLoadHiddenField2.Value;
                }
                else
                {
                    DownLoadMessage.Text = "沒有上傳檔案";
                    return;
                }
            }

            command.Parameters.Add("@id", SqlDbType.Int);
            command.Parameters["@id"].Value = Request.QueryString["id"];

            command.Parameters.Add("@name", SqlDbType.NVarChar);
            command.Parameters["@name"].Value = UpdateDealers1.Text;
            command.Parameters.Add("@main", SqlDbType.NVarChar);
            command.Parameters["@main"].Value = UpdateMain.Value;
            command.Parameters.Add("@cid", SqlDbType.Int);
            command.Parameters["@cid"].Value = DropDownList1.SelectedValue;

            command.Parameters.Add("@photo", SqlDbType.NVarChar);
            command.Parameters["@photo"].Value = fileName;

            getConnection.Open();
            command.ExecuteNonQuery();
            getConnection.Close();
            Response.Redirect("Dealers.aspx");
        }