Example #1
0
        /// <summary>
        /// 读卡
        /// </summary>
        /// <param Name="inCardNo"></param>
        /// <param Name="card"></param>
        /// <param Name="msg"></param>
        /// <returns></returns>
        public static bool GetCzCard(string inCardNo, out MCzCard card, out string msg)
        {
            card          = new MCzCard();
            card.InCardno = inCardNo;
            SqlDataReader rd = null;

            try
            {
                if (!DBTool.Select("InCardNo=@InCardNo", card, string.Empty, out rd, out msg))
                {
                    card = null;
                    return(false);
                }
                else
                {
                    ICollection <MCzCard> list = ObjTool.BuildObject <MCzCard>(rd);
                    rd.Close();
                    if (list.Count == 0)
                    {
                        card = null;
                        msg  = "卡片" + inCardNo + "不存在";
                        return(false);
                    }
                    else
                    {
                        card = list.First();
                        if (card.State == "1")
                        {
                            return(GetCzkType(card.CardTypeCode, out card.CzkType, out msg));
                        }
                        else
                        {
                            msg = "该卡已禁用或已挂失!";
                            return(false);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                msg = "系统异常:" + ex.Message;
                if (rd != null && !rd.IsClosed)
                {
                    rd.Close();
                }
                card = null;
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// 保存储值卡
        /// </summary>
        /// <param name="card"></param>
        /// <param name="tran">事务</param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool SaveCzCard(MCzCard card, SqlTransaction tran, out string msg)
        {
            int i;

            if (!DBTool.Update(card, tran, out i, out msg))
            {
                return(false);
            }

            if (i > 0)
            {
                return(true);
            }
            else
            {
                msg = "卡更新失败,未找到卡" + card.OutCardNo;
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 保存交易
        /// </summary>
        /// <param name="saleFlow"></param>
        /// <param name="payFlow"></param>
        /// <param name="card"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool SaveTrade(MSaleFlow[] saleFlow, MPayFlow[] payFlow, out MCzCard card, out string msg)
        {
            if (saleFlow.Length == 0 || payFlow.Length == 0)
            {
                msg  = "流水不完整";
                card = null;
                return(false);
            }

            //查询储值卡信息
            if (!CzkDAL.GetCzCard(payFlow.First().Ref_no, out card, out msg))
            {
                return(false);
            }
            //检测卡余额
            if (card.Total - card.CzkType.KbMoney < payFlow.First().Total)
            {
                msg = "该卡余额不足";
                return(false);
            }
            //扣减余额
            card.Total   -= payFlow.First().Total;
            card.XfTotal += payFlow.First().Total;

            SqlTransaction tran;

            //开启事务
            if (!DBTool.BeginTransaction(out tran, out msg))
            {
                return(false);
            }
            //插入商品流水
            if (!SaveSaleFlow(saleFlow, tran, out msg))
            {
                if (DBTool.RollbackTransaction(tran, out msg))
                {
                    msg = "保存商品流水失败";
                    return(false);
                }
                else
                {
                    msg = "保存商品流水错误,回滚操作失败";
                    return(false);
                }
            }
            //插入付款流水
            if (!SavePayFlow(payFlow, tran, out msg))
            {
                if (DBTool.RollbackTransaction(tran, out msg))
                {
                    msg = "保存付款流水失败";
                    return(false);
                }
                else
                {
                    msg = "保存付款流水错误,回滚操作失败";
                    return(false);
                }
            }
            //保存储值卡信息
            if (!CzkDAL.SaveCzCard(card, tran, out msg))
            {
                if (DBTool.RollbackTransaction(tran, out msg))
                {
                    msg = "保存储值卡信息失败";
                    return(false);
                }
                else
                {
                    msg = "保存储值卡错误,回滚操作失败";
                    return(false);
                }
            }
            //提交事务
            if (!DBTool.CommitTransaction(tran, out msg))
            {
                msg = "提交事务失败,已回滚";
                return(false);
            }
            //交易成功,查询余额
            if (!CzkDAL.GetCzCard(payFlow.First().Ref_no, out card, out msg))
            {
                msg = "交易成功后确认余额失败";
            }
            return(true);
        }