Exemple #1
0
        public IActionResult MDEditor_API()
        {
            string action = GetParam("action");
            string result = "";

            switch (action)
            {
            case "down":
            {
                string content = RequestEx["content"];
                Stream sm      = IOHelper.BytesToStream(Encoding.UTF8.GetBytes(content));
                //var memi = provider.Mappings[fileExt];
                return(File(sm, "text/plain", "content.md"));
            }

            case "upload":    //上传图片
            {
                var    file  = Request.Form.Files["editormd-image-file"];
                string vpath = ZLHelper.GetUploadDir_Anony("content", "md");
                string fname = function.GetRandomString(10) + "." + GetImgExt(file.FileName);
                string url   = SafeC.SaveFile(vpath, fname, file.OpenReadStream(), (int)file.Length);
                result = JsonHelper.GetJson(
                    new string[] { "success", "message", "url" },
                    new string[] { "1", "上传成功", url });
            }
            break;
            }
            return(Content(result));
        }
        protected void DownToExcel_B_Click(object sender, EventArgs e)
        {
            OfficeHelper office = new OfficeHelper();
            string       name   = ZType.ToLower().Equals("comment") ? "评论排行.xls" : "点击排行.xls";

            SafeC.DownStr(office.ExportExcel(GetDt(), "标题,点击数,评论数,录入者,录入时间"), DateTime.Now.ToString("yyyyMMdd") + "点击排行.xls", Encoding.Default);
        }
Exemple #3
0
        public IActionResult DB_Backup()
        {
            //string dbPath = !this.chBackup.Checked ? backPath : AppDomain.CurrentDomain.BaseDirectory;
            string dbname       = DBHelper.GetAttrByStr(DBCenter.DB.ConnectionString, "Initial Catalog");
            string DatabasePath = GetParam("DatabasePath").Split('.')[0];

            if (SafeC.FileNameCheck(DatabasePath))
            {
                return(WriteErr("文件名不规范"));
            }
            string savePath = "";

            if (DBHelper.IsLocalDB(HttpContext.Connection.LocalIpAddress.ToString(), System.Environment.MachineName))
            {
                savePath = function.VToP(dbPath + GetParam("DatabasePath") + ".bak");
            }
            else
            {
                savePath = "D:\\backup\\" + DatabasePath + ".bak";
            }
            string sql = "backup database [" + dbname + "] to  disk='" + savePath + "'  with  init ";

            if (!Directory.Exists(function.VToP(dbPath)))
            {
                SafeSC.CreateDir(dbPath);
            }
            SqlHelper.ExecuteSql(sql);
            return(WriteOK("数据库备份成功", "DBBackUP"));
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     //B_Admin.CheckIsLogged();
     if (!badmin.CheckLogin())
     {
         SupperGavel.Visible    = true;
         SupperGavelCon.Visible = false;
     }
     else if (badmin.CheckLogin())
     {
         B_Admin.IsSuperManage(); admintop.Visible = true;
     }
     if (!IsPostBack)
     {
         if (ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString.Contains("Data Source"))
         {
             SafeC.Cert_Update();
             ZoomLa.BLL.Install.ChangeConnStr(SafeC.Cert_Encry(SqlHelper.ConnectionString));
         }
         if (LoginCount >= 3)
         {
             function.Script(this, "EnableCode();");
         }
     }
 }
Exemple #5
0
 public static string ReadFileStr(string vpath, bool lines = false)
 {
     if (!File.Exists(function.VToP(vpath)))
     {
         return("");
     }
     return(SafeC.ReadFileStr(vpath, lines));
 }
