コード例 #1
0
ファイル: FileConfig.cs プロジェクト: jjg0519/OA
        public static UserFile GetCompanyItem(string companycode, string StrName)
        {
            UserFile    userFile = new UserFile();
            XmlDocument xDoc     = new XmlDocument();

            xDoc.Load(System.Web.HttpContext.Current.Server.MapPath(path));
            XmlNode node = xDoc.SelectSingleNode("//item[@companycode='" + companycode + "']");

            if (node != null)
            {
                userFile.SavePath     = node.Attributes["savepath"] != null ? node.Attributes["savepath"].Value : "";
                userFile.CompanyCode  = node.Attributes["companycode"] != null ? node.Attributes["companycode"].Value : "";
                userFile.CompanyName  = node.Attributes["companyname"] != null ? node.Attributes["companyname"].Value : "";
                userFile.FileUrl      = node.Attributes["fileurl"] != null ? node.Attributes["fileurl"].Value : "";
                userFile.SystemCode   = node.Attributes["systemcode"] != null ? node.Attributes["systemcode"].Value : "";
                userFile.ThumbnailUrl = node.Attributes["thumbnailurl"] != null ? node.Attributes["thumbnailurl"].Value : "";
                userFile.MaxNumber    = String.IsNullOrEmpty(node.Attributes["maxnumber"].Value) ? 0 : Convert.ToInt32(node.Attributes["maxnumber"].Value);

                userFile.MaxSize     = String.IsNullOrEmpty(node.Attributes["maxsize"].Value) ? 0 : GetByte(node.Attributes["maxsize"].Value);
                userFile.UploadSpeed = String.IsNullOrEmpty(node.Attributes["uploadspeed"].Value) ? 0 : GetByte(node.Attributes["uploadspeed"].Value);
                userFile.ModelCode   = node.Attributes["modelcode"] != null ? node.Attributes["modelcode"].Value : "";
                userFile.Type        = node.Attributes["type"] != null ? node.Attributes["type"].Value : "";
            }
            else
            {
                StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(path), false, System.Text.Encoding.Default);
                try
                {
                    string Filepath = @"C:\文件上传\{0}\{1}\{2}";
                    string aa       = @"<item companycode=" + companycode + " savepath=" + Filepath + " companyname=" + StrName + "   fileurl=\"\" thumbnailurl=\"\" maxnumber=\"2\" maxsize=\"2.MB\" uploadspeed=\"52428800\"/>";
                    sw.Write(aa);
                    sw.Close();
                    //Response.Write("<b>文件写入成功!</b>");
                }
                catch
                {
                    //Response.Write("<b>文件写入失败!</b>");
                }
            }
            return(userFile);
        }
コード例 #2
0
ファイル: FileConfig.cs プロジェクト: JuRogn/OA
        public static UserFile GetCompanyItem(string companycode,string StrName)
        {
            UserFile userFile = new UserFile();
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(System.Web.HttpContext.Current.Server.MapPath(path));
            XmlNode node = xDoc.SelectSingleNode("//item[@companycode='" + companycode + "']");
            if (node != null)
            {
                userFile.SavePath = node.Attributes["savepath"] != null ? node.Attributes["savepath"].Value : "";
                userFile.CompanyCode = node.Attributes["companycode"] != null ? node.Attributes["companycode"].Value : "";
                userFile.CompanyName = node.Attributes["companyname"] != null ? node.Attributes["companyname"].Value : "";
                userFile.FileUrl = node.Attributes["fileurl"] != null ? node.Attributes["fileurl"].Value : "";
                userFile.SystemCode = node.Attributes["systemcode"] != null ? node.Attributes["systemcode"].Value : "";
                userFile.ThumbnailUrl = node.Attributes["thumbnailurl"] != null ? node.Attributes["thumbnailurl"].Value : "";
                userFile.MaxNumber = String.IsNullOrEmpty(node.Attributes["maxnumber"].Value) ? 0 : Convert.ToInt32(node.Attributes["maxnumber"].Value);

                userFile.MaxSize = String.IsNullOrEmpty(node.Attributes["maxsize"].Value) ? 0 : GetByte(node.Attributes["maxsize"].Value);
                userFile.UploadSpeed = String.IsNullOrEmpty(node.Attributes["uploadspeed"].Value) ? 0 : GetByte(node.Attributes["uploadspeed"].Value);
                userFile.ModelCode = node.Attributes["modelcode"] != null ? node.Attributes["modelcode"].Value : "";
                userFile.Type = node.Attributes["type"] != null ? node.Attributes["type"].Value : "";
            }
            else
            {
                StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(path),false, System.Text.Encoding.Default);
                try
                {
                    string Filepath =@"C:\文件上传\{0}\{1}\{2}";
                    string aa=@"<item companycode="+companycode+" savepath="+Filepath+" companyname="+ StrName+"   fileurl=\"\" thumbnailurl=\"\" maxnumber=\"2\" maxsize=\"2.MB\" uploadspeed=\"52428800\"/>";
                    sw.Write(aa);
                    sw.Close();
                    //Response.Write("<b>文件写入成功!</b>");
                }
                catch
                {
                    //Response.Write("<b>文件写入失败!</b>");
                }


            }
            return userFile;
        }
