Beispiel #1
0
        /// <summary>
        /// 自动计算对象的余额,isAdd只能是新增或者删除
        /// 如果需要修改就先删除再新增
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public BankCard CalcBalance(BankCard index, Boolean isAdd)
        {
            Diction dic = new DLDiction().Select(index.BankType);
            var     bal = dic.Note.GetDouble();

            if (isAdd)
            {
                //新增
                if (index.SaveType == 1000200001)//存入
                {
                    bal += index.Price;
                }
                else
                {
                    bal -= index.Price;
                }
            }
            else
            {
                //删除
                if (index.SaveType == 1000200001)//存入
                {
                    bal -= index.Price;
                }
                else
                {
                    bal += index.Price;
                }
            }
            dic.Note      = bal.GetString();
            index.Balance = bal;
            new DLDiction().Update(dic);
            return(index);
        }
Beispiel #2
0
        /// <summary>
        /// 计算所有信息的余额
        /// </summary>
        /// <returns></returns>
        public bool CalcAllBalance()
        {
            Double cal = 0;

            SQLiteParameter[] parm;
            String            sql = String.Empty;

            List <Diction> dics = new DLDiction().Select(new HashTableExp("ParentId", "1000100000"), "");

            foreach (var item in dics)
            {
                item.Note = "0";
            }
            List <BankCard> banks = new DLBankCard().Select(null, "").OrderBy(f => f.Time).ThenBy(f => f.CreateTime).ToList();

            foreach (var item in banks)
            {
                //表示存入
                if (item.SaveType == 1000200001)
                {
                    cal  = dics.Where(f => f.Id == item.BankType).SingleOrDefault().Note.GetDouble();
                    cal += item.Price;
                    dics.Where(f => f.Id == item.BankType).SingleOrDefault().Note = cal.GetString();
                }
                //表示取出
                else
                {
                    cal  = dics.Where(f => f.Id == item.BankType).SingleOrDefault().Note.GetDouble();
                    cal -= item.Price;
                    dics.Where(f => f.Id == item.BankType).SingleOrDefault().Note = cal.GetString();
                }
                item.Balance = cal;
            }

            List <SqlHashTable> hashList = new List <SqlHashTable>();

            foreach (var item in dics)
            {
                sql  = "update Diction set Note=@Note where Id=@Id";
                parm = new SQLiteParameter[] {
                    new SQLiteParameter("@Note", item.Note),
                    new SQLiteParameter("@Id", item.Id)
                };

                hashList.Add(new SqlHashTable(sql, parm));
            }

            foreach (var item in banks)
            {
                sql  = "update Bank_Card set Balance=@Balance where Id=@Id";
                parm = new SQLiteParameter[] {
                    new SQLiteParameter("@Id", item.Id),
                    new SQLiteParameter("@Balance", item.Balance)
                };
                hashList.Add(new SqlHashTable(sql, parm));
            }

            return(SqlLiteHelper.ExecuteSql(hashList) > 0);
        }
Beispiel #3
0
        /// <summary>
        /// 查询所有银行卡的最后一条数据 time格式:2015-01-02
        /// </summary>
        /// <returns></returns>
        public List <VBankCard> SelectCalc(String time)
        {
            String           sql  = String.Empty;
            List <VBankCard> list = new List <VBankCard>();
            //查询所有银行卡
            List <Diction> dics = new DLDiction().Select(new HashTableExp("ParentId", "1000100000"), null);

            foreach (var item in dics)
            {
                //查询最近一次的记录
                String sqlWhere = String.Format("Bank_Type='{0}'", item.Id);
                if (!String.IsNullOrEmpty(time))
                {
                    sqlWhere += String.Format(" and time<='{0}'", time);
                }
                sql = String.Format("select * from V_Bank_Card where {0} order by time desc,create_time desc limit 1 offset 0", sqlWhere);

                DataTable dt = SqlLiteHelper.GetTable(sql, CommandType.Text);
                list = Life.Model.Common <VBankCard> .ConvertToList(dt);
            }
            return(list);
        }