Exemple #6
0
        public string SaveFile()
        {
            C_SFileUP model     = JsonConvert.DeserializeObject <C_SFileUP>(RequestEx["model"]);
            var       file      = Request.Form.Files["file"];
            Stream    stream    = file.OpenReadStream();
            int       conLength = (int)Request.ContentLength;
            //=================================
            string result = "";

            if (Request.ContentLength < 100 || string.IsNullOrEmpty(file.FileName))
            {
                return("");
            }
            string fname = DateTime.Now.ToString("yyyyMMddHHmm") + function.GetRandomString(4) + Path.GetExtension(file.FileName);

            switch (model.FileType)
            {
            case "img":
            {
                if (!SafeSC.IsImage(file.FileName))
                {
                    throw new Exception(Path.GetExtension(file.FileName) + "不是有效的图片格式!");
                }
                //ImgHelper imghelp = new ImgHelper();
                //if (IsCompress)//压缩与最大比只能有一个生效
                //{
                //    imghelp.CompressImg(FileUp_File.PostedFile, 1000, vpath);
                //}
                bool hasSave = false;
                //if (model.MaxWidth > 0 || model.MaxHeight > 0)
                //{
                //    System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
                //    img = imghelp.ZoomImg(img, model.MaxHeight, model.MaxWidth);
                //    result = ImgHelper.SaveImage(GetSaveDir(model.SaveType) + fname, img);
                //    hasSave = true;
                //}
                if (!hasSave)
                {
                    result = SafeC.SaveFile(GetSaveDir(model.SaveType), fname, stream, conLength);
                }
            }
            break;
                //case "office":
                //    {
                //        string[] exname = "doc|docx|xls|xlsx".Split('|');
                //        if (!exname.Contains(Path.GetExtension(file.FileName))) { throw new Exception("必须上传doc|docx|xls|xlsx格式的文件!"); return ""; }
                //        result = ZoomLa.BLL.SafeSC.SaveFile(GetSaveDir(model.SaveType), fname, stream, conLength);
                //    }
                //    break;
                //case "all":
                //default:
                //    {
                //        result = ZoomLa.BLL.SafeSC.SaveFile(GetSaveDir(model.SaveType), fname, file.OpenReadStream(), conLength);
                //    }
                //    break;
            }
            return(result);
        }
Exemple #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string base64 = Request.Form["base64_hid"];

            if (string.IsNullOrEmpty(base64))
            {
                return;
            }
            SafeC.DownFile(IOHelper.StreamToBytes(Base64ToImg(base64)), "view.png");
        }
Exemple #8
0
 protected void Save_Btn_Click(object sender, EventArgs e)
 {
     if (NowImg_Hid.Value.Equals(SourceImg_Hid.Value))
     {
         function.WriteErrMsg("请修改后再保存");
     }
     byte[] img = SafeC.ReadFileByte(NowImg_Hid.Value);
     SafeC.SaveFile(SourceImg_Hid.Value, Path.GetFileName(SourceImg_Hid.Value), img);
     function.Script(this, "AfterSave();");
 }
Exemple #9
0
        protected void Export_B_Click(object sender, EventArgs e)
        {
            OfficeHelper office = new OfficeHelper();
            DataTable    dt     = contentBll.GroupDayCount(DataConverter.CLng(Request.Form["curNid_hid"]), Convert.ToInt32(Request.Form["years"]), Convert.ToInt32(Request.Form["months"]), Convert.ToInt32(Request.Form["model"]));

            dt.Columns.Add("Date");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dt.Rows[i]["Date"] = DataConverter.CDate(dt.Rows[i]["Years"] + "-" + dt.Rows[i]["Months"] + "-" + dt.Rows[i]["Days"]).ToString("yyyy-MM-dd");;
            }
            DataTable newDt = dt.DefaultView.ToTable(false, "Date,PCount,ComCount,Hits".Split(','));

            SafeC.DownStr(office.ExportExcel(newDt, "日期,发稿量,评论数,点击数"), DateTime.Now.ToString("yyyyMMdd") + "时间统计.xls", Encoding.Default);
        }
        protected void DownExcel_Btn_Click(object sender, EventArgs e)
        {
            M_Pub_Excel excelMod = new M_Pub_Excel();
            B_Pub_Excel excelBll = new B_Pub_Excel();
            M_Pub       pubinfo  = pub.GetSelect(PubID);

            excelMod = excelBll.SelByTbName(pubinfo.PubTableName);
            if (excelMod == null)
            {
                function.WriteErrMsg("尚未为表:" + pubinfo.PubTableName + "指定导出规则,请先<a href='PubExcel.aspx?mid=" + pubinfo.PubModelID + "'>点此设定导出规则</a>");
            }
            OfficeHelper ofHelper = new OfficeHelper();

            SafeC.DownStr(ofHelper.GetExcelByDT(GetDT(), excelMod.Fields, excelMod.CNames), DateTime.Now.ToString("yyyyMMdd") + "互动信息.xls", Encoding.Default);
        }
