// este método se ejecutará de manera asíncrona.
 public string LaunchResponsable(out int threadId)
 {
     threadId = Thread.CurrentThread.ManagedThreadId;
     // abrir conexiones 
     PortalProContext ctx = new PortalProContext();
     string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
     SqlConnection con = new SqlConnection(strConnect);
     con.Open();
     string sql = "SELECT COUNT(*) FROM [PortalProTest].[dbo].[Cau_PortalPro_VResponsable]";
     SqlCommand cmd = new SqlCommand(sql, con);
     int totreg = (int)cmd.ExecuteScalar();
     int numreg = 0;
     sql = @"SELECT  
                 [ID]
                 ,[NAME]
                 ,[EMAIL]
             FROM [PortalProTest].[dbo].[Cau_PortalPro_VResponsable]";
     cmd = new SqlCommand(sql, con);
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         numreg++;
         string codax = dr.GetString(0);
         // Buscamos si esa empresa existe
         Responsable res2 = (from e2 in ctx.Responsables
                         where e2.CodAx == codax
                         select e2).FirstOrDefault<Responsable>();
         if (res2 == null)
         {
             res2 = new Responsable();
             ctx.Add(res2);
         }
         res2.CodAx = codax;
         res2.Nombre = dr.GetString(1);
         res2.Email = dr.GetString(2);
         ctx.SaveChanges();
         // Actualizar los registros de proceso
         Progresos progreso = (from p in ctx.Progresos
                               where p.ProgresoId == 5
                               select p).FirstOrDefault<Progresos>();
         if (progreso != null)
         {
             progreso.NumReg = numreg;
             progreso.TotReg = totreg;
             ctx.SaveChanges();
         }
     }
     dr.Close();
     ctx.Dispose();
     con.Close();
     con.Dispose();
     return "";
 }
示例#2
0
 // este método se ejecutará de manera asíncrona.
 public string LaunchPedido(out int threadId)
 {
     threadId = Thread.CurrentThread.ManagedThreadId;
     // abrir conexiones 
     PortalProContext ctx = new PortalProContext();
     // Actualizar los registros de proceso
     Progresos progreso = (from p in ctx.Progresos
                           where p.ProgresoId == 3
                           select p).FirstOrDefault<Progresos>();
     if (progreso != null)
     {
         progreso.NumReg = 0;
         progreso.TotReg = 1;
         ctx.SaveChanges();
     }
     string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
     SqlConnection con = new SqlConnection(strConnect);
     con.Open();
     string sql = "SELECT COUNT(*) FROM [dbo].[Cau_PortalPro_VCabPedido]";
     SqlCommand cmd = new SqlCommand(sql, con);
     int totreg = (int)cmd.ExecuteScalar();
     int numreg = 0;
     sql = @"SELECT  
                 [PURCHID]
                 ,[INVOICEACCOUNT]
                 ,[DATAAREAID]
                 ,[ESTADO]
                 ,[TIPO]
                 ,[CODCONTACTO]
                 ,[CONTACTO]
                 ,[CREATEDDATE]
                 ,[FECHARECEPCION]
                 ,[FECHALIMITE]
             FROM [dbo].[Cau_PortalPro_VCabPedido]";
     cmd = new SqlCommand(sql, con);
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         numreg++;
         string numpedido = dr.GetString(0);
         // Buscamos si esa empresa existe
         Pedido ped2 = (from p2 in ctx.Pedidos
                         where p2.NumPedido == numpedido
                         select p2).FirstOrDefault<Pedido>();
         if (ped2 == null)
         {
             ped2 = new Pedido();
             ctx.Add(ped2);
         }
         ped2.NumPedido = numpedido;
         ped2.Proveedor = (from pr in ctx.Proveedors
                           where pr.CodAx == dr.GetString(1)
                           select pr).FirstOrDefault<Proveedor>();
         ped2.Empresa = (from e in ctx.Empresas
                             where e.CodAx == dr.GetString(2)
                             select e).FirstOrDefault<Empresa>();
         ped2.Actualizado = DateTime.Now;
         if (!dr.IsDBNull(3))
         {
             switch (dr.GetString(3))
             {
                 case "Facturado":
                     ped2.Estado = "FACTURADO";
                     break;
                 case "Pedido Abierto":
                     ped2.Estado = "ABIERTO";
                     break;
                 case "Recibido":
                     ped2.Estado = "RECIBIDO";
                     break;
                 case "Cancelado":
                     ped2.Estado = "CANCELADO";
                     break;
             }
         }
         if (!dr.IsDBNull(4))
         {
             switch (dr.GetString(4))
             {
                 case "Pedido de Compra":
                     ped2.TipoPedido = "COMPRA";
                     break;
                 case "Suscripción":
                     ped2.TipoPedido = "SUSCRIPCION";
                     break;
                 case "Solicitud de Compra":
                     ped2.TipoPedido = "SOLICITUD";
                     break;
             }
         }
         ped2.Responsable = (from r in ctx.Responsables
                             where r.CodAx == dr.GetString(5)
                             select r).FirstOrDefault<Responsable>();
         ped2.FechaAlta = dr.GetDateTime(7);
         if (!dr.IsDBNull(8)) ped2.FechaRecepcion = dr.GetDateTime(8);
         if (!dr.IsDBNull(9)) 
         { 
             ped2.FechaLimite = dr.GetDateTime(9);
             // hay que controlar le fecha nula AX (01/01/1900)
             if (String.Format("{0:dd/MM/yyyy}", ped2.FechaLimite) == "01/01/1900")
             {
                 ped2.FechaLimite = null;
             }
         }
         //try
         //{
             ctx.SaveChanges();
         //}
         //catch (Exception ex)
         //{
         //}
         // cargar las lineas
         LoadAssociateLines(numpedido);
         // Actualizar los registros de proceso
         progreso = (from p in ctx.Progresos
                               where p.ProgresoId == 3
                               select p).FirstOrDefault<Progresos>();
         if (progreso != null)
         {
             progreso.NumReg = numreg;
             progreso.TotReg = totreg;
             ctx.SaveChanges();
         }
     }
     dr.Close();
     ctx.Dispose();
     con.Close();
     con.Dispose();
     return "";
 }