コード例 #3
0
ファイル: FileConfig.cs プロジェクト: jjg0519/OA
        /// <summary>
        /// 获取公司对上传文件的设置信息
        /// </summary>
        /// <param name="companycode">公司代码</param>
        /// <returns></returns>
        public static UserFile GetCompanyItem(string companycode)
        {
            UserFile    userFile = new UserFile();
            XmlDocument xDoc     = new XmlDocument();

            xDoc.Load(System.Web.HttpContext.Current.Server.MapPath(path));
            XmlNode node = xDoc.SelectSingleNode("//item[@companycode='" + companycode + "']");

            if (node != null)
            {
                userFile.SavePath     = node.Attributes["savepath"] != null ? node.Attributes["savepath"].Value : "";
                userFile.CompanyCode  = node.Attributes["companycode"] != null ? node.Attributes["companycode"].Value : "";
                userFile.CompanyName  = node.Attributes["companyname"] != null ? node.Attributes["companyname"].Value : "";
                userFile.FileUrl      = node.Attributes["fileurl"] != null ? node.Attributes["fileurl"].Value : "";
                userFile.SystemCode   = node.Attributes["systemcode"] != null ? node.Attributes["systemcode"].Value : "";
                userFile.ThumbnailUrl = node.Attributes["thumbnailurl"] != null ? node.Attributes["thumbnailurl"].Value : "";
                userFile.MaxNumber    = String.IsNullOrEmpty(node.Attributes["maxnumber"].Value) ? 0 : Convert.ToInt32(node.Attributes["maxnumber"].Value);

                userFile.MaxSize     = String.IsNullOrEmpty(node.Attributes["maxsize"].Value) ? 0 : GetByte(node.Attributes["maxsize"].Value);
                userFile.UploadSpeed = String.IsNullOrEmpty(node.Attributes["uploadspeed"].Value) ? 0 : GetByte(node.Attributes["uploadspeed"].Value);
                userFile.ModelCode   = node.Attributes["modelcode"] != null ? node.Attributes["modelcode"].Value : "";
                userFile.Type        = node.Attributes["type"] != null ? node.Attributes["type"].Value : "";
            }
            else
            {
                //StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(path), false, System.Text.Encoding.Default);
                //try
                //{
                //    sw.Write(TextBox1.Text);
                //    sw.Close();
                //    //Response.Write("<b>文件写入成功!</b>");
                //}
                //catch
                //{
                //    Response.Write("<b>文件写入失败!</b>");
                //}
            }
            return(userFile);
        }