Exemple #11
0
        public IActionResult Question_Add()
        {
            var model = new VM_Question(HttpContext);
            M_Exam_Sys_Questions questMod = Question_FillMod();

            if (Mid > 0)
            {
                questBll.GetUpdate(questMod);
            }
            else
            {
                questMod.p_id = questBll.GetInsert(questMod);
            }
            SafeC.WriteFile(questMod.GetOPDir(), RequestEx["Optioninfo_Hid"]);
            return(WriteOK("操作成功!", "QuestList?NodeID=" + model.NodeID));
        }
        public void MyBind()
        {
            NodeDPBind();
            if (!string.IsNullOrEmpty(Url))//普通页面,新浪等
            {
                string html = htmlHelper.GetHtmlFromSite(Url);
                Content_T.Text = acBll.GetArticleFromWeb(html, Url);
                Title_T.Text   = Request["Title"] == null?htmlHelper.GetTitle(html) : Request["Title"];

                SourceUrl_T.Text = Request["Source"] == null?GetSource(Url) : Request["Source"];

                Author_T.Text = Request["Author"] == null?badmin.GetAdminLogin().AdminName : Request["Author"];

                Synopsis_T.Text = DateTime.Now.ToString();
            }
            else if (!string.IsNullOrEmpty(Request.Form["cms_json_hid"]))//页面下载,视频下载等
            {
                JObject json = (JObject)JsonConvert.DeserializeObject(Request.Form["cms_json_hid"]);
                switch (json["action"].ToString())
                {
                case "downpage":
                    if (json["url"] == null || string.IsNullOrEmpty(json["url"].ToString()))
                    {
                        return;
                    }
                    string title = json["title"].ToString();
                    title = string.IsNullOrEmpty(title) ? "无标题.mht" : SafeC.RemovePathChar(title + ".mht");
                    string vpath = "/Temp/DownPage/" + title;
                    if (!Directory.Exists(Server.MapPath("/Temp/DownPage/")))
                    {
                        Directory.CreateDirectory(Server.MapPath("/Temp/DownPage/"));
                    }
                    vpath = htmlHelper.DownToMHT(json["url"].ToString(), vpath);
                    SafeSC.DownFile(vpath);
                    SafeSC.DelFile(vpath);
                    Response.End();
                    break;

                case "video":
                    Title_T.Text     = json["title"].ToString();
                    SourceUrl_T.Text = GetSource(json["url"].ToString());
                    Content_T.Text   = json["content"].ToString();
                    break;
                }
            }
        }
Exemple #13
0
        public IActionResult CSSEdit_Submit()
        {
            string CSSPath = "";

            if (!string.IsNullOrEmpty(FilePath))
            {
                CSSPath = CSSBaseDir + FilePath.Split('.')[0] + ".css";
            }
            else
            {
                string fname = GetParam("TxtFilename").Replace(" ", "").Split('.')[0];
                if (SafeC.FileNameCheck(fname))
                {
                    return(WriteErr("文件名不符合规则"));
                }
                CSSPath = CSSBaseDir + fname + ".css";
            }
            SafeSC.WriteFile(CSSPath, GetParam("textContent"));
            return(WriteOK("操作成功", "CSSManage"));
        }
