Ejemplo n.º 1
0
        public ActionResult AjaxUpdateStatus(string channelNo, string status)
        {
            SWfsChannelService service = new SWfsChannelService();
            SWfsChannel        channel = service.GetChannelInfo(channelNo);

            channel.Status = Convert.ToInt16(status == "1" ? "0" : "1");
            try
            {
                service.UpdateStatus(channel);

                #region 日志信息
                SWfsSubjectService      channelService = new SWfsSubjectService();
                SWfsSubjectOrChannelLog log            = new SWfsSubjectOrChannelLog();
                log.SubjectOrChannelNo = channelNo;
                log.TypeValue          = 1; //1频道
                log.DateOperator       = DateTime.Now;
                log.OperatorContent    = (status.Equals("1") ? "关闭频道" : "开启频道");
                log.OperatorUserId     = PresentationHelper.GetPassport().UserName;
                log.OperatorActionType = LogActionType.Edit.GetHashCode();
                channelService.InsertSubjectOrChannelLog(log);
                #endregion

                string str = status == "0" ? "开启成功!" : "关闭成功!";
                return(Json(new { result = "1", message = str }));
            }
            catch (Exception ex)
            {
                return(Json(new { result = "0", message = ex.Message }));
            }
        }
Ejemplo n.º 2
0
        private string ValidSubject(string[] tempNoArry)
        {
            SWfsSubjectService subjectService = new SWfsSubjectService();
            SubjectInfo        subjectModel   = null;

            foreach (var item in tempNoArry)
            {
                subjectModel = subjectService.GetSubjectInfo(item);
                if (subjectModel == null)
                {
                    return(string.Format("活动编号{0}错误", item));
                }
                if (subjectModel.SubjectTemplate != 4)
                {
                    return(string.Format("活动编号{0}类型错误", item));
                }
                if (subjectModel.Status != 1)
                {
                    return(string.Format("活动编号{0}状态未开启", item));
                }
                if (subjectModel.IsAudited != 1)
                {
                    return(string.Format("活动编号{0}未审核", item));
                }
                if (subjectModel.DateEnd <= DateTime.Now)
                {
                    return(string.Format("活动编号{0}已经结束", item));
                }
            }
            return(string.Empty);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 查询秒杀商品
        /// </summary>
        /// <param name="subjectNo"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public ActionResult SearchSubjectProduct(string subjectNo, int pageIndex, int pageSize)
        {
            if (string.IsNullOrWhiteSpace(subjectNo))
            {
                return(Json(new { rs = false, msg = "活动编号错误" }, JsonRequestBehavior.AllowGet));
            }
            SWfsSubjectService subjectService = new SWfsSubjectService();
            SubjectInfo        model          = subjectService.GetSubjectInfo(subjectNo);

            if (model == null)
            {
                return(Json(new { rs = false, msg = "活动不存在" }, JsonRequestBehavior.AllowGet));
            }
            if (!model.SubjectTemplate.Equals(5))
            {
                return(Json(new { rs = false, msg = "活动不是促销秒杀类型" }, JsonRequestBehavior.AllowGet));
            }
            if (!model.Status.Equals(1))
            {
                return(Json(new { rs = false, msg = "活动尚未开启" }, JsonRequestBehavior.AllowGet));
            }
            if (model.DateEnd > DateTime.Now)
            {
                RecordPage <SubjectProductRef> productList = subjectService.GetSubjectSpikeProductList(subjectNo, pageIndex, pageSize);
                if (productList == null || productList.Items.Count() <= 0)
                {
                    return(Json(new { rs = false, msg = "活动尚未添加有效商品" }, JsonRequestBehavior.AllowGet));
                }
                return(Json(new { rs = true, content = RenderPartialViewToString("/Areas/Outlet/Views/Channel/SearchSubjectProduct.cshtml", productList) }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { rs = false, msg = "活动已过期" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 上传活动推广图
        /// </summary>
        /// <param name="subjectNo"></param>
        /// <returns></returns>
        public ActionResult ajaxSaveSpreadPicture(string subjectNo)
        {
            SWfsSubjectService          service   = new SWfsSubjectService();
            SubjectInfo                 subject   = service.GetSubjectInfo(subjectNo);
            Dictionary <string, string> spreadPic = new CommonService().PostImg(Request.Files["SpreadPicture"], "width:460,Height:460,Length:150");
            string spreadPicNo    = spreadPic.Values.FirstOrDefault();
            string spreadPicNoKey = spreadPic.Keys.FirstOrDefault();

            if (!string.IsNullOrEmpty(spreadPicNo))
            {
                if (spreadPicNoKey != "error")
                {
                    subject.SpreadPicture = spreadPicNo;
                    bool flag = service.UpdateSpreadPicture(subject);
                    if (flag)
                    {
                        return(Json(new { result = "1", message = "上传成功!" }));
                    }
                    else
                    {
                        return(Json(new { result = "0", message = "上传失败!" }));
                    }
                }
                else
                {
                    return(Json(new { result = "SpreadPictureUpLoad", message = spreadPicNo }));
                }
            }
            else
            {
                return(Json(new { result = "0", message = "请选择图片后上传!" }));
            }
        }
Ejemplo n.º 5
0
        public ActionResult AjaxDelete(string channelNo)
        {
            SWfsChannelService service = new SWfsChannelService();
            int i = service.DeleteChannel(channelNo);

            if (i >= 0)
            {
                #region 日志信息
                SWfsSubjectService      channelService = new SWfsSubjectService();
                SWfsSubjectOrChannelLog log            = new SWfsSubjectOrChannelLog();
                log.SubjectOrChannelNo = channelNo;
                log.TypeValue          = 1; //1频道
                log.DateOperator       = DateTime.Now;
                log.OperatorContent    = "删除频道";
                log.OperatorUserId     = PresentationHelper.GetPassport().UserName;
                log.OperatorActionType = LogActionType.Delete.GetHashCode();
                channelService.InsertSubjectOrChannelLog(log);
                #endregion

                return(Json(new { result = "1", message = "删除成功!" }));
            }
            else
            {
                return(Json(new { result = "0", message = "删除失败!" }));
            }
        }
Ejemplo n.º 6
0
        public RecordPage <SubjectInfo> AddApplyList(MarketOptionSearchParm parm, int pageIndex = 1, int pageSize = 10)
        {
            var dic = new Dictionary <string, object>();

            dic.Add("KeyWord", (parm == null || parm.SubjectNoName == "活动名称或活动编号" || string.IsNullOrEmpty(parm.SubjectNoName)) ? "" : parm.SubjectNoName);
            dic.Add("BrandNo", (parm == null || string.IsNullOrEmpty(parm.BrandNo)) ? "" : parm.BrandNo);
            dic.Add("ApplyBeginTime", (parm == null || string.IsNullOrEmpty(parm.ApplyBeginTime)) ? "" : parm.ApplyBeginTime);
            dic.Add("ApplyEndTime", (parm == null || string.IsNullOrEmpty(parm.ApplyEndTime)) ? "" : parm.ApplyEndTime);
            dic.Add("SpreadStatus", (parm == null || string.IsNullOrEmpty(parm.SpreadStatus)) ? "" : parm.SpreadStatus);
            dic.Add("Level", (parm == null || string.IsNullOrEmpty(parm.Level)) ? "" : parm.Level);
            dic.Add("SubjectType", (parm == null || string.IsNullOrEmpty(parm.SubjectType)) ? "" : parm.SubjectType);
            dic.Add("CategoryNo", (parm == null || string.IsNullOrEmpty(parm.CategoryNo)) ? "" : parm.CategoryNo);
            IEnumerable <SubjectInfo> query = DapperUtil.QueryPaging <SubjectInfo>("ComBeziWfs_SWfsSubjectApply_SubjectList", pageIndex, pageSize, "CreateDateTime desc", dic, new {
                KeyWord        = parm.SubjectNoName,
                BrandNo        = parm.BrandNo,
                ApplyBeginTime = parm.ApplyBeginTime,
                ApplyEndTime   = string.IsNullOrWhiteSpace(parm.ApplyEndTime) ? "" : Convert.ToDateTime(parm.ApplyEndTime).AddDays(1).ToString("yyyy-MM-dd"),
                SpreadStatus   = parm.SpreadStatus,
                Level          = parm.Level,
                SubjectType    = parm.SubjectType,
                CategoryNo     = parm.CategoryNo
            });

            Dictionary <string, List <SWfsSubjectChannelSordRef> > dicSordRef = new SWfsSubjectService().GetSordBySubjectNoList(query.Select(x => x.SubjectNo).ToArray());

            foreach (var subject in query)
            {
                subject.ChannelSordList = dicSordRef.Keys.Contains(subject.SubjectNo) ? dicSordRef[subject.SubjectNo] : null;
            }
            return(PageConvertor.Convert(pageIndex, pageSize, query.ToList()));
        }
Ejemplo n.º 7
0
        public ActionResult Create()
        {
            SWfsSubjectService      service         = new SWfsSubjectService();
            IList <SWfsChannelSord> channelSordList = service.GetChannelSordList(2);

            ViewBag.ChannelSordList = channelSordList;
            return(View());
        }
Ejemplo n.º 8
0
        public ActionResult SubjectStatusModify(string subjectNo)
        {
            SWfsSubjectService service = new SWfsSubjectService();
            SubjectInfo        subject = service.GetSubjectInfo(subjectNo);

            //没有获取到活动信息
            if (subject == null)
            {
                return(Json(new { result = "0", message = "信息获取错误" }));
            }
            string tempStatue = subject.Status == 0 ? "1" : "0";

            //如果状态是关闭活动 点击后开启
            if (subject.Status == 0)
            {
                IList <string> list = service.GetProductListBySubjectNo(subjectNo, "0");
                //存在商品
                if (list != null && list.Count > 0)
                {
                    if (string.IsNullOrEmpty(subject.BelongsSubjectPic) || string.IsNullOrEmpty(subject.TitlePic2) || string.IsNullOrEmpty(subject.IPhonePic))
                    {
                        return(Json(new { result = "0", message = "由于此活动的图片上传不完全,所以不能开启该活动!" }));
                    }

                    if (subject.SubjectPreStartTemplateType != 1 && string.IsNullOrEmpty(subject.BackgroundPic))
                    {
                        return(Json(new { result = "0", message = "由于此活动的图片上传不完全,所以不能开启该活动!" }));
                    }
                }
                else
                {
                    return(Json(new { result = "0", message = "此活动中没有符合前台网站售卖条件的商品,不能开启!" }));
                }
            }
            try
            {
                service.SubjectStatusModify(subjectNo, tempStatue);
                #region 修改活动状态日志
                SWfsSubjectOrChannelLog log = new SWfsSubjectOrChannelLog();
                log.SubjectOrChannelNo = subjectNo;
                log.TypeValue          = 0;
                log.DateOperator       = DateTime.Now;
                log.OperatorContent    = "修改活动状态";
                log.OperatorUserId     = PresentationHelper.GetPassport().UserName;
                service.InsertSubjectOrChannelLog(log);
                #endregion
                return(Json(new { result = "1", message = "活动状态修改成功!" }));
            }
            catch (Exception ex)
            {
                return(Json(new { result = "0", message = "活动状态修改失败!" }));
            }
        }
Ejemplo n.º 9
0
        public ActionResult Edit(string channelNo)
        {
            SWfsChannelService         channel            = new SWfsChannelService();
            SWfsSubjectService         service            = new SWfsSubjectService();
            SWfsChannel                model              = channel.GetChannelInfo(channelNo);
            IList <SWfsChannelSordRef> channelSordRefList = channel.GetSordByChannelNo(channelNo);

            ViewBag.ChannelSordRefList = channelSordRefList;
            IList <SWfsChannelSord> channelSordList = service.GetChannelSordList(2);

            ViewBag.ChannelSordList = channelSordList;
            return(View(model));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 专题页的商品管理
        /// </summary>
        /// <returns></returns>
        public ActionResult ManageProduct(string topicNo, int pageindex = 1)
        {
            int    pageSize        = 10;
            string categoryNo      = Request["CategoryNo"];
            string brandNo         = Request["BrandNo"];
            string productNoOrName = Request["ProductNameOrNo"];

            if (!string.IsNullOrEmpty(productNoOrName) && productNoOrName.Equals("商品编号/商品名称"))
            {
                productNoOrName = "";
            }
            /////////////////////////分页保留查询数据用///////////////////////////////
            ViewBag.CategoryNo      = categoryNo ?? "";
            ViewBag.ProductNameOrNo = productNoOrName ?? "";
            ViewBag.BrandName       = Request.QueryString["BrandName"] ?? "";
            ViewBag.BrandNo         = brandNo ?? "";

            ///////////////////////////分页保留查询数据用/////////////////////////////

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("brandNo", brandNo ?? "");
            dic.Add("productNoOrName", productNoOrName ?? "");
            dic.Add("gCategroyNo", categoryNo ?? "");
            dic.Add("topicId", topicNo ?? "");

            SWfsTopicService topicServ        = new SWfsTopicService();
            var productList                   = topicServ.GetProductListByTopicNo(dic, pageindex, pageSize);
            SWfsProductService productService = new SWfsProductService();
            ProductInventory   pin            = new ProductInventory();

            foreach (var product in productList.Items)
            {
                pin = productService.GetInventoryByProductNo(product.ProductNo);
                product.Quantity     = pin.SumQuantity;
                product.LockQuantity = pin.SumLockQuantity;
            }
            //所有的一级分类
            SWfsSubjectService subject = new SWfsSubjectService();

            ViewBag.AllFirstCategory = subject.SelectErpCategoryByParentNo("ROOT");
            ViewBag.TopicNo          = topicNo;

            SWfsTopics topicModel = topicServ.GetSWfsTopics(topicNo);

            ViewBag.TopicName = (null != topicModel) ? topicModel.TopicName : "";
            return(View(productList));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 查询有效活动
        /// </summary>
        /// <param name="subjectNo"></param>
        /// <returns></returns>
        public ActionResult SearchSubject(string subjectNo)
        {
            SWfsSubjectService subjectService = new SWfsSubjectService();
            SubjectInfo        model          = subjectService.GetSubjectInfo(subjectNo);

            if (model != null)
            {
                if (model.DateEnd > DateTime.Now && model.Status == 1 && model.IsAudited == 1 && model.ChannelNo.Contains("zsqd001"))
                {
                    return(Json(new { result = "1" }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { result = "0" }, JsonRequestBehavior.AllowGet));
                }
            }
            else
            {
                return(Json(new { result = "0" }, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 商品列表--查询添加
        /// </summary>
        /// <param name="topicNo"></param>
        /// <param name="categoryNo"></param>
        /// <param name="brandNo"></param>
        /// <param name="productNameOrNo"></param>
        /// <param name="pageindex"></param>
        /// <returns></returns>
        public ActionResult AddProduct(string topicNo, int pageindex = 1)
        {
            int    pageSize        = 10;
            string categoryNo1     = Request["CategoryNo1"];
            string categoryNo2     = Request["CategoryNo2"];
            string categoryNo3     = Request["CategoryNo3"];
            string categoryNo4     = Request["CategoryNo4"];
            string brandNo         = Request["BrandNo"];
            string productNoOrName = Request["ProductNameOrNo"];
            string gender          = Request["Gender"];

            if (!string.IsNullOrEmpty(productNoOrName) && productNoOrName.Equals("商品编号/商品名称"))
            {
                productNoOrName = "";
            }
            /////////////////////////分页保留查询数据用///////////////////////////////
            ViewBag.CategoryNo      = categoryNo1 ?? "";
            ViewBag.CategoryNo2     = categoryNo2 ?? "";
            ViewBag.CategoryNo3     = categoryNo3 ?? "";
            ViewBag.CategoryNo4     = categoryNo4 ?? "";
            ViewBag.ProductNameOrNo = productNoOrName ?? "";
            ViewBag.BrandName       = Request.QueryString["BrandName"] ?? "";
            ViewBag.Gender          = gender ?? "";
            ///////////////////////////分页保留查询数据用/////////////////////////////

            string gCategroyNo = categoryNo1;

            if (!string.IsNullOrEmpty(categoryNo2))
            {
                gCategroyNo = categoryNo2;
            }
            if (!string.IsNullOrEmpty(categoryNo3))
            {
                gCategroyNo = categoryNo3;
            }
            if (!string.IsNullOrEmpty(categoryNo4))
            {
                gCategroyNo = categoryNo4;
            }


            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("brandNo", brandNo ?? "");
            dic.Add("productNoOrName", productNoOrName ?? "");
            dic.Add("gender", gender ?? "");
            dic.Add("gCategroyNo", gCategroyNo ?? "");

            SWfsTopicService topicServ = new SWfsTopicService();
            var productList            = topicServ.GetProductList(dic, pageindex, pageSize);

            SWfsProductService productService = new SWfsProductService();
            //ProductInventory pin = new ProductInventory();
            ProductInventoryNew   pin     = new ProductInventoryNew();
            SWfsNewProductService service = new SWfsNewProductService();
            decimal bid = 0;

            foreach (var product in productList.Items)
            {
                //pin = productService.GetInventoryByProductNo(product.ProductNo);
                pin = service.GetInventoryByProductNo(product.ProductNo);
                product.Quantity     = pin.SumQuantity;
                product.LockQuantity = pin.SumLockQuantity;


                bid = productService.GetProductBuyPriceByProductNo(product.ProductNo);

                product.sellBid       = product.SellPrice - bid;
                product.marketBid     = product.MarketPrice - bid;
                product.platinumBid   = product.PlatinumPrice - bid;
                product.diamondBid    = product.DiamondPrice - bid;
                product.limitedBid    = product.LimitedPrice - bid;
                product.limitedVipBid = product.LimitedVipPrice - bid;

                product.selBidRate        = product.SellPrice.Equals(0) ? 100 : Math.Round((product.sellBid / product.SellPrice) * 100, 2);
                product.marketBidRate     = product.MarketPrice.Equals(0) ? 100 : Math.Round((product.marketBid / product.MarketPrice) * 100, 2);             // Convert.ToDecimal(Math.Round((Convert.ToDecimal(marketBid) / Convert.ToDecimal(marketPrice)) * 100, 2)).ToString() + "%";
                product.platinumBidRate   = product.PlatinumPrice.Equals(0) ? 100 : Math.Round((product.platinumBid / product.PlatinumPrice) * 100, 2);       // Convert.ToDecimal(Math.Round((Convert.ToDecimal(platinumBid) / Convert.ToDecimal(platinumPrice)) * 100, 2)).ToString() + "%";
                product.diamondBidRate    = product.DiamondPrice.Equals(0) ? 100 : Math.Round((product.diamondBid / product.DiamondPrice) * 100, 2);          //Convert.ToDecimal(Math.Round((Convert.ToDecimal(diamondBid) / Convert.ToDecimal(diamondPrice)) * 100, 2)).ToString() + "%";
                product.limitedBidRate    = product.LimitedPrice.Equals(0) ? 100 : Math.Round((product.limitedBid / product.LimitedPrice) * 100, 2);          // Convert.ToDecimal(Math.Round((Convert.ToDecimal(limitedBid) / Convert.ToDecimal(limitedPrice)) * 100, 2)).ToString() + "%";
                product.limitedVipBidRate = product.LimitedVipPrice.Equals(0) ? 100 : Math.Round((product.limitedVipBid / product.LimitedVipPrice) * 100, 2); // Convert.ToDecimal(Math.Round((Convert.ToDecimal(limitedVipBid) / Convert.ToDecimal(limitedVipPrice)) * 100, 2)).ToString() + "%";
            }

            //所有的一级分类
            SWfsSubjectService subject = new SWfsSubjectService();

            ViewBag.AllFirstCategory = subject.SelectErpCategoryByParentNo("ROOT");
            //该活动下的一级分类
            //ViewBag.FirstCategory = subject.GetErpCategoryListBySubjectNo(subjectNo);

            ViewBag.Category2 = subject.SelectErpCategoryByParentNo(categoryNo1);
            ViewBag.Category3 = subject.SelectErpCategoryByParentNo(categoryNo2);
            ViewBag.Category4 = subject.SelectErpCategoryByParentNo(categoryNo3);

            ViewBag.TopicNo = topicNo;

            SWfsTopics topicModel = topicServ.GetSWfsTopics(topicNo);

            ViewBag.TopicName = (null != topicModel) ? topicModel.TopicName : "";

            ViewBag.SCategoryNo = gCategroyNo;

            return(View(productList));
        }
Ejemplo n.º 13
0
        public ActionResult AddApply(string subjectNo, string flag)
        {
            //flag: AddApply添加申请推广,CheckApply网推检查确认推广信息,AddSeo 添加SEO优化
            if (string.IsNullOrWhiteSpace(flag))
            {
                return(Content("flag参数错误"));
            }
            if (string.IsNullOrWhiteSpace(subjectNo))
            {
                return(Content("subjectNo参数错误"));
            }
            SWfsSubjectService service = new SWfsSubjectService();

            ViewBag.Flag = flag;
            flag         = flag.ToLower();
            #region //添加推广信息
            if (flag.Equals("addapply"))
            {
                SubjectInfo mode = service.GetSubjectInfo(subjectNo);
                if (mode == null)
                {
                    return(Content("活动不存在"));
                }
                if (mode != null && mode.IsPreheat == 1)
                {
                    SubjectPreheatInfoM predheatM = service.GetSubjectPreheatInfo(subjectNo);
                    ViewBag.PreTime = predheatM != null?predheatM.PreheatTime.ToString("yyyy-MM-dd HH:mm:ss") : "";
                }
                else
                {
                    ViewBag.PreTime = "";
                }
                ViewBag.SubjectNo = subjectNo;
                SWfsSubjectApplyPromotion tempmodel = new MarketOptionService().GetModelBySubjectNo(subjectNo);
                return(View(tempmodel));
            }
            #endregion

            #region //网推检查确认推广信息
            if (flag.Equals("checkapply"))
            {
                SubjectInfo mode = service.GetSubjectApplyInfo(subjectNo);
                Dictionary <string, List <SWfsSubjectChannelSordRef> > dicSordRef = new SWfsSubjectService().GetSordBySubjectNoList(subjectNo.Split(',').ToArray());
                mode.ChannelSordList = dicSordRef.Keys.Contains(subjectNo) ? dicSordRef[subjectNo] : null;


                List <SWfsSubjectPromotionChannel> spList = new MarketOptionService().SelectPromotionChannelList();
                ViewBag.PromotionChannelList = spList;
                ViewBag.ChannelSordList      = new SubjectController().GetChannelSordList(2);
                return(View("CheckApply", mode));
            }
            #endregion

            #region //添加SEO优化
            if (flag.Equals("addseo"))
            {
                SubjectInfo mode = service.GetSubjectApplyInfo(subjectNo);
                return(View("AddSeo", mode));
            }
            #endregion

            return(Content("flag参数错误,正确值为addapply|checkapply|addseo之一"));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 通用保存图片 isArea   0 宽大于等于  1 宽大于等于,高等于  2严格宽高
        /// </summary>
        /// <param name="postedFile"></param>
        /// <param name="imgSize">width:640,Height:0,Length:50</param>
        /// <returns></returns>
        public Dictionary <string, string> PostImg(HttpPostedFileBase postedFile, string imgSize, string[] allowTypes, int isArea = 0)
        {
            #region 方案二
            //string types = AppSettingManager.AppSettings["InputSystemImgType"];
            //string[] allowTypes = string.IsNullOrEmpty(types) ? (new string[] { ".jpg", ".gif" }) : (types.Split('/'));
            Dictionary <string, string> result = new Dictionary <string, string>();
            string message = string.Empty;
            if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName))
            {
                string fileFullName = postedFile.FileName;
                string fileType     = Path.GetExtension(fileFullName).ToLower();
                string fileName     = Path.GetFileName(fileFullName);

                if (allowTypes.Contains(fileType))
                {
                    int conLen = postedFile.ContentLength;
                    //读取文件为 二进制流 , 保存到  图片表 , 返回 图片编号
                    byte[] btImgs = new byte[conLen];
                    using (Stream s = postedFile.InputStream)
                    {
                        s.Seek(0, SeekOrigin.Begin);
                        s.Position = 0;
                        s.Read(btImgs, 0, conLen);
                    }
                    System.IO.Stream     stream         = new System.IO.MemoryStream(btImgs);      //将byte数组回归成流
                    System.Drawing.Image original_image = System.Drawing.Image.FromStream(stream); //使用流创建图片
                    int width  = original_image.Width;                                             //图片的宽度
                    int height = original_image.Height;                                            //图片的高度
                    original_image.Dispose();                                                      //释放资源
                    long length = stream.Length / 1024;                                            //图片的大小(KB)
                    stream.Close();
                    stream.Dispose();
                    //string pictureSize = AppSettingManager.AppSettings[imgSize];
                    int img_Width   = Convert.ToInt32(imgSize.Split(',')[0].Split(':')[1].ToString());
                    int img_Heighth = Convert.ToInt32(imgSize.Split(',')[1].Split(':')[1].ToString());
                    int img_Length  = Convert.ToInt32(imgSize.Split(',')[2].Split(':')[1].ToString());
                    if (isArea == 1)//宽大于等于,高等于
                    {
                        if (width < img_Width || height != img_Heighth)
                        {
                            message = "请上传宽大于等于" + img_Width.ToString() + "高等于" + img_Heighth.ToString() + "的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                        if (img_Length > 0 && length > img_Length)
                        {
                            message = "请上传小于" + img_Length.ToString() + "KB的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                    }
                    else if (isArea == 2)  //严格宽高
                    {
                        //如果Length0 则表示不限制此信息······
                        if (img_Length > 0 && length > img_Length)
                        {
                            message = "请上传小于" + img_Length.ToString() + "KB的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                        //如果宽0 高0 则表示不限制此信息······
                        if ((width != img_Width) || (height != img_Heighth))
                        {
                            message = "请上传" + img_Width.ToString() + "*" + img_Heighth.ToString() + "的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                    }
                    else if (isArea == 0)
                    {
                        //如果Length0 则表示不限制此信息······
                        if (img_Length > 0 && length > img_Length)
                        {
                            message = "请上传小于" + img_Length.ToString() + "KB的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                        //如果宽0 高0 则表示不限制此信息······
                        if ((img_Width > 0 && width != img_Width) || (img_Heighth > 0 && height != img_Heighth))
                        {
                            message = "请上传" + img_Width.ToString() + "*" + img_Heighth.ToString() + "的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                    }
                    SystemPictureFile model = new SystemPictureFile();
                    model.FileContent   = Convert.ToBase64String(btImgs);
                    model.Extension     = fileType;
                    model.FileName      = fileName;
                    model.OperatorId    = string.Empty;
                    model.PictureFileNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ThreadSafeRandom.Next(1000).ToString("000");
                    SWfsSubjectService service   = new SWfsSubjectService();
                    string             pictureNo = service.InserSystemImg(model);

                    result.Add("success", pictureNo);
                    return(result);
                }
                else
                {
                    result.Add("error", "上传图片格式不正确!");
                    return(result);
                }
            }
            string typestr = allowTypes.Aggregate((a, b) => a + "," + b);
            result.Add("error", "请上传尺寸为" + imgSize + ",格式为" + typestr + "的图片");
            result.Add("error", "请上传图片!");
            return(result);

            #endregion
        }
Ejemplo n.º 15
0
        /*因为20130913商品活动需求 重构方法 添加最大值 最小值
         * 例width:640|640 split[0]最小值 split[0]最大值 如果都为0 不限制 如果相等固定图片大小
         */
        /// <summary>
        /// 通用保存图片
        /// </summary>
        /// <param name="postedFile"></param>
        /// <param name="imgSize">width:640|640,Height:0|0,Length:50|50</param>
        /// <param name="flag">true图片是固定大小 flase图片大小在区间之内</param>
        /// <returns></returns>
        public Dictionary <string, string> PostImg(HttpPostedFileBase postedFile, string imgSize, bool flag)
        {
            if (flag)
            {
                return(PostImg(postedFile, imgSize));
            }
            string types = AppSettingManager.AppSettings["InputSystemImgType"];

            string[] allowTypes = string.IsNullOrEmpty(types) ? (new string[] { ".jpg", ".gif", "png" }) : (types.Split('/'));
            Dictionary <string, string> result = new Dictionary <string, string>();
            string message = string.Empty;

            if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName))
            {
                string fileFullName = postedFile.FileName;
                string fileType     = Path.GetExtension(fileFullName).ToLower();
                string fileName     = Path.GetFileName(fileFullName);

                if (allowTypes.Contains(fileType))
                {
                    int    conLen = postedFile.ContentLength;
                    byte[] btImgs = new byte[conLen];
                    using (Stream s = postedFile.InputStream)
                    {
                        s.Seek(0, SeekOrigin.Begin);
                        s.Position = 0;
                        s.Read(btImgs, 0, conLen);
                    }
                    System.IO.Stream     stream         = new System.IO.MemoryStream(btImgs);      //将byte数组回归成流
                    System.Drawing.Image original_image = System.Drawing.Image.FromStream(stream); //使用流创建图片
                    int width  = original_image.Width;                                             //图片的宽度
                    int height = original_image.Height;                                            //图片的高度
                    original_image.Dispose();                                                      //释放资源
                    long length = stream.Length / 1024;                                            //图片的大小(KB)
                    stream.Close();
                    stream.Dispose();

                    #region 判断

                    /*因为20130913商品活动需求 重构方法 添加最大值 最小值
                     * 例width:640|640,Height:0|0,Length:50|50
                     * width:640|640 split[0]最小值 split[0]最大值 如果都为0 不限制 如果相等固定图片大小
                     */
                    string getWidth   = imgSize.Split(',')[0].Split(':')[1].ToString();
                    string getHeighth = imgSize.Split(',')[1].Split(':')[1].ToString();
                    string getLength  = imgSize.Split(',')[2].Split(':')[1].ToString();

                    //宽度区间
                    int imgMinWidth, imgMaxWidth;
                    if (getWidth.Contains('|'))
                    {
                        imgMinWidth = Convert.ToInt32(getWidth.Split('|')[0]);
                        imgMaxWidth = Convert.ToInt32(getWidth.Split('|')[1]);
                    }
                    else
                    {
                        imgMinWidth = Convert.ToInt32(getWidth);
                        imgMaxWidth = Convert.ToInt32(getWidth);
                    }
                    //高度区间
                    int imgMinHeight, imgMaxHeight;
                    if (getHeighth.Contains('|'))
                    {
                        imgMinHeight = Convert.ToInt32(getHeighth.Split('|')[0]);
                        imgMaxHeight = Convert.ToInt32(getHeighth.Split('|')[1]);
                    }
                    else
                    {
                        imgMinHeight = Convert.ToInt32(getHeighth);
                        imgMaxHeight = Convert.ToInt32(getHeighth);
                    }
                    //大小区间
                    int imgMinLength, imgMaxLength;
                    if (getLength.Contains('|'))
                    {
                        imgMinLength = Convert.ToInt32(getLength.Split('|')[0]);
                        imgMaxLength = Convert.ToInt32(getLength.Split('|')[1]);
                    }
                    else
                    {
                        imgMinLength = Convert.ToInt32(getLength);
                        imgMaxLength = Convert.ToInt32(getLength);
                    }


                    if (!(imgMinWidth == imgMaxWidth && imgMinWidth == 0))
                    {
                        imgMaxWidth = imgMaxWidth == 0 ? int.MaxValue : imgMaxWidth;
                        if (width < imgMinWidth || width > imgMaxWidth)
                        {
                            if (imgMaxWidth == 0 || imgMaxWidth == int.MaxValue)
                            {
                                message = "请上传宽度大于" + imgMinWidth + "的图片!!";
                            }
                            else
                            {
                                message = "请上传宽度为" + imgMinWidth + "-" + imgMaxWidth + "的图片!!";
                            }
                            result.Add("error", message);
                            return(result);
                        }
                    }

                    if (!(imgMinHeight == imgMaxHeight && imgMaxHeight == 0))
                    {
                        imgMaxHeight = imgMaxHeight == 0 ? int.MaxValue : imgMaxHeight;
                        if (imgMaxHeight != height)
                        {
                            message = "请上传高度为" + imgMinHeight + "的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                        if (height < imgMinHeight || height > imgMaxHeight)
                        {
                            message = "请上传高度为" + imgMinHeight + "-" + imgMaxHeight + "的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                    }
                    if (!(imgMinLength == imgMaxLength && imgMaxLength == 0))
                    {
                        if (length > imgMaxLength)
                        {
                            message = "请上传大小为" + imgMaxLength + "的图片!!";
                            result.Add("error", message);
                            return(result);
                        }
                    }
                    #endregion

                    SystemPictureFile model = new SystemPictureFile();
                    model.FileContent   = Convert.ToBase64String(btImgs);
                    model.Extension     = fileType;
                    model.FileName      = fileName;
                    model.OperatorId    = string.Empty;
                    model.PictureFileNo = DateTime.Now.ToString("yyyyMMddHHmmssfff") + ThreadSafeRandom.Next(1000).ToString("000");
                    SWfsSubjectService service   = new SWfsSubjectService();
                    string             pictureNo = service.InserSystemImg(model);
                    result.Add("success", pictureNo);
                    return(result);
                }
                else
                {
                    result.Add("error", "请上传.jpg或.gif格式的图片!");
                    return(result);
                }
            }
            result.Add("error", "请上传尺寸为" + imgSize + ",格式为" + types + "的图片");
            return(result);
        }