コード例 #4
0
ファイル: FileConfig.cs プロジェクト: JuRogn/OA
        /// <summary>
        /// 获取公司对上传文件的设置信息
        /// </summary>
        /// <param name="companycode">公司代码</param>
        /// <returns></returns>
        public static UserFile GetCompanyItem(string companycode)
        {
            UserFile userFile = new UserFile();
            XmlDocument xDoc = new XmlDocument();
            xDoc.Load(System.Web.HttpContext.Current.Server.MapPath(path));
            XmlNode node = xDoc.SelectSingleNode("//item[@companycode='" + companycode + "']");
            if (node != null)
            {
                userFile.SavePath = node.Attributes["savepath"] != null ? node.Attributes["savepath"].Value : "";
                userFile.CompanyCode = node.Attributes["companycode"] != null ? node.Attributes["companycode"].Value : "";
                userFile.CompanyName = node.Attributes["companyname"] != null ? node.Attributes["companyname"].Value : "";
                userFile.FileUrl = node.Attributes["fileurl"] != null ? node.Attributes["fileurl"].Value : "";
                userFile.SystemCode = node.Attributes["systemcode"] != null ? node.Attributes["systemcode"].Value : "";
                userFile.ThumbnailUrl = node.Attributes["thumbnailurl"] != null ? node.Attributes["thumbnailurl"].Value : "";
                userFile.MaxNumber = String.IsNullOrEmpty(node.Attributes["maxnumber"].Value) ? 0 : Convert.ToInt32(node.Attributes["maxnumber"].Value);

                userFile.MaxSize = String.IsNullOrEmpty(node.Attributes["maxsize"].Value) ? 0 : GetByte(node.Attributes["maxsize"].Value);
                userFile.UploadSpeed = String.IsNullOrEmpty(node.Attributes["uploadspeed"].Value) ? 0 : GetByte(node.Attributes["uploadspeed"].Value);
                userFile.ModelCode = node.Attributes["modelcode"] != null ? node.Attributes["modelcode"].Value : "";
                userFile.Type = node.Attributes["type"] != null ? node.Attributes["type"].Value : "";
            }
            else
            {
                //StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(path), false, System.Text.Encoding.Default);
                //try
                //{
                //    sw.Write(TextBox1.Text);
                //    sw.Close();
                //    //Response.Write("<b>文件写入成功!</b>");
                //}
                //catch
                //{
                //    Response.Write("<b>文件写入失败!</b>");
                //}


            }
            return userFile;
        }
