コード例 #1
0
        public int upload(UploadImg request)
        {
            int    i          = -1;
            string folderPath = "";

            if (!string.IsNullOrEmpty(request.Key))
            {
                try
                {
                    using (var db = DbConnectionFactory.OpenDbConnection())
                    {
                        string       strSQL = "Select  DocumentPath From Saco1 ";
                        List <Saco1> saco1  = db.Select <Saco1>(strSQL);
                        if (saco1.Count > 0)
                        {
                            folderPath = saco1[0].DocumentPath + "\\" + request.TableName + "\\" + request.Key;
                        }
                    }
                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                    if (Directory.Exists(folderPath))
                    {
                        //if (!FolderSecurityHelper.ExistFolderRights(folderPath))
                        //{
                        FolderSecurityHelper.SetFolderRights(folderPath);
                        //}
                    }
                    if (string.IsNullOrEmpty(request.FileName))
                    {
                        return(i);
                    }
                    string resultFile = Path.Combine(folderPath, request.FileName);
                    if (File.Exists(resultFile))
                    {
                        File.Delete(resultFile);
                    }
                    //Image img = System.Drawing.Image.FromStream(request.RequestStream);
                    //img.Save(System.IO.Path.GetTempPath() + "\\" + request.FileName, ImageFormat.Jpeg);
                    if (!string.IsNullOrEmpty(request.Base64))
                    {
                        string   strBase64 = request.Base64;
                        string[] base64s   = strBase64.Split(',');
                        if (base64s.Length > 0)
                        {
                            byte[] arr = Convert.FromBase64String(base64s[1]);
                            using (MemoryStream ms = new MemoryStream(arr))
                            {
                                Bitmap bmp = new Bitmap(ms);
                                bmp.Save(resultFile, System.Drawing.Imaging.ImageFormat.Png);
                                //bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp);
                                //bmp.Save(txtFileName + ".gif", ImageFormat.Gif);
                                //bmp.Save(txtFileName + ".png", ImageFormat.Png);
                                i = 0;
                            }
                        }
                    }
                    else
                    {
                        using (FileStream file = File.Create(resultFile))
                        {
                            request.RequestStream.Copy(file);
                            i = 0;
                        }
                    }
                    if (i.Equals(0))
                    {
                        using (var db = DbConnectionFactory.OpenDbConnection())
                        {
                            if (request.TableName == "Aemp1")
                            {
                                db.Update(request.TableName,
                                          "AttachmentFlag = 'Y'",
                                          " TrxNo='" + request.Key + "'");
                            }
                            else
                            {
                                db.Update(request.TableName,
                                          " AttachmentFlag = 'Y'",
                                          " DeliveryOrderNo='" + request.Key + "'");
                            }
                        }
                    }
                }
                catch { throw; }
            }
            return(i);
        }
コード例 #2
0
ファイル: UploadImg.cs プロジェクト: sysmagicapp/TMS-Basis
        public int upload(UploadImg request)
        {
            int    i        = -1;
            string filePath = "";

            if (!string.IsNullOrEmpty(request.JobNo))
            {
                try
                {
                    using (var db = DbConnectionFactory.OpenDbConnection())
                    {
                        string       strSQL = "Select Top 1 DocumentPath From Saco1";
                        List <Saco1> saco1  = db.Select <Saco1>(strSQL);
                        if (saco1.Count > 0)
                        {
                            filePath = saco1[0].DocumentPath + "\\Tobk1\\" + request.JobNo;
                        }
                    }
                    if (!Directory.Exists(filePath))
                    {
                        Directory.CreateDirectory(filePath);
                    }
                    string resultFile = Path.Combine(filePath, request.FileName);
                    if (File.Exists(resultFile))
                    {
                        File.Delete(resultFile);
                    }
                    //Image img = System.Drawing.Image.FromStream(request.RequestStream);
                    //img.Save(System.IO.Path.GetTempPath() + "\\" + request.FileName, ImageFormat.Jpeg);
                    if (!string.IsNullOrEmpty(request.Base64))
                    {
                        string   strBase64 = request.Base64;
                        string[] base64s   = strBase64.Split(',');
                        if (base64s.Length > 0)
                        {
                            byte[] arr = Convert.FromBase64String(base64s[1]);
                            using (MemoryStream ms = new MemoryStream(arr))
                            {
                                Bitmap bmp = new Bitmap(ms);
                                bmp.Save(resultFile, System.Drawing.Imaging.ImageFormat.Png);
                                //bmp.Save(txtFileName + ".bmp", ImageFormat.Bmp);
                                //bmp.Save(txtFileName + ".gif", ImageFormat.Gif);
                                //bmp.Save(txtFileName + ".png", ImageFormat.Png);
                                i = 0;
                            }
                        }
                    }
                    if (i.Equals(0))
                    {
                        using (var db = DbConnectionFactory.OpenDbConnection())
                        {
                            i = db.Update <Tobk1>(
                                new
                            {
                                AttachmentFlag = "Y"
                            },
                                p => p.JobNo == request.JobNo
                                );
                        }
                    }
                }
                catch { throw; }
            }
            return(i);
        }