protected void Page_Load(object sender, EventArgs e)
        {
            String url = ConfigurationManager.AppSettings["PaymentProcessorURL"];
            HttpWebRequest req;
            req = (HttpWebRequest)WebRequest.Create(url);
            AppException.LogEvent("Check:" + url);
            String ttt = Context.Request.QueryString.ToString();
            AppException.LogEvent("Check:" + ttt);

            String item_number ;//= getValue(ttt, "item_number");
            String payment_date ;//= getValue(ttt, "payment_date");
            String txn_id;// = getValue(ttt, "txn_id");
            String mc_gross ;//= getValue(ttt, "mc_gross");
            String comment;

            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest ;
            if (param.Length == 0)
            {
                strRequest = ttt;
            }
            else
            {
                strRequest = Encoding.ASCII.GetString(param);
            }
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;

            AppException.LogEvent("Sending Response");
            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;
            string strResponse = "";
            try
            {
                //Send the request to PayPal and get the response
                StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
                streamOut.Write(strRequest);
                streamOut.Close();
                StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
                strResponse = streamIn.ReadToEnd();
                streamIn.Close();
                AppException.LogEvent("Response Received:" + strResponse);
            }
            catch (Exception writeOutEx)
            {
                AppException.LogEvent("Here 2 " + writeOutEx.Message);
            }

            if (strResponse == "VERIFIED")
            {
                //check the payment_status is Completed
                //check that txn_id has not been previously processed
                //check that receiver_email is your Primary PayPal email
                //check that payment_amount/payment_currency are correct
                //process payment

                try
                {
                    Dictionary<String, String> httpParsedResponse = new Dictionary<string, string>();
                    String[] httpKVArray = strRequest.Split('&');
                    foreach (String i in httpKVArray)
                    {
                        String[] pair = i.Split('=');
                        if (pair.Length > 1)
                        {
                            httpParsedResponse.Add(pair[0], pair[1]);
                        }
                        else
                        {
                            httpParsedResponse.Add(pair[0], "");
                        }
                    }

                    AppException.LogEvent("Adding here 2.1:[" + strRequest + "]");
                    item_number = getValue(strRequest, "item_number");
                    payment_date = getValue(strRequest, "payment_date");
                    txn_id = getValue(strRequest, "txn_id");
                    mc_gross = getValue(strRequest, "mc_gross");
                    comment = getValue(strRequest, "custom");
                    AppException.LogEvent("Adding here 2.2:" + item_number);

                    AppException.LogEvent(String.Format("item_number={0}, payment_date={1}, txn_id={2}, mc_gross={3}, comment={4}",
                                        item_number, payment_date, txn_id, mc_gross, comment));

                    int item_no = Convert.ToInt32(item_number);
                    Decimal amount = Convert.ToDecimal(mc_gross);
                    WebModules.Business.UserShows us = new Fpp.WebModules.Business.UserShows(item_no);

                    us.Status = (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID;
                    us.Save();

                    AppException.LogEvent("Adding Transaction");
                    //
                    // Add to transaction log for auditing purposes
                    Transaction.Add(item_number, 1, Convert.ToDecimal(mc_gross), txn_id, us.ShowID, us.Userid, ConvertFromPayPalDate(payment_date, 0));
                }
                catch (Exception e1)
                {
                    AppException.LogEvent("here3: " + e1.Message);
                }

                //
                //
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
                AppException.LogEvent("Check: INVALID");
            }
            else
            {
                //log response/ipn data for manual investigation
                AppException.LogEvent("Not processed");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Post back to either sandbox or live

            string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            //string strLive = "https://www.paypal.com/cgi-bin/webscr";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);

            String ttt = Context.Request.QueryString.ToString();

            String item_number ;//= getValue(ttt, "item_number");
            String payment_date ;//= getValue(ttt, "payment_date");
            String txnID;// = getValue(ttt, "txnID");
            String mc_gross ;//= getValue(ttt, "mc_gross");

            //Set values for the request back
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
            string strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            req.ContentLength = strRequest.Length;

            //for proxy
            //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
            //req.Proxy = proxy;

            //Send the request to PayPal and get the response
            StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
            string strResponse = streamIn.ReadToEnd();
            streamIn.Close();

            if (strResponse == "VERIFIED")
            {
                //check the payment_status is Completed
                //check that txnID has not been previously processed
                //check that receiver_email is your Primary PayPal email
                //check that payment_amount/payment_currency are correct
                //process payment

                item_number = getValue(strRequest, "item_number");
                payment_date = getValue(strRequest, "payment_date");
                txnID = getValue(strRequest, "txnID");
                mc_gross = getValue(strRequest, "mc_gross");

                int item_no = Convert.ToInt32(item_number.Substring(11, 6));
                Decimal amount = Convert.ToDecimal(mc_gross);
                WebModules.Business.UserShows us = new Fpp.WebModules.Business.UserShows(item_no);

                us.Status = (int)UserShows.UserStatus.STATUS_ENTERED_AND_PAID;
                us.Save();

                //
                // Add to transaction log for auditing purposes

                Transaction tr = new Transaction();
                tr.Amount = Convert.ToDecimal(mc_gross);
                tr.RefCode = txnID;
                tr.Showid = us.ShowID;
                tr.TransactionDate = ConvertFromPayPalDate(payment_date, 0);

                //
                //
            }
            else if (strResponse == "INVALID")
            {
                //log for manual investigation
            }
            else
            {
                //log response/ipn data for manual investigation
            }
        }
        public static UserShows SaveEntry(HttpContext context, String data, Fpp.WebModules.Business.User currentUser, Shows thisShow)
        {
            DogClasses dc = new DogClasses();
            int handlertype = Convert.ToInt32(context.Request["handlertype"]);
            String[] dogs = data.Split(',');
            String[] altHandlersList = context.Request["althandlerslist"].Split(',');
            int waitingList = Convert.ToInt32(context.Request["waitinglist"]);

            //
            //  Multidog format is packed as
            //  <dogid>@<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>][,<dogid>#<clsid>:<handlername>.<dogname>[;<handlername>.<dogname>]]
            //
            MultiDog.DeleteUserFromShow(currentUser.ID, thisShow.ID);
            String[] pairTeams = context.Request["pairteams"].Split(',');
            if (!String.IsNullOrEmpty(context.Request["pairteams"])) {
                foreach (String pairTeam in pairTeams)
                {
                    String[] pt = pairTeam.Split(';');
                    int DogID = -1;
                    int ClsID = -1; ;

                    foreach (String p in pt)
                    {
                        String[] dogcls;
                        String[] otherHandlerDog;
                        if (p.IndexOf(':') > 0)
                        {
                            dogcls = p.Split(':')[0].Split('@');
                            DogID = Convert.ToInt32(dogcls[0]);
                            ClsID = Convert.ToInt32(dogcls[1]);
                            otherHandlerDog = p.Split(':')[1].Split('.');

                            String []handlerDetails = otherHandlerDog[0].Split('-');
                            if (handlerDetails.Length > 1)
                            {
                                String handlerName = handlerDetails[0];
                                int handlerID = -1;
                                int.TryParse(handlerDetails[1], out handlerID);

                                String[] dogDetails = otherHandlerDog[1].Split('-');
                                String dogName = dogDetails[0];
                                int dogID = -1;
                                int.TryParse(dogDetails[1], out  dogID );

                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, handlerName, dogName, handlerID, dogID);
                            }
                            else
                            {
                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, otherHandlerDog[0], otherHandlerDog[1]);
                            }
                        }
                        else
                        {
                            otherHandlerDog = p.Split('.');
                            String[] handlerDetails = otherHandlerDog[0].Split('-');
                            if (handlerDetails.Length > 1)
                            {
                                String handlerName = handlerDetails[0];
                                int handlerID = -1;
                                int.TryParse(handlerDetails[1], out handlerID);

                                String[] dogDetails = otherHandlerDog[1].Split('-');
                                String dogName = dogDetails[0];
                                int dogID = -1;
                                int.TryParse(dogDetails[1], out  dogID);

                                MultiDog.Add(currentUser.ID, DogID, ClsID, thisShow.ID, handlerName, dogName, handlerID, dogID);
                            }
                        }
                    }
                }
            }

            foreach (String dog in dogs)
            {
                String[] details = dog.Split(':');
                int dogid = Convert.ToInt32(details[0]);

                String[] clslist = details[1].Split('.');
                List<int> classes = new List<int>();
                List<int> altHandlers = new List<int>();
                foreach (String clsid in clslist)
                {
                    if (clsid.Length > 0)
                    {
                        int altid = 0;
                        classes.Add(Convert.ToInt32(clsid));
                        for (int ii = 0; ii < altHandlersList.Length; ii++)
                        {
                            String[] kvPairs = altHandlersList[ii].Split(':');
                            if (kvPairs[0] == clsid && kvPairs[2] == details[0])
                            {
                                altid = Convert.ToInt32(kvPairs[1]);
                            }
                        }
                        altHandlers.Add(altid);
                    }
                }
                dc.Save(dogid, thisShow.ID, classes, altHandlers);
            }

            UserShows us = new UserShows(currentUser.ID, thisShow.ID);
            us.Status = us.Status = (int)UserShows.UserStatus.STATUS_SAVED ;

            //
            // add check to see if this person is on the judging list.
            if (Judge.isJudgeAtShow(currentUser.ID, thisShow.ID))
            {
                us.HandlerType = (int)UserShows.HandlerTypes.JUDGE;
            }
            else
            {
                us.HandlerType = handlertype;
            }
            if ( !String.IsNullOrEmpty(context.Request["optout"] )  ) {
                us.Optout = Convert.ToInt32(context.Request["optout"]);
            }
            us.Save();

            Camping camping = new Camping(thisShow.ID);
            if (camping.ID > -1)
            {
                String campParty = "";
                String campDays = "";
                String campComments = "";
                if (!String.IsNullOrEmpty(context.Request["campingdays"])) campDays = context.Request["campingdays"];
                if (!String.IsNullOrEmpty(context.Request["campingparty"])) campParty = context.Request["campingparty"];
                if (!String.IsNullOrEmpty(context.Request["campcomments"])) campComments = context.Request["campcomments"];
                if (campDays.Length > 0)
                {
                    UserCamping.Add(us.ID, campParty, campComments, campDays);
                }
            }

            if (waitingList == 1)
            {
                WaitingList.Add(us.ShowID, us.Userid);

            }

            return us;
        }