Esempio n. 1
0
        public IActionResult UploadPicByArticle([FromForm] ArticlePic source)
        {
            _logger.LogInformation(String.Format(@"****** PictureController UploadPicByArticle fired!! ******"));

            string rootdir    = Directory.GetCurrentDirectory();
            var    localStr   = _config.GetSection("AppSettings:ArticleUrl").Value;
            var    pathToSave = rootdir + localStr + source.Article;

            pathToSave = pathToSave.Replace("DKS-API", "DKS-SPA");

            //檔名含副檔名
            //var fileName = ContentDispositionHeaderValue.Parse(source.File.ContentDisposition).FileName.Trim('"');
            var fileName = source.Article + "_" + source.No + ".jpg";
            //新增檔名的全路徑
            var fullPath = Path.Combine(pathToSave, fileName);

            if (!Directory.Exists(pathToSave))
            {
                DirectoryInfo di = Directory.CreateDirectory(pathToSave);
            }
            using (var stream = new FileStream(fullPath, FileMode.Create))
            {
                source.File.CopyTo(stream);

                var     staff   = _dksDao.SearchStaffByLOGIN(source.User);
                UserLog userlog = new UserLog();
                userlog.PROGNAME   = "F205";
                userlog.LOGINNAME  = staff.Result.LOGIN;
                userlog.HISTORY    = "Add Picture " + fileName;
                userlog.UPDATETIME = DateTime.Now;
                _dksDao.AddUserLogAsync(userlog);
            }
            return(Ok());
        }
Esempio n. 2
0
        public IActionResult DeletePicByArticle([FromForm] ArticlePic source)
        {
            _logger.LogInformation(String.Format(@"****** PictureController DeletePicByArticle fired!! ******"));

            string rootdir    = Directory.GetCurrentDirectory();
            var    localStr   = _config.GetSection("AppSettings:ArticleUrl").Value;
            var    pathToSave = rootdir + localStr + source.Article;

            pathToSave = pathToSave.Replace("DKS-API", "DKS-SPA");

            var fileName = source.Article + "_" + source.No + ".jpg";
            //新增檔名的全路徑
            var  fullPath = Path.Combine(pathToSave, fileName);
            bool isExist  = System.IO.File.Exists(fullPath);

            if (isExist)
            {
                string birdUrl = rootdir + "\\Resources\\article_null.jpg"; //讀取API的那張鳥圖

                using (var stream = new FileStream(fullPath, FileMode.Create))
                {
                    var fileStream = System.IO.File.OpenRead(birdUrl);
                    fileStream.CopyTo(stream);
                    fileStream.Close();
                }
                var     staff   = _dksDao.SearchStaffByLOGIN(source.User);
                UserLog userlog = new UserLog();
                userlog.PROGNAME   = "F205";
                userlog.LOGINNAME  = staff.Result.LOGIN;
                userlog.HISTORY    = "Delete Picture " + fileName;
                userlog.UPDATETIME = DateTime.Now;
                _dksDao.AddUserLogAsync(userlog);
            }
            return(Ok());
        }
Esempio n. 3
0
        public IActionResult CheckF420Valid([FromForm] ArticlePic excel)
        {
            _logger.LogInformation(String.Format(@"****** DKSController CheckF420Valid fired!! ******"));

            int processIndex = 0;//use in debug

            string rootdir  = Directory.GetCurrentDirectory();
            string filePath = rootdir + "\\Resources\\Temp";
            var    fileName = "F420.xls";
            //新增檔名的全路徑
            var fullPath = Path.Combine(filePath, fileName);

            using (var stream = new FileStream(fullPath, FileMode.Create))
            {
                excel.File.CopyTo(stream);
            }

            List <F418_F420Dto> list = new List <F418_F420Dto>();

            //read excel
            Aspose.Cells.Workbook wk = new Aspose.Cells.Workbook(fullPath);
            Worksheet             ws = wk.Worksheets[0];
            DataTable             dt = ws.Cells.ExportDataTable(0, 0, ws.Cells.MaxDataRow + 1, ws.Cells.MaxDataColumn + 1);

            for (int i = 1; i < dt.Rows.Count; i++)
            {
                processIndex = i;
                string orderNo = dt.Rows[i][1].ToString().Trim();  //Order No
                string qty     = dt.Rows[i][30].ToString().Trim(); //廠商出貨數量
                if (orderNo == "" || qty == "")
                {
                    continue;                             //如果任一沒輸入忽略
                }
                decimal nQty = decimal.Parse(qty);
                //檢查該訂購單號還有幾個要驗收
                var     result  = _dksDao.GetF420F418View(orderNo);
                decimal compare = nQty - result.NEEDQTY;
                if (compare > 0)    //驗收數量大於數量
                {
                    result.NEEDQTY = compare;
                    list.Add(result);
                }
            }
            return(Ok(list));
        }