Exemplo n.º 1
0
        /// <summary>
        /// 添加广告位图片
        /// </summary>
        /// <param name="addimage"></param>
        /// <param name="image_name"></param>
        /// <returns></returns>
        public string adverAddImage(AdverAddImage addimage, string image_name, string username, string ip)
        {
            string responseText = "";

            responseText = imagedal.adverAddImage(addimage, image_name, username, ip);
            return(responseText);
        }
        /// <summary>
        /// 添加广告位图片
        /// </summary>
        /// <param name="addimage"></param>
        /// <param name="image_name"></param>
        /// <returns></returns>
        public string adverAddImage(AdverAddImage addimage, string image_name, string username, string ip)
        {
            string    responseText = "";
            string    sql          = "";
            string    newsort      = "";
            int       flag         = 0;
            DataTable dt;
            string    log     = "";
            bool      logFlag = false;

            sql = string.Format("select * from GX_AD_POSITION where 1=1 and DEL_FLAG='0' and AD_IMAGE='{0}'", image_name);
            dt  = OracleHelper.GetTable(sql, null);
            if (dt.Rows.Count > 0)
            {
                return("[{\"msg\":\"fail\",\"status\":\"该图片已存在服务器,可修改图片名字重新上传\"}]");
            }
            sql     = string.Format("select nvl(max(SORT),'0')  from GX_AD_POSITION where  DEL_FLAG='0' and CLASS_ID='{0}'", addimage.Adver_class);
            dt      = OracleHelper.GetTable(sql, null);
            newsort = (Convert.ToInt32(dt.Rows[0][0].ToString()) + 1).ToString();
            string nowtime = DateTime.Now.ToString();

            sql  = string.Format("insert into GX_AD_POSITION(AD_IMAGE,WIDTH,HIGH,CLASS_ID,ADD_TIME,SORT,LINK_ADDRESS,IS_SHOW) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}')", image_name, addimage.Width, addimage.High, addimage.Adver_class, nowtime, newsort, addimage.Link_address, addimage.Is_show);
            flag = OracleHelper.ExecuteNonQuery(sql, null);
            if (flag > 0)
            {
                logFlag      = true;
                responseText = "[{\"msg\":\"success\",\"status\":\"上传成功\"}]";
            }

            else
            {
                responseText = "[{\"msg\":\"fail\",\"status\":\"插入数据库失败\"}]";
            }
            if (logFlag)
            {
                log = username + " 上传一张" + addimage.Adver_class + "分类且名字为" + image_name + "的图片成功";
            }
            else
            {
                log = username + " 上传一张" + addimage.Adver_class + "分类且名字为" + image_name + "的图片失败";
            }
            lgdal.setOperationLog(username, log, ip);
            return(responseText);
        }
        public ActionResult AdverAddImage(AdverAddImage addimage)
        {
            string        responseText = "";
            string        fileExt      = "";
            List <string> filename     = new List <string>();
            string        filenames    = "";

            if (Request.Cookies["ip"] != null)
            {
                ip = Request.Cookies["ip"].Value;
            }
            if (Request.Cookies["userName"] != null)
            {
                username = System.Web.HttpContext.Current.Server.UrlDecode(Request.Cookies["userName"].Value);
            }
            /****************上传图片到服务器****************/
            int cnt = System.Web.HttpContext.Current.Request.Files.Count;

            if (cnt == 0)
            {
                responseText = "[{\"msg\":\"fail\",\"status\":\"未能获取到图片,请重新上传\"}]";
                return(Content(responseText));
            }
            for (int i = 0; i < cnt; i++)
            {
                HttpPostedFile hpf = System.Web.HttpContext.Current.Request.Files[i];
                filenames = Path.GetFileName(hpf.FileName);
                fileExt   = Path.GetExtension(hpf.FileName).ToLower();//带.的后缀
                filename.Add(filenames);
                string fileFilt = ".jpg|.png|.JPG|.PNG|......";
                if ((fileFilt.IndexOf(fileExt) <= -1) || (fileExt == "") || (hpf.ContentLength > 4 * 1024 * 1024))
                {
                    continue;
                }

                //   hpf.SaveAs("D:\\MVCRoot\\blueunion\\uploadimages\\Carouselfigure\\" + filenames);

                hpf.SaveAs("D:\\MVCRoot\\gxdzbackstage\\image\\Carouselfigure\\" + filenames);
            }
            /****************上传图片到服务器****************/
            responseText = imagebll.adverAddImage(addimage, filenames, username, ip);
            return(Content(responseText));
        }