コード例 #5
0
ファイル: UploadService.cs プロジェクト: JuRogn/OA
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="strSystemCode">系统编号</param>
        /// <param name="strModelCode">模块编号</param>
        /// <param name="strFileName">文件名</param>
        /// <param name="strMd5Name">加密文件名</param>
        /// <param name="strID">存储ID(业务ID)</param>
        /// <param name="strGuid">用于真实存储ID(些ID动态产生,用于唯一性)</param>
        /// <param name="data">数据流</param>
        /// <param name="BytesUploaded">已上传量</param>
        /// <param name="dataLength">每次上传文件的大小</param>
        /// <param name="firstChunk">第一块</param>
        /// <param name="lastChunk">最后一块</param>
        /// <param name="strCreateUserID">创建用户ID</param>
        /// <param name="model">model类</param>
        /// <returns></returns>       
        public string SaveUpLoadFile(string strSystemCode, string strModelCode, string strFileName, string strMd5Name, string strID, string strGuid, byte[] data, int BytesUploaded, int dataLength, bool firstChunk, bool lastChunk, string strCreateUserID,UserFile model)
        {
          //  string strPath = string.Format(SavePath, strSystemCode, strModelCode);
            string NewPath = "";
            try
            {
                string strPath = string.Format(model.SavePath, model.CompanyCode, model.SystemCode, model.ModelCode);
                if (!System.IO.Directory.Exists(strPath))
                {
                    if (strPath.IndexOf("\\\\") == 0)
                    {
                        string FirstName = "";
                        string UserName = "";
                        string StrPwd = "";
                        string ComputerName = "";
                        if (StrAuthUser.IndexOf(",") > 0)
                        {
                            FirstName = StrAuthUser.Split(',')[0];
                            ComputerName = FirstName.Split('/')[0];
                            UserName = FirstName.Split('/')[1];
                            StrPwd = StrAuthUser.Split(',')[1];
                        }
                        //LogonImpersonate imper = new LogonImpersonate("user1", "123456");
                        LogonImpersonate imper = new LogonImpersonate(UserName, StrPwd);
                        //WNetHelper.WNetAddConnection(@"liujianxng/user1", "123456", @"//172.16.1.57/fileupload", "Z:");
                        //Directory.CreateDirectory(strPath);
                        string path = @"Z:\" + model.CompanyCode + @"\" + model.SystemCode + @"\" + model.ModelCode;
                        string OldPath = model.SavePath.Split('{')[0].TrimEnd('\\');
                        if (CreateDirectory(path, UserName, StrPwd, OldPath))
                        {
                            SMT.Foundation.Log.Tracer.Debug("创建了驱动器映射");
                        }
                        else
                        {
                            SMT.Foundation.Log.Tracer.Debug("有问题");
                        }
                        //Directory.CreateDirectory(@"Z:\" + model.CompanyCode + @"\" + model.SystemCode + @"\" + model.ModelCode);
                        //file1.SaveAs(@"Z:/newfolder/test.jpg");


                    }
                    else
                    {
                        System.IO.Directory.CreateDirectory(strPath);
                    }
                }
                NewPath = Path.Combine(strPath, strMd5Name); //还未上传完成的路径
                string OldFilePath = Path.Combine(strPath, strFileName); //原来上传的文件
                string PassWordKey = "";//加密字符串
                if (strMd5Name.Length > 8)
                {
                    PassWordKey = strMd5Name.Substring(0, 8);
                }
                else
                {
                    PassWordKey = "12345678";
                }
                if (File.Exists(NewPath))
                {//如果存在,追加内容(续传)
                    using (FileStream fs = File.Open(NewPath, FileMode.Append))
                    {
                        //DecryptFile(fs,strPath, "");
                        fs.Write(data, 0, dataLength);//datalength:文件已上传量
                        fs.Close();
                        fs.Dispose();
                    }
                    using (FileStream fsOld = File.Open(OldFilePath, FileMode.Append))
                    {
                        //DecryptFile(fs,strPath, "");
                        fsOld.Write(data, 0, dataLength);//datalength:文件已上传量
                        fsOld.Close();
                        fsOld.Dispose();
                    }
                }
                else
                {//如果不存在,就创建
                    using (FileStream fs = File.Create(NewPath))
                    {

                        fs.Write(data, 0, data.Length);
                        fs.Close();
                        fs.Dispose();

                    }
                    //创建上传过来的文件
                    using (FileStream fsOld = File.Create(OldFilePath))
                    {

                        fsOld.Write(data, 0, data.Length);
                        fsOld.Close();
                        fsOld.Dispose();

                    }
                }
                if (lastChunk)
                {
                    //string[] strExtension = strMd5Name.Split('.');
                    //string fileName = strID + "." + strExtension[strExtension.Length - 1];
                    string strTempName = Path.Combine(strPath, strMd5Name);//已经上传完成的路径

                    File.Move(NewPath, strTempName);
                    NewPath = strTempName;//最近返回已完成的路径      

                    SMT_FILELIST entity = new SMT_FILELIST();
                    entity.FILENAME = model.FileName;
                    entity.FILESIZE = Convert.ToDecimal(model.FileSize);
                    entity.REMARK = model.Remark;
                    entity.SMTFILELISTID = model.SmtFileListId;// uc.SmtFileListId;//主键ID              
                    entity.FILEURL = model.FileUrl;//文件地址
                    entity.COMPANYCODE = model.CompanyCode;//公司代号
                    entity.COMPANYNAME = model.CompanyName;//公司名字
                    entity.PASSWORD = PassWordKey;//加密字符串
                    //entity.COMPANYNAOWNERDEPARTMENTIDME = model.CompanyName;//公司名字
                    entity.SYSTEMCODE = model.SystemCode;//系统代号
                    entity.MODELCODE = model.ModelCode;//模块代号
                    entity.APPLICATIONID = model.ApplicationID;//业务ID
                    entity.THUMBNAILURL = model.ThumbnailUrl;//缩略图地址
                    entity.FILETYPE = model.FileType;
                    entity.INDEXL = model.INDEXL;//排序
                    entity.REMARK = model.Remark;//备注
                    entity.CREATETIME = model.CreateTime;//创建时间
                    entity.CREATENAME = model.CreateName;//创建人
                    entity.UPDATETIME = model.UpdateTime;//修改时间
                    entity.UPDATENAME = model.UpdateName;//修改人
                    entity.OWNERCOMPANYID = model.OWNERCOMPANYID;
                    entity.OWNERDEPARTMENTID = model.OWNERDEPARTMENTID;
                    entity.OWNERPOSTID = model.OWNERPOSTID;
                    
                    entity.OWNERID = model.OWNERID;
                    entity.FILEURL = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\" + strMd5Name);
                    
                    string imageType = ".JPEG,.JPG,.GIF,.BMP";
                    //判断上传的模块的类型,如果是新闻则生成缩略图

                    if (imageType.IndexOf(entity.FILETYPE) > 0 || imageType.ToLower().IndexOf(entity.FILETYPE) > 0)
                    {
                            
                        string thumbPath = string.Format(model.SavePath, model.CompanyCode, model.SystemCode, model.ModelCode)+"\\thumb\\";
                        if (!System.IO.Directory.Exists(thumbPath))
                        {
                            if (strPath.IndexOf("\\\\") == 0)
                            {
                                string FirstName = "";
                                string UserName = "";
                                string StrPwd = "";
                                string ComputerName = "";
                                if (StrAuthUser.IndexOf(",") > 0)
                                {
                                    FirstName = StrAuthUser.Split(',')[0];
                                    ComputerName = FirstName.Split('/')[0];
                                    UserName = FirstName.Split('/')[1];
                                    StrPwd = StrAuthUser.Split(',')[1];
                                }
                                //LogonImpersonate imper = new LogonImpersonate("user1", "123456");
                                LogonImpersonate imper = new LogonImpersonate(UserName, StrPwd);
                                //WNetHelper.WNetAddConnection(@"liujianxng/user1", "123456", @"//172.16.1.57/fileupload", "Z:");
                                //Directory.CreateDirectory(strPath);
                                string path = @"Z:\" + model.CompanyCode + @"\" + model.SystemCode + @"\" + model.ModelCode;
                                string OldPath = model.SavePath.Split('{')[0].TrimEnd('\\');
                                if (CreateDirectory(path, UserName, StrPwd, OldPath))
                                {
                                    SMT.Foundation.Log.Tracer.Debug("创建了驱动器映射");
                                }
                                else
                                {
                                    SMT.Foundation.Log.Tracer.Debug("有问题");
                                }
                                //Directory.CreateDirectory(@"Z:\" + model.CompanyCode + @"\" + model.SystemCode + @"\" + model.ModelCode);
                                //file1.SaveAs(@"Z:/newfolder/test.jpg");


                            }
                            else
                            {
                                System.IO.Directory.CreateDirectory(thumbPath);
                            }
                        }
                        string thumbFile = thumbPath + strMd5Name;
                        string strType = "JPG"; 
                        strType = entity.FILETYPE.Substring(1, entity.FILETYPE.Length-1).ToUpper();
                        MakeImageThumb.MakeThumbnail(OldFilePath, thumbFile, 250, 200, "DB", strType);
                        //保存到数据库的路径
                        string strSaveThumb = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\thumb\\" + strMd5Name);
                        //entity.THUMBNAILURL = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\" + strMd5Name);
                        entity.THUMBNAILURL = strSaveThumb;
                    }
                    

                    dal.AddEntity(entity);
                    //DecryptFile(NewPath);
                    //Encrypt(NewPath, PassWordKey);
                    //FileStream filOutStream = new FileStream(NewfilePath, FileMode.OpenOrCreate, FileAccess.Write);
                    //InputFileStream = File.OpenWrite(FileName);
                    CryptoHelp.EncryptFile(OldFilePath, NewPath, PassWordKey);
                    //Decrypt(NewPath);
                    //model.FileUrl = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode +"\\"+ fileName);
                    //dal.Add(model);

                }
                
            }
            catch (Exception ex)
            {                
                SMT.Foundation.Log.Tracer.Debug("model.SavePath:" +model.SavePath);
                SMT.Foundation.Log.Tracer.Debug("model.CompanyCode:" +model.CompanyCode);
                SMT.Foundation.Log.Tracer.Debug("model.SystemCode:" +model.SystemCode);
                SMT.Foundation.Log.Tracer.Debug("model.ModelCode:" +model.ModelCode);
                SMT.Foundation.Log.Tracer.Debug("调用上传文件出错:"+ex.ToString());
            }
            return NewPath;
        }