示例#3
0
        private void LoadAssociateLines(string numPedido)
        {
            PortalProContext ctx = new PortalProContext();
            // buscamos la cabecera de pedido relacionada
            Pedido pedido = (from p in ctx.Pedidos
                             where p.NumPedido == numPedido
                             select p).FirstOrDefault<Pedido>();
            string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnect);
            con.Open();
            string sqlb = @"SELECT [PURCHID]
                              ,[LINENUM]
                              ,[ITEMID]
                              ,[NAME]
                              ,[PURCHQTY]
                              ,[PURCHUNIT]
                              ,[PURCHPRICE]
                              ,[LINEAMOUNT]
                              ,[ESTADO]
                              ,[REMAINPURCHPHYSICAL]
                              ,[REMAINPURCHFINANCIAL]
                              ,[FECHARECEPCION]
                              ,[INVENTTRANSID]
                          FROM [dbo].[Cau_PortalPro_VLinPedido]  WHERE [PURCHID] = '{0}';";
            string sql = String.Format(sqlb, numPedido);
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataReader dr = cmd.ExecuteReader();
            decimal totalPedido = 0;
            decimal totalFacturado = 0;
            while (dr.Read())
            {
                int numLinea = (int)(dr.GetDecimal(1));
                // --
                LinPedido lped = (from lp in ctx.LinPedidos
                                  where lp.NumPedido == numPedido
                                  && lp.NumLinea == numLinea
                                  select lp).FirstOrDefault<LinPedido>();
                if (lped == null)
                {
                    lped = new LinPedido();
                    ctx.Add(lped);
                }
                lped.Pedido = pedido;
                lped.NumPedido = numPedido;
                lped.NumLinea = numLinea;
                lped.InventTransId = dr.GetString(12);
                lped.Descripcion = dr.GetString(3);
                lped.Importe = dr.GetDecimal(7);
                totalPedido += lped.Importe;
                string estado = dr.GetString(8);
                switch (estado)
                {
                    case "Facturado":
                        lped.Estado = "FACTURADO";
                        lped.Facturado = lped.Importe;
                        totalFacturado += lped.Importe;
                        break;
                    case "Recibido":
                        lped.Estado = "RECIBIDO";
                        break;
                    case "Pedido Abierto":
                        lped.Estado = "ABIERTO";
                        break;

                }
                if (!dr.IsDBNull(11)) lped.FechaRecepcion = dr.GetDateTime(11);
            }
            pedido.TotalPedido = totalPedido;
            pedido.TotalFacturado = totalFacturado;
            try
            {
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
            }
            dr.Close();
            ctx.Dispose();
            con.Close();
            con.Dispose();
        }