Exemple #14
0
        static DBCenter()
        {
            //根据类型,初始化不同的辅助类,和读取连接字符串
            string dbtype = ConfigurationManager.AppSettings["DBType"];

            if (string.IsNullOrEmpty(dbtype))
            {
                dbtype = "mssql";
            }
            DB = SqlBase.CreateHelper(dbtype);
            switch (dbtype)//为多数据库读取
            {
            case "oracle":
                DB.ConnectionString = ConfigurationManager.ConnectionStrings["OraConnection String"].ConnectionString;
                break;

            default:
                DB.ConnectionString = SafeC.Cert_Decry(ConfigurationManager.ConnectionStrings["Connection String"].ConnectionString);
                break;
            }
        }
Exemple #15
0
 private string SafeValue(string result)
 {
     if (!string.IsNullOrEmpty(result))
     {
         result = HttpUtility.UrlDecode(result);
         result = result.Replace(" ", "").Replace(".", "");
         if (SafeC.CheckData(result))
         {
             result = "";
         }
         result = HttpUtility.HtmlEncode(result);
         if (result.Length > 20)
         {
             result = "";
         }
     }
     else
     {
         result = "";
     }
     return(result);
 }
Exemple #16
0
    /// <summary>
    /// 将字符串转换为图片,用于水印
    /// </summary>
    /// <imgvpath>生成的文字水印图片存储位置</imgvpath>
    /// <FontModel>字体模型,包含文本,字体颜色,大小等</imgvpath>
    /// <returns></returns>
    public static System.Drawing.Image ConverFontToImg(string imgvpath, FontModel model)
    {
        int width  = model.intsize * model.text.Length * 2;
        int height = model.intsize * 2;
        //-----------根据指定宽高,生成图片
        string imgppath = function.VToP(imgvpath);

        SafeC.CreateDir(imgvpath);
        //System.Drawing.Image image, image2 = System.Drawing.Image.FromFile(imgppath);
        System.Drawing.Image image = new Bitmap(width, height);
        Graphics             g     = Graphics.FromImage(image);

        //g.FillRectangle(new SolidBrush(Color.FromArgb(model.GetRGB(model.background, "red"), model.GetRGB(model.background, "yellow"), model.GetRGB(model.background, "blue"))), 0, 0, width, height); //背景色
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        //------------指定文字与字体样式
        FontStyle fs     = FontStyle.Regular;
        Font      f      = new Font(model.family, model.intsize, fs);
        SizeF     crSize = g.MeasureString(model.text, f);
        //string color = "0x" + "#333333".Replace("#", "");
        //SolidBrush b = new SolidBrush(Color.FromArgb(255, Color.FromArgb(Convert.ToInt32(color, 16))));//定义字体画笔
        SolidBrush   b         = new SolidBrush(Color.FromArgb(model.GetRGB(model.color, "red"), model.GetRGB(model.color, "yellow"), model.GetRGB(model.color, "blue")));
        StringFormat StrFormat = new StringFormat();
        int          ap        = 40;//透明度

        if (ap > 100 || ap < 0)
        {
            ap = 100;
        }
        int        m_alpha = 255 * (ap / 100);
        int        posx = 3, posy = 3;//文字的起始位置
        SolidBrush semiTransBrush2 = new SolidBrush(Color.FromArgb(m_alpha, 0, 0, 0));

        g.DrawString(model.text, f, semiTransBrush2, new PointF(posx + 1, posy + 1), StrFormat);    //?无用
        g.DrawString(model.text, f, b, new PointF(posx, posy), StrFormat);
        g.Dispose();
        return(image);
    }
