Example #1
0
        /// <summary>
        /// 將記憶體的資料丟進去資料庫裡
        /// NOTE:因FEMS沒有實體建立key entity不能新增
        /// </summary>
        /// <param name="invSource">盤點</param>
        /// <param name="fixSource">維修</param>
        /// <param name="attendSource">考勤</param>
        /// <param name="parameter"></param>
        private void processDataToServer(List <GlassFibreClothItem> glassfibreClothList, List <CopperFoilItem> copperFoilList)
        {
            var currentDate = DateTime.Now;

            //物件轉成資料庫物件

            using (TransactionScope scope = new TransactionScope())
            {
                using (BookingCarSSISEntities db = new BookingCarSSISEntities())
                {
                    #region gFibreClothList
                    _logger.Debug("GlassFibreCloth => v28caxrf_s2 資料總筆數:{0}", glassfibreClothList.Count);

                    foreach (var item in glassfibreClothList)
                    {
                        var existItem = db.v28caxrf_s2.Where(x => x.ROWIdx == item.ROWIdx).FirstOrDefault();
                        _logger.Debug("RowIdx:{0}", item.ROWIdx);
                        if (existItem != null)
                        {
                            DateTime?checkTime = ApiUtils.stringTimeToDataTimeParse(item.CheckTime);
                            existItem.CheckAccount = item.CheckAccount;
                            existItem.CheckTime    = checkTime;
                            _logger.Debug("RowIdx:{0}... has update CheckAccount:{1};CheckTime:{2}", item.ROWIdx, item.CheckAccount, item.CheckTime);
                            db.SaveChanges();
                        }
                        else
                        {
                            _logger.Debug("RowIdx:{0} not found", item.ROWIdx);
                        }
                    }
                    #endregion

                    _logger.Debug("CopperFoil => V28EFQ7J 資料總筆數:{0}", copperFoilList.Count);
                    foreach (var item in copperFoilList)
                    {
                        var existItem = db.V28EFQ7J.Where(x => x.ROWIdx == item.ROWIdx).FirstOrDefault();
                        if (existItem != null)
                        {
                            DateTime?checkTime = ApiUtils.stringTimeToDataTimeParse(item.CheckTime);
                            existItem.CheckAccount = item.CheckAccount;
                            existItem.CheckTime    = checkTime;
                            _logger.Debug("RowIdx:{0}... has update CheckAccount:{1};CheckTime:{2}", item.ROWIdx, item.CheckAccount, item.CheckTime);
                            db.SaveChanges();
                        }
                        else
                        {
                            _logger.Debug("RowIdx:{0} not found", item.ROWIdx);
                        }
                    }
                }

                scope.Complete();
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="warehouseID"></param>
        /// <returns></returns>
        public HttpResponseMessage Get()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            //_logger.Debug("Download 參數 warehouseID:{0}", warehouseID);
            var isDebug = bool.Parse(CommonUtils.AppSettings("IsDebug"));
            var preDay  = -6; // 往前抓幾天!?

            DownloadViewModel viewModel       = new DownloadViewModel();
            string            packageFileName = string.Format("Shipcheck_{0}.zip", DateTime.Now.ToString("yyyyMMddHHmmssfff"));
            var currentDate = DateTime.Now.ToString("yyyyMMdd hhmmss");

            try
            {
                _logger.Debug("download start...");
                using (BookingCarSSISEntities db = new BookingCarSSISEntities())
                {
                    //createMapInit();
                    var startDate = DateTime.Today.AddDays(preDay);

                    var glassFibreCloth = db.v28caxrf_s2
                                          .Where(x => string.IsNullOrEmpty(x.CheckAccount))
                                          .Where(x => DbFunctions.TruncateTime(x.DateCreated) >= startDate)
                                          .AsEnumerable()
                                          .Select(x => new GlassFibreClothItem
                    {
                        ROWIdx       = x.ROWIdx,
                        CUFN         = x.CUFN,
                        ODNO         = x.ODNO,
                        UNPKWGT      = x.UNPKWGT.HasValue ? x.UNPKWGT.Value.ToString() : null,
                        PDID         = x.PDID,
                        CLHRLNO      = x.CLHRLNO,
                        L            = x.L,
                        GRSWGT       = x.GRSWGT.HasValue ? x.GRSWGT.Value.ToString() : null,
                        DateCreated  = x.DateCreated.HasValue ? x.DateCreated.Value.ToString(Resource.StrDateTimeFormat) : null,
                        PrintTime    = x.PrintTime.HasValue ? x.PrintTime.Value.ToString(Resource.StrDateTimeFormat) : null,
                        CheckAccount = x.CheckAccount,
                        CheckTime    = x.CheckTime.HasValue ? x.CheckTime.Value.ToString(Resource.StrDateTimeFormat) : null,
                        OUTMDAT      = x.OUTMDAT
                    })
                                          .OrderBy(x => x.ROWIdx)
                                          .ToList();



                    viewModel.GlassFibreCloth = glassFibreCloth;


                    var copperFoil = db.V28EFQ7J
                                     .Where(x => string.IsNullOrEmpty(x.CheckAccount))
                                     .Where(x => DbFunctions.TruncateTime(x.DateCreated) >= startDate)
                                     .AsEnumerable()
                                     .Select(x => new CopperFoilItem
                    {
                        ROWIdx       = x.ROWIdx,
                        CUNO         = x.CUNO,
                        OMNO         = x.OMNO,
                        KD           = x.KD,
                        SPEC         = x.SPEC,
                        IKPCNO       = x.IKPCNO,
                        L            = x.L.ToString(),
                        NETWGT       = x.NETWGT.HasValue ? x.NETWGT.Value : (int?)null,
                        DateCreated  = x.DateCreated.HasValue ? x.DateCreated.Value.ToString(Resource.StrDateTimeFormat) : null,
                        PrintTime    = x.PrintTime.HasValue ? x.PrintTime.Value.ToString(Resource.StrDateTimeFormat) : null,
                        CheckAccount = x.CheckAccount,
                        CheckTime    = x.CheckTime.HasValue ? x.CheckTime.Value.ToString(Resource.StrDateTimeFormat) : null,
                        IKDAT        = x.IKDAT
                    })
                                     .OrderBy(x => x.ROWIdx)
                                     .ToList();


                    viewModel.CopperFoil = copperFoil;

                    //產出SQLite
                    var tempSqliteFilePath = SQLiteUtils.GenerateSQLiteZip(viewModel);

                    if (isDebug)
                    {
                        response = Request.CreateResponse(HttpStatusCode.OK);
                    }
                    else
                    {
                        if (File.Exists(tempSqliteFilePath))
                        {
                            FileStream fileStream = new FileStream(tempSqliteFilePath, FileMode.Open, FileAccess.Read)
                            {
                            };
                            response         = Request.CreateResponse(HttpStatusCode.OK);
                            response.Content = new StreamContent(fileStream);
                            response.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
                            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                            {
                                FileName = packageFileName
                            };
                        }
                        else
                        {
                            response = Request.CreateResponse(HttpStatusCode.InternalServerError);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("發生錯誤:{0}", ex.Message);
                response = Request.CreateResponse(HttpStatusCode.InternalServerError);
                throw ex;
            }
            finally
            {
                _logger.Debug("download done...");
            }

            return(response);
        }