예제 #1
0
        public string Upload(Image strJson)
        {
            string     pId      = Context.Request["productId"];
            cmUserInfo model    = (cmUserInfo)Context.Session["UserModel"];
            string     username = model.username.ToString();
            string     fileUrl  = "";

            try
            {
                HttpPostedFile _upfile = Context.Request.Files["file"];
                if (_upfile == null)
                {
                    throw new Exception("请先选择文件!");
                }
                else
                {
                    string fileName = _upfile.FileName;                                            /*获取文件名: C:\Documents and Settings\Administrator\桌面\123.jpg*/
                    string suffix   = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower(); /*获取后缀名并转为小写: jpg*/
                    int    bytes    = _upfile.ContentLength;                                       //获取文件的字节大小
                    if (!(suffix == "jpg" || suffix == "gif" || suffix == "png" || suffix == "jpeg"))
                    {
                        throw new Exception("只能上传JPE,GIF,PNG文件");
                    }
                    if (bytes > 1024 * 1024 * 2)
                    {
                        throw new Exception("图片最大只能传2M");
                    }
                    string newfileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string fileDir     = HttpContext.Current.Server.MapPath("~/upfiles/" + MyInfo.user + "/");
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }
                    //string phyPath = context.Request.PhysicalApplicationPath;
                    //string savePath = phyPath + virPath;
                    string saveDir = fileDir + newfileName + "." + suffix; //文件服务器存放路径
                    fileUrl = "/upfiles/" + username + "/" + newfileName + "." + suffix;
                    _upfile.SaveAs(saveDir);                               //保存图片
                    #region 存到sql图片库
                    imageInfo img = new imageInfo();
                    img.imageId   = newfileName;
                    img.imageURL  = fileUrl;
                    img.userId    = model.Id;
                    img.productId = int.Parse(pId);
                    bll.AddImg(img);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                return(json.WriteJson(0, ex.Message, new { }));
            }
            return(json.WriteJson(1, "上传成功", new { imgUrl = fileUrl }));
        }
예제 #2
0
파일: BLL.cs 프로젝트: fbkc/toolWebsevice
    /// <summary>
    /// 软件上传图片
    /// </summary>
    /// <param name="img"></param>
    public void AddImg(imageInfo img)
    {
        int a = SqlHelper.ExecuteNonQuery(@"INSERT INTO [AutouSend].[dbo].[imageInfo]
       ([imageId]
       ,[imageURL]
       ,addTime
       ,userId
       ,productId)
 VALUES
       (@imageId
       ,@imageURL
       ,getdate()
       ,@userId
       ,@productId)",
                                          new SqlParameter("@imageId", SqlHelper.ToDBNull(img.imageId)),
                                          new SqlParameter("@imageURL", SqlHelper.ToDBNull(img.imageURL)),
                                          new SqlParameter("@productId", SqlHelper.ToDBNull(img.productId)),
                                          new SqlParameter("@userId", SqlHelper.ToDBNull(img.userId)));
    }
