예제 #1
0
        private void _setSqlParameters(IDbCommand command)
        {
            command.Parameters.Clear();

            if (SqlParameters != null)
            {
                foreach (var item in SqlParameters)
                {
                    command.Parameters.Add(DbParamConverter.Convert(item));
                }
            }
        }
예제 #2
0
        public bool AddRecorde(string memberCardId, ConsueType consueType, long cash, long amount, string productName, string createUserId, string note)
        {
            var consu = new Consumption()
            {
                MemberCardId = memberCardId,
                ConsueType   = Convert.ToInt32(consueType),
                Cash         = 0,
                Amount       = 0,
                ProductName  = productName,
                CreateUserId = createUserId,
                Note         = note
            };

            if (consueType == ConsueType.Consume)
            {
                consu.Amount = amount;
            }
            else if (consueType == ConsueType.Recharge)
            {
                consu.Amount = amount * -1;
                consu.Cash   = cash;
            }
            var sql      = new StringBuilder();
            var dbcontex = BizStore.Context;
            var trans    = dbcontex.Database.BeginTransaction();

            try
            {
                dbcontex.Set <Consumption>().Add(consu);
                dbcontex.SaveChanges();
                if (consu.Amount != 0 || consu.Cash != 0)
                {
                    sql.Append(@"Update mc_m_membercards set Balance=Balance-@Amount,CashSum=CashSum+@Cash where MemberCardId=@MemberCardId");
                    var p_amount       = DbParamConverter.Convert(new SqlParamWrapper("Amount", Convert.ToInt32(consu.Amount)));
                    var p_cash         = DbParamConverter.Convert(new SqlParamWrapper("Cash", Convert.ToInt32(consu.Cash)));
                    var p_memberCardId = DbParamConverter.Convert(new SqlParamWrapper("MemberCardId", memberCardId));
                    dbcontex.Database.ExecuteSqlCommand(sql.ToString(), new object[] { p_amount, p_cash, p_memberCardId });
                }
                else
                {
                    var cardStatus = MemberCardStatus.Init;
                    if (consueType == ConsueType.Open)
                    {
                        cardStatus = MemberCardStatus.Opend;
                    }
                    else if (consueType == ConsueType.Loss)
                    {
                        cardStatus = MemberCardStatus.Losed;
                    }
                    else if (consueType == ConsueType.LiftLoss)
                    {
                        cardStatus = MemberCardStatus.Opend;
                    }
                    else if (consueType == ConsueType.Invalid)
                    {
                        cardStatus = MemberCardStatus.Invalided;
                    }
                    if (cardStatus != MemberCardStatus.Init)
                    {
                        sql.Append(@"Update mc_m_membercards set Status=@Status where MemberCardId=@MemberCardId");

                        var p_status       = DbParamConverter.Convert(new SqlParamWrapper("Status", Convert.ToInt32(cardStatus)));
                        var p_memberCardId = DbParamConverter.Convert(new SqlParamWrapper("MemberCardId", memberCardId));
                        dbcontex.Database.ExecuteSqlCommand(sql.ToString(), p_status, p_memberCardId);
                    }
                }
                trans.Commit();
                return(true);
            }
            catch (Exception)
            {
                trans.Rollback();
                return(false);
            }
        }