Esempio n. 1
0
        public void registerTodo(int metodo)
        {
            brPayment = new BrPayments();
            brUser    = new BrUser();
            int typeRegister = 0;

            if (Session["typeRegister"] == null)
            {
                Session["typeRegister"] = 0;
            }

            typeRegister = int.Parse(Session["typeRegister"].ToString());
            //REGISTER
            string[] dataLogin   = HttpContext.Current.User.Identity.Name.Split('¬');
            string   userCurrent = dataLogin[0];

            if (dataLogin.Length > 1)
            {
                userCurrent = dataLogin[1];
            }
            string dataBdd        = Session["datos"].ToString();
            string TypeMembership = (dataBdd.Split('$')[3]).Split('|')[7];

            if (!string.IsNullOrEmpty((string)Session["tienda"]))
            {
                if (Session["tienda"].ToString() != "1")
                {
                    string   data2 = (string)Session["civilState"];
                    string[] oIdMembreship_amount = brUser.RegisterUser(dataBdd, data2).Split('¬');

                    if (oIdMembreship_amount.Length < 2)
                    {
                        Response.Write("false¬Ha Ocurrido Un Error al Intentar Registrar al Usuario");
                        return;
                    }
                    string[] array1     = Session["cronogramaYa"].ToString().Split('^');
                    string[] datosMem   = array1[0].Split('|');
                    string[] array2     = array1[1].Split('~');
                    string[] cuotas     = array2[0].Split('¬');
                    string   cronoActiv = "";
                    for (int i = 0; i < cuotas.Length - 1; i++)
                    {
                        var fila = cuotas[i].Split('|');
                        if (fila[0].Substring(0, 7) != "Inicial")
                        {
                            cronoActiv += DateTime.Parse(fila[1]).ToString("yyyy-MM-dd");
                            //amountFinanciade = double.Parse(fila[2].Replace("S/.", ""));
                            break;
                        }
                        else
                        {
                            cronoActiv += DateTime.Parse(fila[1]).ToString("yyyy-MM-dd") + "¬";
                        }
                    }

                    string[] parameterPerson  = dataBdd.Split('$');
                    string[] arraydata        = parameterPerson[0].Split('|');
                    string[] arrayTypeaccount = parameterPerson[2].Split('|');
                    string[] arrayaccount     = parameterPerson[3].Split('|');

                    string parameterAccount = arraydata[5].Trim() + "|" + arrayTypeaccount[7].Trim() + '|' + userCurrent + '|' + oIdMembreship_amount[0];

                    newUserName = brUser.GenerateAccount(parameterAccount);
                    bool notAvilable = brUser.NotAvailableUser(newUserName);
                    if (string.IsNullOrEmpty(newUserName))
                    {
                        Response.Write("false¬Ha Ocurrido Un Error al Intentar Registrar al Usuario");
                        return;
                    }


                    //END REGISTER
                    if (typeRegister == 1)
                    {
                        string arrayKit = Session["arrayKit"].ToString() + "¬" + newUserName;
                        //'2018-10-19¬31¬31¬31¬userName'
                        string data3        = Session["financedAmount"].ToString();
                        string codeCurrency = Session["TypeCurrency"].ToString();

                        Int32 ansNmembershi = brUser.RegisterNmembership(TypeMembership + '|' + newUserName, data3, 1, codeCurrency);

                        if (ansNmembershi > 0)
                        {
                            //GeneracionDePuntos
                            bool isRegister = brUser.PutRegisterkIT(arrayKit, ansNmembershi);
                        }

                        //monto a pagar

                        /*subidaDeRecibo con newUserName*/
                        brUser = new BrUser();
                        BrPayments brPayments = new BrPayments();
                        bool       upload     = brPayments.UploadReceipt(ansNmembershi.ToString() + '|' + nombreArchivo);
                        if (!string.IsNullOrEmpty(newUserName))
                        {
                            bool UpdateD = brUser.UpdateInitialQuoteDescription(newUserName);
                        }
                        else
                        {
                            bool UpdateD = brUser.UpdateInitialQuoteDescription(userCurrent);
                        }

                        BrActivation brActivation = new BrActivation();
                        bool         registerActi = brActivation.PutCronograma(cronoActiv, newUserName, ansNmembershi);

                        string[] username_idmen_amount_email = brUser.getAmountPay(newUserName).Split('¬');
                        if (username_idmen_amount_email.Length < 4)
                        {
                            Response.Write("false¬Ha Ocurrido Un Error al Intentar Obtener el monto a Pagar");
                            return;
                        }
                        idMemberDetails = int.Parse(username_idmen_amount_email[1]);

                        double amountPay    = double.Parse(username_idmen_amount_email[2]);
                        string emailNewUser = username_idmen_amount_email[3];
                        username_idmen_amount_email = null;
                    }

                    if (typeRegister == 2)
                    {
                        string     dataKitMember = Session["cronograma"].ToString();
                        string     date          = dataKitMember.Split('$')[1];
                        BrPayments brPayments    = new BrPayments();
                        string     respData      = brPayments.PersonGetData(newUserName);
                        respData = respData + '^' + dataKitMember;
                        brUser   = new BrUser();
                        string data3        = Session["financedAmount"].ToString();
                        string codeCurrency = Session["TypeCurrency"].ToString();

                        Int32 ansNmembershi = brUser.RegisterNmembership(TypeMembership + '|' + newUserName, data3, 1, codeCurrency);
                        //GeneracionDePuntosConLaInicialDeLaMembresia
                        //string exchange2 = "";
                        var exchange = Session["exchange"];

                        bool isRegister = brPayments.GetCalculatePaymentSchedule(respData, newUserName, ansNmembershi, exchange.ToString(), 0);
                        brUser = new BrUser();
                        //TODO: la fecha de pago debe ser el dia de subida del voucher
                        bool upload = brPayments.UploadReceipt(ansNmembershi.ToString() + '|' + nombreArchivo);


                        BrActivation brActivation = new BrActivation();
                        bool         registerActi = brActivation.PutCronograma(cronoActiv, newUserName, ansNmembershi);



                        if (!isRegister)
                        {
                            Response.Write("false¬Ha Ocurrido Un Error al Intentar Registrar el Cronograma de Pagos del Usuario");
                            return;
                        }
                        //obtengo el monto a pagar

                        string[] username_idmen_amount_email = brUser.getAmountPay(newUserName).Split('¬');
                        if (username_idmen_amount_email.Length < 4)
                        {
                            Response.Write("false¬Ha Ocurrido Un Error al Intentar Obtener el monto a Pagar");
                            return;
                        }
                        idMemberDetails = int.Parse(username_idmen_amount_email[1]);


                        date = null;
                        username_idmen_amount_email = null;
                        dataKitMember = null;
                        respData      = null;
                    }
                }
            }
            else
            {
                //entra aqui pagar despues
                string   data2 = (string)Session["civilState"];
                string[] oIdMembreship_amount = brUser.RegisterUser(dataBdd, data2).Split('¬');

                if (oIdMembreship_amount.Length < 2)
                {
                    Response.Write("false¬Ha Ocurrido Un Error al Intentar Registrar al Usuario");
                    return;
                }

                string[] parameterPerson  = dataBdd.Split('$');
                string[] arraydata        = parameterPerson[0].Split('|');
                string[] arrayTypeaccount = parameterPerson[2].Split('|');
                string[] arrayaccount     = parameterPerson[3].Split('|');

                string parameterAccount = arraydata[5].Trim() + "|" + arrayTypeaccount[7].Trim() + '|' + userCurrent + '|' + oIdMembreship_amount[0];

                newUserName = brUser.GenerateAccount(parameterAccount);


                string dataKitMember = "";
                string date          = "";
                if (!string.IsNullOrEmpty((string)Session["cronograma"]))
                {
                    dataKitMember = Session["cronograma"].ToString();
                    date          = dataKitMember.Split('$')[1];
                }

                string[] array1     = Session["cronogramaYa"].ToString().Split('^');
                string[] datosMem   = array1[0].Split('|');
                string[] array2     = array1[1].Split('~');
                string[] cuotas     = array2[0].Split('¬');
                string   cronoActiv = "";
                for (int i = 0; i < cuotas.Length - 1; i++)
                {
                    var fila = cuotas[i].Split('|');
                    if (fila[0].Substring(0, 7) != "Inicial")
                    {
                        cronoActiv += fila[1];
                        break;
                    }
                    else
                    {
                        cronoActiv += fila[1] + "¬";
                    }
                }

                BrPayments brPayments = new BrPayments();
                string     respData   = brPayments.PersonGetData(dataLogin[0]);
                respData = respData + '^' + dataKitMember;
                brUser   = new BrUser();
                string financedAmountsa = Session["financedAmount"].ToString();
                string codeCurrency     = Session["TypeCurrency"].ToString();

                Int32 ansNmembershi = brUser.RegisterNmembership(TypeMembership + '|' + newUserName, financedAmountsa, 1, codeCurrency);
                //GeneracionDePuntosConLaInicialDeLaMembresia
                string        exchange      = "";
                BrInformacion brInformacion = new BrInformacion();
                string[]      info          = brInformacion.GetInformation().Split('¬');



                if (!string.IsNullOrEmpty(info[1]))
                {
                    exchange = info[1];
                }
                else
                {
                    exchange = "0.00";
                }
                string   currentUser = "";
                string[] arrayLink   = Session["link"].ToString().Split('|');
                if (arrayLink.Length > 1)
                {
                    currentUser = arrayLink[0];
                }
                else
                {
                    currentUser = dataLogin[0];
                }

                bool isRegister = brPayments.GetCalculatePaymentSchedule(respData, currentUser, ansNmembershi, exchange, 0);

                BrActivation brActivation = new BrActivation();
                bool         registerActi = brActivation.PutCronograma(cronoActiv, newUserName, ansNmembershi);

                /*subidaDeRecibo con newUserName*/
                if (!string.IsNullOrEmpty(nombreArchivo))
                {
                    brUser = new BrUser();
                    bool upload = brPayments.UploadReceipt(currentUser + '|' + nombreArchivo);
                    if (!string.IsNullOrEmpty(newUserName))
                    {
                        bool UpdateD = brUser.UpdateInitialQuoteDescription(newUserName);
                        //bool ans = brPayment.UploadReceiptCalendar(newUserName + '|' + nombreArchivo);
                    }
                    else
                    {
                        bool UpdateD = brUser.UpdateInitialQuoteDescription(userCurrent);
                        //bool ans = brPayment.UploadReceiptCalendar(newUserName + '|' + nombreArchivo);
                    }
                }

                if (!isRegister)
                {
                    Response.Write("false¬Ha Ocurrido Un Error al Intentar Registrar el Cronograma de Pagos del Usuario");
                    return;
                }
                return;
            }
            return;
            /*TRY MERGE*/
        }