示例#1
0
        public ActionResult ReinicioContrasena(ResetPassword formReset, string email)
        {
            if (ModelState.IsValid)
            {
                string rutUsuario = formReset.rut;
                object o;
                try
                {
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
                    o = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", rutUsuario);
                    string resp = o.ToString();

                    string[] usuario1 = resp.Split('|');
                    string   existe   = usuario1[0];
                    string   rutUser  = usuario1[1];
                    if (existe == "TRUE")
                    {
                        //si el usuario existe, rescatar los Ultimos 4 números del rut
                        string[] splitRutUser = rutUser.Split('-');
                        string   theRut       = splitRutUser[0];
                        int      numRut       = theRut.Length;
                        //con la pw nueva. guardo en AX el email y la contraseña nueva.
                        string pwNueva = theRut.Substring(numRut - 4, 4);

                        //ingresar datos al AX, CreateCustTable
                        object UpdateCustTable;
                        UpdateCustTable = DynAx.CallStaticClassMethod("WebPageConection", "UpdateCustPassword", rutUser, pwNueva);
                        if (UpdateCustTable.ToString() == "True")
                        {
                            ViewBag.OkReset = "Contraseña actualizada";
                            //enviar mail con link de recuperación
                            string url = Url.Action("Recuperar", "Usuarios",
                                                    new System.Web.Routing.RouteValueDictionary(new { id = formReset.rut }),
                                                    "http", Request.Url.Host);
                            SendEMail(email, url);
                        }
                        else
                        {
                            ViewBag.errorUpdatePw = "No se pudo recuperar la contraseña";
                        }
                    }
                    else
                    {
                        ViewBag.message2 = "No existes como usuario";
                    }
                    DynAx.Logoff();
                }
                catch (Exception ex)
                {
                    ViewBag.error = ("ERROR: " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", "Formulario no válido");
            }
            return(View());
        }
示例#2
0
        public string conexionaxapta()
        {
            try
            {
                //     System.Net.NetworkCredential nc = new System.Net.NetworkCredential(userproxy, passwordproxy, dominio);
                //   System.Net.NetworkCredential nc = new System.Net.NetworkCredential("wsconectorax", "wsc0n3ct@x*", "genesiscr.local");
                System.Net.NetworkCredential nc = new System.Net.NetworkCredential("wsconectorax", "wsc0n3ct@x*", "genesiscr.local");

                axp = new Bcn.Axapta();
                //  axp.LogonAs(nc.UserName, "genesiscr.local", nc,  "jsm", "", "JSM@genesiscrax:2711",  ConfigurationManager.AppSettings["AxCfgFile"]);
                axp.LogonAs(nc.UserName, "genesiscr.local", nc, "JSM", "", "JSM@genesiscrax:2712", "C:\\inetpub\\Desarrollo.axc");


                conectadoax = true;
            }
            catch (Exception ex)
            {
                conectadoax = false;
                return(ex.Message);
            }


            //     conectadoax = true ;
            return("se conecto exitosamente a axapta ");
        }
示例#3
0
        public ActionResult Recuperar(string id)
        {
            //id es el rut del usuario

            object getUser;

            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
            getUser = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", id);

            string resp = getUser.ToString();

            string[] usuario1 = resp.Split('|');
            string   existe   = usuario1[0];


            if (existe == "TRUE")
            {
                ViewBag.rutUsuario = id;
            }
            else
            {
                ViewBag.noexistes = "No existes como cliente";
            }
            DynAx.Logoff();
            return(View());
        }
示例#4
0
        public ActionResult Recuperar(Resetpw formPw, string id, string OldPw)
        {
            if (ModelState.IsValid)
            {
                object o;
                object getUser;

                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");


                getUser = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", id);
                string   resp     = getUser.ToString();
                string[] usuario1 = resp.Split('|');
                string   pw       = usuario1[2];

                if (OldPw == pw)
                {
                    if (OldPw != formPw.ConfirmPassword)
                    {
                        o = DynAx.CallStaticClassMethod("WebPageConection", "UpdateCustPassword", id, formPw.ConfirmPassword);
                        if (o.ToString() == "True")
                        {
                            //var updatepw = from cli in db.Clientes
                            //               where id = cli.RutCliente
                            //               select cli;
                            ViewBag.cambio = "CONTRASEÑA CAMBIADA CON EXITO";
                        }
                    }
                    else
                    {
                        ViewBag.badOldpw = "La contraseña nueva no puede ser igual ";
                    }
                }
                else
                {
                    ViewBag.badOldpw = "No coincide la contraseña antigua";
                }
                DynAx.Logoff();
            }
            else
            {
                ModelState.AddModelError("", "Formulario no válido");
            }


            return(View());
        }
示例#5
0
        public ActionResult LogIn(UserModel users, string ReturnUrl)
        {
            var usmodel = new UserModel();

            //validar si el usuario ya tiene una sesion activa con un npedido asociado
            if (ModelState.IsValid)
            {
                //var user = db.Clientes.FirstOrDefault(u => u.RutCliente == users.rut);
                //var pass = db.Clientes.FirstOrDefault(u => u.Password == users.password);
                //var comp = db.CabeceraCarro.Any(c => c.RutCliente == users.rut);
                //var existe_usuario = (from c in db.Clientes
                //                         where c.RutCliente + "-" + c.DigCliente == users.rut
                //                     select c);
                object getUsuario;

                try
                {
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
                    try
                    {
                        string usuario = users.rut;
                        getUsuario = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", usuario);
                        string resp = getUsuario.ToString();

                        string[] usuario1   = resp.Split('|');
                        string   existeEnAX = usuario1[0];


                        if (existeEnAX == "TRUE")
                        {
                            string rutUsuario = usuario1[1];
                            string pw         = usuario1[2];

                            string[] splitRutUser = rutUsuario.Split('-');
                            string   theRut       = splitRutUser[0];
                            int      numRut       = theRut.Length;
                            //con la pw nueva. guardo en AX el email y la contraseña nueva.
                            string pwNueva = theRut.Substring(numRut - 4, 4);

                            string NombreCliente = usuario1[3];

                            string EmailCliente = usuario1[4];
                            if (users.password == pwNueva)
                            {
                                return(RedirectToAction("Recuperar", "Usuarios", new { id = rutUsuario }));
                            }
                            else
                            {
                                if (pw == users.password)
                                {
                                    //si loguea
                                    Session["nombreuser"] = NombreCliente;
                                    Session["rutuser"]    = rutUsuario;
                                    Session["emailuser"]  = EmailCliente;
                                    TempData["logueado"]  = "Sent";
                                }
                                else
                                {
                                    //no loguea
                                    ViewBag.badpw = "Contraseña Incorrecta";
                                    //Response.Write("Contraseña Incorrecta");
                                    usmodel.rut      = rutUsuario;
                                    usmodel.password = pw;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ViewBag.error = (ex.Message);
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.error = ("NO HUBO CONEXION CON EL SISTEMA, ERROR: " + ex.Message);
                }
            }

            return(View(users));
        }
示例#6
0
        public ActionResult Registration(DatosPersonalesModel user)
        {
            ViewBag.Comunas = db.AddressCounty.Where(c => c.StateId == "Región Met").OrderBy(c => c.Name).ToList();
            if (ModelState.IsValid)
            {
                string   rut   = user.rut;
                string[] rutus = Convert.ToString(rut).Split('-');
                string   rut1  = rutus[0];
                string   dig1  = rutus[1];

                //var existeuser = (from u in db.Clientes
                //                  where u.RutCliente + "" + u.DigCliente == rut1 + "" + dig1
                //                  select u).FirstOrDefault();

                //if (existeuser == null)
                //{
                //    var crearuser = db.Clientes.Create();
                //    crearuser.RutCliente = rut1;
                //    crearuser.DigCliente = dig1;
                //    crearuser.Nombre = user.Nombre;
                //    crearuser.Apellido = user.Apellido;
                //    crearuser.Email = user.Email;
                //    crearuser.Direccion = user.Direccion;
                //    crearuser.Comuna = user.Comuna;
                //    crearuser.TelFijo = user.TelFijo;
                //    crearuser.TelMovil = user.TelMovil;
                //    crearuser.Password = user.Password;
                //    crearuser.ConfirmPassword = user.ConfirmPassword;
                //    db.Clientes.Add(crearuser);

                //    try
                //    {
                //        db.SaveChanges();
                //    }
                //    catch (Exception p)
                //    {
                //        ViewBag.error = p.Message;
                //    }

                //}
                //else
                //{
                //    Response.Write("ya existes como usuario");
                //}

                object RegistraUsuario;
                object o1;
                try
                {
                    Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                    System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                    DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                    try
                    {
                        string rutcom = rut1 + "-" + dig1;

                        o1 = DynAx.CallStaticClassMethod("WebPageConection", "FindCustTable", rutcom);
                        string   resp     = o1.ToString();
                        string[] usuario1 = resp.Split('|');
                        string   existe   = usuario1[0];

                        if (existe == "FALSE")
                        {
                            RegistraUsuario = DynAx.CallStaticClassMethod("WebPageConection", "CreateCust", rut1 + "-" + dig1, dig1, user.Nombre + " " + user.Apellido, user.Email, user.TelFijo, user.TelMovil, user.Comuna, user.Direccion, user.Password);
                            //Response.Write(o.ToString());
                            ViewBag.Message = "Registrado";
                            return(View("RegistrationExitosa"));
                        }
                        else
                        {
                            ViewBag.error = "Estas registrado en el sistema";
                        }
                    }
                    catch (Exception e)
                    {
                        ViewBag.error = "[15]" + e.Message;
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.error = ("ERROR: " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", "Formulario no válido");
            }
            return(View());
        }
示例#7
0
        public ActionResult MetodoDePago(string radiobt, string rut, string NombreDespacho, int ncarro, string Retira, string Local, string Responsable, string Comunas, string Calle, string Obs, string Despacho1, string Email, string EmailRetira, string tipoDocumento)
        {
            var totalCompra = (from d in db.DetalleCarro
                               where d.NPedido == ncarro && d.CabeceraCarro.EstadoOc == false
                               select d.Subtotal).Sum();


            var CarroCliente = from c in db.DetalleCarro
                               where c.NPedido == ncarro && c.CabeceraCarro.EstadoOc == false
                               select c;

            ViewBag.RutUsuariocomprador = rut;

            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

            object o;

            if (radiobt == "despacho")
            {
                TempData["rutDespacho"] = rut;

                //el proceso de despacho
                object o1;
                string itemcode = string.Empty;
                string canti    = string.Empty;

                try
                {
                    foreach (var p in CarroCliente)
                    {
                        itemcode += p.ItemBarCode + "|";
                        canti    += p.Cantidad + "|";
                    }
                    o1 = DynAx.CallStaticClassMethod("WebPageConection", "CalcFreight", itemcode, canti);

                    string valorflete = o1.ToString();

                    var Despacho = from c in db.CabeceraCarro
                                   where c.NPedido == ncarro && c.EstadoOc == false
                                   select c;

                    int montodesp = Convert.ToInt32(valorflete) + totalCompra;
                    foreach (var i in Despacho)
                    {
                        i.RutCliente          = rut;
                        i.NombreCliente       = NombreDespacho;
                        i.ComunaDespacho      = Comunas;
                        i.CalleDespacho       = Calle;
                        i.ObservacionDespacho = Obs;
                        i.CostoDespacho       = valorflete;
                        i.ModoEntrega         = Despacho1;
                        i.Local         = "03";
                        i.EmailCliente  = Email;
                        i.MontoPagado   = montodesp.ToString();
                        i.tipoDocumento = tipoDocumento;
                    }

                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception p)
                    {
                        ViewBag.error = "[01] " + p.Message;
                    }


                    foreach (var c in CarroCliente)
                    {
                        o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                        "03", c.Cantidad);
                        //Response.Write(c.ItemBarCode + "<br/>");
                        if (o.ToString() == "1")
                        {
                            //Response.Write(totalCompra);
                            int dp = Convert.ToInt32(valorflete);
                            ViewBag.despacho = dp;
                            return(View("MetodoDePago", db.DetalleCarro));
                        }
                        else
                        {
                            TempData["error"] = "Producto no disponible para despacho";
                            return(RedirectToAction("Despacho", new { id = c.NPedido }));
                        }
                    }

                    DynAx.Logoff();
                }
                catch (Exception ex)
                {
                    ViewBag.error = "[3]" + ex.Message;
                }
            }
            else
            {
                //proceso retira en tienda

                var Despacho = from c in db.CabeceraCarro
                               where c.NPedido == ncarro && c.EstadoOc == false
                               select c;

                foreach (var i in Despacho)
                {
                    i.RutCliente          = rut;
                    i.ResponsableDespacho = Responsable;
                    i.RutResponsable      = rut;
                    i.ModoEntrega         = Retira;
                    i.Local         = Local;
                    i.EmailCliente  = EmailRetira;
                    i.MontoPagado   = totalCompra.ToString();
                    i.tipoDocumento = tipoDocumento;
                }
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ep)
                {
                    ViewBag.error = ep.Message;
                }

                foreach (var c in CarroCliente)
                {
                    o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                    Local, c.Cantidad);
                    //Response.Write(c.ItemBarCode + "<br/>");
                    if (o.ToString() == "1")
                    {
                        ViewBag.Comunas = db.AddressCounty.Where(c1 => c1.DlvRoute != "").OrderBy(c1 => c1.Name).ToList();
                        //Response.Write(totalCompra);
                        ViewBag.Tienda = Local;
                        return(View("MetodoDePago", db.DetalleCarro));
                    }
                    else
                    {
                        TempData["error"] = "Producto no disponible en la tienda";
                        return(RedirectToAction("Despacho", new { id = c.NPedido }));
                    }
                }
                DynAx.Logoff();
            }

            return(View(db.DetalleCarro));
        }
示例#8
0
        public ActionResult TipoPago(string Comunas, string Calle, string Obs, int ncarro, string Despacho1, string tipoDocumento)
        {
            ViewBag.Comunas = db.AddressCounty.Where(c => c.DlvRoute != "").OrderBy(c => c.Name).ToList();
            if (ModelState.IsValid)
            {
                if (Session["cart"] != null)
                {
                    object o;
                    object o1;
                    string itemcode = string.Empty;
                    string canti    = string.Empty;


                    var CarroCliente = from c in db.DetalleCarro
                                       where c.NPedido == ncarro && c.CabeceraCarro.EstadoOc == false
                                       select c;

                    var totalCompra = (from d in db.DetalleCarro
                                       where d.NPedido == ncarro && d.CabeceraCarro.EstadoOc == false
                                       select d.Subtotal).Sum();

                    try
                    {
                        Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                        System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                        DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                        try
                        {
                            //ingresar el pedido.
                            foreach (var p in CarroCliente)
                            {
                                itemcode += p.ItemBarCode + "|";
                                canti    += p.Cantidad + "|";
                            }
                            o1 = DynAx.CallStaticClassMethod("WebPageConection", "CalcFreight", itemcode, canti);

                            string valorflete = o1.ToString();

                            var Despacho = from c in db.CabeceraCarro
                                           where c.NPedido == ncarro && c.EstadoOc == false
                                           select c;

                            int montodesp = Convert.ToInt32(valorflete) + totalCompra;
                            foreach (var i in Despacho)
                            {
                                i.RutCliente          = Session["rutuser"].ToString();
                                i.NombreCliente       = Session["nombreuser"].ToString();
                                i.ComunaDespacho      = Comunas;
                                i.CalleDespacho       = Calle;
                                i.ObservacionDespacho = Obs;
                                i.CostoDespacho       = valorflete;
                                i.ModoEntrega         = Despacho1;
                                i.Local         = "03";
                                i.MontoPagado   = montodesp.ToString();
                                i.tipoDocumento = tipoDocumento;
                            }

                            try
                            {
                                db.SaveChanges();
                            }
                            catch (Exception p)
                            {
                                ViewBag.error = "[01] " + p.Message;
                            }


                            foreach (var c in CarroCliente)
                            {
                                o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                                "03", c.Cantidad);
                                //Response.Write(c.ItemBarCode + "<br/>");
                                if (o.ToString() == "1")
                                {
                                    //Response.Write(totalCompra);
                                    int dp = Convert.ToInt32(valorflete);
                                    ViewBag.despacho = dp;
                                    return(View(db.DetalleCarro));
                                }
                                else
                                {
                                    TempData["error"] = "Producto no disponible en la tienda";
                                    return(RedirectToAction("Despacho", new { id = c.NPedido }));
                                }
                            }
                            DynAx.Logoff();
                        }
                        catch (Exception ex)
                        {
                            ViewBag.error = "[2] " + ex.Message;
                        }

                        DynAx.Logoff();
                    }
                    catch (Exception ex)
                    {
                        ViewBag.error = "[3]" + ex.Message;
                    }
                }
            }
            else
            {
                ViewBag.error = "Error en formulario";
            }

            return(View(db.DetalleCarro));
        }
示例#9
0
        public ActionResult TipopagoRet(string Responsable, string rut, int ncarro, string radiobt, string Local, string tipoDocumento)
        {
            ViewBag.Comunas = db.AddressCounty.Where(c => c.DlvRoute != "").OrderBy(c => c.Name).ToList();

            ViewBag.despacho = "Retira en tienda";
            if (Session["cart"] != null)
            {
                object o;
                var    totalCompra = (from d in db.DetalleCarro
                                      where d.NPedido == ncarro && d.CabeceraCarro.EstadoOc == false
                                      select d.Subtotal).Sum();


                var Despacho = (from c in db.CabeceraCarro
                                where c.NPedido == ncarro && c.EstadoOc == false
                                select c).FirstOrDefault();

                var CarroCliente = from c in db.DetalleCarro
                                   where c.NPedido == ncarro && c.CabeceraCarro.EstadoOc == false
                                   select c;

                Despacho.RutCliente          = Session["rutuser"].ToString();
                Despacho.NombreCliente       = Session["nombreuser"].ToString();
                Despacho.ResponsableDespacho = Responsable;
                Despacho.RutResponsable      = rut;
                Despacho.ModoEntrega         = radiobt;
                Despacho.Local         = Local;
                Despacho.MontoPagado   = totalCompra.ToString();
                Despacho.tipoDocumento = tipoDocumento;
                try
                {
                    db.SaveChanges();
                }
                catch (Exception ep)
                {
                    ViewBag.error = ep.Message;
                }
                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

                foreach (var c in CarroCliente)
                {
                    o = DynAx.CallStaticClassMethod("WebPageConection", "CheckStock", c.ItemBarCode,
                                                    Local, c.Cantidad);
                    //Response.Write(c.ItemBarCode + "<br/>");
                    if (o.ToString() == "1")
                    {
                        ViewBag.Comunas = db.AddressCounty.Where(c1 => c1.DlvRoute != "").OrderBy(c1 => c1.Name).ToList();
                        //Response.Write(totalCompra);
                        return(View(db.DetalleCarro));
                    }
                    else
                    {
                        TempData["error"] = "Producto no disponible en la tienda";
                        return(RedirectToAction("Despacho", new { id = c.NPedido }));
                    }
                }

                DynAx.Logoff();
            }

            return(View(db.DetalleCarro));
        }
示例#10
0
        public ActionResult ConfirmaTransferencia(int id)
        {
            //ingresar transferencia AX y enviar correos. validar si es retira
            var CbPagadas = from c in db.CabeceraCarro
                            where c.NPedido == id && c.EstadoOc == true
                            select c;//tomar el email de aca y el rut

            var getdata = CbPagadas.FirstOrDefault();

            ViewBag.npedido = id;

            Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
            System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
            DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");

            object IngresaCabecera;
            object IngresaPago;
            object MontoDespacho;
            object IngresaDetalleCarro;

            if (PagaOrden(id) == true)
            {
                //ingresar cabecera en AX
                foreach (var it in CbPagadas)
                {
                    if (it.ModoEntrega == "D")
                    {
                        try
                        {
                            IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                          "AWeb_" + getdata.NPedido,
                                                                          "1-9",
                                                                          getdata.ComunaDespacho,
                                                                          getdata.CalleDespacho,
                                                                          getdata.ObservacionDespacho,
                                                                          "D",
                                                                          "03");
                        }
                        catch (Exception ep)
                        {
                            ViewBag.error = "[15] " + ep.Message;
                        }


                        try
                        {
                            IngresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                      "AWeb_" + getdata.NPedido,
                                                                      "1-9",
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      "",
                                                                      getdata.MontoPagado);
                        }
                        catch (Exception jp)
                        {
                            ViewBag.error = "[16] " + jp.Message;
                        }

                        try
                        {
                            MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                        "AWeb_" + getdata.NPedido,
                                                                        getdata.CostoDespacho);
                        }
                        catch (Exception lp)
                        {
                            ViewBag.error = "[17]" + lp.Message;
                        }

                        try
                        {
                            var CarrosPagados = from prd in db.DetalleCarro
                                                where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
                                                select prd;

                            foreach (var d in CarrosPagados)
                            {
                                IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                                  "AWeb_" + d.NPedido,
                                                                                  d.ItemBarCode,
                                                                                  d.Cantidad,
                                                                                  d.Precio);
                            }
                        }
                        catch (Exception op)
                        {
                            ViewBag.error = "[18]" + op.Message;
                        }

                        ViewBag.ExitoT = "exito";
                    }
                    else
                    {
                        try
                        {
                            if (Session["rutuser"] != null)
                            {
                                //si se registra enviar el rut
                                IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                              "AWeb_" + getdata.NPedido,
                                                                              Session["rutuser"].ToString(),
                                                                              getdata.ComunaDespacho,
                                                                              getdata.CalleDespacho,
                                                                              getdata.ObservacionDespacho,
                                                                              "R",
                                                                              getdata.Local);
                            }
                            else
                            {
                                //si no es registro. el pedido se registra con rut-9
                                IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                              "AWeb_" + getdata.NPedido,
                                                                              "1-9",
                                                                              getdata.ComunaDespacho,
                                                                              getdata.CalleDespacho,
                                                                              getdata.ObservacionDespacho,
                                                                              "R",
                                                                              getdata.Local);
                            }
                        }
                        catch (Exception ep)
                        {
                            ViewBag.error = "[15] " + ep.Message;
                        }

                        try
                        {
                            if (Session["rutuser"] != null)
                            {
                                IngresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                          "AWeb_" + getdata.NPedido,
                                                                          Session["rutuser"].ToString(),
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          getdata.MontoPagado);
                            }
                            else
                            {
                                IngresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                          "AWeb_" + getdata.NPedido,
                                                                          "1-9",
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          "",
                                                                          getdata.MontoPagado);
                            }
                        }
                        catch (Exception jp)
                        {
                            ViewBag.error = "[16] " + jp.Message;
                        }

                        //try
                        //{
                        //    MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight", "Web_" + getdata.NPedido, getdata.CostoDespacho);
                        //}
                        //catch (Exception lp)
                        //{
                        //    ViewBag.error = "[17]" + lp.Message;
                        //}

                        try
                        {
                            var CarrosPagados = from prd in db.DetalleCarro
                                                where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
                                                select prd;

                            foreach (var d in CarrosPagados)
                            {
                                IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                                  "AWeb_" + d.NPedido,
                                                                                  d.ItemBarCode,
                                                                                  d.Cantidad,
                                                                                  d.Precio);
                            }
                        }
                        catch (Exception op)
                        {
                            ViewBag.error = "[18]" + op.Message;
                        }

                        ViewBag.ExitoT = "exito";
                    }
                }
            }
            DynAx.Logoff();//cierro session ax

            return(View());
        }