示例#4
0
 // este método se ejecutará de manera asíncrona.
 public string LaunchFactura(out int threadId)
 {
     threadId = Thread.CurrentThread.ManagedThreadId;
     // abrir conexiones 
     PortalProContext ctx = new PortalProContext();
     string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
     SqlConnection con = new SqlConnection(strConnect);
     con.Open();
     string sql = "SELECT COUNT(*) FROM [PortalProTest].[dbo].[Cau_PortalPro_VCabFactura]";
     SqlCommand cmd = new SqlCommand(sql, con);
     int totreg = (int)cmd.ExecuteScalar();
     int numreg = 0;
     sql = @"SELECT  
                 [ACCOUNTNUM]
                 ,[IDEMPRESA]
                 ,[INVOICEID]
                 ,[INVOICEDATE]
                 ,[INVOICEAMOUNT]
                 ,[FECHAPAGO]
                 ,[ESTADI]
                 ,[FECHAVENCIMIENTO]
             FROM [PortalProTest].[dbo].[Cau_PortalPro_VCabFactura]";
     cmd = new SqlCommand(sql, con);
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         numreg++;
         string codAxProveedor = dr.GetString(0);
         string numFactura = dr.GetString(2);
         DateTime fechaFactura = dr.GetDateTime(3);
         Proveedor proveedor = (from pr in ctx.Proveedors
                                where pr.CodAx == codAxProveedor
                                select pr).FirstOrDefault<Proveedor>();
         // Buscamos si la fcatura ya existe
         CabFactura fac = (from f in ctx.CabFacturas
                           where f.NumFactura == numFactura &&
                                 f.FechaEmision == fechaFactura
                           select f).FirstOrDefault<CabFactura>();
         if (fac == null)
         {
             fac = new CabFactura();
             fac.FechaAlta = DateTime.Now;
             ctx.Add(fac);
         }
         fac.Proveedor = proveedor;
         fac.NumFactura = numFactura;
         fac.FechaEmision = fechaFactura;
         fac.Empresa = (from e in ctx.Empresas
                        where e.CodAx == dr.GetString(1)
                        select e).FirstOrDefault<Empresa>();
         string estado = dr.GetString(6);
         switch (estado)
         {
             case "Pagado":
                 fac.Estado = "PAGADA";
                 break;
             case "Recibido":
                 fac.Estado = "PROCESADA";
                 break;
         }
         fac.TotalFactura = dr.GetDecimal(4);
         if (!dr.IsDBNull(5))
             fac.FechaCobro = dr.GetDateTime(5);
         if (!dr.IsDBNull(7))
             fac.FechaPrevistaCobro = dr.GetDateTime(7);
         try
         {
             ctx.SaveChanges();
         }
         catch (Exception ex)
         {
         }
         // cargar las lineas
         try
         {
             LoadAssociateLines(numFactura, fechaFactura);
         }
         catch (Exception ex)
         {
         }
         // Actualizar los registros de proceso
         Progresos progreso = (from p in ctx.Progresos
                               where p.ProgresoId == 4
                               select p).FirstOrDefault<Progresos>();
         if (progreso != null)
         {
             progreso.NumReg = numreg;
             progreso.TotReg = totreg;
             ctx.SaveChanges();
         }
     }
     dr.Close();
     ctx.Dispose();
     con.Close();
     con.Dispose();
     return "";
 }
