Example #1
0
    private void UploadFileCommon(FileUpload fileUpload1, string tag, string dateName, string wihe)
    {
        string url = "http://qijia.7fshop.com/detail/";

        if (CheckFileIsSave(fileUpload1))
        {
            Jia_ImgCustomer imgCus  = new Jia_ImgCustomer();
            Guid            imgId   = Guid.NewGuid();
            string          picName = dateName + "/" + imgId + ".jpg";
            //保存原图
            fileUpload1.PostedFile.SaveAs(Server.MapPath(picName));
            string picsName = "~/temp/" + imgId + "_s.jpg";

            //生成合理尺寸图(对照模板)
            string[] widhei = wihe.Split('*');
            HttpUtil.MakeThumbnail(picName, Server.MapPath(picsName), int.Parse(widhei[0]), int.Parse(widhei[1]), "Cut");
            imgCus.ItemId = id;
            imgCus.Tag    = tag;
            imgCus.Guid   = Guid.NewGuid().ToString();
            imgCus.MyImg  = url + picName;

            imgCus.JiaImg = "http://qijia.7fshop.com/temp/" + imgId + "_s.jpg";

            //发送图片到齐家网站
            List <Parameter> list     = new List <Parameter>();
            Parameter        paramter = new Parameter("image", Server.MapPath(picsName));
            list.Add(paramter);
            try
            {
                string   realUrl = UploadFile.HttpPostWithFile("http://mall.jia.com/site/upload_describe_image", "", list);
                string[] chars   = Regex.Split(realUrl, "=>");

                imgCus.JiaImg = chars[2].Replace(")", "").Trim();
            }
            catch (Exception ex)
            {
                LogHelper.LogInfo.Add("用户上传图片错误", ex.Message);
            }

            //可做删除生成的图片操作(暂未做)

            string    sql = "SELECT * FROM Jia_ImgCustomer WHERE ItemId = '" + id + "' AND tag = '" + tag + "'";
            DataTable dt  = DBHelper.ExecuteDataTable(sql);
            if (dt.Rows.Count == 0)
            {
                icDal.AddJia_ImgCustomer(imgCus);
            }
            else
            {
                imgCus.Guid = dt.Rows[0]["guid"].ToString();
                icDal.ModifyJia_ImgCustomer(imgCus);
            }
        }
    }
Example #2
0
    private void UploadFileArray(List <FileUpload> list, List <string> sizeList, string dateName)
    {
        string url = "http://qijia.7fshop.com/detail/";
        IList <Jia_ImgCustomer> cList       = new List <Jia_ImgCustomer>();
        List <string>           picList     = new List <string>();
        List <string>           realPicList = new List <string>();

        for (int i = 1; i < 7; i++)
        {
            if (CheckFileIsSave(list[i - 1]))
            {
                Jia_ImgCustomer imgCus  = new Jia_ImgCustomer();
                Guid            imgId   = Guid.NewGuid();
                string          picName = dateName + "/" + imgId + ".jpg";
                //保存原图
                list[i - 1].PostedFile.SaveAs(Server.MapPath(picName));
                string picsName = "~/temp/" + imgId + "_s.jpg";

                //生成合理尺寸图(对照模板)
                string[] widhei = sizeList[i - 1].Split('*');
                HttpUtil.MakeThumbnail(picName, Server.MapPath(picsName), int.Parse(widhei[0]), int.Parse(widhei[1]), "Cut");
                imgCus.ItemId = id;
                imgCus.Tag    = "{item" + i + "}";
                imgCus.Guid   = Guid.NewGuid().ToString();
                //imgCus.MyImg = url + picName;

                imgCus.JiaImg = "http://qijia.7fshop.com/temp/" + imgId + "_s.jpg";

                picList.Add(Server.MapPath(picsName));
                cList.Add(imgCus);
                realPicList.Add(imgCus.JiaImg);

                //可做删除生成的图片操作(暂未做)
            }
        }

        //发送图片到齐家网站
        List <Parameter> pList = new List <Parameter>();

        for (int i = 1; i <= picList.Count; i++)
        {
            Parameter paramter = new Parameter("image" + i, picList[i - 1]);
            pList.Add(paramter);
        }
        try
        {
            string realUrl = UploadFile.HttpPostWithFile("http://mall.jia.com/site/upload_describe_image", "", pList);
            LogHelper.LogInfo.Add("图片集合", realUrl);
            string[] chars = Regex.Split(realUrl, @"\[\d+\] =>");

            for (int i = 1; i < chars.Length; i++)
            {
                if (chars[i].Contains("http://"))
                {
                    string JiaImg = chars[i].Replace(")", "").Trim();
                    realPicList[i - 1] = JiaImg;
                }
            }
        }
        catch (Exception ex)
        {
            LogHelper.LogInfo.Add("用户上传图片错误", ex.Message);
        }

        for (int i = 0; i < cList.Count; i++)
        {
            cList[i].JiaImg = realPicList[i];
            string    sql = "SELECT * FROM Jia_ImgCustomer WHERE ItemId = '" + id + "' AND tag = '" + cList[i].Tag + "'";
            DataTable dt  = DBHelper.ExecuteDataTable(sql);
            if (dt.Rows.Count == 0)
            {
                icDal.AddJia_ImgCustomer(cList[i]);
            }
            else
            {
                cList[i].Guid = dt.Rows[0]["guid"].ToString();
                icDal.ModifyJia_ImgCustomer(cList[i]);
            }
        }
    }