예제 #3
0
        public void processFBRReport(string fbrFileLocation)
        {
            DataRow dr = dtFBR.NewRow();

            dr["FILE_NAME"] = Path.GetFileName(fbrFileLocation);

            var stringBuilder = new StringBuilder();

            Microsoft.Office.Interop.PowerPoint.Application pptApp =
                new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations pptPresentations =
                pptApp.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation =
                pptPresentations.Open(fbrFileLocation,
                                      Microsoft.Office.Core.MsoTriState.msoTrue,
                                      Microsoft.Office.Core.MsoTriState.msoFalse,
                                      Microsoft.Office.Core.MsoTriState.msoFalse);

            Microsoft.Office.Interop.PowerPoint.Slides pptSlides = pptPresentation.Slides;

            Graphics gr = this.CreateGraphics();

            var slidesCount = pptSlides.Count;
            int imgCrt      = 0;

            for (int slideIndex = 1; slideIndex <= slidesCount; slideIndex++)
            {
                var slide = pptSlides[slideIndex];

                foreach (Microsoft.Office.Interop.PowerPoint.Shape textShape in slide.Shapes)
                {
                    if (textShape.Type == Microsoft.Office.Core.MsoShapeType.msoPicture)
                    {
                        listofImages.Add(textShape);

                        imgCrt++;
                        textShape.Export(sPowerPointFolderImg + textShape.ZOrderPosition.ToString()
                                         + "-" + ((textShape.Left * gr.DpiX) / 72).ToString("0.00")
                                         + "-" + ((textShape.Top * gr.DpiX) / 72).ToString("0.00")
                                         + "-" + ((textShape.Width * gr.DpiX) / 72).ToString("0.00")
                                         + "-" + ((textShape.Height * gr.DpiX) / 72).ToString("0.00")
                                         + ".png",
                                         Microsoft.Office.Interop.PowerPoint.PpShapeFormat.ppShapeFormatPNG,
                                         0,
                                         0,
                                         Microsoft.Office.Interop.PowerPoint.PpExportMode.ppScaleXY);
                    }

                    if (textShape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue &&
                        textShape.TextFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
                    {
                        Microsoft.Office.Interop.PowerPoint.TextRange pptTextRange = textShape.TextFrame.TextRange;

                        if (pptTextRange != null && pptTextRange.Length > 0)
                        {
                            stringBuilder.Append(" " + pptTextRange.Text);

                            if (pptTextRange.Text.StartsWith("ACTUAL CUSTOMER COMPLAINT") == true)
                            {
                                string tmpString = pptTextRange.Text;
                                tmpString = pptTextRange.Text.Replace("ACTUAL CUSTOMER COMPLAINT", string.Empty);

                                dr["ACTUAL CUSTOMER COMPLAINT"] = tmpString.Replace(",", "").Replace("\r", String.Empty);
                            }
                            else if (pptTextRange.Text.Trim().ToUpper().Equals("MARKET FEED BACK") == true)
                            {
                            }
                            else if (pptTextRange.Text.Trim().ToUpper().StartsWith("RANK:") == true)
                            {
                                string tmpString = pptTextRange.Text.ToUpper();
                                tmpString = pptTextRange.Text.Replace("RANK:", string.Empty);
                                var regex = new Regex(Regex.Escape("\r"));
                                tmpString = regex.Replace(tmpString, "", 1);

                                dr["RANK"] = tmpString;
                            }
                            else if (pptTextRange.Text.Trim().ToUpper().StartsWith("TRACKING #") == true)
                            {
                                string tmpString = pptTextRange.Text.ToUpper();
                                tmpString      = tmpString.ToUpper().Replace("TRACKING #:", string.Empty);
                                dr["TRACKING"] = tmpString.Replace(",", "").Replace("\r", String.Empty);
                            }
                            else if (pptTextRange.Text.Trim().StartsWith("This sheet is intended for quick feed back to increase associate") == true)
                            {
                            }
                            else if (pptTextRange.Text.Trim().Equals("For Reference Only") == true)
                            {
                            }
                            else
                            {
                                if (textShape.Name.ToString().Equals("Title 1") == true)
                                {
                                    dr["TITLE"] = pptTextRange.Text.Replace(",", "").Replace("\r", String.Empty);
                                }
                            }
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptTextRange);
                        }
                    }

                    if (textShape.HasTable == Microsoft.Office.Core.MsoTriState.msoTrue)
                    {
                        if (textShape.Table.Rows.Count > 1)
                        {
                            int iNumRows = textShape.Table.Rows.Count;
                            int iNumCols = textShape.Table.Rows[1].Cells.Count;

                            string sKey = textShape.Table.Rows[1].Cells[1].Shape.TextFrame.TextRange.Text;
                            if ((sKey.Trim().ToUpper().Equals("VIN") == true) ||
                                (sKey.Trim().ToUpper().Equals("PART NAME") == true) ||
                                (sKey.Trim().ToUpper().Equals("CUSTOMER CONCERN:") == true) ||
                                (sKey.Trim().ToUpper().Equals("DEALER REPAIR:") == true) ||
                                (sKey.Trim().ToUpper().Equals("ADDITIONAL DETAILS:") == true) ||
                                (sKey.Trim().ToUpper().Equals("CLAIM COST:") == true)
                                )
                            {
                                //Process VIN Block
                                for (int iCol = 1; iCol <= iNumCols; iCol++)
                                {
                                    dr[textShape.Table.Rows[1].Cells[iCol].Shape.TextFrame.TextRange.Text] =
                                        textShape.Table.Rows[2].Cells[iCol].Shape.TextFrame.TextRange.Text.Replace(",", String.Empty).Replace("\r", String.Empty);
                                }
                            }
                            if ((sKey.Trim().ToUpper().Equals("MODEL:") == true) ||
                                (sKey.Trim().ToUpper().Equals("DEPT:") == true) ||
                                (sKey.Trim().ToUpper().Equals("ISSUED DATE:") == true) ||
                                (sKey.Trim().ToUpper().Equals("ISSUER:") == true)
                                )
                            {
                                //Process VIN Block
                                for (int iRow = 1; iRow <= iNumRows; iRow++)
                                {
                                    dr[textShape.Table.Rows[iRow].Cells[1].Shape.TextFrame.TextRange.Text] =
                                        textShape.Table.Rows[iRow].Cells[2].Shape.TextFrame.TextRange.Text.Replace(",", "");
                                }
                            }
                        }
                    }
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(textShape);
                }

                System.Runtime.InteropServices.Marshal.ReleaseComObject(slide);
            }

            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptSlides);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentation);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptPresentations);
            System.Runtime.InteropServices.Marshal.ReleaseComObject(pptApp);

            dtFBR.Rows.Add(dr);
            string[] filePaths = Directory.GetFiles(sPowerPointFolderImg);

            int min_left   = 10000000;
            int min_top    = 10000000;
            int max_bottom = 0;
            int max_right  = 0;

            foreach (string filePath in filePaths)
            {
                string   imagefilename = Path.GetFileNameWithoutExtension(filePath);
                string[] filesplit     = imagefilename.Split('-');

                imageInfo imgInfoObj = new imageInfo();
                imgInfoObj.position = Convert.ToInt32(filesplit[0]);
                imgInfoObj.left     = Convert.ToInt32(filesplit[1].Substring(0, filesplit[1].IndexOf('.')));
                imgInfoObj.top      = Convert.ToInt32(filesplit[2].Substring(0, filesplit[2].IndexOf('.')));
                imgInfoObj.width    = Convert.ToInt32(filesplit[3].Substring(0, filesplit[3].IndexOf('.')));
                imgInfoObj.height   = Convert.ToInt32(filesplit[4].Substring(0, filesplit[4].IndexOf('.')));
                imgInfoObj.filename = filePath;
                dicImageFileInfo.Add(imgInfoObj.position, imgInfoObj);

                if (imgInfoObj.left < min_left)
                {
                    min_left = imgInfoObj.left;
                }
                if (imgInfoObj.top < min_top)
                {
                    min_top = imgInfoObj.top;
                }
                if (max_bottom < (imgInfoObj.height + imgInfoObj.top))
                {
                    max_bottom = (imgInfoObj.height + imgInfoObj.top);
                }
                if (max_right < (imgInfoObj.left + imgInfoObj.width))
                {
                    max_right = imgInfoObj.left + imgInfoObj.width;
                }
            }

            List <int> list = dicImageFileInfo.Keys.ToList();

            list.Sort();

            Bitmap target = new Bitmap(max_right - min_left + 50, max_bottom - min_top + 50);

            using (Graphics g = Graphics.FromImage(target))
            {
                g.PixelOffsetMode   = PixelOffsetMode.HighQuality;
                g.InterpolationMode = InterpolationMode.NearestNeighbor;

                foreach (var key in list)
                {
                    imageInfo temImgInfo = (imageInfo)dicImageFileInfo[key];
                    Bitmap    src        = Image.FromFile(temImgInfo.filename) as Bitmap;

                    g.DrawImage(src,
                                (temImgInfo.left - min_left),
                                ((temImgInfo.top - min_top)));
                    src.Dispose();
                }

                g.Dispose();
            }
            string sImageNameCropTemp = sPowerPointFolderImgProcessed + Path.GetFileName(fbrFileLocation) + "_MergedImages.png";

            target.Save(sImageNameCropTemp);
            dicImageFileInfo.Clear();
            target.Dispose();
            gr.Dispose();
            Array.ForEach(Directory.GetFiles(sPowerPointFolderImg), File.Delete);
        }
