示例#1
0
        private PayCardInfo FillData(IDataReader r)
        {
            PayCardInfo info = new PayCardInfo();

            if (!r.IsDBNull(r.GetOrdinal("ID")))
            {
                info.ID = r.GetInt32(r.GetOrdinal("ID"));
            }
            if (!r.IsDBNull(r.GetOrdinal("UserId")))
            {
                info.UserId = r.GetString(r.GetOrdinal("UserId"));
            }
            if (!r.IsDBNull(r.GetOrdinal("CardId")))
            {
                info.CardId = r.GetString(r.GetOrdinal("CardId"));
            }
            if (!r.IsDBNull(r.GetOrdinal("ResulId")))
            {
                info.ResulId = r.GetString(r.GetOrdinal("ResulId"));
            }
            if (!r.IsDBNull(r.GetOrdinal("Msg")))
            {
                info.Msg = r.GetString(r.GetOrdinal("Msg"));
            }
            if (!r.IsDBNull(r.GetOrdinal("ResulFull")))
            {
                info.ResulFull = r.GetString(r.GetOrdinal("ResulFull"));
            }
            if (!r.IsDBNull(r.GetOrdinal("CreateDate")))
            {
                info.CreateDate = r.GetDateTime(r.GetOrdinal("CreateDate"));
            }

            return(info);
        }
示例#2
0
 public int Add(PayCardInfo info)
 {
     SqlParameter[] param =
     {
         new SqlParameter("@UserId",     info.UserId),
         new SqlParameter("@CardId",     info.CardId),
         new SqlParameter("@ResulId",    info.ResulId),
         new SqlParameter("@Msg",        info.Msg),
         new SqlParameter("@ResulFull",  info.ResulFull),
         new SqlParameter("@CreateDate", info.CreateDate)
     };
     return(int.Parse(DataHelper.ExecuteScalar(Config.ConnectString, "usp_PayCard_Add", param).ToString()));
 }
示例#3
0
        //public int Update(PayCardInfo info)
        //{
        //    SqlParameter[] param = {
        //                                new SqlParameter("@ID", info.ID),
        //                                new SqlParameter("@UserId", info.UserId),
        //                                new SqlParameter("@CardId", info.CardId),
        //                                new SqlParameter("@ResulId", info.ResulId),
        //                                new SqlParameter("@Msg", info.Msg),
        //                                new SqlParameter("@ResulFull", info.ResulFull),
        //                                new SqlParameter("@CreateDate", info.CreateDate)
        //                           };
        //    return DataHelper.ExecuteNonQuery(Config.ConnectString, "usp_PayCard_Update", param);
        //}


        //public int Delete(int id)
        //{
        //    SqlParameter[] param = {
        //                               new SqlParameter("@ID", id)
        //                           };
        //    return DataHelper.ExecuteNonQuery(Config.ConnectString, "usp_PayCard_Delete", param);
        //}

        public PayCardInfo GetInfo(int id)
        {
            PayCardInfo info = null;

            SqlParameter[] param =
            {
                new SqlParameter("@ID", id)
            };
            var r = DataHelper.ExecuteReader(Config.ConnectString, "usp_PayCard_GetById", param);

            if (r != null)
            {
                info = new PayCardInfo();
                while (r.Read())
                {
                    info = FillData(r);
                }
                r.Close();
                r.Dispose();
            }
            return(info);
        }
示例#4
0
        public void ProcessRequest(HttpContext context)
        {
            if (!Security.AllowCall(context))
            {
                return;
            }
            context.Response.ContentType = "application/json";

            string sUserId  = context.Request["UserId"];
            string sCardId  = context.Request["CardId"];
            string sCaptCha = context.Request["CaptCha"];

            if (string.IsNullOrEmpty(sCaptCha))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 1, "Chưa nhập captcha"));
                return;
            }


            if (context.Session[Config.GetSessionCode] == null)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 2, "Captcha time out"));
                return;
            }

            if (context.Session[Config.GetSessionCode].ToString().ToUpper() != sCaptCha.ToUpper())
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 3, "Captcha không đúng"));
                return;
            }

            if (string.IsNullOrEmpty(sUserId) || string.IsNullOrEmpty(sCardId))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 4, "Chưa nhập đủ thông tin"));
                return;
            }

            if (sCardId.Trim().Length != 12)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 5, "Số thẻ phải là 12 ký tự"));
                return;
            }

            if (sUserId.Trim().Length != 12 && sUserId.Trim().Length != 14)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 6, "Số thuê bao phải là 12 hoặc 14 ký tự"));
                return;
            }

            if (!Utility.isOnlyNumber(sUserId) || !Utility.isOnlyNumber(sCardId))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 7, "Số hợp đồng và số thẻ phải là kiểu số"));
                return;
            }

            PayCardInfo info = new PayCardInfo()
            {
                UserId     = sUserId,
                CardId     = sCardId,
                CreateDate = DateTime.Now
            };

            try
            {
                //call services
                NapClient napClient = new NapClient();
                string    sTrans_id = sUserId + sCardId + string.Format("{0:yyMMddHHmmss}", DateTime.Now);
                var       oResult   = napClient.submitVoucherByScratchcard(sUserId, sCardId, sTrans_id);

                if (oResult != null)
                {
                    info.ResulFull = XMLReader.ReadResultVocher(oResult.responseData ?? "");
                    info.ResulId   = oResult.returnCode;
                    info.Msg       = oResult.returnCodeDescription ?? "";

                    if (info.ResulId == "" && info.ResulFull != "")
                    {
                        context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 0, info.ResulFull));
                    }
                    else
                    {
                        context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 8, info.Msg));
                    }
                }
                else
                {
                    context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 9, "SERVER đang bận"));
                }
            }
            catch (Exception e)
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", e.GetHashCode(), e.Message));
                //throw;
            }
            finally
            {
                //insert log to database
                PayCardData.instance.Add(info);
                context.Session.Remove(Config.GetSessionCode);
            }
        }