Exemple #17
0
        protected void GetPic_Btn_Click(object sender, EventArgs e)
        {
            //http://h.hiphotos.baidu.com/zhidao/wh%3D450%2C600/sign=3dc4538262d0f703e6e79dd83dca7d0b/7a899e510fb30f24f570e996c895d143ac4b03b8.jpg
            if (string.IsNullOrEmpty(Remote_Url.Text))
            {
                return;
            }
            string vdir    = SiteConfig.SiteOption.UploadDir;
            M_Node nodeMod = new B_Node().GetNodeXML(DataConverter.CLng(NodeID_Hid.Value));

            vdir += nodeMod.NodeDir + "/" + DateTime.Now.ToString("yyyy/MM/");
            //-------------------
            string[] imgurl = Remote_Url.Text.Split('\r');
            string   result = "";

            for (int i = 0; i < imgurl.Length; i++)
            {
                string imgname = GetFNameFromUrl(imgurl[i]);
                if (!SafeC.IsImage(imgname))
                {
                    continue;
                }
                string url = imgurl[i].ToLower().Replace(" ", "");
                if (string.IsNullOrEmpty(url) || (!url.Contains("http") && !url.Contains("https")))
                {
                    continue;
                }                                                                                                //function.WriteErrMsg("错误:" + url);
                string vpath = vdir + RemoveChar(imgname);
                try { httpHelper.DownFile(url, vpath); }
                catch (Exception) { }//function.WriteErrMsg("抓取失败,原因:" + ex.Message);
                result += vpath + "|";
            }
            result          = result.TrimEnd('|').Replace("//", "/");
            Remote_Url.Text = "";
            function.Script(this, "AddAttach('" + result + "');");
        }
Exemple #18
0
        protected void ExportExcel_B_Click(object sender, EventArgs e)
        {
            OfficeHelper helper = new OfficeHelper();
            DataTable    dt     = orderBll.IDC_Sel((int)M_OrderList.OrderEnum.IDC, souchtable.SelectedValue, souchkey.Text, OrderBy, SelType);

            dt.Columns.Add("UserName");
            dt.Columns.Add("IsExpire"); //是否过期
            dt.Columns.Add("OStatus");  //状态
            dt.Columns.Add("PStatus");  //财务
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                dr["UserName"] = GetUsers(dr["UserID"].ToString());
                dr["Domain"]   = dr["Domain"].ToString().ToLower().Replace("www.", "");
                dr["STime"]    = DataConvert.CDate(dr["STime"]).ToString("yyyy-MM-dd");
                dr["ETime"]    = DataConvert.CDate(dr["ETime"]).ToString("yyyy-MM-dd");
                dr["OStatus"]  = RemoveHtml(formatzt(dr["OrderStatus"].ToString(), "0"));
                dr["PStatus"]  = RemoveHtml(formatzt(dr["Paymentstatus"].ToString(), "1"));
            }
            DataTable newDt      = dt.DefaultView.ToTable(false, "ID,OrderNo,Domain,UserName,Proname,STime,ETime,IsExpire,OStatus,PStatus".Split(','));
            string    columnames = "ID,订单号,绑定域名,会员,商品名称,生效时间,到期时间,是否到期,状态,财务";

            SafeC.DownStr(helper.ExportExcel(newDt, columnames), DateTime.Now.ToString("yyyyMMdd") + "IDC订单表.xls", Encoding.UTF8);
        }
        public string GetAttach(string attach)
        {
            string imgresult = "", attachresult = "";
            int    max = 3;

            foreach (string file in attach.Split('|'))
            {
                if (string.IsNullOrEmpty(file))
                {
                    continue;
                }
                if (SafeC.IsImage(file) && max > 0)//jpg,png,gif图片显示预览,只显示前三张
                {
                    imgresult += string.Format(imgTlp, Mid, file); max--;
                }
                else
                {
                    string fname = Path.GetFileName(file); fname = fname.Length > 6 ? fname.Substring(0, 6) + ".." : fname;
                    attachresult += string.Format(attachTlp, file, Path.GetExtension(file).ToLower().Replace(".", ""), fname);
                }
            }
            imgresult = string.IsNullOrEmpty(imgresult) ? "" : "<div class='thumbnail_div'>" + imgresult + "</div>";
            return(imgresult + attachresult + "<div class='clearfix'></div>");
        }
