Exemplo n.º 1
0
        public Boolean FileAdd(IFormFile file, string FunctionName, string userId, string userName, out PDC_File item, Int64 SourceID = 0, string FileDescription = "")
        {
            item = new PDC_File();
            try
            {
                string FilePath = SaveAndGetExcelPath(file);
                if (FilePath != "Error")
                {
                    item.FileFullName    = Path.GetFileName(FilePath);
                    item.FileName        = file.FileName;
                    item.FileExtension   = Path.GetExtension(FilePath);
                    item.FileType        = 2;
                    item.FileCategory    = 1;
                    item.FileSize        = file.Length;
                    item.FunctionName    = FunctionName;
                    item.FileDescription = FileDescription;
                    item.SourceID        = SourceID;
                    item.Creator         = userId;
                    item.CreatorDate     = DateTime.Now;
                    item.CreatorName     = userName;
                    _context.PDC_File.Add(item);
                    _context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
        public IActionResult UploadWorkDetail(string ParameterText, string ParameterValue, IFormFile file)
        {
            ParameterService parameterService = new ParameterService(_context);
            FileService      FileService      = new FileService(_hostingEnvironment, _context);
            string           ErrorMsg         = string.Empty;
            string           userId           = _userManager.GetUserId(HttpContext.User);
            string           userName         = HttpContext.User.Identity.Name;

            PDC_File      newFile = new PDC_File();
            PDC_Parameter item    = parameterService.GetParameterOne("ConfigurationWorkDetail");

            if (file.Length > 0)
            {
                PDC_File WorkDetail_File = FileService.GetFileList("ConfigurationWorkDetail", item.ParameterID).FirstOrDefault();

                if (WorkDetail_File != null)
                {
                    FileService.FileRemove(WorkDetail_File.FileID);
                }

                FileService.FileAdd(file, "ConfigurationWorkDetail", userId, userName, out newFile, item.ParameterID);
            }

            item.ParameterText  = ParameterText;
            item.ParameterValue = ParameterValue;
            item.Modifyer       = userId;
            item.ModifyerName   = userName;
            item.ModifyerDate   = DateTime.Now;

            parameterService.UpdateParameter(item, ref ErrorMsg);

            return(Json(new { ErrorMsg = ErrorMsg, File = newFile }));
        }
Exemplo n.º 3
0
        public PDC_File GetFileOne(Int64 FileID)
        {
            PDC_File PDC_File = new PDC_File();

            PDC_File = _context.PDC_File.Where(x => x.FileID == FileID).SingleOrDefault();

            return(PDC_File);
        }
Exemplo n.º 4
0
        public m_ConfigurationPartial()
        {
            CNS_Sample       = new PDC_File();
            HomeLinkList     = new List <PDC_Parameter>();
            HomeLinkFileList = new List <PDC_File>();
            m_HomeLink       = new PDC_Parameter();
            m_HomeLinkFile   = new PDC_File();

            PCBTypeList     = new List <SelectListItem>();
            PCBTypeItemList = new List <SelectListItem>();
        }
        public IActionResult PCBFileRemove(Int64 FileID)
        {
            ExcelHepler Helper = new ExcelHepler(_hostingEnvironment);

            if (_context.PDC_File.Where(x => x.FileID == FileID).Any())
            {
                PDC_File item = _context.PDC_File.Where(x => x.FileID == FileID).SingleOrDefault();
                _context.PDC_File.Remove(item);
                _context.SaveChanges();
            }

            return(Json("刪除成功"));
        }
Exemplo n.º 6
0
        public Boolean FileAdd(ref PDC_File item)
        {
            try
            {
                _context.PDC_File.Add(item);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                return(false);
            }

            return(true);
        }
        public IActionResult UploadFile(IFormFile file)
        {
            FileService FileService = new FileService(_hostingEnvironment, _context);

            m_ConfigurationPartial model  = new m_ConfigurationPartial();
            ExcelHepler            Helper = new ExcelHepler(_hostingEnvironment);
            string userId   = _userManager.GetUserId(HttpContext.User);
            string userName = HttpContext.User.Identity.Name;

            Stream stream = file.OpenReadStream();
            //轉NPOI類型
            XSSFWorkbook ExcelFile = new XSSFWorkbook(stream);

            if (Helper.ExcelSampleCheck(ExcelFile))
            {
                ////存檔並返回檔案路徑
                //string FilePath = Helper.SaveAndGetExcelPath(file);

                //if (FilePath != "Error")
                //{
                //    model.CNS_Sample.FileFullName = Path.GetFileName(FilePath);
                //    model.CNS_Sample.FileName = file.FileName;
                //    model.CNS_Sample.FileExtension = Path.GetExtension(FilePath);
                //    model.CNS_Sample.FileType = 2;
                //    model.CNS_Sample.FileCategory = 1;
                //    model.CNS_Sample.FileSize = file.Length;
                //    model.CNS_Sample.FunctionName = "ConfigurationSample";
                //    model.CNS_Sample.Creator = "c5805dbf-dac5-41e6-bb72-5eb0b449134d";
                //    model.CNS_Sample.CreatorDate = DateTime.Now;
                //    model.CNS_Sample.CreatorName = "*****@*****.**";
                //    _context.PDC_File.Add(model.CNS_Sample);
                //    _context.SaveChanges();
                //}
                PDC_File item = new PDC_File();
                if (!FileService.FileAdd(file, "ConfigurationSample", userId, userName, out item))
                {
                    model.ErrorMsg = "檔案儲存失敗";
                }
                model.CNS_Sample = item;
            }
            else
            {
                model.ErrorMsg = "Failed, 含多餘工作表";
            }


            return(Json(model));
        }
        public IActionResult DeleteWorkDetailFile(Int64 FileID)
        {
            FileService FileService = new FileService(_hostingEnvironment, _context);
            string      ErrorMsg    = string.Empty;

            PDC_File WorkDetail_File = FileService.GetFileOne(FileID);

            if (WorkDetail_File.FileID > 0)
            {
                FileService.FileRemove(WorkDetail_File.FileID);
            }



            return(Json("刪除成功"));
        }
Exemplo n.º 9
0
 public Boolean FileRemove(Int64 FileID)
 {
     try
     {
         if (_context.PDC_File.Where(x => x.FileID == FileID).Any())
         {
             PDC_File item = _context.PDC_File.Where(x => x.FileID == FileID).SingleOrDefault();
             _context.PDC_File.Remove(item);
             _context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 10
0
        public IActionResult PCBFileAdd(IFormFile file, string FileDescription, Int64 ParameterID)
        {
            FileService FileService = new FileService(_hostingEnvironment, _context);
            string      userId      = _userManager.GetUserId(HttpContext.User);
            string      userName    = HttpContext.User.Identity.Name;

            PDC_File m_PCBFile = new PDC_File();
            string   ErrorMsg  = string.Empty;

            if (FileService.FileAdd(file, "Configuration_PCBFile", userId, userName, out m_PCBFile, ParameterID, FileDescription))
            {
                return(Json(m_PCBFile));
            }
            else
            {
                return(Json(new PDC_File()));
            }
        }
Exemplo n.º 11
0
        public IActionResult HomeLinkDelete(Int64 ParameterID)
        {
            ExcelHepler Helper = new ExcelHepler(_hostingEnvironment);

            if (_context.PDC_Parameter.Where(x => x.ParameterID == ParameterID).Any())
            {
                PDC_Parameter item = _context.PDC_Parameter.Where(x => x.ParameterID == ParameterID).SingleOrDefault();
                _context.PDC_Parameter.Remove(item);

                if (_context.PDC_File.Where(x => x.SourceID == ParameterID).Any())
                {
                    PDC_File File = _context.PDC_File.Where(x => x.SourceID == ParameterID && x.FunctionName == "Configuration_HomeLink").SingleOrDefault();
                    _context.PDC_File.Remove(File);
                }
                _context.SaveChanges();
            }

            return(Json("刪除成功"));
        }
Exemplo n.º 12
0
        public IActionResult DownloadSample()
        {
            ExcelHepler Helper      = new ExcelHepler(_hostingEnvironment);
            FileService FileService = new FileService(_hostingEnvironment, _context);

            if (FileService.GetFileList("ConfigurationSample").Any())
            {
                PDC_File Sample = FileService.GetFileList("ConfigurationSample").FirstOrDefault();

                return(RedirectToAction("Download", new { fileName = Sample.FileFullName }));
            }

            //取得範例
            MemoryStream stream = Helper.ExportExcelSample();

            string sFileName = HttpUtility.UrlEncode("Sample.xlsx");


            return(File(stream.ToArray(), "application/vnd.ms-excel", sFileName));
        }
Exemplo n.º 13
0
        //consume custom security service to get all roles
        public IActionResult Index()
        {
            FileService      FileService      = new FileService(_hostingEnvironment, _context);
            ParameterService ParameterService = new ParameterService(_context);
            m_ExcelPartial   model            = new m_ExcelPartial();

            //取得要同步驗證的資料
            model.FastLinkList = ParameterService.GetParameterList("Configuration_HomeLink").Where(x => x.IsSync == true).OrderBy(x => x.OrderNo).ToList();
            //取得要同步驗證的連結
            model.FastLinkFileList = FileService.GetFileList("Configuration_HomeLink").Where(x => model.FastLinkList.Select(pa => pa.ParameterID).Contains(x.SourceID)).ToList();
            //取得Excel範本
            PDC_File sample = FileService.GetFileList("ConfigurationSample").FirstOrDefault();

            //加入Excel範本
            if (sample != null)
            {
                model.FastLinkFileList.Add(sample);
            }

            return(View(model));
        }
Exemplo n.º 14
0
        public IActionResult HomeLinkAdd(IFormFile file, string ParameterText, int IsSync, string Link, int HomeLinkOrderNo)
        {
            ExcelHepler      Helper           = new ExcelHepler(_hostingEnvironment);
            ParameterService parameterService = new ParameterService(_context);
            FileService      FileService      = new FileService(_hostingEnvironment, _context);
            string           userId           = _userManager.GetUserId(HttpContext.User);
            string           userName         = HttpContext.User.Identity.Name;

            m_ConfigurationPartial ViewModel = new m_ConfigurationPartial();

            if (!string.IsNullOrEmpty(Link))
            {
                string ErrorMsg = string.Empty;

                PDC_Parameter NewParameter = new PDC_Parameter();
                NewParameter.IsSync         = IsSync == 1 ? true : false;
                NewParameter.OrderNo        = HomeLinkOrderNo;
                NewParameter.ParameterText  = ParameterText;
                NewParameter.ParameterGroup = "Configuration_HomeLink";
                NewParameter.Creator        = userId;
                NewParameter.CreatorName    = userName;
                NewParameter.CreatorDate    = DateTime.Now;


                if (parameterService.AddParameter(ref NewParameter, ref ErrorMsg))
                {
                    PDC_File NewFile = new PDC_File();
                    NewFile.SourceID     = NewParameter.ParameterID;
                    NewFile.FunctionName = "Configuration_HomeLink";
                    NewFile.FileType     = 5;
                    NewFile.FileName     = Link;
                    NewFile.FileCategory = 2;
                    NewFile.Creator      = userId;
                    NewFile.CreatorName  = userName;
                    NewFile.CreatorDate  = DateTime.Now;
                    FileService.FileAdd(ref NewFile);

                    ViewModel.m_HomeLink     = NewParameter;
                    ViewModel.m_HomeLinkFile = NewFile;
                }
            }
            else
            {
                //存檔並返回檔案路徑
                string FilePath = Helper.SaveAndGetExcelPath(file);
                if (FilePath != "Error")
                {
                    ViewModel.m_HomeLink.IsSync         = IsSync == 1 ? true : false;
                    ViewModel.m_HomeLink.OrderNo        = HomeLinkOrderNo;
                    ViewModel.m_HomeLink.ParameterText  = ParameterText;
                    ViewModel.m_HomeLink.ParameterGroup = "Configuration_HomeLink";
                    ViewModel.m_HomeLink.Creator        = "m901c018";
                    ViewModel.m_HomeLink.CreatorDate    = DateTime.Now;
                    ViewModel.m_HomeLink.CreatorName    = "Mike";
                    _context.PDC_Parameter.Add(ViewModel.m_HomeLink);
                    _context.SaveChanges();

                    ViewModel.m_HomeLinkFile.SourceID      = ViewModel.m_HomeLink.ParameterID;
                    ViewModel.m_HomeLinkFile.FunctionName  = "Configuration_HomeLink";
                    ViewModel.m_HomeLinkFile.FileFullName  = Path.GetFileName(FilePath);
                    ViewModel.m_HomeLinkFile.FileName      = file.FileName;
                    ViewModel.m_HomeLinkFile.FileExtension = Path.GetExtension(FilePath);
                    ViewModel.m_HomeLinkFile.FileType      = 2;
                    ViewModel.m_HomeLinkFile.FileCategory  = 1;
                    ViewModel.m_HomeLinkFile.FileSize      = file.Length;
                    ViewModel.m_HomeLinkFile.Creator       = "m901c018";
                    ViewModel.m_HomeLinkFile.CreatorDate   = DateTime.Now;
                    ViewModel.m_HomeLinkFile.CreatorName   = "Mike";

                    _context.PDC_File.Add(ViewModel.m_HomeLinkFile);
                    _context.SaveChanges();
                }
            }
            //存檔並返回檔案路徑UserManager<IdentityUser>
            //string FilePath = Helper.SaveAndGetExcelPath(file);



            return(Json(ViewModel));
        }