Beispiel #1
0
        /// <summary>
        /// 根据上传的文件名,生成包含文件名的文件存储的绝对URl
        /// </summary>
        /// <param name="fileName">需要上传的文件名</param>
        /// <param name="absoluteUrl">上传后访问该文件的绝对URl地址</param>
        /// <param name="saveFullPath">该文件的磁盘保存路径</param>
        /// <param name="uploadFileType">上传文件类型</param>
        /// <returns></returns>
        public static void GetSaveFullPath(UploadFileTypes uploadFileType, string fileName, out string saveFullPath, out string absoluteUrl)
        {
            //生成用于保存文件的完整路径
            DateTime now = DateTime.Now;
            //资源访问的相对url目录
            string newUrl = FILE_UPLOAD_PATH.JoinUrl(uploadFileType.ToString()).JoinUrl(now.ToString("yyyyMM"));
            string newDir = System.Web.HttpContext.Current.Server.MapPath(newUrl);

            //如果目录不存在,那么就创建目录
            if (!Directory.Exists(newDir))
            {
                Directory.CreateDirectory(newDir);
            }

            //生成上传后的文件名
            string newFileName = null;
            int    no          = 0;

            do
            {
                newFileName  = string.Format("{0}{1}", now.Ticks + no, System.IO.Path.GetExtension(fileName));
                saveFullPath = newDir.JoinPath(newFileName);
                no++;
            } while (File.Exists(saveFullPath));

            //获取资源的绝对URL
            absoluteUrl = newUrl.JoinUrl(newFileName);
        }
Beispiel #2
0
        // GET: Loans/BulkLoan
        public async Task <IActionResult> BulkLoan(Guid loadFormatId, UploadFileTypes uploadFileType, string delimiter)
        {
            UpLoadLoanViewModel viewModel = new UpLoadLoanViewModel
            {
                LoadFormatID   = loadFormatId,
                UploadFileType = uploadFileType,
                Delimiter      = delimiter,
                TableName      = "Loan",
                ComponentList  = new SelectList(await _context.Components.ToListAsync(), "ID", "Name", await _context.Components.FirstOrDefaultAsync())
            };

            return(View(viewModel));
        }
Beispiel #3
0
        // GET: FormatTypes/Edit/5
        public async Task <IActionResult> Edit(Guid productId, Guid Id, UploadFileTypes uploadFileType)
        {
            var formatType = await _context.FormatTypes.SingleOrDefaultAsync(m => m.ID == Id);

            FormatTypeViewModel viewModel = new FormatTypeViewModel
            {
                ProductID      = productId,
                UploadFileType = uploadFileType,
                FormatType     = formatType
            };

            return(View(viewModel));
        }
Beispiel #4
0
        // GET: Products/BulkPremium
        public async Task <IActionResult> BulkPremium(Guid loadFormatId, UploadFileTypes uploadFileType, string delimiter)
        {
            UpLoadPremiumViewModel viewModel = new UpLoadPremiumViewModel
            {
                LoadFormatID    = loadFormatId,
                UploadFileType  = uploadFileType,
                Delimiter       = delimiter,
                TableName       = "Premium",
                ReceivableDate  = DateTime.Now,
                PaymentTypeList = new SelectList(await _context.PaymentTypes.ToListAsync(), "ID", "Name", await _context.PaymentTypes.FirstOrDefaultAsync()),
                PremiumTypeList = new SelectList(await _context.PremiumTypes.ToListAsync(), "ID", "Name", await _context.PremiumTypes.FirstOrDefaultAsync())
            };

            return(View(viewModel));
        }
        // GET: LoadFormats/EditFormatType
        public async Task <IActionResult> EditFormatType(Guid productId, Guid loadFormatId,
                                                         string tableName, UploadFileTypes uploadFileType)
        {
            var formattypes = await(from r in _context.FormatTypes
                                    where r.LoadFormatID == loadFormatId &&
                                    r.TableName == tableName
                                    orderby r.FieldLabel
                                    select r).ToListAsync();

            FormatTypesViewModel viewModel = new FormatTypesViewModel
            {
                ProductID      = productId,
                UploadFileType = uploadFileType,
                FormatTypes    = formattypes
            };

            return(View(viewModel));
        }
Beispiel #6
0
        private bool CheckFileTypeExtension()
        {
            try
            {
                string[] fileTypeArray = UploadFileTypes.Split('|');
                bool     validFile     = false;
                for (var i = 0; i < fileTypeArray.Length; i++)
                {
                    if (_fileName.PostedFile.FileName.ToLower().LastIndexOf(fileTypeArray[i].Trim().ToLower()) > 0)
                    {
                        validFile = true;
                    }
                }

                return(validFile);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #7
0
        // GET: FormatTypes
        public async Task <IActionResult> Index(Guid loadFormatId, UploadFileTypes uploadFileType)
        {
            var tables = _context.FormatTypes
                         .Where(t => t.LoadFormatID == loadFormatId)
                         .Select(t => t.TableName).Distinct()
                         .ToList();

            var _tablename = tables.FirstOrDefault();

            var formattypes = await _context.FormatTypes
                              .Include(f => f.LoadFormat)
                              .AsNoTracking()
                              .OrderBy(c => c.FieldName)
                              .Where(f => f.LoadFormatID == loadFormatId &&
                                     f.TableName == _tablename).ToListAsync();

            FormatTypesViewModel viewModel = new FormatTypesViewModel
            {
                FormatTypes    = formattypes,
                UploadFileType = uploadFileType
            };

            return(View(viewModel));
        }
        public async Task <IActionResult> SelectTable(Guid productId, Guid loadFormatId, UploadFileTypes uploadFileType)
        {
            var tables = await _context.FormatTypes
                         .Select(t => t.TableName).Distinct()
                         .ToListAsync();

            SelectedTableViewModel viewModel = new SelectedTableViewModel
            {
                ProductID      = productId,
                LoadFormatID   = loadFormatId,
                UploadFileType = uploadFileType,
                TableList      = new SelectList(tables.Select(tablename => new SelectListItem
                {
                    Value = tablename,
                    Text  = tablename
                }).ToList(), "Value", "Text", tables.FirstOrDefault())
            };

            return(View(viewModel));
        }