コード例 #6
0
ファイル: UploadService.cs プロジェクト: JuRogn/OA
 public UserFile CheckFileExists(UserFile model, string strMd5Name)
 {           
     string strPath = string.Format(model.SavePath, model.CompanyCode, model.SystemCode, model.ModelCode);
     string NewPath = Path.Combine(strPath, strMd5Name); //还未上传完成的路径
     if (File.Exists(NewPath))
     {
         FileInfo fi = new FileInfo(NewPath);
         model.BytesUploaded = fi.Length;
         model.FileUrl = NewPath;
         
         //return fi.Length;
     }
     return model;
 }
コード例 #7
0
ファイル: UploadService.cs プロジェクト: JuRogn/OA
        public string SaveUpLoadFileIsExist(string strSystemCode, string strModelCode, string strFileName, string strMd5Name, string strID, string strGuid, byte[] data, int BytesUploaded, int dataLength, bool firstChunk, bool lastChunk, string strCreateUserID,UserFile model)
        {
          
            string NewPath = "";
            try
            {
                string strPath = string.Format(model.SavePath, model.CompanyCode, model.SystemCode, model.ModelCode);
                                
                string PassWordKey = "";//加密字符串
                if (strMd5Name.Length > 8)
                {
                    PassWordKey = strMd5Name.Substring(0, 8);
                }
                else
                {
                    PassWordKey = "12345678";
                }
                
                
                    //string[] strExtension = strMd5Name.Split('.');
                    //string fileName = strID + "." + strExtension[strExtension.Length - 1];
                string strTempName = Path.Combine(strPath, strMd5Name);//已经上传完成的路径

                //File.Move(NewPath, strTempName);
                NewPath = strTempName;//最近返回已完成的路径      

                SMT_FILELIST entity = new SMT_FILELIST();
                entity.FILENAME = model.FileName;
                entity.FILESIZE = Convert.ToDecimal(model.FileSize);
                entity.REMARK = model.Remark;
                entity.SMTFILELISTID = model.SmtFileListId;// uc.SmtFileListId;//主键ID              
                entity.FILEURL = strTempName;//model.FileUrl;//文件地址
                entity.COMPANYCODE = model.CompanyCode;//公司代号
                entity.COMPANYNAME = model.CompanyName;//公司名字
                entity.PASSWORD = PassWordKey;//加密字符串
                //entity.COMPANYNAOWNERDEPARTMENTIDME = model.CompanyName;//公司名字
                entity.SYSTEMCODE = model.SystemCode;//系统代号
                entity.MODELCODE = model.ModelCode;//模块代号
                entity.APPLICATIONID = model.ApplicationID;//业务ID
                entity.THUMBNAILURL = model.ThumbnailUrl;//缩略图地址
                entity.FILETYPE = model.FileType;
                entity.INDEXL = model.INDEXL;//排序
                entity.REMARK = model.Remark;//备注
                entity.CREATETIME = model.CreateTime;//创建时间
                entity.CREATENAME = model.CreateName;//创建人
                entity.UPDATETIME = model.UpdateTime;//修改时间
                entity.UPDATENAME = model.UpdateName;//修改人
                entity.OWNERCOMPANYID = model.OWNERCOMPANYID;
                entity.OWNERDEPARTMENTID = model.OWNERDEPARTMENTID;
                entity.OWNERPOSTID = model.OWNERPOSTID;
                entity.OWNERID = model.OWNERID;
                entity.FILEURL = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\" + strMd5Name);
                if (this.GetFileListByApplicationIDAndFileName(model.ApplicationID,strMd5Name).FileList != null)
                {
                    if (this.GetFileListByApplicationIDAndFileName(model.ApplicationID,strMd5Name).FileList.Count() > 0)
                    {
                        NewPath = "EXIST";
                    }
                    else
                    {
                        dal.AddEntity(entity);
                    }
                }
                else
                {
                    dal.AddEntity(entity);
                }
                    //DecryptFile(NewPath);
                    
                
                
            }
            catch (Exception ex)
            {                
                SMT.Foundation.Log.Tracer.Debug("model.SavePath:" +model.SavePath);
                SMT.Foundation.Log.Tracer.Debug("model.CompanyCode:" +model.CompanyCode);
                SMT.Foundation.Log.Tracer.Debug("model.SystemCode:" +model.SystemCode);
                SMT.Foundation.Log.Tracer.Debug("model.ModelCode:" +model.ModelCode);
                SMT.Foundation.Log.Tracer.Debug("调用上传文件出错:"+ex.ToString());
            }
            return NewPath;
        }
