コード例 #1
0
ファイル: BD_ImageList.cs プロジェクト: kkwkk/ybyzt
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Hi.Model.BD_ImageList model)
 {
     return(dal.Add(model));
 }
コード例 #2
0
ファイル: BD_ImageList.cs プロジェクト: kkwkk/ybyzt
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Hi.Model.BD_ImageList model)
 {
     return(dal.Update(model));
 }
コード例 #3
0
    public Dis_Order_Version3.ResultEdit UpGoodsPic(String JSon)
    {
        string UserID      = string.Empty;
        string CompID      = string.Empty;
        string StringImage = string.Empty;
        string FileName    = string.Empty;
        string GoodID      = string.Empty;

        try
        {
            #region//JSon取值
            JsonData JInfo = JsonMapper.ToObject(JSon);
            if (JInfo["UserID"].ToString().Trim() == "" || JInfo["CompID"].ToString().Trim() == "" ||
                JInfo["StringImage"].ToString().Trim() == "" || JInfo["FileName"].ToString().Trim() == "" || JInfo["GoodID"].ToString().Trim() == "")
            {
                return(new Dis_Order_Version3.ResultEdit()
                {
                    Result = "F", Description = "参数异常"
                });
            }
            UserID      = JInfo["UserID"].ToString();
            CompID      = JInfo["CompID"].ToString();
            StringImage = JInfo["StringImage"].ToString();
            FileName    = Common.NoHTML(JInfo["FileName"].ToString());
            GoodID      = JInfo["GoodID"].ToString();
            //判断登录信息是否异常
            Hi.Model.SYS_Users one = new Hi.Model.SYS_Users();
            if (!new Common().IsLegitUser(int.Parse(UserID), out one, Int32.Parse(CompID)))
            {
                return(new Dis_Order_Version3.ResultEdit()
                {
                    Result = "F", Description = "登录信息异常"
                });
            }
            //判断核心企业信息是否异常
            Hi.Model.BD_Company comp = new Hi.BLL.BD_Company().GetModel(Int32.Parse(CompID));
            if (comp == null || comp.dr == 1 || comp.IsEnabled == 0 || comp.AuditState == 0)
            {
                return new Dis_Order_Version3.ResultEdit()
                       {
                           Result = "F", Description = "核心企业信息异常"
                       }
            }
            ;
            #endregion

            string ext = FileName.Substring(FileName.LastIndexOf("."));
            if (!(ext.ToUpper() == ".JPG" || ext.ToUpper() == ".PNG" || ext.ToUpper() == ".JPEG"))
            {
                return new Dis_Order_Version3.ResultEdit()
                       {
                           Result = "F", Description = "图片格式不正确"
                       }
            }
            ;
            string        ImgFolder = "GoodsImg/";
            string        name      = Guid.NewGuid().ToString() + ext;
            string        path      = GetWebConfigKey("ImgPath") + ImgFolder;
            string        viewPath  = GetWebConfigKey("ImgViewPath") + ImgFolder;
            DirectoryInfo di        = new DirectoryInfo(path);
            if (!di.Exists)
            {
                di.Create();
            }
            DirectoryInfo di2 = new DirectoryInfo(GetWebConfigKey("ImgPath") + "PicSpace/" + CompID);
            if (!di2.Exists)
            {
                di2.Create();
            }
            string     toFileName = name;
            string     saveFile   = path + "D" + toFileName;
            byte[]     b          = Convert.FromBase64String(StringImage);
            FileStream fs         = new FileStream(saveFile, FileMode.Create, FileAccess.Write);
            fs.Write(b, 0, b.Length);
            fs.Flush();
            fs.Close();

            ////单独保存图片
            string ThumbPath = GetWebConfigKey("ImgPath") + "PicSpace/" + CompID + "/" + FileName;
            //HttpFile.SaveAs(ThumbPath);
            //大缩略图
            string bigThumbPath = path + "X" + toFileName;
            MakeThumbnail(saveFile, bigThumbPath, 400, 400, "Cut");
            //小缩略图
            string smallThumbPath = path + toFileName;
            MakeThumbnail(saveFile, smallThumbPath, 200, 200, "Cut");

            FileStream fs1 = new FileStream(ThumbPath, FileMode.Create, FileAccess.Write);
            fs1.Write(b, 0, b.Length);
            fs1.Flush();
            fs1.Close();
            //新增一条BD_ImageList数据
            Hi.Model.BD_ImageList modelImg = new Hi.Model.BD_ImageList();
            modelImg.CompID       = comp.ID;
            modelImg.GoodsID      = Int32.Parse(GoodID);
            modelImg.Pic          = toFileName;
            modelImg.Pic2         = "X" + toFileName;
            modelImg.Pic3         = "D" + toFileName;
            modelImg.IsIndex      = 0;
            modelImg.CreateDate   = DateTime.Now;
            modelImg.CreateUserID = Int32.Parse(UserID);
            modelImg.ts           = DateTime.Now;
            modelImg.modifyuser   = Int32.Parse(UserID);
            if (new Hi.BLL.BD_ImageList().Add(modelImg) <= 0)
            {
                return new Dis_Order_Version3.ResultEdit()
                       {
                           Result = "F", Description = "图片上传失败"
                       }
            }
            ;
        }
        catch (Exception ex)
        {
            Common.CatchInfo(ex.Message + ":" + ex.StackTrace, "UpGoodsPic:" + JSon);
            return(new Dis_Order_Version3.ResultEdit()
            {
                Result = "F", Description = "图片上传失败"
            });
        }

        return(new Dis_Order_Version3.ResultEdit()
        {
            Result = "T", Description = "图片上传成功"
        });
    }