Пример #1
0
        //根据日期模糊查询获取编号
        public string GetIdByTime(string dateTime)
        {
            T_File    fileModel = new T_File();
            DataTable file      = dal.GetIdByTime(dateTime);
            string    str       = null;

            if (file.Rows.Count == 0)
            {
                str = dateTime + "001";
            }
            else
            {
                fileModel.FileId = file.Rows[0]["C_FileId"].ToString().Trim();
                int strId = Int32.Parse(fileModel.FileId.Substring(8, 3)) + 1;
                if (strId >= 10)
                {
                    str = dateTime + "0" + strId.ToString().Trim();
                }
                else if (strId >= 100)
                {
                    str = dateTime + strId.ToString().Trim();
                }
                else
                {
                    str = dateTime + "00" + strId.ToString().Trim();
                }
            }
            return(str);
        }
        public ActionResult CreateFileMgr(HttpPostedFileWrapper file, string name)
        {
            var fileModel = new T_File()
            {
                Name       = name ?? file.FileName,
                Path       = SaveFile(file, "files"),
                CreateDate = DateTime.Now
            };

            dbContent.File.Add(fileModel);
            dbContent.SaveChanges();
            return(Ok());
        }
Пример #3
0
        //插入
        public int Insert(T_File file)
        {
            string sql = "insert into T_File values(@id,@name,@time,@sector,@summary,@path,@ext,@num)";

            SqlParameter[] sp =
            {
                new SqlParameter("@id",      file.FileId),
                new SqlParameter("@name",    file.FileName),
                new SqlParameter("@time",    file.FileTime),
                new SqlParameter("@sector",  file.FileSector),
                new SqlParameter("@summary", file.FileSummary),
                new SqlParameter("@path",    file.FilePath),
                new SqlParameter("@ext",     file.FileExt),
                new SqlParameter("@num",     file.FileDowNum)
            };
            return(SqlHelper.ExecuteNonQuery(sql, CommandType.Text, sp));
        }
Пример #4
0
        //转化datatable 为list
        public List <T_File> DataTableToList(DataTable tb)
        {
            List <T_File> list = new List <T_File>();

            if (tb.Rows.Count > 0)
            {
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    T_File model = new T_File();
                    model.FileId = tb.Rows[i]["C_FileId"].ToString();
                    if (tb.Rows[i]["C_FileId"].ToString() != "")
                    {
                        model.FileName = tb.Rows[i]["C_FileName"].ToString();
                    }
                    if (tb.Rows[i]["C_FileSector"].ToString() != "")
                    {
                        model.FileSector = tb.Rows[i]["C_FileSector"].ToString();
                    }
                    if (tb.Rows[i]["C_FileTime"] != null)
                    {
                        DateTime time = DateTime.Parse(tb.Rows[i]["C_FileTime"].ToString());
                        model.FileTime = time.ToString("yyyy-MM-dd");
                    }
                    if (tb.Rows[i]["C_FileSummary"].ToString() != "")
                    {
                        model.FileSummary = tb.Rows[i]["C_FileSummary"].ToString();
                    }
                    if (tb.Rows[i]["C_FilePath"].ToString() != "")
                    {
                        model.FilePath = tb.Rows[i]["C_FilePath"].ToString();
                    }
                    if (tb.Rows[i]["C_FileExt"].ToString() != "")
                    {
                        model.FileExt = tb.Rows[i]["C_FileExt"].ToString();
                    }
                    if (tb.Rows[i]["C_FileDowNum"].ToString() != "")
                    {
                        model.FileDowNum = int.Parse(tb.Rows[i]["C_FileDowNum"].ToString());
                    }
                    list.Add(model);
                }
            }
            return(list);
        }
Пример #5
0
        //根据id获取mode
        public T_File GetModelById(string id)
        {
            DataTable tb    = dal.GetModelById(id);
            T_File    model = new T_File();

            if (tb.Rows.Count > 0)
            {
                model.FileId = tb.Rows[0]["C_FileId"].ToString();
                if (tb.Rows[0]["C_FileId"].ToString() != "")
                {
                    model.FileName = tb.Rows[0]["C_FileName"].ToString();
                }
                if (tb.Rows[0]["C_FileSector"].ToString() != "")
                {
                    model.FileSector = tb.Rows[0]["C_FileSector"].ToString();
                }
                if (tb.Rows[0]["C_FileTime"] != null)
                {
                    DateTime time = DateTime.Parse(tb.Rows[0]["C_FileTime"].ToString());
                    model.FileTime = time.ToString("yyyy-MM-dd");
                }
                if (tb.Rows[0]["C_FileSummary"].ToString() != "")
                {
                    model.FileSummary = tb.Rows[0]["C_FileSummary"].ToString();
                }
                if (tb.Rows[0]["C_FilePath"].ToString() != "")
                {
                    model.FilePath = tb.Rows[0]["C_FilePath"].ToString();
                }
                if (tb.Rows[0]["C_FileExt"].ToString() != "")
                {
                    model.FileExt = tb.Rows[0]["C_FileExt"].ToString();
                }
                if (tb.Rows[0]["C_FileDowNum"].ToString() != "")
                {
                    model.FileDowNum = int.Parse(tb.Rows[0]["C_FileDowNum"].ToString());
                }
            }
            return(model);
        }
