Beispiel #1
0
        /// <summary>
        //删除文件《对外接口》
        /// </summary>
        /// <param name="filename">文件名</param>
        /// <param name="ctype">文件类型(图片,视频,红外)</param>
        public ActionResult AppDeleteFile(string filename, string module, string ctype)
        {
            string strJson = "success";

            try
            {
                string filePath = Server.MapPath("~/UploadFiles/" + module + DateTime.Now.ToString("yyMM") + "/" + ctype);
                //删除数据库表中数据ctype分为image,file,video if (ctype.Equals("file"))
                List <t_cm_files> list = bll.t_cm_files.Where(d => d.FileName.Contains(filename) && d.Modules == module && d.FileType == ctype).ToList();
                if (list.Count > 0)
                {
                    string mappth   = System.AppDomain.CurrentDomain.BaseDirectory;
                    string fileName = mappth + list[0].FilePath.Replace("~", "").Replace("/", "\\");
                    DirectoryUtil.DeleteFile(fileName);
                    t_cm_files img = list[0];
                    bll.t_cm_files.DeleteObject(img);
                    bll.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                strJson = "error";
            }
            return(Content(strJson));
        }
Beispiel #2
0
        /// <summary>
        /// 删除已经上传的文件
        /// </summary>
        /// <param name="id"></param>
        public ActionResult DeleteFile(string filename, string ctype, int pid)
        {
            string strJson = "success";

            try
            {
                int epid = 0;
                //记录预案编号
                string filePath = Server.MapPath("~/UploadFiles/PDR/");
                DirectoryUtil.DeleteFile(filePath + filename);

                //删除文件t_cm_files表中。
                List <t_cm_files> Filelist = bll.t_cm_files.Where(d => (d.FilePath.Contains(filename) && d.FileType == ctype && d.Modules == "PDR")).ToList();
                if (Filelist.Count > 0)
                {
                    t_cm_files files_Temp = Filelist[0];
                    epid = int.Parse(files_Temp.Fk_ID.ToString().Trim());
                    bll.t_cm_files.DeleteObject(files_Temp);
                    bll.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                strJson = "error";
            }
            return(Content(strJson));
        }
        /// <summary>
        /// 向系统资料表中添加记录
        /// </summary>
        /// <param name="filesInfo">记录信息</param>
        /// <returns>true:表示保存成功,false:表示保存失败</returns>
        private bool AddFilesInfo(t_cm_files filesInfo)
        {
            bool flag = false;

            try
            {
                bll.t_cm_files.AddObject(filesInfo);
                bll.SaveChanges();
                flag = true;
            }
            catch (Exception ex)
            {
                flag = false;
            }
            return(flag);
        }
        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="epid"></param>
        /// <returns></returns>
        public ActionResult OnDelete(int epid)
        {
            string strJson = "success";

            try
            {
                string fileSaveName = string.Empty;
                //从t_cm_files表中获取文件名称,并删除表中记录
                List <t_cm_files> Filelist = bll.t_cm_files.Where(d => (d.Fk_ID == epid && d.Modules == "EmergencyPlan")).ToList();
                if (Filelist.Count > 0)
                {
                    t_cm_files files_Temp    = Filelist[0];
                    string     filePath_Temp = files_Temp.FilePath;
                    string[]   fileArry      = filePath_Temp.Split('/');
                    if (fileArry.Length > 0)
                    {
                        fileSaveName = fileArry[fileArry.Length - 1];
                    }
                    else
                    {
                    }
                    //删除文件
                    string filePath = Server.MapPath("~/UploadFiles/EmergencyPlan/");
                    DirectoryUtil.DeleteFile(filePath + fileSaveName);
                    //删除记录
                    bll.t_cm_files.DeleteObject(files_Temp);
                    bll.SaveChanges();
                    Common.InsertLog("应急预案管理", CurrentUser.UserName, "删除应急预案[" + epid + "]");//log
                }
                //在t_PM_EmergencyPlan表中删除记录。
                List <t_PM_EmergencyPlan> list = bll.t_PM_EmergencyPlan.Where(d => (d.EPID == epid)).ToList();
                if (list.Count > 0)
                {
                    t_PM_EmergencyPlan EmergencyPlan = list[0];
                    bll.t_PM_EmergencyPlan.DeleteObject(EmergencyPlan);
                    bll.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                strJson = "error";
            }
            return(Content(strJson));
        }
Beispiel #5
0
        //新增文件
        public ActionResult AddFile(t_cm_files file)
        {
            string strResult = "ok";

            try
            {
                file.CommitTime = DateTime.Now;
                file.CommitUser = CurrentUser.UserName;
                bll.t_cm_files.AddObject(file);

                int recount = bll.SaveChanges();
                //log
                Common.InsertLog("新增文件", CurrentUser.UserName, "新增资料,资料模块[" + file.Modules + "_" + file.ID + "]");
            }
            catch
            {
                strResult = "error";
            }
            return(Content(strResult));
        }
        /// <summary>
        /// 删除已经上传的文件
        /// </summary>
        /// <param name="id"></param>
        public ActionResult DeleteFile2(string filename, string ctype, int pid)
        {
            string strJson = "success";

            try
            {
                int epid = 0;
                //记录预案编号
                string filePath = Server.MapPath("~/UploadFiles/EmergencyPlan/");
                DirectoryUtil.DeleteFile(filePath + filename);

                //删除文件到t_PM_EmergencyPlan表和t_cm_files表中。
                List <t_cm_files> Filelist = bll.t_cm_files.Where(d => (d.FileName.Contains(filename) && d.FileType == ctype && d.Modules == "EmergencyPlan")).ToList();
                if (Filelist.Count > 0)
                {
                    t_cm_files files_Temp = Filelist[0];
                    epid = int.Parse(files_Temp.Fk_ID.ToString().Trim());
                    string mappth   = System.AppDomain.CurrentDomain.BaseDirectory;
                    string fileName = "";
                    fileName = mappth + files_Temp.FilePath.Replace("~", "").Replace("/", "\\");//删除对应路径的文件
                    DirectoryUtil.DeleteFile(fileName);
                    bll.t_cm_files.DeleteObject(files_Temp);
                    bll.SaveChanges();
                }

                List <t_PM_EmergencyPlan> list = bll.t_PM_EmergencyPlan.Where(d => (d.EPID == epid && d.PID == pid)).ToList();
                if (list.Count > 0)
                {
                    t_PM_EmergencyPlan EmergencyPlan = list[0];
                    bll.t_PM_EmergencyPlan.DeleteObject(EmergencyPlan);
                    bll.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                strJson = "error";
            }
            return(Content(strJson));
        }
Beispiel #7
0
        /// <summary>
        /// 资料上传《对外接口》
        /// </summary>
        /// <param name="files">文件列表</param>
        /// <param name="Modules">所属模块</param>
        /// <param name="fk_id">ID</param>
        /// <param name="FSource">来源</param>
        /// <param name="FileType">资料类型(图片,视频)</param>
        /// <param name="Remark">备注</param>
        /// <param name="CommitUser">上传用户</param>
        /// <returns>0表示未登录,1表示成功,2表示太大 3上传失败,网络超时</returns>
        public ActionResult MultiUpload(IEnumerable <HttpPostedFileBase> files, string Modules, int fk_id, string FSource, string Remark, string CommitUser)
        {
            string reCode = "0";

            try
            {
                double maxsize = 1024;
                //设置文件上传路径
                string pathForSaving = "";// Server.MapPath("~/UploadFiles/" + Modules + DateTime.Now.ToString("yyMM"));
                //检查目录是否存在,如果不存在,则新建目录

                string     filename, filePath, fileExtension, saveName; //原文件名称,文件路径,文件后缀,文件重命名
                int        fileSize;                                    //文件大小
                byte[]     FileData;                                    //获取文件信息
                double     fileSizeKB;                                  //转换文件大小,单位KB
                string     fSize;                                       //文件大小完整,如:54KB
                string     FileType = "unknow";                         //文件类型
                t_cm_files obj;
                string[]   pic = { ".jpg", ".jpeg", ".bmp", ".png", ".gif" };
                string[]   ved = { ".avi", ".rmvb", ".mp4", ".flv", ".wmv", ".mkv", ".mpeg" };
                string[]   voi = { ".wav", ".mp3", ".wma", ".ogg", ".ape", ".acc", ".3gp" };
                // 遍历文件
                foreach (var file in files)
                {
                    if (file != null && file.ContentLength > 0)
                    {
                        filename      = file.FileName;
                        fileExtension = Path.GetExtension(filename);        //文件扩展名
                        saveName      = DateTime.Now.Ticks + fileExtension; //文件重命名
                        //根据判断文件类型
                        string LFE = fileExtension.ToLower();
                        if (pic.Contains(LFE))
                        {
                            FileType = "image";
                        }
                        else if (ved.Contains(LFE))
                        {
                            FileType = "infrared";
                        }
                        else if (voi.Contains(LFE))
                        {
                            FileType = "voice";
                        }
                        pathForSaving = Server.MapPath("~/UploadFiles/" + Modules + DateTime.Now.ToString("yyMM") + "/" + FileType);
                        //判断文件是否存在
                        if (this.CreateFolderIfNeeded(pathForSaving))
                        {
                            //上传资料
                            var path = Path.Combine(pathForSaving, saveName);
                            file.SaveAs(path);//上传资料到服务器
                            FileData   = ReadFileBytes(file);
                            fileSize   = FileData.Length;
                            fileSizeKB = fileSize / 1024;
                            fileSizeKB = Math.Round(fileSizeKB, 2);
                            if (ConfigurationManager.AppSettings[Modules + "size"] != null)
                            {
                                maxsize = Convert.ToDouble(ConfigurationManager.AppSettings[Modules + "size"]);
                            }
                            //判断资料大小
                            //if (fileSizeKB > maxsize)
                            //{
                            //    reCode = "2";
                            //    break;
                            //}
                            //else
                            //{}

                            fSize = fileSizeKB + "KB";
                            //文件大小限制(后期添加)
                            filePath = "~/UploadFiles/" + Modules + DateTime.Now.ToString("yyMM") + "/" + FileType + "/" + saveName;
                            //保存到资料库
                            obj               = new t_cm_files();
                            obj.CommitTime    = DateTime.Now;
                            obj.CommitUser    = CommitUser;
                            obj.FileName      = filename;
                            obj.FilePath      = filePath;
                            obj.FileExtension = fileExtension;
                            obj.FileSize      = fSize;
                            obj.FileType      = FileType;
                            obj.Fk_ID         = fk_id;
                            obj.FSource       = FSource;
                            obj.MaxTemp       = 0;
                            obj.MinTemp       = 0;
                            obj.Remark        = Remark;
                            obj.Modules       = Modules;
                            bll.t_cm_files.AddObject(obj);
                            bll.SaveChanges();
                        }
                    }
                }
                reCode = "1";
            }
            catch (Exception ex)
            {
                reCode = "3";
            }
            return(Content(reCode));
        }
Beispiel #8
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="fileData"></param>
        /// <param name="folder"></param>
        /// <param name="pid">配电室编号</param>
        /// <param name="ctype"></param>
        /// <returns></returns>
        public ActionResult Upload(HttpPostedFileBase fileData, string folder, string ctype = "file", int pid = 1)
        {
            if (fileData != null)
            {
                try
                {
                    //备注
                    string Remark = string.Empty;
                    //上传用户
                    string CommitUser = string.Empty;
                    //资料类型(图片,视频,文档)
                    string FileType = string.Empty;
                    //来源(web,app)
                    string FSource = string.Empty;
                    //所属模块
                    string Modules = string.Empty;

                    ControllerContext.HttpContext.Request.ContentEncoding  = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.Charset         = "UTF-8";

                    // 文件上传后的保存路径
                    string url      = "~/UploadFiles/PDR/";
                    string filePath = Server.MapPath(url);

                    DirectoryUtil.CreateDirectory(filePath);

                    string fileName      = Path.GetFileName(fileData.FileName); //原始文件名称
                    string fileExtension = Path.GetExtension(fileName);         //文件扩展名
                    //string saveName = Guid.NewGuid().ToString() + fileExtension; //保存文件名称
                    string saveName = DateTime.Now.Ticks + fileExtension;
                    fileData.SaveAs(filePath + saveName);
                    byte[] FileData   = ReadFileBytes(fileData);
                    double fileSize   = FileData.Length;
                    double fileSizeKB = fileSize / 1024;
                    fileSizeKB = Math.Round(fileSizeKB, 2);
                    string fSize = fileSizeKB + "KB";

                    //上传文件到t_cm_files表

                    //资料类型(图片,视频,文档)
                    FileType = ctype;
                    //来源(web,app)
                    FSource = "web";
                    //所属模块
                    Modules = "PDR";
                    //保存到资料库t_cm_files表
                    t_cm_files obj = new t_cm_files();
                    obj.CommitTime    = DateTime.Now;
                    obj.CommitUser    = CurrentUser.UserName;
                    obj.FileName      = fileName;
                    obj.FilePath      = url + saveName;
                    obj.FileExtension = fileExtension;
                    obj.FileSize      = fSize;
                    obj.FileType      = FileType;
                    obj.Fk_ID         = pid;
                    obj.FSource       = FSource;
                    obj.MaxTemp       = 0;
                    obj.MinTemp       = 0;
                    obj.Remark        = Remark;
                    obj.Modules       = Modules;
                    bll.t_cm_files.AddObject(obj);
                    bll.SaveChanges();
                    return(Content(saveName));
                }
                catch (Exception ex)
                {
                    return(Content(ex.ToString()));
                }
            }
            else
            {
                return(Content("false"));
            }
        }
        /// <summary>
        /// 信息查询
        /// </summary>
        /// <param name="epid">预案编号</param>
        /// <param name="pid">配电室编号</param>
        /// <returns></returns>
        public ActionResult OnSearch(int epid, int pid)
        {
            try
            {
                string        strJson      = string.Empty;
                StringBuilder sbSearchInfo = new StringBuilder();
                sbSearchInfo.Append(" <ul> ");
                if (epid == 0 && pid == 0)
                {
                    //编号都为空
                }
                else if (epid == 0 && pid != 0)
                {
                    //按照配电房编号进行查询
                    //t_PM_EmergencyPlan表
                    List <t_PM_EmergencyPlan> list = bll.t_PM_EmergencyPlan.Where(d => (d.PID == pid)).ToList();
                    if (list.Count > 0)
                    {
                        for (int i = 0; i < list.Count; i++)
                        {
                            t_PM_EmergencyPlan EmergencyPlan = list[i];
                            //t_cm_files表中。
                            List <t_cm_files> Filelist = bll.t_cm_files.Where(d => (d.Fk_ID == EmergencyPlan.EPID && d.Modules == "EmergencyPlan")).ToList();
                            if (Filelist.Count > 0)
                            {
                                //获取当前预案上传文件的详细信息
                                t_cm_files files_Temp = Filelist[0];
                                sbSearchInfo.Append("  <li>  ");
                                sbSearchInfo.Append("  <div> ");
                                sbSearchInfo.Append("  <img src=\"../content/images/wordicon.png\" /> ");
                                sbSearchInfo.Append("  <span>");
                                sbSearchInfo.Append("  <h3>");
                                string   fileSaveName      = string.Empty;
                                string[] fileNameArry_Temp = files_Temp.FileName.Split('.');
                                if (fileNameArry_Temp.Length > 0)
                                {
                                    fileSaveName = fileNameArry_Temp[0];
                                }
                                else
                                {
                                }
                                sbSearchInfo.Append(fileSaveName);
                                sbSearchInfo.Append("  </h3>");
                                sbSearchInfo.Append("  <p>");
                                DateTime dateTime_Temp = new DateTime();
                                dateTime_Temp = DateTime.Parse(files_Temp.CommitTime.ToString().Trim());
                                sbSearchInfo.Append("  上传:");
                                sbSearchInfo.Append(dateTime_Temp.ToString("yyyy-MM-dd HH:mm:ss"));
                                sbSearchInfo.Append("  </p>");
                                sbSearchInfo.Append("  <p>");
                                sbSearchInfo.Append("  大小:");
                                sbSearchInfo.Append(files_Temp.FileSize);
                                sbSearchInfo.Append("  </p>");
                                sbSearchInfo.Append("  </span>");
                                sbSearchInfo.Append("  </div>  ");
                                sbSearchInfo.Append("  <div class=\"standfile_btn\">");
                                sbSearchInfo.Append("  <button");
                                sbSearchInfo.Append("  title=\"下 载\" onclick=\"DoDownload('");
                                string[] fileDirArry_Temp = files_Temp.FilePath.Split('/');
                                string   newFileDir       = string.Empty;
                                if (fileDirArry_Temp.Length > 0)
                                {
                                    for (int j = 1; j < fileDirArry_Temp.Length; j++)
                                    {
                                        newFileDir = newFileDir + "/" + fileDirArry_Temp[j].Trim();
                                    }
                                }
                                else
                                {
                                }
                                sbSearchInfo.Append(newFileDir);
                                sbSearchInfo.Append("')\"");
                                sbSearchInfo.Append("  class=\"page_table_but3 radius5\"><img src=\"../content/images/download.png\" />下载</button>");
                                sbSearchInfo.Append("  <button");
                                sbSearchInfo.Append("  title=\"删 除\" onclick=\"DoDelete(");
                                sbSearchInfo.Append(files_Temp.Fk_ID.ToString());
                                sbSearchInfo.Append(")\"");
                                sbSearchInfo.Append("  class=\"page_table_but3 radius5\"><img src=\"../content/images/delete_new.png\" />删除</button>");

                                sbSearchInfo.Append("  </div>");
                                sbSearchInfo.Append("  </li>  ");
                            }
                        }
                    }
                }
                else if (epid != 0)
                {
                    //按照预案编号进行查询,直接进入t_cm_file表中查询
                    List <t_cm_files> Filelist = bll.t_cm_files.Where(d => (d.Fk_ID == epid && d.Modules == "EmergencyPlan")).ToList();
                    if (Filelist.Count > 0)
                    {
                        //获取当前预案上传文件的详细信息
                        t_cm_files files_Temp = Filelist[0];
                        sbSearchInfo.Append("  <li>  ");
                        sbSearchInfo.Append("  <div> ");
                        sbSearchInfo.Append("  <img src=\"../content/images/wordicon.png\" /> ");
                        sbSearchInfo.Append("  <span>");
                        sbSearchInfo.Append("  <h3>");
                        string   fileSaveName      = string.Empty;
                        string[] fileNameArry_Temp = files_Temp.FileName.Split('.');
                        if (fileNameArry_Temp.Length > 0)
                        {
                            fileSaveName = fileNameArry_Temp[0];
                        }
                        else
                        {
                        }
                        sbSearchInfo.Append(fileSaveName);
                        sbSearchInfo.Append("  </h3>");
                        sbSearchInfo.Append("  <p>");
                        DateTime dateTime_Temp = new DateTime();
                        dateTime_Temp = DateTime.Parse(files_Temp.CommitTime.ToString().Trim());
                        sbSearchInfo.Append("  上传:");
                        sbSearchInfo.Append(dateTime_Temp.ToString("yyyy-MM-dd HH:mm:ss"));
                        sbSearchInfo.Append("  </p>");
                        sbSearchInfo.Append("  <p>");
                        sbSearchInfo.Append("  大小:");
                        sbSearchInfo.Append(files_Temp.FileSize);
                        sbSearchInfo.Append("  </p>");
                        sbSearchInfo.Append("  </span>");
                        sbSearchInfo.Append("  </div>  ");
                        sbSearchInfo.Append("  <div class=\"standfile_btn\">");
                        sbSearchInfo.Append("  <button");
                        sbSearchInfo.Append("  title=\"下 载\" onclick=\"DoDownload('");
                        string[] fileDirArry_Temp = files_Temp.FilePath.Split('/');
                        string   newFileDir       = string.Empty;
                        if (fileDirArry_Temp.Length > 0)
                        {
                            for (int j = 1; j < fileDirArry_Temp.Length; j++)
                            {
                                newFileDir = newFileDir + "/" + fileDirArry_Temp[j].Trim();
                            }
                        }
                        else
                        {
                        }
                        sbSearchInfo.Append(newFileDir);
                        sbSearchInfo.Append("')\"");
                        sbSearchInfo.Append("  class=\"page_table_but3 radius5\"><img src=\"../content/images/download.png\" />下载</button>");
                        sbSearchInfo.Append("  <button");
                        sbSearchInfo.Append("  title=\"删 除\" onclick=\"DoDelete(");
                        sbSearchInfo.Append(files_Temp.Fk_ID.ToString());
                        sbSearchInfo.Append(")\"");
                        sbSearchInfo.Append("  class=\"page_table_but3 radius5\"><img src=\"../content/images/delete_new.png\" />删除</button>");
                        sbSearchInfo.Append("  </div>");
                        sbSearchInfo.Append("  </li>  ");
                    }
                }
                else
                {
                    //为空
                }
                sbSearchInfo.Append(" <ul> ");
                strJson = sbSearchInfo.ToString();
                return(Content(strJson));
            }
            catch (Exception ex)
            {
                string error = ex.ToString();
                return(Content(""));
            }
        }