コード例 #1
0
 /// <summary>
 /// Db 組成 D05ViewModel
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private D05ViewModel DbToD05ViewModel(Group_Product_Code_Mapping data)
 {
     return(new D05ViewModel()
     {
         Group_Product_Code = data.Group_Product_Code,
         Group_Product = data.Group_Product.Group_Product_Name,
         Product_Code = data.Product_Code,
         Processing_Date = TypeTransfer.dateTimeNToString(data.Processing_Date)
     });
 }
コード例 #2
0
        /// <summary>
        /// D05 save db
        /// </summary>
        /// <param name="dataModel"></param>
        /// <returns></returns>
        public MSGReturnModel saveD05(string debtType, string actionType, D05ViewModel dataModel)
        {
            MSGReturnModel result = new MSGReturnModel();

            try
            {
                if (debtType != dataModel.Group_Product_Code.Substring(0, 1))
                {
                    result.RETURN_FLAG = false;
                    result.DESCRIPTION = "套用產品群代碼 第一個字必須是 " + debtType;
                    return(result);
                }

                if (actionType == "Add")
                {
                    if (db.Group_Product_Code_Mapping.Where(x => x.Product_Code == dataModel.Product_Code).Count() > 0)
                    {
                        result.RETURN_FLAG = false;
                        result.DESCRIPTION = "資料重複:" + dataModel.Product_Code + " 已存在";
                        return(result);
                    }

                    db.Group_Product_Code_Mapping.Add(
                        new Group_Product_Code_Mapping()
                    {
                        Group_Product_Code = dataModel.Group_Product_Code,
                        Product_Code       = dataModel.Product_Code,
                        Processing_Date    = DateTime.Parse(dataModel.Processing_Date)
                    });
                }
                else if (actionType == "Modify")
                {
                    Group_Product_Code_Mapping oldData = db.Group_Product_Code_Mapping.Find(dataModel.Product_Code);
                    oldData.Group_Product_Code = dataModel.Group_Product_Code;
                    oldData.Product_Code       = dataModel.Product_Code;
                    oldData.Processing_Date    = DateTime.Parse(dataModel.Processing_Date);
                }

                db.SaveChanges(); //Save
                result.RETURN_FLAG = true;
            }
            catch (DbUpdateException ex)
            {
                result.RETURN_FLAG = false;
                result.DESCRIPTION = Message_Type
                                     .save_Fail.GetDescription("D05",
                                                               $"message: {ex.Message}" +
                                                               $", inner message {ex.InnerException?.InnerException?.Message}");
            }

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// C03 Mortgage save
        /// </summary>
        /// <param name="yearQuartly"></param>
        public void saveC03Mortgage(string yearQuartly)
        {
            string   logPath   = log.txtLocation(TableType.C03Mortgage.ToString());
            DateTime startTime = DateTime.Now;

            try
            {
                List <Loan_default_Info> A06Data = db.Loan_default_Info
                                                   .Where(x => x.Year_Quartly == yearQuartly).ToList();

                List <Econ_Domestic> A07Data = db.Econ_Domestic
                                               .Where(x => x.Year_Quartly == yearQuartly).ToList();
                if (!A06Data.Any())
                {
                    log.txtLog(
                        TableType.C03Mortgage.ToString(),
                        false,
                        startTime,
                        logPath,
                        "Loan_default_Info 無 " + yearQuartly + " 的資料");
                }
                else if (!A07Data.Any())
                {
                    log.txtLog(
                        TableType.C03Mortgage.ToString(),
                        false,
                        startTime,
                        logPath,
                        "Econ_Domestic 無 " + yearQuartly + " 的資料");
                }
                else
                {
                    string productCode = GroupProductCode.M.GetDescription();
                    Group_Product_Code_Mapping gpcm = db.Group_Product_Code_Mapping.Where(x => x.Group_Product_Code.StartsWith(productCode)).FirstOrDefault();
                    if (gpcm == null)
                    {
                        log.txtLog(
                            TableType.C03Mortgage.ToString(),
                            false,
                            startTime,
                            logPath,
                            "Group_Product_Code_Mapping 無房貸的 Product_Code");
                    }
                    else
                    {
                        productCode = gpcm.Product_Code;

                        var query = db.Econ_D_YYYYMMDD
                                    .Where(x => x.Year_Quartly == yearQuartly);
                        db.Econ_D_YYYYMMDD.RemoveRange(query);

                        db.Econ_D_YYYYMMDD.AddRange(
                            A07Data.Select(x => new Econ_D_YYYYMMDD()
                        {
                            Processing_Date = DateTime.Now.ToString("yyyy/MM/dd"),
                            Product_Code    = productCode,
                            Data_ID         = "",
                            Year_Quartly    = x.Year_Quartly,
                            PD_Quartly      = A06Data[0].PD_Quartly,
                            var1            = Extension.doubleNToDouble(x.TWSE_Index),
                            var2            = Extension.doubleNToDouble(x.TWRGSARP_Index),
                            var3            = Extension.doubleNToDouble(x.TWGDPCON_Index),
                            var4            = Extension.doubleNToDouble(x.TWLFADJ_Index),
                            var5            = Extension.doubleNToDouble(x.TWCPI_Index),
                            var6            = Extension.doubleNToDouble(x.TWMSA1A_Index),
                            var7            = Extension.doubleNToDouble(x.TWMSA1B_Index),
                            var8            = Extension.doubleNToDouble(x.TWMSAM2_Index),
                            var9            = Extension.doubleNToDouble(x.GVTW10YR_Index),
                            var10           = Extension.doubleNToDouble(x.TWTRBAL_Index),
                            var11           = Extension.doubleNToDouble(x.TWTREXP_Index),
                            var12           = Extension.doubleNToDouble(x.TWTRIMP_Index),
                            var13           = Extension.doubleNToDouble(x.TAREDSCD_Index),
                            var14           = Extension.doubleNToDouble(x.TWCILI_Index),
                            var15           = Extension.doubleNToDouble(x.TWBOPCUR_Index),
                            var16           = Extension.doubleNToDouble(x.EHCATW_Index),
                            var17           = Extension.doubleNToDouble(x.TWINDPI_Index),
                            var18           = Extension.doubleNToDouble(x.TWWPI_Index),
                            var19           = Extension.doubleNToDouble(x.TARSYOY_Index),
                            var20           = Extension.doubleNToDouble(x.TWEOTTL_Index),
                            var21           = Extension.doubleNToDouble(x.SLDETIGT_Index),
                            var22           = Extension.doubleNToDouble(x.TWIRFE_Index),
                            var23           = Extension.doubleNToDouble(x.SINYI_HOUSE_PRICE_index),
                            var24           = Extension.doubleNToDouble(x.CATHAY_ESTATE_index),
                            var25           = Extension.doubleNToDouble(x.Real_GDP2011),
                            var26           = Extension.doubleNToDouble(x.MCCCTW_Index),
                            var27           = Extension.doubleNToDouble(x.TRDR1T_Index)
                        })
                            );

                        db.SaveChanges();

                        log.txtLog(
                            TableType.C03Mortgage.ToString(),
                            true,
                            startTime,
                            logPath,
                            MessageType.Success.GetDescription());
                    }
                }
            }
            catch (Exception ex)
            {
                log.txtLog(
                    TableType.C03Mortgage.ToString(),
                    false,
                    startTime,
                    logPath,
                    ex.Message);
            }
        }
コード例 #4
0
        /// <summary>
        /// C03 Mortgage save
        /// </summary>
        /// <param name="todayDate"></param>
        public void saveC03Mortgage(string todayDate)
        {
            string   logPath   = log.txtLocation(TableType.C03Mortgage.ToString());
            DateTime startTime = DateTime.Now;

            try
            {
                string thisYear         = todayDate.Substring(0, 4);
                string lastYear         = (int.Parse(thisYear) - 1).ToString();
                string startYearQuartly = lastYear + "Q1";
                string endYearQuartly   = thisYear + "Q4";

                IEnumerable <Loan_default_Info> A06Data = db.Loan_default_Info
                                                          .Where(x => x.Year_Quartly.CompareTo(startYearQuartly) >= 0 &&
                                                                 x.Year_Quartly.CompareTo(endYearQuartly) <= 0
                                                                 ).AsEnumerable();

                IEnumerable <Econ_Domestic> A07Data = db.Econ_Domestic
                                                      .Where(x => x.Year_Quartly.CompareTo(startYearQuartly) >= 0 &&
                                                             x.Year_Quartly.CompareTo(endYearQuartly) <= 0
                                                             ).AsEnumerable();

                if (!A06Data.Any())
                {
                    log.txtLog(
                        TableType.C03Mortgage.ToString(),
                        false,
                        startTime,
                        logPath,
                        "Loan_default_Info 無 " + startYearQuartly + " ~ " + endYearQuartly + " 的資料");
                }
                else if (!A07Data.Any())
                {
                    log.txtLog(
                        TableType.C03Mortgage.ToString(),
                        false,
                        startTime,
                        logPath,
                        "Econ_Domestic 無 " + startYearQuartly + " ~ " + endYearQuartly + " 的資料");
                }
                else
                {
                    string productCode = GroupProductCode.M.GetDescription();
                    Group_Product_Code_Mapping gpcm = db.Group_Product_Code_Mapping.Where(x => x.Group_Product_Code.StartsWith(productCode)).FirstOrDefault();
                    if (gpcm == null)
                    {
                        log.txtLog(
                            TableType.C03Mortgage.ToString(),
                            false,
                            startTime,
                            logPath,
                            "Group_Product_Code_Mapping 無房貸的 Product_Code");
                    }
                    else
                    {
                        productCode = gpcm.Product_Code;

                        var query = db.Econ_D_YYYYMMDD
                                    .Where(x => x.Year_Quartly.CompareTo(startYearQuartly) >= 0 &&
                                           x.Year_Quartly.CompareTo(endYearQuartly) <= 0
                                           ).ToList();
                        db.Econ_D_YYYYMMDD.RemoveRange(query);

                        string nowDate = DateTime.Now.ToString("yyyy/MM/dd");

                        var addData = (
                            from a in A06Data
                            join b in A07Data
                            on new { a.Year_Quartly }
                            equals new { b.Year_Quartly }
                            select new Econ_D_YYYYMMDD()
                        {
                            Processing_Date = nowDate,
                            Product_Code = productCode,
                            Data_ID = "",
                            Year_Quartly = b.Year_Quartly,
                            PD_Quartly = a.PD_Quartly,
                            TWSE_Index = Extension.doubleNToDouble(b.TWSE_Index),
                            TWRGSARP_Index = Extension.doubleNToDouble(b.TWRGSARP_Index),
                            TWGDPCON_Index = Extension.doubleNToDouble(b.TWGDPCON_Index),
                            TWLFADJ_Index = Extension.doubleNToDouble(b.TWLFADJ_Index),
                            TWCPI_Index = Extension.doubleNToDouble(b.TWCPI_Index),
                            TWMSA1A_Index = Extension.doubleNToDouble(b.TWMSA1A_Index),
                            TWMSA1B_Index = Extension.doubleNToDouble(b.TWMSA1B_Index),
                            TWMSAM2_Index = Extension.doubleNToDouble(b.TWMSAM2_Index),
                            GVTW10YR_Index = Extension.doubleNToDouble(b.GVTW10YR_Index),
                            TWTRBAL_Index = Extension.doubleNToDouble(b.TWTRBAL_Index),
                            TWTREXP_Index = Extension.doubleNToDouble(b.TWTREXP_Index),
                            TWTRIMP_Index = Extension.doubleNToDouble(b.TWTRIMP_Index),
                            TAREDSCD_Index = Extension.doubleNToDouble(b.TAREDSCD_Index),
                            TWCILI_Index = Extension.doubleNToDouble(b.TWCILI_Index),
                            TWBOPCUR_Index = Extension.doubleNToDouble(b.TWBOPCUR_Index),
                            EHCATW_Index = Extension.doubleNToDouble(b.EHCATW_Index),
                            TWINDPI_Index = Extension.doubleNToDouble(b.TWINDPI_Index),
                            TWWPI_Index = Extension.doubleNToDouble(b.TWWPI_Index),
                            TARSYOY_Index = Extension.doubleNToDouble(b.TARSYOY_Index),
                            TWEOTTL_Index = Extension.doubleNToDouble(b.TWEOTTL_Index),
                            SLDETIGT_Index = Extension.doubleNToDouble(b.SLDETIGT_Index),
                            TWIRFE_Index = Extension.doubleNToDouble(b.TWIRFE_Index),
                            SINYI_HOUSE_PRICE_index = Extension.doubleNToDouble(b.SINYI_HOUSE_PRICE_index),
                            CATHAY_ESTATE_index = Extension.doubleNToDouble(b.CATHAY_ESTATE_index),
                            Real_GDP2011 = Extension.doubleNToDouble(b.Real_GDP2011),
                            MCCCTW_Index = Extension.doubleNToDouble(b.MCCCTW_Index),
                            TRDR1T_Index = Extension.doubleNToDouble(b.TRDR1T_Index)
                        }
                            ).AsEnumerable();

                        db.Econ_D_YYYYMMDD.AddRange(addData);
                        db.SaveChanges();

                        log.txtLog(
                            TableType.C03Mortgage.ToString(),
                            true,
                            startTime,
                            logPath,
                            MessageType.Success.GetDescription());
                    }
                }
            }
            catch (Exception ex)
            {
                log.txtLog(
                    TableType.C03Mortgage.ToString(),
                    false,
                    startTime,
                    logPath,
                    ex.Message);
            }
        }