Ejemplo n.º 1
0
        public override BaseResult Add(dynamic entity)
        {
            Tb_User_Pic pic   = (Tb_User_Pic)entity;
            Hashtable   param = new Hashtable();

            param.Add("id_master", pic.id_master);
            IList <Tb_User_Pic> lst = DAL.QueryList <Tb_User_Pic>(typeof(Tb_User_Pic), param) ?? new List <Tb_User_Pic>();

            if (lst.Count > 0)
            {
                pic.xh = Convert.ToByte(lst.Max(m => m.xh) + 1);
            }
            else
            {
                pic.xh = 1;
            }
            BaseResult br = new BaseResult();

            if (pic != null)
            {
                DAL.Add(pic);
                br.Success = true;
                br.Message.Add("上传图片成功");
            }
            return(br);
        }
Ejemplo n.º 2
0
        public ActionResult UploadPic(string obj)
        {
            BaseResult  br    = new BaseResult();
            Hashtable   param = JSON.Deserialize <Hashtable>(obj);
            ParamVessel p     = new ParamVessel();

            p.Add("id_master", (long)0, HandleType.ReturnMsg);
            param = param.Trim(p);
            try
            {
                HttpPostedFileBase postedFile = Request.Files.Count > 0 ? Request.Files[0] : null;
                if (postedFile == null || postedFile.ContentLength <= 0)
                {
                    br.Success = false;
                    br.Level   = ErrorLevel.Error;
                    br.Message.Add("<h5>上传失败</h5>");
                    br.Message.Add("");
                    br.Message.Add("未发现上传的文件!");
                    return(Json(br));
                }
                if (!CyVerify.IsImage(postedFile.InputStream))
                {
                    br.Success = false;
                    br.Message.Add("<h5>上传失败</h5>");
                    br.Message.Add("");
                    br.Message.Add("上传的文件格式不正确,必须图片文件!");
                    br.Level = ErrorLevel.Warning;
                    return(Json(br));
                }
                Tb_User_Pic pic          = new Tb_User_Pic();
                string      guid         = Guid.NewGuid().ToString();
                string      extension    = Path.GetExtension(postedFile.FileName);
                string      fileName     = guid + extension;                  //文件名
                string      url          = "/UpLoad/User/Master/" + fileName; //存入数据库中的图片路径
                string      fileFullName = ApplicationInfo.UserMasterPath + "\\" + fileName;
                if (!Directory.Exists(ApplicationInfo.UserMasterPath))
                {
                    Directory.CreateDirectory(ApplicationInfo.UserMasterPath);
                }
                //上传原图
                postedFile.SaveAs(fileFullName);
                //生成缩略图至UpLoad/Master下
                string minUrl = "/UpLoad/User/Master/_480x480_" + fileName;
                ImgExtension.MakeThumbnail(url, minUrl, 480, 480, ImgCreateWay.Cut, false);
                pic.id_master = long.Parse(param["id_master"].ToString());
                pic.id_create = GetLoginInfo <long>("id_user");
                pic.photo     = url;
                pic.photo_min = minUrl;
                br            = BusinessFactory.UserPic.Add(pic);
                br.Data       = url;
                br.Success    = true;
            }
            catch (CySoftException cex)
            {
                br = cex.Result;
            }
            catch (Exception)
            {
                br.Success = false;
                br.Level   = ErrorLevel.Error;
                br.Message.Add("<h5>上传失败</h5>");
                br.Message.Add("");
                br.Message.Add("请重试或与管理员联系!");
            }
            return(Json(br));
        }
Ejemplo n.º 3
0
        public override BaseResult Update(dynamic entity)
        {
            BaseResult    br    = new BaseResult();
            Hashtable     param = new Hashtable();
            Tb_User_Query model = (Tb_User_Query)entity;
            //if (!model.email.IsEmpty() && model.email != model.email_old)
            //{
            //    param.Clear();
            //    param.Add("not_id", model.id);
            //    param.Add("email", model.email);
            //    if (DAL.GetCount(typeof(Tb_User), param) > 0)
            //    {
            //        br.Success = true;
            //        br.Message.Add("此邮箱已被占用");
            //        br.Level = ErrorLevel.Warning;
            //        br.Data = "email";
            //        return br;
            //    }
            //}
            DateTime dbDateTime = DAL.GetDbDateTime();

            param.Clear();
            param.Add("id", model.id);
            param.Add("new_companyname", model.companyname);
            //param.Add("new_id_hy", model.id_hy);
            param.Add("new_id_province", model.id_province);
            param.Add("new_id_city", model.id_city);
            param.Add("new_id_county", model.id_county);
            param.Add("new_address", model.address);
            param.Add("new_zipcode", model.zipcode);
            param.Add("new_tel", model.tel);
            param.Add("new_fax", model.fax);
            //param.Add("new_location", model.location);
            //param.Add("new_pic_erwei", model.pic_erwei);
            //param.Add("new_name", model.name);
            //param.Add("new_job", model.job);
            //param.Add("new_phone", model.phone);
            //param.Add("new_qq", model.qq);
            //param.Add("new_email", model.email);
            param.Add("new_id_edit", model.id_edit);
            param.Add("new_rq_edit", dbDateTime);
            DAL.UpdatePart(typeof(Tb_User), param);
            //图片上传
            if (model.picUrl != null && model.picUrl.Count > 0)
            {
                Tb_User_Pic pic;
                int         xh = 0;
                //获取图册结果集
                param.Clear();
                param.Add("id_master", model.id_master);
                IList <Tb_User_Pic> lst = DAL.QueryList <Tb_User_Pic>(typeof(Tb_User_Pic), param) ?? new List <Tb_User_Pic>();
                if (lst.Count > 0)
                {
                    xh = Convert.ToInt32(lst[lst.Count - 1].xh);  //取最大的序号
                }
                foreach (var url in model.picUrl)
                {
                    //只添加新上传的图片
                    if (url.Contains("Temp"))
                    {
                        pic = new Tb_User_Pic();
                        string[] url_img   = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                        string   guid      = Guid.NewGuid().ToString();
                        string   extension = Path.GetExtension(url_img[url_img.Length - 1]); //取图片后缀名
                        string   fileName  = guid + extension;                               //文件名

                        // 复制原图到 Master 文件夹下
                        FileExtension.Copy(System.Web.HttpContext.Current.Server.MapPath(url), System.Web.HttpContext.Current.Server.MapPath("/UpLoad/User/Master/" + fileName));
                        //生成缩略图至UpLoad/Master下
                        ImgExtension.MakeThumbnail(url, "/UpLoad/User/Master/_480x480_" + fileName, 480, 480, ImgCreateWay.Cut, false);
                        pic.photo     = string.Format("/UpLoad/User/Master/{0}", fileName);
                        pic.photo_min = string.Format("/UpLoad/User/Master/_480x480_{0}", fileName);
                        //pic.id_create = model.id;
                        pic.id_master = model.id_master;
                        xh++;
                        pic.xh = Convert.ToByte(xh);
                        DAL.Add(pic);
                    }
                }
            }

            br.Success = true;
            br.Message.Add(String.Format("更新公司信息。信息:流水号:{0},公司名称:{1}", model.id, model.companyname));
            return(br);
        }