Exemple #20
0
    protected void Page_Load(object sender, EventArgs e)
    {
        B_Admin.CheckIsLogged();
        if (function.isAjax())
        {
            string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径
            if (vpath.Contains("?"))
            {
                vpath = vpath.Substring(0, vpath.IndexOf("?"));
            }
            switch (action)
            {
            case "crop":    //根据提交的图片路径与宽度等参数,完成剪切
                int x1     = int.Parse(Request.Form["x1"]);
                int y1     = int.Parse(Request.Form["y1"]);
                int width  = int.Parse(Request.Form["width"]);
                int height = int.Parse(Request.Form["height"]);
                savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
                break;

            case "fontwater":    //文字水印
            {
                System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg");
                savePath += "fontw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
                result   += "?" + function.GetRandomString(6);
            }
            break;

            case "imgwater":    //水印图片路径
            {
                string watervpath = Request.Form["watervpath"];
                int    trans      = DataConverter.CLng(Request.Form["trans"]);
                savePath += "imgw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans);
                result   += "?" + function.GetRandomString(6);
            }
            break;
            }
            Response.Write(result); Response.Flush(); Response.End();
        }
        if (!IsPostBack)
        {
            if (string.IsNullOrEmpty(IPath) || !SafeC.IsImage(IPath))
            {
                function.WriteErrMsg("只允许编辑图片文件!");
            }
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(Server.MapPath(savePath));
            }
            if (!File.Exists(Server.MapPath(IPath)))
            {
                function.WriteErrMsg("需要修改的图片" + IPath + "不存在");
            }
            NowImg_Hid.Value = SourceImg_Hid.Value = IPath;
            RPT.DataSource   = GetWaterImgDT();
            RPT.DataBind();
            //string warning;
            //----剪切图
            //vpath = ImageDealLib.imgcrop("/test/222.jpg", "/test/", 200, 200, 200, 200, ImageDealLib.FileCache.Save, out warning);
            //function.WriteErrMsg(vpath);
            //----生成水印
            //string watervpath = AddFontWater();
            //ImageDealLib.makewatermark("/test/222.jpg", "/test/usbqyr.jpg", ImageDealLib.WaterType.RightDown, "/test/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
            //----我们的水印
            //WaterImages water = new WaterImages();
            //string localPath = Server.MapPath("/test/222.jpg");
            //string tempurl = Server.MapPath("/test/watered12.jpg");
            //water.DrawImage(localPath, function.VToP("/Images/admin_logo.jpg"), tempurl);
        }
    }
Exemple #21
0
 public static string PathDeal(string path)
 {
     return(SafeC.PathDeal(path));
 }
Exemple #22
0
        protected void Export_Click(object sender, EventArgs e)
        {
            OfficeHelper office = new OfficeHelper();

            SafeC.DownStr(office.ExportExcel(SelDT(), "编辑,发稿量,评论量,点击数"), DateTime.Now.ToString("yyyyMMdd") + "编辑统计.xls", Encoding.Default);
        }
 //生成证书,并写入连接字符串
 private void WriteConnstr(string connstr)
 {
     SafeC.Cert_Update();
     connstr = SafeC.Cert_Encry(connstr);
     ZoomLa.BLL.Install.ChangeConnStr(connstr);
 }
Exemple #24
0
 public static string WriteFile(string vpath, string content)
 {
     return(SafeC.WriteFile(vpath, content));
 }
Exemple #25
0
 public static void DirPathDel(ref string vpath)
 {
     SafeC.DirPathDel(ref vpath);
 }
Exemple #26
0
 /// <summary>
 /// SafeSC.SaveFile(Path.GetDirectoryName(strFileName) + "\\", Path.GetFileName(strFileName), bytes);
 /// </summary>
 public static string SaveFile(string vpath, string fileName, byte[] file)
 {
     return(SafeC.SaveFile(vpath, fileName, file));
 }
