Ejemplo n.º 1
0
    protected void btnSavePhoto_Click(object sender, ImageClickEventArgs e)
    {
        if (!FileUpload1.HasFile)
        {
            return;
        }
        string fileName  = FileUpload1.FileName;
        string strExtent = fileName.Substring(fileName.LastIndexOf("."));

        fileName = CommonFunction.Get_DynamicString() + strExtent;
        string fileName1 = "m_" + fileName;
        string fileName2 = "v_" + fileName;
        string filePath  = Server.MapPath("~/RoadPhoto/" + fileName);
        string filePath1 = Server.MapPath("~/RoadPhoto/" + fileName1);
        string filePath2 = Server.MapPath("~/RoadPhoto/" + fileName2);

        FileUpload1.PostedFile.SaveAs(filePath);
        ImgFunction.MakeThumbnail(filePath, filePath1, 600, 480, "W");
        ImgFunction.MakeThumbnail(filePath, filePath2, 150, 120, "W");
        System.IO.File.Delete(filePath);
        Image1.ImageUrl = "../RoadPhoto/" + fileName1;
        string sqlStr = "update R_RoadDepart set RD_MainPhoto='" + fileName1 + "',RD_ViewPhoto='" + fileName2 + "' where RD_ID='" + ViewState["rdid"].ToString() + "'";

        DBHelper.ExecuteCommand(sqlStr);
    }
Ejemplo n.º 2
0
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string strAction  = ViewState["strAction"].ToString();
        string strContent = PubClass.Tool.CheckStr(Request.Form["t_contents"].ToString());

        if (cboSel.Checked)
        {
            if (strAction == "add" && !FileUpload1.HasFile)
            {
                return;
            }
            if (FileUpload1.HasFile)
            {
                string fileName  = FileUpload1.FileName;
                string strExtent = fileName.Substring(fileName.LastIndexOf("."));
                fileName = CommonFunction.Get_DynamicString() + strExtent;
                string fileName1 = "v_" + fileName;
                string fileName2 = "vv_" + fileName;
                string filePath  = Server.MapPath("~/NewsImg/" + fileName);
                string filePath1 = Server.MapPath("~/NewsImg/" + fileName1);
                string filePath2 = Server.MapPath("~/NewsImg/" + fileName2);
                FileUpload1.PostedFile.SaveAs(filePath);
                ImgFunction.MakeThumbnail(filePath, filePath1, 600, 400, "W");
                ImgFunction.MakeThumbnail(filePath, filePath2, 180, 120, "W");
                System.IO.File.Delete(filePath);
                ViewState["ImgPath"] = fileName1;
                ViewState["ImgView"] = fileName2;
            }
        }
        string sqlStr = "";

        if (strAction == "add")
        {
            sqlStr = "insert into S_NewsInfo(N_Title,N_Content,N_From,N_Date,N_TSID,N_TID,N_ImgPath,N_ImgView) values('" + txtTitle.Text.Trim() + "','" + strContent + "','" + txtFrom.Text.Trim() + "','" + txtDate.Text.Trim() + "','" + ((UserInfo)Session["StationUser"]).U_TollStation.TS_ID + "','" + ((DataTable)ViewState["dtType"]).Rows[0]["T_ID"].ToString() + "','" + ViewState["ImgPath"].ToString() + "','" + ViewState["ImgView"].ToString() + "')";
        }
        else if (strAction == "update")
        {
            sqlStr = "update S_NewsInfo set N_Title='" + txtTitle.Text.Trim() + "',N_Content='" + strContent + "',N_From='" + txtFrom.Text.Trim() + "',N_Date='" + txtDate.Text.Trim() + "',N_ImgPath='" + ViewState["ImgPath"].ToString() + "',N_ImgView='" + ViewState["ImgView"].ToString() + "'  where N_ID='" + ViewState["nid"].ToString() + "'";
        }
        if (DBHelper.ExecuteCommand(sqlStr) > 0)
        {
            Response.Redirect(((DataTable)ViewState["dtType"]).Rows[0]["SelectURL"].ToString());
        }
    }