Esempio n. 1
0
        private bool FilterFileInSystem(ModelGetRiskFile riskFiles)
        {
            ModelViewRiskImport _model = new ModelViewRiskImport
            {
                RC_NAME = riskFiles.RC_NAME,
                YEAR    = riskFiles.YEAR
            };

            string _path = Path.Combine(GetPathUploadPath(_model), riskFiles.FILE_NAME);

            return(System.IO.File.Exists(_path));
        }
Esempio n. 2
0
        //[AuthorizeController.CustomAuthorize]
        public JsonResult ListFile(ModelViewRiskImport model)
        {
            StringBuilder strCommand = new StringBuilder();

            strCommand.AppendFormat("SELECT * FROM RISK_FILE WHERE YEAR = {0} AND RC_NAME = '{1}'", model.YEAR, model.RC_NAME);

            DAL.DAL dal = new DAL.DAL();
            List <ModelGetRiskFile> riskFiles = dal.ReadData(strCommand.ToString(), x => new ModelGetRiskFile(x)).ToList();

            //Filter file in system
            string[] FileList = riskFiles.Where(x => this.FilterFileInSystem(x)).Select(x => x.FILE_NAME).ToArray();

            return(Json(FileList, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
        private string GetPathUploadPath(ModelViewRiskImport model)
        {
            string dir = Server.MapPath("~/UploadedFiles");

            if (string.IsNullOrEmpty(model.RC_NAME))
            {
                dir = Path.Combine(dir, "year", model.YEAR.ToString());
            }
            else
            {
                dir = Path.Combine(dir, "rc", model.RC_NAME, model.YEAR.ToString());
            }

            return(dir);
        }
Esempio n. 4
0
        private List <ModelGetRisk> GetData(ModelViewRiskReport model)
        {
            string strCommand = $"SELECT * FROM VIEW_RISK_HISTORY WHERE YEAR = {model.Year}";

            if (model.Type.Equals("risk"))
            {
                strCommand = $"{strCommand} AND (RISK_SCORE_RISK = 'RISK' OR INTERNAL_CORROSION_RISK = 'RISK' OR EXTERNAL_CORROSION_RISK = 'RISK' OR THIRD_PARTY_INTERFERENCE_RISK = 'RISK' OR LOSS_OF_GROUND_SUPPORT_RISK = 'RISK')";
            }
            else if (model.Lists != null)
            {
                if (model.Type.Equals("region"))
                {
                    strCommand = $"{strCommand} AND REGION IN ('{ string.Join("','", model.Lists) }')";
                }
                else if (model.Type.Equals("license"))
                {
                    strCommand = $"{strCommand} AND LICENSE_NO IN ('{ string.Join("','", model.Lists) }')";
                }
            }
            DAL.DAL             dal        = new DAL.DAL();
            List <ModelGetRisk> riskReport = dal.ReadData(strCommand, x => new ModelGetRisk(x)).ToList();

            riskReport.ForEach(x =>
            {
                ModelViewRiskImport _model = new ModelViewRiskImport
                {
                    RC_NAME = x.RC_NAME,
                    YEAR    = x.YEAR
                };

                string _path      = GetPathUploadPath(_model);;
                string[] FileList = new string[] { };

                if (Directory.Exists(_path))
                {
                    DirectoryInfo d  = new DirectoryInfo(_path);
                    FileInfo[] Files = d.GetFiles(); //Getting files
                    FileList         = Files.Select(s => s.Name).ToArray();
                }

                x.FILES    = FileList;
                x.HAS_FILE = FileList.Count() > 0;
            });

            return(riskReport);
        }
Esempio n. 5
0
        public ActionResult Download(ModelViewRiskDownload model)
        {
            ModelViewRiskImport _model = new ModelViewRiskImport
            {
                RC_NAME = model.RC_NAME,
                YEAR    = model.YEAR
            };

            string _path = Path.Combine(GetPathUploadPath(_model), model.FILE_NAME);

            if (System.IO.File.Exists(_path))
            {
                FileStream file = System.IO.File.OpenRead(_path);
                return(File(file, "Application/octet-stream", model.FILE_NAME));
            }

            return(HttpNotFound());
        }
Esempio n. 6
0
        //[AuthorizeController.CustomAuthorize]
        public JsonResult Upload(ModelViewRiskImport model)
        {
            string _dir = GetPathUploadPath(model);

            // Check Directory Exist
            if (!Directory.Exists(_dir))
            {
                Directory.CreateDirectory(_dir);
            }

            foreach (HttpPostedFileBase FILE in model.FILES)
            {
                string _fileName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + "_" + FILE.FileName;
                string _path     = Path.Combine(_dir, _fileName);
                FILE.SaveAs(_path);

                var    dto      = new DtoRisk();
                string username = User.Identity.Name;
                dto.InsertRiskFile(username, model.RC_NAME, model.YEAR, _fileName);
                dto = null;
            }

            return(Json(new { }));
        }