Exemple #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        buser.CheckIsLogin();
        if (function.isAjax())
        {
            string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径
            if (vpath.Contains("?"))
            {
                vpath = vpath.Substring(0, vpath.IndexOf("?"));
            }
            switch (action)
            {
            case "crop":    //根据提交的图片路径与宽度等参数,完成剪切
            {
                int x1     = int.Parse(Request.Form["x1"]);
                int y1     = int.Parse(Request.Form["y1"]);
                int width  = int.Parse(Request.Form["width"]);
                int height = int.Parse(Request.Form["height"]);
                savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
            }
            break;

            case "rotate":
            {
                int    angle = DataConverter.CLng(Request.Form["angle"]);
                Bitmap bmp   = imgHelper.Rotate(vpath, angle);
                savePath += function.GetRandomString(6) + Path.GetExtension(vpath);
                result    = imgHelper.SaveImg(savePath, bmp);
                bmp.Dispose();
            }
            break;

            case "zoom":    //缩放
            {
                int width  = int.Parse(Request.Form["width"]);
                int height = int.Parse(Request.Form["height"]);
                savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                Bitmap bmp = imgHelper.ZoomImg(vpath, height, width);
                result = imgHelper.SaveImg(savePath, bmp);
            }
            break;

            case "fontwater":    //文字水印
            {
                System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg");
                savePath += "fontw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
                result   += "?" + function.GetRandomString(6);
            }
            break;

            case "imgwater":    //水印图片路径
            {
                string watervpath = Request.Form["watervpath"];
                int    trans      = DataConverter.CLng(Request.Form["trans"]);
                savePath += "imgw_" + Path.GetFileName(vpath);
                result    = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans);
                result   += "?" + function.GetRandomString(6);
            }
            break;
            }
            Response.Write(result); Response.Flush(); Response.End();
        }
        if (!IsPostBack)
        {
            M_UserInfo mu       = buser.GetLogin();
            string     ipath    = Request.QueryString["ipath"].ToLower().Replace("/uploadfiles/user/", "");
            string     UserPath = "/UploadFiles/User/" + mu.UserName + mu.UserID + "/" + ipath.TrimStart('/');//不做过多的限制,如需要文件安全,则使用单独的文件服务器
            if (string.IsNullOrEmpty(UserPath) || !SafeC.IsImage(UserPath))
            {
                function.WriteErrMsg("只允许编辑图片文件!");
            }
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(Server.MapPath(savePath));
            }
            if (!File.Exists(Server.MapPath(UserPath)))
            {
                function.WriteErrMsg("需要修改的图片" + UserPath + "不存在");
            }
            NowImg_Hid.Value = SourceImg_Hid.Value = UserPath;
            System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(UserPath));
            ImgWidth_Hid.Value  = img.Width.ToString();
            ImgHeight_Hid.Value = img.Height.ToString();
            RPT.DataSource      = GetWaterImgDT();
            RPT.DataBind();
            img.Dispose();
            //string warning;
            //----剪切图
            //vpath = ImageDealLib.imgcrop("/test/222.jpg", "/test/", 200, 200, 200, 200, ImageDealLib.FileCache.Save, out warning);
            //function.WriteErrMsg(vpath);
            //----生成水印
            //string watervpath = AddFontWater();
            //ImageDealLib.makewatermark("/test/222.jpg", "/test/usbqyr.jpg", ImageDealLib.WaterType.RightDown, "/test/", ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
            //----我们的水印
            //WaterImages water = new WaterImages();
            //string localPath = Server.MapPath("/test/222.jpg");
            //string tempurl = Server.MapPath("/test/watered12.jpg");
            //water.DrawImage(localPath, function.VToP("/Images/admin_logo.jpg"), tempurl);
        }
    }