Пример #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (Request["fileid"] != "" || Request["fileid"] != null)
     {
         string id = Context.Request["fileid"];
         model = bll.GetModelById(id);
         if (model.FileName == null)
         {
             Response.Redirect("error.html");
         }
         //上下篇
         List <T_File> lastFileList = bll.GetLastFile(id);
         List <T_File> nextFileList = bll.GetNextFile(id);
         if (lastFileList.Count > 0)
         {
             lastFileHref  = "FileDetail.aspx?FileId=" + lastFileList[0].FileId;
             lastFileTitle = lastFileList[0].FileSummary;
         }
         else
         {
             lastFileHref  = "";
             lastFileTitle = "没有了";
         }
         if (nextFileList.Count > 0)
         {
             nextFileHref  = "FileDetail.aspx?FileId=" + nextFileList[0].FileId;
             nextFileTitle = nextFileList[0].FileSummary;
         }
         else
         {
             nextFileHref  = "";
             nextFileTitle = "没有了";
         }
     }
     else
     {
         Response.Redirect("error.html");
     }
 }
Пример #7
0
        public ResponseBase InsertOrUpdate(ManipulationLibraryModel model, List <ManipulationEquipmentModel> TMUModel, List <FileUploadModel> fileModel)
        {
            try
            {
                using (db = new IEDEntities())
                {
                    var result = new ResponseBase();
                    T_ManipulationLibrary   mani          = null;
                    T_ManipulationEquipment maniEquipment = null;
                    T_ManipulationFile      maniFile      = null;
                    T_File file = null;
                    if (CheckExists(model.Name.Trim().ToUpper(), model.Id, true))
                    {
                        result.IsSuccess = false;
                        result.Errors.Add(new Error()
                        {
                            MemberName = "Insert  ", Message = "Tên Thao Tác này đã tồn tại . Vui lòng chọn lại Tên khác !."
                        });
                        return(result);
                    }
                    if (!string.IsNullOrEmpty(model.Code))
                    {
                        if (CheckExists(model.Code.Trim().ToUpper(), model.Id, false))
                        {
                            result.IsSuccess = false;
                            result.Errors.Add(new Error()
                            {
                                MemberName = "Insert  ", Message = "Mã Thao Tác này đã tồn tại này. Vui lòng chọn lại Mã khác !."
                            });
                            return(result);
                        }
                    }
                    if (model.Id == 0)
                    {
                        #region add
                        mani                    = new T_ManipulationLibrary();
                        mani.Id                 = model.Id;
                        mani.Name               = model.Name;
                        mani.Code               = model.Code;
                        mani.Description        = model.Description;
                        mani.ManipulationTypeId = model.ManipulationTypeId;
                        mani.StandardTMU        = Math.Round(model.StandardTMU, 2);
                        mani.UserTMU            = Math.Round(model.UserTMU, 2);
                        if (model.Distance == 0)
                        {
                            mani.EquipmentTypeId = null;
                            mani.StopPrecisionId = null;
                            mani.ApplyPressureId = null;
                            mani.NatureCutsId    = null;
                            mani.Distance        = null;
                        }
                        else
                        {
                            mani.EquipmentTypeId = model.EquipmentTypeId;
                            mani.ApplyPressureId = model.ApplyPressureId;
                            mani.NatureCutsId    = model.NatureCutsId;
                            mani.StopPrecisionId = model.StopPrecisionId;
                            mani.Distance        = model.Distance;
                        }
                        mani.CreatedUser = model.ActionUser;
                        mani.CreatedDate = DateTime.Now;


                        if (TMUModel != null && TMUModel.Count > 0)
                        {
                            mani.T_ManipulationEquipment = new System.Collections.ObjectModel.Collection <T_ManipulationEquipment>();
                            foreach (var item in TMUModel)
                            {
                                maniEquipment = new T_ManipulationEquipment();
                                Parse.CopyObject(item, ref maniEquipment);
                                maniEquipment.T_ManipulationLibrary = mani;
                                maniEquipment.CreatedUser           = mani.CreatedUser;
                                maniEquipment.CreatedDate           = mani.CreatedDate;
                                mani.T_ManipulationEquipment.Add(maniEquipment);
                            }
                        }

                        if (fileModel != null && fileModel.Count > 0)
                        {
                            mani.T_ManipulationFile = new System.Collections.ObjectModel.Collection <T_ManipulationFile>();
                            foreach (var item in fileModel)
                            {
                                // add file
                                file = new T_File();
                                Parse.CopyObject(item, ref file);
                                file.T_ManipulationFile = new System.Collections.ObjectModel.Collection <T_ManipulationFile>();
                                file.CreatedUser        = mani.CreatedUser;
                                file.CreatedDate        = mani.CreatedDate;


                                // add commodity file
                                maniFile = new T_ManipulationFile();
                                maniFile.T_ManipulationLibrary = mani;
                                //maniFile.FileId = file.Id;
                                maniFile.CreatedUser = mani.CreatedUser;
                                maniFile.CreatedDate = mani.CreatedDate;
                                maniFile.T_File      = file;
                                mani.T_ManipulationFile.Add(maniFile);
                                file.T_ManipulationFile.Add(maniFile);
                                db.T_File.Add(file);
                            }
                        }

                        db.T_ManipulationLibrary.Add(mani);
                        #endregion
                    }
                    else
                    {
                        #region Update
                        mani = db.T_ManipulationLibrary.FirstOrDefault(x => !x.IsDeleted && x.Id == model.Id);
                        if (mani == null)
                        {
                            result.IsSuccess = false;
                            result.Errors.Add(new Error()
                            {
                                MemberName = "Update  ", Message = "Dữ liệu bạn đang thao tác đã bị xóa hoặc không tồn tại. Vui lòng kiểm tra lại !."
                            });
                            return(result);
                        }
                        else
                        {
                            mani.Name               = model.Name;
                            mani.Code               = model.Code;
                            mani.Description        = model.Description;
                            mani.ManipulationTypeId = model.ManipulationTypeId;
                            mani.StandardTMU        = Math.Round(model.StandardTMU, 2);
                            mani.UserTMU            = Math.Round(model.UserTMU, 2);
                            //if (maniModel.Distance == null)
                            //{
                            //    mani.EquipmentTypeId = null;
                            //    mani.StopPrecisionId = null;
                            //    mani.ApplyPressureId = null;
                            //    mani.NatureCutsId = null;
                            //    mani.Distance = null;
                            //}
                            //else
                            //{
                            mani.EquipmentTypeId = model.EquipmentTypeId;
                            mani.ApplyPressureId = model.ApplyPressureId;
                            mani.NatureCutsId    = model.NatureCutsId;
                            mani.StopPrecisionId = model.StopPrecisionId;
                            mani.Distance        = model.Distance;
                            //}
                            mani.UpdatedUser = model.ActionUser;
                            mani.UpdatedDate = DateTime.Now;

                            //remove old
                            if (model.isListMachineTMUChange)
                            {
                                var maniEquipOld = db.T_ManipulationEquipment.Where(x => !x.IsDeleted && x.ManipulationId == model.Id);
                                if (maniEquipOld != null && maniEquipOld.Count() > 0)
                                {
                                    foreach (var item in maniEquipOld)
                                    {
                                        item.IsDeleted   = true;
                                        item.DeletedUser = mani.UpdatedUser;
                                        item.DeletedDate = mani.UpdatedDate;
                                    }
                                }
                                // add new
                                if (TMUModel != null && TMUModel.Count() > 0)
                                {
                                    foreach (var item in TMUModel)
                                    {
                                        maniEquipment = new T_ManipulationEquipment();
                                        Parse.CopyObject(item, ref maniEquipment);
                                        maniEquipment.ManipulationId = mani.Id;
                                        maniEquipment.CreatedUser    = mani.UpdatedUser ?? 0;
                                        maniEquipment.CreatedDate    = mani.UpdatedDate ?? DateTime.Now;
                                        db.T_ManipulationEquipment.Add(maniEquipment);
                                    }
                                }
                            }

                            #region File
                            if (model.isListAttachFileChange)
                            {
                                var maniFiles = db.T_ManipulationFile.Where(x => !x.IsDeleted && x.ManipulationId == mani.Id);
                                if (maniFiles != null && maniFiles.Count() > 0)
                                {
                                    foreach (var item in maniFiles)
                                    {
                                        item.IsDeleted   = true;
                                        item.DeletedUser = mani.UpdatedUser;
                                        item.DeletedDate = mani.UpdatedDate;
                                    }
                                }

                                if (fileModel != null && fileModel.Count > 0)
                                {
                                    // mani.T_ManipulationFile = new System.Collections.ObjectModel.Collection<T_ManipulationFile>();
                                    foreach (var item in fileModel)
                                    {
                                        // add file
                                        file = new T_File();
                                        Parse.CopyObject(item, ref file);
                                        file.T_ManipulationFile = new System.Collections.ObjectModel.Collection <T_ManipulationFile>();
                                        file.CreatedUser        = mani.UpdatedUser ?? 0;
                                        file.CreatedDate        = mani.UpdatedDate ?? DateTime.Now;


                                        // add commodity file
                                        maniFile = new T_ManipulationFile();
                                        //  maniFile.T_ManipulationLibrary = mani;
                                        maniFile.ManipulationId = model.Id;
                                        maniFile.CreatedUser    = mani.UpdatedUser ?? 0;
                                        maniFile.CreatedDate    = mani.UpdatedDate ?? DateTime.Now;
                                        maniFile.T_File         = file;
                                        //mani.T_ManipulationFile.Add(maniFile);
                                        file.T_ManipulationFile.Add(maniFile);
                                        db.T_File.Add(file);
                                    }
                                }
                            }
                            #endregion
                            #endregion
                        }
                    }
                    db.SaveChanges();
                    result.IsSuccess = true;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            String aspxUrl = context.Request.Path.Substring(0, context.Request.Path.LastIndexOf("/") + 1);

            //文件保存目录路径
            String savePath = "/FileSavePath/";

            //文件保存目录URL
            String saveUrl = "/FileSavePath/";

            //定义允许上传的文件扩展名
            Hashtable extTable = new Hashtable();

            extTable.Add("flash", "swf,flv");
            extTable.Add("media", "mp3,wmv,avi,rmvb");
            extTable.Add("file", "doc,docx,xls,xlsx,ppt,pdf,txt,html,txt,zip,rar");

            //最大文件大小
            int maxSize = 2000000;

            this.context = context;

            HttpPostedFile imgFile = context.Request.Files["files"];

            if (imgFile == null)
            {
                showError("请选择文件。");
            }

            String dirPath = context.Server.MapPath(savePath);

            if (!Directory.Exists(dirPath))
            {
                showError("上传目录不存在。");
            }
            string dirName  = "";
            String fileName = imgFile.FileName;
            String fileExt  = Path.GetExtension(fileName).ToLower();

            if (CheckFileExt(fileExt) != "")
            {
                dirName = CheckFileExt(fileExt);
            }

            if (String.IsNullOrEmpty(dirName))
            {
                dirName = "file";
            }
            if (!extTable.ContainsKey(dirName))
            {
                showError("目录名不正确。");
            }



            if (imgFile.InputStream == null || imgFile.InputStream.Length > maxSize)
            {
                showError("上传文件大小超过限制。");
            }

            if (String.IsNullOrEmpty(fileExt) || Array.IndexOf(((String)extTable[dirName]).Split(','), fileExt.Substring(1).ToLower()) == -1)
            {
                showError("上传文件扩展名是不允许的扩展名。\n只允许" + ((String)extTable[dirName]) + "格式。");
            }

            //创建文件夹
            dirPath += dirName + "/";
            saveUrl += dirName + "/";
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }
            String ymd = DateTime.Now.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);

            dirPath += ymd + "/";
            saveUrl += ymd + "/";
            if (!Directory.Exists(dirPath))
            {
                Directory.CreateDirectory(dirPath);
            }

            String newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + fileExt;
            String filePath    = dirPath + newFileName;

            imgFile.SaveAs(filePath);

            String fileUrl = saveUrl + newFileName;

            //构造输出显示的model
            //FileDescription fileDes = new FileDescription();
            //fileDes.FileName = Path.GetFileNameWithoutExtension(fileName);
            //fileDes.FileSize = (imgFile.ContentLength / 1024).ToString()+"KB";
            //fileDes.FileTime = DateTime.Now.ToString();
            //fileDes.FileSavePath =filePath;
            //fileDes.FileExt = fileExt;
            //构造插入内容
            T_File model = new T_File();

            model.FileId      = bll.GetIdByTime(DateTime.Now.ToString("yyyyMMdd"));
            model.FileName    = fileName;
            model.FilePath    = fileUrl;
            model.FileExt     = fileExt;
            model.FileSector  = "";//(context.Session["model"] as T_InfoAdmin).InfoAdminSector;
            model.FileSummary = context.Request["summary"];
            model.FileTime    = DateTime.Now.ToString();
            model.FileSector  = "liushangnan";
            bll.Insert(model);
            context.Response.Write("添加成功,请关闭此窗口~");
        }
Пример #9
0
 //插入
 public int Insert(T_File file)
 {
     return(dal.Insert(file));
 }