示例#5
0
 private void LoadAssociateLines(string numFactura, DateTime fechaFactura)
 {
     PortalProContext ctx = new PortalProContext();
     // buscamos la cabecera de pedido relacionada
     CabFactura factura = (from f in ctx.CabFacturas
                           where f.NumFactura == numFactura &&
                                 f.FechaEmision == fechaFactura
                           select f).FirstOrDefault<CabFactura>();
     string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
     SqlConnection con = new SqlConnection(strConnect);
     con.Open();
     string sqlb = @"SELECT [INVOICEID]
                       ,[INVOICEDATE]
                       ,[LINENUM]
                       ,[PURCHID]
                       ,[LINEAMOUNT]
                       ,[PORIVA]
                   FROM [PortalProTest].[dbo].[Cau_portalpro_VLinFactura] WHERE [INVOICEID] = '{0}' AND [INVOICEDATE] = '{1:yyyMMdd}';";
     string sql = String.Format(sqlb, numFactura, fechaFactura);
     SqlCommand cmd = new SqlCommand(sql, con);
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         int numLinea = (int)(dr.GetDecimal(2));
         // --
         LinFactura lf = (from l in ctx.LinFacturas
                          where l.NumFactura == numFactura &&
                                l.FechaEmision == fechaFactura &&
                                l.NumLineaFactura == numLinea
                          select l).FirstOrDefault<LinFactura>();
         if (lf == null)
         {
             lf = new LinFactura();
             ctx.Add(lf);
         }
         lf.CabFactura = factura;
         lf.NumFactura = numFactura;
         lf.FechaEmision = fechaFactura;
         lf.NumLineaFactura = numLinea;
         lf.Descripcion = "";
         lf.Importe = dr.GetDecimal(4);
         lf.PorcentajeIva = dr.GetDecimal(5);
         ctx.SaveChanges();
     }
     dr.Close();
     ctx.Dispose();
     con.Close();
     con.Dispose();
 }
示例#6
0
 // este método se ejecutará de manera asíncrona.
 public string LaunchProveedor(out int threadId)
 {
     threadId = Thread.CurrentThread.ManagedThreadId;
     // abrir conexiones 
     PortalProContext ctx = new PortalProContext();
     string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
     SqlConnection con = new SqlConnection(strConnect);
     con.Open();
     string sql = "SELECT COUNT(*) FROM [PortalProTest].[dbo].[Cau_PortalPro_VProveedores]";
     SqlCommand cmd = new SqlCommand(sql, con);
     int totreg = (int)cmd.ExecuteScalar();
     int numreg = 0;
     sql = @"SELECT  
                 [ACCOUNTNUM]
                 ,[NAME]
                 ,[ADDRESS]
                 ,[CITY]
                 ,[ZIPCODE]
                 ,[COUNTRYREGIONID]
                 ,[PHONE]
                 ,[TELEFAX]
                 ,[CELLULARPHONE]
                 ,[EMAIL]
                 ,[VATNUM]
                 ,[CONTACTO]
                 ,[LINEOFBUSINESSID]
                 ,[CAUPORTALPROEMAIL]
                 ,[BANKIBAN]
                 ,[CAUPORTALPROALLOWINVOICE]
             FROM [PortalProTest].[dbo].[Cau_PortalPro_VProveedores]";
     cmd = new SqlCommand(sql, con);
     SqlDataReader dr = cmd.ExecuteReader();
     while (dr.Read())
     {
         numreg++;
         string accountnum = dr.GetString(0);
         Proveedor pr2 = (from p2 in ctx.Proveedors
                          where p2.CodAx == accountnum
                          select p2).FirstOrDefault<Proveedor>();
         if (pr2 == null)
         {
             pr2 = new Proveedor();
             ctx.Add(pr2);
         }
         pr2.CodAx = accountnum;
         pr2.NombreComercial = dr.GetString(1);
         pr2.RazonSocial = dr.GetString(1);
         pr2.Direccion = dr.GetString(2);
         pr2.Localidad = dr.GetString(3);
         pr2.CodPostal = dr.GetString(4);
         pr2.Pais = dr.GetString(5);
         pr2.Telefono = dr.GetString(6);
         pr2.Fax = dr.GetString(7);
         pr2.Movil = dr.GetString(8);
         pr2.Email = dr.GetString(9);
         pr2.Nif = dr.GetString(10);
         if (!dr.IsDBNull(11)) pr2.PersonaContacto = dr.GetString(11);
         pr2.EmailFacturas = dr.GetString(13);
         if (!dr.IsDBNull(14)) pr2.IBAN = dr.GetString(14);
         ctx.SaveChanges();
         // Actualizar los registros de proceso
         Progresos progreso = (from p in ctx.Progresos
                               where p.ProgresoId == 2
                               select p).FirstOrDefault<Progresos>();
         if (progreso != null)
         {
             progreso.NumReg = numreg;
             progreso.TotReg = totreg;
             ctx.SaveChanges();
         }
     }
     dr.Close();
     ctx.Dispose();
     con.Close();
     con.Dispose();
     return "";
 }
        // este método se ejecutará de manera asíncrona.
        public string LaunchActividadPrincipal(out int threadId)
        {
            threadId = Thread.CurrentThread.ManagedThreadId;
            // abrir conexiones 
            PortalProContext ctx = new PortalProContext();
            // Actualizar los registros de proceso para dejar bloqueada la barra
            Progresos progreso = (from p in ctx.Progresos
                                  where p.ProgresoId == 6
                                  select p).FirstOrDefault<Progresos>();
            if (progreso != null)
            {
                progreso.NumReg = 0;
                progreso.TotReg = 1;
                ctx.SaveChanges();
            }

            string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnect);
            con.Open();
            string sql = "SELECT COUNT(*) FROM [dbo].[Cau_PortalProv_LineOfBusiness]";
            SqlCommand cmd = new SqlCommand(sql, con);
            int totreg = (int)cmd.ExecuteScalar();
            int numreg = 0;
            sql = @"SELECT  
                        [LINEOFBUSINESSID]
                        ,[DESCRIPTION]
                    FROM [dbo].[Cau_PortalProv_LineOfBusiness]";
            cmd = new SqlCommand(sql, con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                numreg++;
                string codax = dr.GetString(0);
                // Buscamos si esa ActividadPrincipal existe
                ActividadPrincipal emp2 = (from e2 in ctx.ActividadPrincipals
                                where e2.CodAx == codax
                                select e2).FirstOrDefault<ActividadPrincipal>();
                if (emp2 == null)
                {
                    emp2 = new ActividadPrincipal();
                    ctx.Add(emp2);
                }
                emp2.CodAx = codax;
                emp2.Nombre = dr.GetString(1);
                ctx.SaveChanges();
                // Actualizar los registros de proceso
                progreso = (from p in ctx.Progresos
                                      where p.ProgresoId == 6
                                      select p).FirstOrDefault<Progresos>();
                if (progreso != null)
                {
                    progreso.NumReg = numreg;
                    progreso.TotReg = totreg;
                    ctx.SaveChanges();
                }
            }
            dr.Close();
            ctx.Dispose();
            con.Close();
            con.Dispose();
            return "";
        }