Exemple #28
0
 public static string SaveFile(string vpath, FileUpload file, string fileName = "")
 {
     return(SafeC.SaveFile(vpath, file, fileName));
 }
Exemple #29
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (B_Admin.GetLogin() == null)
            {
                B_User.CheckIsLogged();
            }
            else
            {
                B_Admin.CheckIsLogged();
            }
            if (function.isAjax())
            {
                string action = Request.Form["action"], vpath = Request.Form["vpath"], result = "", warning = "";//动作,需要加水印的图片路径
                if (vpath.Contains("?"))
                {
                    vpath = vpath.Substring(0, vpath.IndexOf("?"));
                }
                switch (action)
                {
                case "crop":    //根据提交的图片路径与宽度等参数,完成剪切
                {
                    int x1     = int.Parse(Request.Form["x1"]);
                    int y1     = int.Parse(Request.Form["y1"]);
                    int width  = int.Parse(Request.Form["width"]);
                    int height = int.Parse(Request.Form["height"]);
                    savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                    result    = ImageDealLib.imgcrop(vpath, savePath, x1, y1, width, height, ImageDealLib.FileCache.Save, out warning);
                }
                break;

                case "rotate":
                {
                    int    angle = DataConverter.CLng(Request.Form["angle"]);
                    Bitmap bmp   = imgHelper.Rotate(vpath, angle);
                    savePath += function.GetRandomString(6) + Path.GetExtension(vpath);
                    result    = imgHelper.SaveImg(savePath, bmp);
                    bmp.Dispose();
                }
                break;

                case "zoom":    //缩放
                {
                    int width  = int.Parse(Request.Form["width"]);
                    int height = int.Parse(Request.Form["height"]);
                    savePath += (function.GetRandomString(4) + Path.GetFileName(vpath));
                    Bitmap bmp = imgHelper.ZoomImg(vpath, height, width);
                    result = imgHelper.SaveImg(savePath, bmp);
                }
                break;

                case "fontwater":    //文字水印
                {
                    System.Drawing.Image fontimg = AddFontWater(savePath + function.GetRandomString(6) + ".jpg");
                    savePath += "fontw_" + Path.GetFileName(vpath);
                    result    = ImageDealLib.makewatermark(vpath, fontimg, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning);
                    result   += "?" + function.GetRandomString(6);
                }
                break;

                case "imgwater":    //水印图片路径
                {
                    string watervpath = Request.Form["watervpath"];
                    int    trans      = DataConverter.CLng(Request.Form["trans"]);
                    savePath += "imgw_" + Path.GetFileName(vpath);
                    result    = ImageDealLib.makewatermark(vpath, watervpath, GetWaterType(Request.Form["pos"]), savePath, ImageDealLib.ImageType.JPEG, ImageDealLib.FileCache.Save, out warning, trans);
                    result   += "?" + function.GetRandomString(6);
                }
                break;
                }
                Response.Write(result); Response.Flush(); Response.End();
            }
            if (!IsPostBack)
            {
                if (string.IsNullOrEmpty(IPath) || !SafeC.IsImage(IPath))
                {
                    function.WriteErrMsg("只允许编辑图片文件!");
                }
                if (!Directory.Exists(Server.MapPath(savePath)))
                {
                    Directory.CreateDirectory(Server.MapPath(savePath));
                }
                if (!File.Exists(Server.MapPath(IPath)))
                {
                    function.WriteErrMsg("需要修改的图片" + IPath + "不存在");
                }
                NowImg_Hid.Value = SourceImg_Hid.Value = IPath;
                System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(IPath));
                ImgWidth_Hid.Value  = img.Width.ToString();
                ImgHeight_Hid.Value = img.Height.ToString();
                RPT.DataSource      = GetWaterImgDT();
                RPT.DataBind();
                img.Dispose();
            }
        }
Exemple #30
0
 public static string SaveFile(string vpath, HttpPostedFile file, string fileName = "")
 {
     return(SafeC.SaveFile(vpath, file, fileName));
 }