Beispiel #1
0
        public async Task <IActionResult> CopyeVSfile(DevDtrVsFile dto, string fileName)
        {
            _logger.LogInformation(String.Format(@"******DKSController CopyeVSfile fired!! ******"));
            // generate local path
            List <string> nastFileName = new List <string>();

            nastFileName.Add("DTRVS");
            nastFileName.Add(dto.SEASON);
            nastFileName.Add(dto.ARTICLE);
            nastFileName.Add(dto.FILENAME);
            var pathList = _fileService.GetLocalPath("F340PpdPic", nastFileName);

            if (!Directory.Exists(pathList[0]))
            {
                return(Ok("The file is empty"));
            }

            List <string> l = fileName.Split(',').ToList();

            foreach (string i in l)
            {
                //check the article last id
                int last = _devDtrVsFileDAO.FindAll(x => x.ARTICLE == i)
                           .OrderByDescending(x => x.ID).Select(x => x.ID).ToList().FirstOrDefault().ToInt();
                last += 1;
                // ###### copy file start ######
                // generate local path
                List <string> newNastFileName = new List <string>();
                newNastFileName.Add("DTRVS");
                newNastFileName.Add(dto.SEASON);
                newNastFileName.Add(i);
                //C_SS22_GY0793_1.pdf
                var newFileName = String.Format("{0}_{1}_{2}_{3}.pdf", dto.FACTORYID, dto.SEASON, i, last.ToString());
                newNastFileName.Add(newFileName);
                var newPathList = _fileService.GetLocalPath("F340PpdPic", newNastFileName);
                if (!Directory.Exists(newPathList[0]))
                {
                    DirectoryInfo di = Directory.CreateDirectory(newPathList[0]);
                }
                System.IO.File.Copy(pathList[1], newPathList[1]);
                // ###### copy file end ######
                _logger.LogInformation(String.Format(@"******DTRController AddVSfile Add a PDF: {0}!! ******", fileName));
                //save to DAO
                DevDtrVsFile model = new DevDtrVsFile();
                model.FACTORYID = dto.FACTORYID;
                model.SEASON    = dto.SEASON;
                model.ARTICLE   = i;
                model.ID        = last.ToString();
                model.FILENAME  = newFileName;
                model.REMARK    = String.Format("{0}", dto.REMARK);

                model.UPUSR = dto.UPUSR;
                model.UPDAY = DateTime.Now;

                _devDtrVsFileDAO.Add(model);
                await _devDtrVsFileDAO.SaveAll();
            }

            return(Ok());
        }
Beispiel #2
0
        public async Task <IActionResult> AddVSfile([FromForm] DevDtrVisStandardDto devDtrVisStandardDto)
        {
            _logger.LogInformation(String.Format(@"******DTRController AddVSfile fired!! ******"));


            // FactoryId + Season + Article + Id .pdf
            var fileName = string.Format("{0}_{1}_{2}_{3}.pdf", devDtrVisStandardDto.FactoryId, devDtrVisStandardDto.Season, devDtrVisStandardDto.Article, devDtrVisStandardDto.Id);

            // save file to server
            List <string> nastFileName = new List <string>();

            nastFileName.Add("DTRVS");
            nastFileName.Add(devDtrVisStandardDto.Season);
            nastFileName.Add(devDtrVisStandardDto.Article);
            nastFileName.Add(fileName);

            DevDtrVsFile model = new DevDtrVsFile();

            if (devDtrVisStandardDto.File.Length > 0)       //save to server
            {
                if (await _fileService.SaveFiletoServer(devDtrVisStandardDto.File, "F340PpdPic", nastFileName))
                {
                    _logger.LogInformation(String.Format(@"******DTRController AddVSfile Add a PDF: {0}!! ******", fileName));
                    //save to DAO
                    model.FACTORYID = devDtrVisStandardDto.FactoryId;
                    model.SEASON    = devDtrVisStandardDto.Season.Trim();
                    model.ARTICLE   = devDtrVisStandardDto.Article.Trim();
                    model.ID        = devDtrVisStandardDto.Id.Trim();
                    model.FILENAME  = fileName;
                    if (String.IsNullOrEmpty(devDtrVisStandardDto.Remark))
                    {
                        model.REMARK = "";
                    }
                    else
                    {
                        model.REMARK = devDtrVisStandardDto.Remark.Trim();
                    }
                    model.UPUSR = devDtrVisStandardDto.LoginUser;
                    model.UPDAY = DateTime.Now;
                    _devDtrVsFileDAO.Add(model);
                    await _devDtrVsFileDAO.SaveAll();
                }
            }

            return(Ok(model));
        }
Beispiel #3
0
        public async Task <IActionResult> DeleteVSResult(DevDtrVsFile devDtrVsFile)
        {
            _logger.LogInformation(String.Format(@"****** DTRController DeleteVSResult fired!! ******"));
            if (devDtrVsFile != null)
            {
                //Step1: kill the pdf
                List <string> nastFileName = new List <string>();
                nastFileName.Add("DTRVS");
                nastFileName.Add(devDtrVsFile.SEASON);
                nastFileName.Add(devDtrVsFile.ARTICLE);
                nastFileName.Add(devDtrVsFile.FILENAME);
                if (await _fileService.SaveFiletoServer(null, "F340PpdPic", nastFileName))
                {
                    _logger.LogInformation(String.Format(@"******DTRController DeleteVSResult Delete a PDF: {0}!! ******", devDtrVsFile.FILENAME));
                    //Step2: kill fgt result
                    _devDtrVsFileDAO.Remove(devDtrVsFile);
                    await _devDtrVsFileDAO.SaveAll();

                    return(Ok(true));
                }
            }
            return(Ok(false));
        }