示例#11
0
        public ActionResult TransferenciaSinRegistro(int id)
        {
            //ingresar transferencia AX y enviar correos. validar si es retira
            var CbPagadas = from c in db.CabeceraCarro
                            where c.NPedido == id && c.EstadoOc == true
                            select c;//tomar el email de aca y el rut

            var getdata = CbPagadas.FirstOrDefault();

            DateTime hoydia      = DateTime.Today;
            string   fecha       = hoydia.ToString("MMdd");
            string   fecha_exito = hoydia.ToString("dd/MM/yyyy");

            if (PagaOrden(id) == true)
            {
                ViewBag.npedido = id;
                object IngresaCabecera;
                object IngresaDetalleCarro;
                object ingresaPago;
                object MontoDespacho;
                var    CarrosPagados = from prd in db.DetalleCarro
                                       where prd.NPedido == id && prd.CabeceraCarro.EstadoOc == true
                                       select prd;

                int montototal = 0;


                string textBody = string.Empty;
                Microsoft.Dynamics.BusinessConnectorNet.Axapta DynAx = new Microsoft.Dynamics.BusinessConnectorNet.Axapta();
                System.Net.NetworkCredential jj = new System.Net.NetworkCredential("irojas", "italo123");
                DynAx.LogonAs("irojas", "yolito.cl", jj, "yod", "", "", "");
                try
                {
                    //ingresar el pedido.
                    IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                  "AWeb_" + getdata.NPedido,
                                                                  "1-9", getdata.ComunaDespacho,
                                                                  getdata.CalleDespacho,
                                                                  getdata.ObservacionDespacho,
                                                                  "D",
                                                                  "03");

                    ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                              "AWeb_" + getdata.NPedido,
                                                              "1-9",
                                                              "",
                                                              "",
                                                              "",
                                                              "", getdata.MontoPagado);

                    MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                "AWeb_" + getdata.NPedido,
                                                                getdata.CostoDespacho);

                    if (getdata.ModoEntrega == "D")
                    {
                        int valordesp   = Convert.ToInt32(getdata.CostoDespacho);
                        int valorpagado = Convert.ToInt32(getdata.MontoPagado);

                        montototal = valordesp + valorpagado;

                        IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                      "AWeb_" + getdata.NPedido,
                                                                      "1-9",
                                                                      getdata.ComunaDespacho,
                                                                      getdata.CalleDespacho,
                                                                      getdata.ObservacionDespacho,
                                                                      "D",
                                                                      "03");

                        ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                  "AWeb_" + getdata.NPedido,
                                                                  "1-9",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  getdata.MontoPagado);

                        MontoDespacho = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLineFreight",
                                                                    "AWeb_" + getdata.NPedido,
                                                                    getdata.CostoDespacho);

                        textBody = "Hola estimado, <strong>" + getdata.NombreCliente + "</strong><br />" +
                                   "<br /> El detalle de tu compra es: <br /><table ><tr><td>Pedido:</td> <td>" + "Web_" + id + "</td></tr><tr><td>Fecha de pago:</td><td>" + fecha_exito + "</td></tr><tr><td>Tipo Pago:</td> <td>Transferencia</td></tr><tr><td>Modo entrega: </td><td>" + "Despacho" + "</td></tr><tr><td>Monto total:</td><td>" + montototal.ToString("#,##") + "</td></tr></table> <br /> Detalle de los productos comprados: <br/>";
                    }

                    else
                    {
                        IngresaCabecera = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesTable",
                                                                      "AWeb_" + getdata.NPedido,
                                                                      "1-9",
                                                                      "Retira",
                                                                      "Retira",
                                                                      "Retira en local",
                                                                      "R",
                                                                      getdata.Local);

                        ingresaPago = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesWebpay",
                                                                  "AWeb_" + getdata.NPedido,
                                                                  "1-9",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  "",
                                                                  getdata.MontoPagado);

                        textBody = "Hola estimado, <strong>" + getdata.NombreCliente + "</strong><br />" +
                                   "<br /> El detalle de tu compra es: <br /><table ><tr><td>Pedido pagado:</td> <td>" + "Web_" + id + "</td></tr><tr><td>Fecha de pago:</td><td>" + fecha_exito + "</td></tr><tr><td>Tipo Pago:</td> <td>Transferencia</td></tr><tr><td>Modo Entrega:</td><td>" + getdata.ModoEntrega + "</td></tr><tr><td>Local :</td><td>" + getdata.Local + "</td></tr><tr><td>Monto total:</td><td>" + getdata.MontoPagado + "</td></tr></table> <br /> Detalle de los productos comprados: <br/>";
                    }
                    foreach (var d in CarrosPagados)
                    {
                        IngresaDetalleCarro = DynAx.CallStaticClassMethod("WebPageConection", "CreateSalesLine",
                                                                          "AWeb_" + d.NPedido,
                                                                          d.ItemBarCode,
                                                                          d.Cantidad,
                                                                          d.Precio);
                    }

                    DynAx.Logoff();
                }
                catch (Exception ex)
                {
                    ViewBag.error = "[6]" + ex.Message;
                    DynAx.Logoff();
                }
                var ProductosComprados = from pr in db.DetalleCarro
                                         where pr.NPedido == id && pr.CabeceraCarro.EstadoOc == true
                                         select pr;

                SmtpClient smtp = new SmtpClient();
                smtp.Host                  = "smtp.gmail.com";
                smtp.Port                  = 587;
                smtp.EnableSsl             = true;
                smtp.DeliveryMethod        = SmtpDeliveryMethod.Network;
                smtp.UseDefaultCredentials = false;
                smtp.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "ventasweb.2017");

                var send_mail = new MailMessage();
                send_mail.IsBodyHtml = true;
                send_mail.From       = new MailAddress("*****@*****.**", "Yolito Centro ferretero");
                send_mail.To.Add(new MailAddress("*****@*****.**"));

                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Bcc.Add(new MailAddress("*****@*****.**"));
                send_mail.Subject = "Confirmación de transferencia del Pedido Número: " + "AWeb_" + id + ", Fecha: " + fecha_exito;
                foreach (var pc in ProductosComprados)
                {
                    textBody = textBody + ("<br/>Nombre del producto : <strong>" + pc.ItemName + " </strong><br />" + "Código del producto: <strong>" + pc.ItemBarCode + " </strong><br />" + "Precio: <strong>" + pc.Precio + "</strong> <br/>" + "Cantidad: <strong>" + pc.Cantidad + "</strong><hr />");
                }
                send_mail.Body = textBody;
                try
                {
                    smtp.Send(send_mail);
                }
                catch (Exception p)
                {
                    ViewBag.error = "[8]" + p.Message;
                }
            }
            else
            {
                ViewBag.error = "No se actualizo el estado del pedido";
            }

            return(View());
        }