示例#8
0
        // este método se ejecutará de manera asíncrona.
        public string LaunchComunidad(out int threadId)
        {
            threadId = Thread.CurrentThread.ManagedThreadId;
            // abrir conexiones 
            PortalProContext ctx = new PortalProContext();
            // Actualizar los registros de proceso para dejar bloqueada la barra
            Progresos progreso = (from p in ctx.Progresos
                                  where p.ProgresoId == 8
                                  select p).FirstOrDefault<Progresos>();
            if (progreso != null)
            {
                progreso.NumReg = 0;
                progreso.TotReg = 1;
                ctx.SaveChanges();
            }

            string strConnect = ConfigurationManager.ConnectionStrings["PortalProTestConnection"].ConnectionString;
            SqlConnection con = new SqlConnection(strConnect);
            con.Open();
            string sql = "SELECT COUNT(*) FROM [dbo].[Cau_PortalProv_AddressState]";
            SqlCommand cmd = new SqlCommand(sql, con);
            int totreg = (int)cmd.ExecuteScalar();
            int numreg = 0;
            sql = @"SELECT  
                        [STATEID]
                        ,[NAME]
                        ,[COUNTRYREGIONID]
                    FROM [dbo].[Cau_PortalProv_AddressState]";
            cmd = new SqlCommand(sql, con);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                numreg++;
                string codax = dr.GetString(0);
                // Buscamos si esa Pais existe
                Comunidad emp2 = (from e2 in ctx.Comunidads
                                where e2.CodAx == codax
                                select e2).FirstOrDefault<Comunidad>();
                if (emp2 == null)
                {
                    emp2 = new Comunidad();
                    ctx.Add(emp2);
                }
                emp2.CodAx = codax;
                emp2.Nombre = dr.GetString(1);
                // buscamos el pais al que pertenela comunidad
                codax = dr.GetString(2);
                Pais pais = (from p in ctx.Pais
                             where p.CodAx == codax
                             select p).FirstOrDefault<Pais>();
                emp2.Pais = pais;
                ctx.SaveChanges();
                // Actualizar los registros de proceso
                progreso = (from p in ctx.Progresos
                                      where p.ProgresoId == 8
                                      select p).FirstOrDefault<Progresos>();
                if (progreso != null)
                {
                    progreso.NumReg = numreg;
                    progreso.TotReg = totreg;
                    ctx.SaveChanges();
                }
            }
            dr.Close();
            ctx.Dispose();
            con.Close();
            con.Dispose();
            return "";
        }