예제 #1
0
        public int AddFile(TB_FILES files)
        {
            int         result = 0;
            TB_FILESSql sql    = new TB_FILESSql();
            string      data   = sql.InsertReturnId(files);

            if (!string.IsNullOrEmpty(data))
            {
                result = Int32.Parse(data);
            }
            else
            {
                result = -1;
            }
            return(result);
        }
예제 #2
0
        public bool DeleteFile(int fileId, string filePath)
        {
            TB_FILES file = new TB_FILES();

            file = new TB_FILESSql().SelectByPrimaryKey(fileId);
            TB_FILESSql sql = new TB_FILESSql();
            string      url = filePath + file.FileUrl;

            if (sql.Delete(fileId))
            {
                File.Delete(url);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #3
0
        public JsonResult UploadFiles(List <HttpPostedFileBase> files)
        {
            string          folderPath = Server.MapPath("~/Files");
            string          filePath   = "";
            AjaxResultModel Result     = new AjaxResultModel();
            List <TB_FILES> data       = new List <TB_FILES>();

            try
            {
                if (!folderPath.EndsWith("/"))
                {
                    filePath += "/" + DateTime.Now.ToString("yyyy_MM_dd") + "/";
                }
                else
                {
                    filePath += DateTime.Now.ToString("yyyy_MM_dd") + "/";
                }
                IOHelper.CreateFolder(folderPath + filePath);
                int value = -1;
                if (files != null)
                {
                    foreach (var file in files)
                    {
                        var InputFileName = DateTime.Now.ToString("yyyyMMddHHmmss_") + Path.GetFileName(file.FileName);
                        //var ServerSavePath = Path.Combine(Server.MapPath("~/Files/") + InputFileName);
                        TB_FILES fTemp = new TB_FILES();
                        fTemp.FileName    = Path.GetFileName(file.FileName);
                        fTemp.FileUrl     = "/Files" + filePath + InputFileName;
                        fTemp.FileRef     = InputFileName;
                        fTemp.FileType    = file.ContentType;
                        fTemp.FileService = "USER";
                        file.SaveAs(folderPath + filePath + InputFileName);
                        value = Files_Service.AddFile(fTemp);
                        if (value != -1)
                        {
                            data.Add(fTemp);
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (value != -1)
                    {
                        Result.Code   = 0;
                        Result.Result = value;
                    }
                }
                else
                {
                    Result.Code   = 1;
                    Result.Result = "Thao tác không thành công";
                }
            }
            catch (Exception Ex)
            {
                Result.Code = 0;
                IOHelper.WriteLog(StartUpPath, IpAddress, "Product::_ChiTiet:GetAllProvider:", Ex.Message, Ex.ToString());
                throw;
            }
            return(Json(new JsonResult()
            {
                Data = Result
            }));
        }
예제 #4
0
 public bool Update(TB_FILES files)
 {
     return(new TB_FILESSql().Update(files));
 }
예제 #5
0
 public bool Insert(TB_FILES files)
 {
     return(new TB_FILESSql().Insert(files));
 }