예제 #4
0
        public void ProcessRequest(HttpContext context)
        {
            BLL bll = new BLL();

            context.Response.ContentType = "image/png";
            context.Response.AddHeader("Access-Control-Allow-Origin", "*");
            string pId      = context.Request["productId"];//产品Id
            string username = context.Request["username"];
            string key      = context.Request["key"];
            string keyValue = NetHelper.GetMD5(username + "100dh888");

            if (key != keyValue)
            {
                context.Response.Write(json.WriteJson(0, "key值错误", new { }));
            }
            cmUserInfo userInfo = bll.GetUser(string.Format("where username='******'", username.Trim()));

            if (userInfo == null)
            {
                context.Response.Write(json.WriteJson(0, "该用户不存在", new { }));
            }
            if (userInfo.isStop)
            {
                context.Response.Write(json.WriteJson(0, "该用户已被停用", new { }));
            }
            string fileUrl = "";

            try
            {
                HttpPostedFile _upfile = context.Request.Files["file"];
                if (_upfile == null)
                {
                    throw new Exception("请先选择文件!");
                }
                else
                {
                    string fileName = _upfile.FileName;                                            /*获取文件名: C:\Documents and Settings\Administrator\桌面\123.jpg*/
                    string suffix   = fileName.Substring(fileName.LastIndexOf(".") + 1).ToLower(); /*获取后缀名并转为小写: jpg*/
                    int    bytes    = _upfile.ContentLength;                                       //获取文件的字节大小
                    if (!(suffix == "jpg" || suffix == "gif" || suffix == "png" || suffix == "jpeg"))
                    {
                        throw new Exception("只能上传JPE,GIF,PNG文件");
                    }
                    if (bytes > 1024 * 1024 * 2)
                    {
                        throw new Exception("图片最大只能传2M");
                    }
                    string newfileName = DateTime.Now.ToString("yyyyMMddHHmmss");
                    string fileDir     = HttpContext.Current.Server.MapPath("~/upfiles/" + username + "/");
                    if (!Directory.Exists(fileDir))
                    {
                        Directory.CreateDirectory(fileDir);
                    }
                    string saveDir = fileDir + newfileName + "." + suffix; //文件服务器存放路径
                    fileUrl = "/upfiles/" + username + "/" + newfileName + "." + suffix;
                    _upfile.SaveAs(saveDir);                               //保存图片
                    #region 存到sql图片库
                    imageInfo img = new imageInfo();
                    img.imageId   = newfileName;
                    img.imageURL  = fileUrl;
                    img.userId    = userInfo.Id;
                    img.productId = int.Parse(pId);
                    bll.AddImg(img);
                    #endregion
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(ex.ToString());
            }
            context.Response.Write(json.WriteJson(1, "上传成功", new { imgUrl = "http://tool.100dh.cn" + fileUrl }));
        }