Exemple #1
0
        public Results CreateType(Guid id, string name, int inOrOut, DateTime createOn, Guid createBy, string remark)
        {
            if (StringHelper.IsNullOrEmptyOrWhiteSpace(name))
            {
                return(new Results("类型名不能为空"));
            }
            TypesModel model = new TypesModel();

            model.Id       = id;
            model.Name     = name;
            model.InOrOut  = inOrOut;
            model.CreateOn = createOn;
            model.CreateBy = createBy;
            model.Remark   = remark;

            return(_typesDapper.Create(model));
        }
Exemple #2
0
        public Results CreateFromCsv(Guid memberShipId, string path)
        {
            //判断是不是有类型Type
            Guid typeOutId = Guid.Empty;
            var  typeOut   = _typesDapper.GetTypeByName("支付宝支出").ToList();

            if (typeOut.Count < 1)
            {
                TypesModel typeOutModel = new TypesModel();
                typeOutModel.Id       = Guid.NewGuid();
                typeOutModel.InOrOut  = 1;
                typeOutModel.CreateBy = memberShipId;
                typeOutModel.CreateOn = DateTime.Now;
                typeOutModel.Name     = "支付宝支出";
                var createTypeOutResult = _typesDapper.Create(typeOutModel);
                if (createTypeOutResult.Success)
                {
                    typeOutId = typeOutModel.Id;
                }
                else
                {
                    return(new Results("创建类型失败"));
                }
            }
            else
            {
                typeOutId = typeOut[0].Id;
            }
            Guid typeInId = Guid.Empty;
            var  typeIn   = _typesDapper.GetTypeByName("支付宝收入").ToList();

            if (typeIn.Count < 1)
            {
                TypesModel typeInModel = new TypesModel();
                typeInModel.Id       = Guid.NewGuid();
                typeInModel.InOrOut  = 0;
                typeInModel.CreateBy = memberShipId;
                typeInModel.CreateOn = DateTime.Now;
                typeInModel.Name     = "支付宝收入";
                var createTypeInResult = _typesDapper.Create(typeInModel);
                if (createTypeInResult.Success)
                {
                    typeInId = typeInModel.Id;
                }
                else
                {
                    return(new Results("创建类型失败"));
                }
            }
            else
            {
                typeInId = typeIn[0].Id;
            }

            //添加数据
            var dt     = FileHelper.OpenCSV(path);
            var length = dt.Rows.Count;
            var type1  = dt.Rows[2][10].ToString();
            List <RecordsModel> list = new List <RecordsModel>();

            for (int i = 0; i < length; i++)
            {
                if (!StringHelper.IsNullOrEmptyOrWhiteSpace(dt.Rows[i][10].ToString()))
                {
                    RecordsModel model = new RecordsModel();
                    model.Id       = Guid.NewGuid();
                    model.Money    = decimal.Parse(dt.Rows[i][9].ToString());
                    model.Remark   = dt.Rows[i][8].ToString();
                    model.CreateBy = memberShipId;
                    model.CreateOn = StringHelper.DateTimeConver(dt.Rows[i][2].ToString().Split(' ')[0]);
                    model.Source   = "支付宝";
                    var type = dt.Rows[i][10].ToString().TrimEnd();
                    if (type == "收入")
                    {
                        model.TypeId = typeInId;
                    }
                    if (type == "支出")
                    {
                        model.TypeId = typeOutId;
                    }
                    list.Add(model);
                }
            }
            foreach (var item in list)
            {
                _recordDapper.Create(item);
            }
            return(new Results());
        }