示例#1
0
        /// <summary>
        /// 将dataTable保存到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public String SaveData(DataTable dt, String userId)
        {
            List <BankCard> list = new List <BankCard>();
            String          msg  = "";

            foreach (DataRow row in dt.Rows)
            {
                BankCard index = new BankCard();
                String   type  = row["操作类型"].ToString();
                //判断操作类型是否存在
                HashTableExp hash = new HashTableExp("Name", type);
                hash.Add("ParentId", "1000200000");
                List <Diction> dictions = new BLDiction().Select(hash);
                if (dictions.Count <= 0)
                {
                    msg += "<br/>" + type + "不存在";
                    continue;
                }
                else
                {
                    index.SaveType = dictions[0].Id;
                }

                //判断银行卡是否正确
                type = row["银行卡名称"].ToString();
                hash.Clear();
                hash.Add("Name", type);
                hash.Add("ParentId", "1000100000");
                dictions = new BLDiction().Select(hash);
                if (dictions.Count <= 0)
                {
                    msg += "<br/>" + type + "不存在";
                    continue;
                }
                else
                {
                    index.BankType = dictions[0].Id;
                }

                DateTime time;
                //判断时间是否正确
                if (!DateTime.TryParse(row["时间"].ToString(), out time))
                {
                    msg += "<br/>" + row["时间"] + "不是时间类型";
                    continue;
                }
                else
                {
                    index.Time = time;
                }

                double price;

                //判断金额是否正确
                if (!double.TryParse(row["金额"].ToString(), out price))
                {
                    msg += "<br/>" + row["金额"] + "不是数字类型";
                    continue;
                }
                else
                {
                    index.Price = price;
                }

                index.Id         = Guid.NewGuid().ToString();
                index.Note       = row["备注"].ToString();
                index.CreateBy   = index.UpdateBy = userId;
                index.CreateTime = index.UpdateTime = DateTime.Now;
                list.Add(index);
            }

            int result = dLBankCard.Add(list);

            if (result > 0)
            {
                return("成功保存" + result + "条数据." + msg);
            }
            else
            {
                return(msg);
            }
        }
示例#2
0
        /// <summary>
        /// 将dataTable保存到数据库
        /// </summary>
        /// <param name="dt"></param>
        /// <returns></returns>
        public String SaveData(DataTable dt, String userId)
        {
            List <LifingCost> list = new List <LifingCost>();
            String            msg  = "";

            foreach (DataRow row in dt.Rows)
            {
                LifingCost index = new LifingCost();
                String     type  = row["消费类型"].ToString();
                //判断类型是否存在
                HashTableExp hash = new HashTableExp("Name", type);
                hash.Add("ParentId", "1000300000");
                List <Diction> dictions = new BLDiction().Select(hash);
                if (dictions.Count <= 0)
                {
                    msg += "<br/>" + type + "不存在";
                    continue;
                }

                DateTime time;
                //判断时间是否正确
                if (!DateTime.TryParse(row["消费时间"].ToString(), out time))
                {
                    msg += "<br/>" + row["消费时间"] + "不是时间类型";
                    continue;
                }
                else
                {
                    index.Time = time;
                }

                double price;

                //判断金额是否正确
                if (!double.TryParse(row["消费金额"].ToString(), out price))
                {
                    msg += "<br/>" + row["消费金额"] + "不是数字类型";
                    continue;
                }
                else
                {
                    index.Price = price;
                }

                index.Id         = Guid.NewGuid().ToString();
                index.Reason     = row["消费名称"].ToString();
                index.CostTypeId = dictions[0].Id;
                index.Notes      = row["备注"].ToString();
                index.CreateBy   = userId;
                index.CreateTime = DateTime.Now;
                list.Add(index);
            }

            int result = dLLifingCost.Add(list);

            if (result > 0)
            {
                return("成功保存" + result + "条数据." + msg);
            }
            else
            {
                return(msg);
            }
        }