Пример #1
0
        private void GetInfo(HttpContext context)
        {
            string sUserId = context.Request["UserId"];

            if (string.IsNullOrEmpty(sUserId))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 5, "Chưa nhập đủ thông tin"));
                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))
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 7, "Số hợp đồng phải là kiểu số"));
                return;
            }

            WSClient client = new WSClient();
            var      cred   = new credential {
                clientId = Config.ClientIdSmartLink
            };
            var result = client.getVoucherPaymentInfo(cred, sUserId);

            if (result.returnCode != "")
            {
                context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", result.returnCode, result.returnCodeDescription));
                return;
            }
            else
            {
                CustomerGateInfo info = XMLReader.ReadInfo(result.responseData);
                if (info != null)
                {
                    string sVoucher = "";
                    if (info.vouchers != null && info.vouchers.Count > 0)
                    {
                        foreach (voucher voucher in info.vouchers)
                        {
                            if (sVoucher == "")
                            {
                                sVoucher += string.Format("{{\"vouchervalue\":\"{0}\",\"duration\":\"{1}\",\"vouchername\":\"{2}\",\"durationuomaltcode\":\"{3}\",\"voucherdesc\":\"{4}\"}}", voucher.vouchervalue, voucher.duration, voucher.vouchername, voucher.durationuomaltcode, voucher.voucherdesc);
                            }
                            else
                            {
                                sVoucher += "," + string.Format("{{\"vouchervalue\":\"{0}\",\"duration\":\"{1}\",\"vouchername\":\"{2}\",\"durationuomaltcode\":\"{3}\",\"voucherdesc\":\"{4}\"}}", voucher.vouchervalue, voucher.duration, voucher.vouchername, voucher.durationuomaltcode, voucher.voucherdesc);
                            }
                        }
                    }

                    context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\",\"subnum\":\"{2}\",\"contactname\":\"{3}\",\"contactaddress\":\"{4}\"," +
                                                         "\"contactphone\":\"{5}\",\"contactemail\":\"{6}\",\"servicename\":\"{7}\",\"substatusname\":\"{8}\"," +
                                                         "\"expirationdate\":\"{9}\",\"vouchers\":[{10}] }}",
                                                         0, "load thông tin ok", info.subnum, info.contactname, info.contactaddress, info.contactphone, info.contactemail, info.servicename, info.substatusname, info.expirationdate, sVoucher));
                    context.Session[Config.GetSessionUser] = info;
                }
                else
                {
                    context.Response.Write(string.Format("{{\"error\":{0},\"msg\":\"{1}\"}}", 8, "Không tìm thấy thông tin khách hàng"));
                }
            }
        }
Пример #2
0
        public static CustomerGateInfo ReadInfo(string sResult)
        {
            CustomerGateInfo info   = new CustomerGateInfo();
            XmlDocument      xDoc   = new XmlDocument();
            XmlReader        reader = XmlReader.Create(new StringReader(sResult));

            xDoc.Load(reader);

            XmlNodeList subnum = xDoc.GetElementsByTagName("subnum");
            string      sRead  = subnum[0].InnerText;

            info.subnum = sRead;

            XmlNodeList contactname = xDoc.GetElementsByTagName("contactname");

            sRead            = contactname[0].InnerText;
            info.contactname = sRead;

            XmlNodeList contactaddress = xDoc.GetElementsByTagName("contactaddress");

            sRead = contactaddress[0].InnerText;
            info.contactaddress = sRead;

            XmlNodeList contactphone = xDoc.GetElementsByTagName("contactphone");

            sRead             = contactphone[0].InnerText;
            info.contactphone = sRead;

            XmlNodeList contactemail = xDoc.GetElementsByTagName("contactemail");

            sRead             = contactemail[0].InnerText;
            info.contactemail = sRead;

            XmlNodeList taxnumber = xDoc.GetElementsByTagName("taxnumber");

            sRead          = taxnumber[0].InnerText;
            info.taxnumber = sRead;

            XmlNodeList idnumber = xDoc.GetElementsByTagName("idnumber");

            sRead         = idnumber[0].InnerText;
            info.idnumber = sRead;

            XmlNodeList servicename = xDoc.GetElementsByTagName("servicename");

            sRead            = servicename[0].InnerText;
            info.servicename = sRead;

            XmlNodeList subtypename = xDoc.GetElementsByTagName("subtypename");

            sRead            = subtypename[0].InnerText;
            info.subtypename = sRead;

            XmlNodeList billschemaname = xDoc.GetElementsByTagName("billschemaname");

            sRead = billschemaname[0].InnerText;
            info.billschemaname = sRead;

            XmlNodeList substatusname = xDoc.GetElementsByTagName("substatusname");

            sRead = substatusname[0].InnerText;
            info.substatusname = sRead;

            XmlNodeList institemserialnum1 = xDoc.GetElementsByTagName("institemserialnum1");

            sRead = institemserialnum1[0].InnerText;
            info.institemserialnum1 = sRead;

            XmlNodeList institemserialnum2 = xDoc.GetElementsByTagName("institemserialnum2");

            sRead = institemserialnum2[0].InnerText;
            info.institemserialnum2 = sRead;

            XmlNodeList expirationdate = xDoc.GetElementsByTagName("expirationdate");

            sRead = expirationdate[0].InnerText;
            info.expirationdate = sRead;

            //vouchers
            List <voucher> oList    = new List <voucher>();
            XmlNodeList    vouchers = xDoc.GetElementsByTagName("voucher");

            for (int i = 0; i < vouchers.Count; i++)
            {
                voucher item = new voucher();

                XmlNodeList voucher = vouchers[i].ChildNodes;
                item.vouchervalue       = voucher[0].InnerText;            //vouchervalue
                item.duration           = int.Parse(voucher[1].InnerText); //duration
                item.vouchername        = voucher[2].InnerText;            //vouchername
                item.durationuomaltcode = voucher[3].InnerText;            //durationuomaltcode
                item.voucherdesc        = voucher[4].InnerText;            //durationuomaltcode
                oList.Add(item);
            }
            info.vouchers = oList;
            return(info);
        }