Ejemplo n.º 1
0
        /// <summary>
        /// 保存Http数据
        /// </summary>
        public bool SaveHttpData()
        {
            var      lsRate   = GetHttpData();
            var      dt       = queryData.QueryLatestInterestRateTime();
            DateTime datetime = DateTime.Parse(dt.Rows[0][0].ToString());
            var      rate     = lsRate.Where(p => !DateTime.Equals(p.LoadTime, datetime)).ToList();

            if (rate.Count != 0)
            {
                insertData.BathInsertInterestRate(rate);
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
        public bool ReadInterestRate(string fileName, out string errorMsg)
        {
            string[] ExcelColumns = new string[] { "利率", "标类型", "还款方式", "借款时间", "借款期限" };
            var      lsDt         = ExcelHelper.ReadWholeExcel(fileName);
            //逐个DataTable校验
            int Count = lsDt.Count;

            for (int i = 0; i < Count; i++)
            {
                if (lsDt[i].Rows.Count == 0)
                {
                    i--; Count--;
                    lsDt.RemoveAt(i);
                    continue;
                }
                foreach (var col in ExcelColumns)
                {
                    if (!lsDt[i].Columns.Contains(col))
                    {
                        i--; Count--;
                        lsDt.RemoveAt(i);
                        break;
                    }
                }
            }

            if (Count == 0)
            {
                errorMsg = "Excel 模板错误或导入模板为空.";
                return(false);
            }

            var lsRate = new List <InterestRateModel>();

            try {
                foreach (var dt in lsDt)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        var rate = new InterestRateModel()
                        {
                            InterestRate = decimal.Parse(dr["利率"].ToString())
                            ,
                            MarkTypeName = dr["标类型"].ToString()
                            ,
                            PaymentMethod = dr["还款方式"].ToString()
                            ,
                            LoadTime = DateTime.Parse(dr["借款时间"].ToString())
                            ,
                            TimeLimit = int.Parse(dr["借款期限"].ToString())
                        };
                        lsRate.Add(rate);
                    }
                }
            }catch (Exception ex)
            {
                errorMsg = ex.Message;
                return(false);
            }
            errorMsg = null;
            return(insertData.BathInsertInterestRate(lsRate) > 0);
        }