コード例 #8
0
ファイル: UploadService.cs プロジェクト: JuRogn/OA
        public string SaveUploadFileForMvc(string strSystemCode, string strModelCode, string strFileName, string strMd5Name, string strID, string strGuid, string strCreateUserID, UserFile model)
        {
            string NewPath = "";
            try
            {
                SMT.Foundation.Log.Tracer.Debug("mvc2.0开始添加上传文件的记录");
                string strPath = string.Format(model.SavePath, model.CompanyCode, model.SystemCode, model.ModelCode);

                NewPath = Path.Combine(strPath, strMd5Name); //还未上传完成的路径
                string OldFilePath = Path.Combine(strPath, strFileName); //原来上传的文件
                string PassWordKey = "";//加密字符串
                if (strMd5Name.Length > 8)
                {
                    PassWordKey = strMd5Name.Substring(0, 8);
                }
                else
                {
                    PassWordKey = "12345678";
                }
                string strTempName = Path.Combine(strPath, strMd5Name);//已经上传完成的路径
                SMT.Foundation.Log.Tracer.Debug("开始添加上传文件的记录strTempName:" + strTempName);
                
                NewPath = strTempName;//最近返回已完成的路径
                SMT_FILELIST entity = new SMT_FILELIST();
                entity.FILENAME = model.FileName;
                entity.FILESIZE = Convert.ToDecimal(model.FileSize);
                entity.REMARK = model.Remark;
                entity.SMTFILELISTID = model.SmtFileListId;// uc.SmtFileListId;//主键ID              
                entity.FILEURL = model.FileUrl;//文件地址
                entity.COMPANYCODE = model.CompanyCode;//公司代号
                entity.COMPANYNAME = model.CompanyName;//公司名字
                entity.PASSWORD = PassWordKey;//加密字符串
                //entity.COMPANYNAOWNERDEPARTMENTIDME = model.CompanyName;//公司名字
                entity.SYSTEMCODE = model.SystemCode;//系统代号
                entity.MODELCODE = model.ModelCode;//模块代号
                entity.APPLICATIONID = model.ApplicationID;//业务ID
                entity.THUMBNAILURL = model.ThumbnailUrl;//缩略图地址
                entity.FILETYPE = model.FileType;
                entity.INDEXL = model.INDEXL;//排序
                entity.REMARK = model.Remark;//备注
                entity.CREATETIME = model.CreateTime;//创建时间
                entity.CREATENAME = model.CreateName;//创建人
                entity.UPDATETIME = model.UpdateTime;//修改时间
                entity.UPDATENAME = model.UpdateName;//修改人
                entity.OWNERCOMPANYID = model.OWNERCOMPANYID;
                entity.OWNERDEPARTMENTID = model.OWNERDEPARTMENTID;
                entity.OWNERPOSTID = model.OWNERPOSTID;

                entity.OWNERID = model.OWNERID;
                entity.FILEURL = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\" + strMd5Name);

                string imageType = ".JPEG,.JPG,.GIF,.BMP";
                //判断上传的模块的类型,如果是新闻则生成缩略图
                if (imageType.IndexOf(entity.FILETYPE) > 0 || imageType.ToLower().IndexOf(entity.FILETYPE) > 0)
                {
                    string thumbPath = string.Format(model.SavePath, model.CompanyCode, model.SystemCode, model.ModelCode) + "\\thumb\\";
                    string thumbFile = thumbPath + strMd5Name;
                    string strType = "JPG";
                    strType = entity.FILETYPE.Substring(1, entity.FILETYPE.Length - 1).ToUpper();
                    //MakeImageThumb.MakeThumbnail(OldFilePath, thumbFile, 250, 200, "DB", strType);
                    //保存到数据库的路径
                    string strSaveThumb = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\thumb\\" + strMd5Name);
                    //entity.THUMBNAILURL = string.Format("\\{0}\\{1}\\{2}", model.CompanyCode, model.SystemCode, model.ModelCode + "\\" + strMd5Name);
                    entity.THUMBNAILURL = strSaveThumb;
                }
                int intResult = dal.AddEntity(entity);
                if (intResult > 0)
                {
                    SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc添加成功:" + entity.APPLICATIONID);
                    SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc添加FileUrl成功:" + entity.FILEURL);
                    SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc添加FileName成功:" + entity.FILENAME);
                }
                else
                {
                    SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc添加失败:" + entity.APPLICATIONID);
                    SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc添加FileUrl失败:" + entity.FILEURL);
                    SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc添加FileName失败:" + entity.FILENAME);
                }
            }
            catch (Exception ex)
            {
                SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc操作model.SavePath:" + model.SavePath);
                SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc操作model.CompanyCode:" + model.CompanyCode);
                SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc操作.SystemCode:" + model.SystemCode);
                SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc操作model.ModelCode:" + model.ModelCode);
                SMT.Foundation.Log.Tracer.Debug("SaveUploadFileForMvc操作调用上传文件出错:" + ex.ToString());
                NewPath = "";
            }
            return NewPath;
        }