private void Cliente_Buscar(string idAgenda)
        {
            AgendaWCFClient objAgendaWCFClient;
            VBG01134Result  objAgendaCliente;
            decimal?        lineaCredito    = null;
            DateTime?       fechaVecimiento = null;
            decimal?        TC = null;

            try
            {
                objAgendaWCFClient = new AgendaWCFClient();
                objAgendaCliente   = new VBG01134Result();

                objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(((Usuario_LoginResult)Session["Usuario"]).idEmpresa,
                                                                           ((Usuario_LoginResult)Session["Usuario"]).codigoUsuario, idAgenda, ref lineaCredito, ref fechaVecimiento, ref TC);

                //if (!string.IsNullOrEmpty(objAgendaCliente.RUC))
                //{
                //    txtRUCCliente.Text = objAgendaCliente.RUC;
                //    txtNombreCliente.Text = objAgendaCliente.Nombre;
                //    lblCodigoCliente.Value = objAgendaCliente.RUC;
                //}
                //else
                //{
                //    txtRUCCliente.Text = idAgenda;
                //}
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        private void Cliente_Buscar(string idAgenda)
        {
            AgendaWCFClient objAgendaWCFClient;
            VBG01134Result  objAgendaCliente;
            decimal?        lineaCredito    = null;
            decimal?        TC              = null;
            DateTime?       fechaVecimiento = null;

            try
            {
                objAgendaWCFClient = new AgendaWCFClient();
                objAgendaCliente   = new VBG01134Result();

                objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(((Usuario_LoginResult)Session["Usuario"]).idEmpresa,
                                                                           ((Usuario_LoginResult)Session["Usuario"]).codigoUsuario, idAgenda, ref lineaCredito, ref fechaVecimiento, ref TC);

                String txtClienteObj = objAgendaCliente.Nombre;

                ViewState["LineaCredito"]     = lineaCredito;
                ViewState["FechaVencimiento"] = fechaVecimiento;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void Item_Cargar(decimal idPrecioCliente)
        {
            ItemWCFClient  objItemWCF     = new ItemWCFClient();
            VBG01124Result objProducto    = new VBG01124Result();
            VBG01134Result objCliente     = new VBG01134Result();
            string         ID_Item        = null;
            decimal?       precioEspecial = null;
            DateTime?      vigInicio      = null;
            DateTime?      vigFinal       = null;

            try
            {
                btnBuscarProducto.Visible = false;
                objItemWCF.Item_BuscarPrecioCliente(((Usuario_LoginResult)Session["Usuario"]).idEmpresa,
                                                    ((Usuario_LoginResult)Session["Usuario"]).codigoUsuario, idPrecioCliente, ref precioEspecial, ref vigInicio,
                                                    ref vigFinal, ref objCliente, ref objProducto, ref ID_Item);
                AutoCompleteBoxEntry entry = new AutoCompleteBoxEntry();
                entry.Text = objCliente.ID_Agenda + "-" + objCliente.Nombre;
                acbCliente.Entries.Add(entry);
                acbCliente.Enabled = false;
                entry      = new AutoCompleteBoxEntry();
                entry.Text = ID_Item + "-" + objProducto.Nombre;
                acbProducto.Entries.Add(entry);
                acbProducto.Enabled        = false;
                txtKardex.Text             = objProducto.Item_ID.ToString();
                cboMoneda.SelectedValue    = objProducto.ID_Moneda.ToString();
                txtPrecio.Text             = objProducto.Precio.ToString();
                txtUnidad.Text             = objProducto.UnidadInv;
                txtPrecEspecial.Value      = Convert.ToDouble(precioEspecial);
                dpFechaInicio.SelectedDate = vigInicio;
                if (vigFinal != null)
                {
                    dpFechaFinal.SelectedDate = vigFinal;
                }
                else
                {
                    dpFechaFinal.Enabled = false;
                    btnTermino.Checked   = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void Destino_Buscar(string idAgenda)
        {
            AgendaWCFClient objAgendaWCFClient;
            VBG01134Result  objAgendaCliente;
            decimal?        lineaCredito    = null;
            DateTime?       fechaVecimiento = null;
            decimal?        TC = null;

            try
            {
                objAgendaWCFClient = new AgendaWCFClient();
                objAgendaCliente   = new VBG01134Result();

                objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(((Usuario_LoginResult)Session["Usuario"]).idEmpresa,
                                                                           ((Usuario_LoginResult)Session["Usuario"]).codigoUsuario, idAgenda, ref lineaCredito, ref fechaVecimiento, ref TC);

                //txtDestino.Text = objAgendaCliente.Nombre;
                //if (!string.IsNullOrEmpty(objAgendaCliente.RUC))
                //    txtRUCDestino.Text = objAgendaCliente.RUC;
                //else
                //{
                //    txtRUCDestino.Text = idAgenda;
                //    lblRUC.Text = "DNI";
                //}
                //txtTEA.Text = objAgendaCliente.TEA.ToString();
                //txtDiasCredito.Text = objAgendaCliente.DiasCredito.ToString();
                //cboMoneda.SelectedValue = objAgendaCliente.ID_MonedaCompra.ToString();
                ViewState["LineaCredito"]     = lineaCredito;
                ViewState["FechaVencimiento"] = fechaVecimiento;
                if (lineaCredito <= 0)
                {
                    //lblLineaCredito.Text = "Linea de crédito insuficiente $." + Math.Round(Convert.ToDouble(lineaCredito.ToString()), 3).ToString();
                    //lblLineaCredito.CssClass = "mensajeError";
                }
                else
                {
                    //lblLineaCredito.Text = "Linea de crédito disponible $." + Math.Round(Convert.ToDouble(lineaCredito.ToString()), 3).ToString();
                    //lblLineaCredito.CssClass = "mensajeExito";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void Item_BuscarPrecioCliente(int idEmpresa, int codigoUsuario, decimal idPrecioCliente, ref decimal?precioEspecial,
                                             ref DateTime?vigInicio, ref DateTime?vigFinal, ref VBG01134Result objCliente, ref VBG01124Result objProducto, ref string ID_Item)
        {
            //using (dmIntranetDataContext dci = new dmIntranetDataContext(ConfigurationManager.ConnectionStrings["genesys"].ConnectionString))
            using (dmIntranetDataContext dci = new dmIntranetDataContext(GS.configuration.Init.GetValue(Constant.sistema, Constant.key, "genesys")))
            {
                //dmGenesysDataContext dcg = new dmGenesysDataContext(string.Format(ConfigurationManager.ConnectionStrings[dci.Empresa.SingleOrDefault(x => x.idEmpresa == idEmpresa).baseDatos].ConnectionString, "usrGEN" + (10000 + codigoUsuario).ToString().Substring(1, 4)));
                dmGenesysDataContext dcg = new dmGenesysDataContext(string.Format(GS.configuration.Init.GetValue(Constant.sistema, Constant.key, dci.Empresa.SingleOrDefault(x => x.idEmpresa == idEmpresa).baseDatos), "usrGEN" + (10000 + codigoUsuario).ToString().Substring(1, 4)));
                string  ID_Cliente = null;
                int?    tipoDscto = null;
                decimal?dsctoAdicional = null, iD_ClienteSucursal = null;
                string  nomRelComercial = null;
                bool?   existe          = null;
                try
                {
                    dcg.VBG01312(idPrecioCliente, ref ID_Cliente, ref ID_Item, ref vigInicio, ref vigFinal, ref precioEspecial, ref tipoDscto, ref dsctoAdicional, ref iD_ClienteSucursal);

                    objCliente  = dcg.VBG01134(ID_Cliente, 0, ref nomRelComercial, ref existe).Single();
                    objProducto = dcg.VBG01124(ID_Item, null, null).Single();
                }
                catch (Exception ex)
                {
                    dci.Excepcion_Registrar(ex.Message, ex.TargetSite.Name);
                    dci.SubmitChanges();
                    throw new ArgumentException("No se puede listar los precios de los clientes consultados.");
                }
            }
        }
Example #6
0
        public void Item_BuscarPrecioCliente(int idEmpresa, int codigoUsuario, decimal idPrecioCliente, ref decimal?precioEspecial,
                                             ref DateTime?vigInicio, ref DateTime?vigFinal, ref VBG01134Result objCliente, ref VBG01124Result objProducto, ref string ID_Item)
        {
            ItemBL objItemBL;

            try
            {
                objItemBL = new ItemBL();
                objItemBL.Item_BuscarPrecioCliente(idEmpresa, codigoUsuario, idPrecioCliente, ref precioEspecial, ref vigInicio,
                                                   ref vigFinal, ref objCliente, ref objProducto, ref ID_Item);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        //public static void ReadFileFromFTP(int idEmpresa, List<string> files, string RutaOrigen, string RutaSubmit, string RutaFail, string user, string pass)
        public static void ReadFileFromFTP(int idEmpresa, List <Cargar_Pedidos_ConfirmacionResult> ListaPedido)
        {
            List <gsInterfacePedidos_LeerResult> lstPedidos;
            //string Nombre;
            int codigoUsuario = 1;
            int idOrdenVenta;


            //foreach (Cargar_Pedidos_ConfirmacionResult file in ListaPedido)
            //{

            try
            {
                lstPedidos = new List <gsInterfacePedidos_LeerResult>();


                foreach (Cargar_Pedidos_ConfirmacionResult file in ListaPedido)
                {
                    gsInterfacePedidos_LeerResult Pedido = new gsInterfacePedidos_LeerResult();
                    //Pedido.NroPedido = "30313"; // file.NumeroDeDocumento; // Campos[0];                     //Op OV
                    //Pedido.ID_Item = "10210109003514"; //( file.CodigoDeArticulo;  //  Campos[1];                       //Item
                    //Pedido.Lote = "170831-0171-2050"; // file.CodigoDeLote; // Campos[2];                          //Lote
                    //Pedido.CantidadPedido = 6; // (decimal)file.UnidadesPedido; // decimal.Parse(Campos[3]);    //Cantidad
                    //Pedido.CantidadEntrega = 6; // (decimal)file.UnidadesEntregadas; // int.Parse(Campos[4]);       //Cantidad entregada
                    //Pedido.CantidadPendiente = 0; // (decimal)(file.Diferencia); // decimal.Parse(Campos[5]); //Diferencia
                    //Pedido.EstadoPedido = "D"; // file.Anticipado; // Campos[7];             // Estado
                    //Pedido.Id_Amarre = 76851; // decimal.Parse(file.IDDeLinea); // decimal.Parse(Campos[8]); // Id_Amarre
                    //Pedido.TransferidoTabla = "SILPT"; // file.Empresa;
                    //Pedido.Servicio = file.NumeroDeAlbaran;

                    /////////////-------------------------------------------------
                    Pedido.NroPedido         = file.NumeroDeDocumento;           // Campos[0];                     //Op OV
                    Pedido.ID_Item           = file.CodigoDeArticulo;            //  Campos[1];                       //Item
                    Pedido.Lote              = file.CodigoDeLote;                // Campos[2];                          //Lote
                    Pedido.CantidadPedido    = (decimal)file.UnidadesPedido;     // decimal.Parse(Campos[3]);    //Cantidad
                    Pedido.CantidadEntrega   = (decimal)file.UnidadesEntregadas; // int.Parse(Campos[4]);       //Cantidad entregada
                    Pedido.CantidadPendiente = (decimal)(file.Diferencia);       // decimal.Parse(Campos[5]); //Diferencia
                    Pedido.EstadoPedido      = file.Anticipado;                  // Campos[7];             // Estado
                    Pedido.Id_Amarre         = decimal.Parse(file.IDDeLinea);    // decimal.Parse(Campos[8]); // Id_Amarre
                    Pedido.TransferidoTabla  = file.Empresa;
                    Pedido.Servicio          = file.NumeroDeAlbaran;

                    lstPedidos.Add(Pedido);
                }


                lstPedidos = lstPedidos.OrderBy(x => x.Op).ToList();

                foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos)
                {
                    try
                    {
                        WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient();
                        objWmsInsert.WmsPedidosPendientes_Insertar(idEmpresa, 1, pedido.NroPedido, pedido.ID_Item, pedido.Lote,
                                                                   decimal.Parse(pedido.CantidadPedido.ToString()), decimal.Parse(pedido.CantidadEntrega.ToString()),
                                                                   decimal.Parse(pedido.CantidadPendiente.ToString()),
                                                                   pedido.EstadoPedido, int.Parse(pedido.Id_Amarre.ToString()));      //1=SILVESTRE; 2=NEOAGRUM; 6=INATEC

                        //objWmsInsert.WmsPedidosPendientes_UpdateEstilos(idEmpresa, codigoUsuario, pedido.TransferidoTabla, pedido.Servicio);

                        Console.Write("Se registro Op" + pedido.NroPedido + " - " + pedido.Id_Amarre);
                    }
                    catch (Exception ex)
                    {
                        Console.Write("Error: Registrar TXT: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString());
                    }
                }

                Console.Write("Se registro los pedidos consumidos.");

                //---------------------------Pedido--------------------------------

                //var lstOpOV = lstPedidos.Select(x => x.NroPedido).Distinct();


                foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos)
                {
                    try
                    {
                        GuiaWCFClient       objGuiaVentaWCF  = new GuiaWCFClient();
                        OrdenVentaWCFClient objOrdenVentaWCF = new OrdenVentaWCFClient();

                        gsOV_BuscarCabeceraResult     objOrdenVentaCab;
                        gsOV_BuscarDetalleResult[]    objOrdenVentaDet      = null;
                        gsGuia_BuscarCabeceraResult   objGuiaVentaCab       = new gsGuia_BuscarCabeceraResult();
                        gsGuia_BuscarDetalleResult[]  objGuiaVentaDet       = null;
                        gsGuia_BuscarDetalleResult    objGuiaVentaDetUpdate = null;
                        gsOV_BuscarDetalleResult      objOrdenVenta_Linea   = null;
                        List <DM.gsItem_BuscarResult> lstProductos          = new List <DM.gsItem_BuscarResult>();
                        gsOV_BuscarImpuestoResult[]   lstImpuestos          = null;
                        GuiaVenta_LotesItemsResult[]  lstLotes = null;

                        bool?           bloqueado      = false;
                        string          mensajeBloqueo = null;
                        AgendaWCFClient objAgendaWCFClient;

                        VBG01134Result objAgendaCliente;

                        decimal?lineaCredito = null;
                        decimal?Id_Amarre    = 0;
                        decimal?TC           = 0;

                        DateTime?fechaVecimiento = null;

                        Console.Write("OP:" + pedido.NroPedido);
                        objAgendaWCFClient = new AgendaWCFClient();
                        objAgendaCliente   = new VBG01134Result();

                        idOrdenVenta     = int.Parse(pedido.NroPedido.ToString());
                        objOrdenVentaCab = objOrdenVentaWCF.OrdenVenta_Buscar_Guia(idEmpresa, codigoUsuario, idOrdenVenta, ref objOrdenVentaDet, ref lstImpuestos, ref bloqueado, ref mensajeBloqueo);

                        objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(idEmpresa, codigoUsuario, objOrdenVentaCab.ID_Agenda,
                                                                                   ref lineaCredito, ref fechaVecimiento, ref TC);
                        Id_Amarre = pedido.Id_Amarre;

                        objOrdenVenta_Linea = objOrdenVentaDet.ToList().FindAll(x => x.ID_Amarre == Id_Amarre).Single();

                        int idGuiaOp      = 0;
                        int idGuiaOpLinea = 0;
                        int item_id       = 0;

                        idGuiaOp      = int.Parse(objOrdenVentaCab.OpGuia.ToString());
                        idGuiaOpLinea = int.Parse(objOrdenVenta_Linea.OpGuia.ToString());
                        item_id       = int.Parse(objOrdenVenta_Linea.Item_ID.ToString());

                        if (objOrdenVenta_Linea == null)
                        {
                        }
                        else
                        {
                            if (idGuiaOpLinea > 0)
                            {
                                objGuiaVentaCab = objGuiaVentaWCF.GuiaVenta_Buscar(idEmpresa, codigoUsuario, idGuiaOp, ref objGuiaVentaDet, ref bloqueado, ref mensajeBloqueo);
                            }
                            else
                            {
                                objGuiaVentaCab = GuiaVenta_ObtenerCabecera(objOrdenVentaCab, idGuiaOp);
                                objGuiaVentaDet = GuiaVenta_ObtenerDetalle(objOrdenVentaCab, objOrdenVentaDet, idEmpresa, codigoUsuario).ToArray();
                            }

                            if (idGuiaOp > 0)
                            {
                                lstLotes = objGuiaVentaWCF.GuiaVenta_LotesItemBuscar(idEmpresa, codigoUsuario, int.Parse(idGuiaOp.ToString()), int.Parse(objOrdenVenta_Linea.Item_ID.ToString()));
                            }



                            List <GuiaVenta_LotesItemsResult> LotesUp = new List <GuiaVenta_LotesItemsResult>();
                            if (lstLotes == null)
                            {
                                LotesUp = new List <GuiaVenta_LotesItemsResult>();
                            }
                            else
                            {
                                LotesUp = ((GuiaVenta_LotesItemsResult[])lstLotes).ToList();
                            }

                            objGuiaVentaDetUpdate = GuiaVenta_ObtenerDetalle_Update(objGuiaVentaDet, lstPedidos, Id_Amarre, ref LotesUp, item_id);

                            lstLotes = (GuiaVenta_LotesItemsResult[])LotesUp.ToArray();



                            try
                            {
                                int Error = 0;
                                int cont  = 0;
                                WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient();

                                List <VBG00971Result> Lista_LoteVar = objGuiaVentaWCF.GuiaVenta_BuscarLotesxItem(idEmpresa, 1, int.Parse(pedido.NroPedido), (int)item_id, (int)objGuiaVentaCab.ID_AlmacenAnexo, (int)pedido.Id_Amarre).ToList();

                                foreach (VBG00971Result Lote in Lista_LoteVar)
                                {
                                    if (Lote.Lote == pedido.Lote)
                                    {
                                        cont++;
                                        break;
                                    }
                                }

                                if (cont == 0)
                                {
                                    objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "No se encuentra Lote para el Item");
                                }
                                else
                                {
                                    try
                                    {
                                        objGuiaVentaWCF.GuiaVenta_Registrar(idEmpresa, 1, objGuiaVentaCab, objGuiaVentaDetUpdate, decimal.Parse(idGuiaOp.ToString()), lstLotes);
                                        objWmsInsert.WmsPedidosPendientes_UpdateEstilos(idEmpresa, codigoUsuario, pedido.TransferidoTabla, pedido.Servicio);
                                        objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "S", "Se registro correctamente.");
                                    }
                                    catch (Exception ex)
                                    {
                                        objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "Error, al registrar la Guia.");
                                        Console.Write("Error al registrar guias: " + ex.Message.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.Write("Error: Registrar Guia: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString());
                    }
                }

                ////------------------Mover archivos---------

                //    //MoverArchivos(RutaOrigen, RutaSubmit, file, user, pass);
                ////}
            }
            catch (Exception ex)
            {
                Console.Write("Error: Registrar Guia, " + ex.Message.ToString());
                //MoverArchivos(RutaOrigen, RutaFail, file, user, pass);
            }
            //}
        }
Example #8
0
        //public static void ReadFileFromFTP(int idEmpresa, List<string> files, string RutaOrigen, string RutaSubmit, string RutaFail, string user, string pass)
        public static void ReadFileFromFTP(int idEmpresa, DataTable ListaPedido, string esquema, string EmpresaPT)
        {
            //string Nombre;
            int codigoUsuario = 1;
            int idOrdenVenta;

            try
            {
                List <gsInterfacePedidos_LeerResult> lstPedidos = new List <gsInterfacePedidos_LeerResult>();

                foreach (DataRow file in ListaPedido.Rows)
                {
                    gsInterfacePedidos_LeerResult Pedido = new gsInterfacePedidos_LeerResult();
                    //Pedido.NroPedido = "30313"; // file.NumeroDeDocumento; // Campos[0];                     //Op OV
                    //Pedido.ID_Item = "10210109003514"; //( file.CodigoDeArticulo;  //  Campos[1];                       //Item
                    //Pedido.Lote = "170831-0171-2050"; // file.CodigoDeLote; // Campos[2];                          //Lote
                    //Pedido.CantidadPedido = 6; // (decimal)file.UnidadesPedido; // decimal.Parse(Campos[3]);    //Cantidad
                    //Pedido.CantidadEntrega = 6; // (decimal)file.UnidadesEntregadas; // int.Parse(Campos[4]);       //Cantidad entregada
                    //Pedido.CantidadPendiente = 0; // (decimal)(file.Diferencia); // decimal.Parse(Campos[5]); //Diferencia
                    //Pedido.EstadoPedido = "D"; // file.Anticipado; // Campos[7];             // Estado
                    //Pedido.Id_Amarre = 76851; // decimal.Parse(file.IDDeLinea); // decimal.Parse(Campos[8]); // Id_Amarre
                    //Pedido.TransferidoTabla = "SILPT"; // file.Empresa;
                    //Pedido.Servicio = file.NumeroDeAlbaran;

                    //-------------------------------------------------
                    Pedido.NroPedido         = file["NumeroDeDocumento"];                            // Campos[0];                     //Op OV
                    Pedido.ID_Item           = file["CodigoDeArticulo"];                             //  Campos[1];                       //Item
                    Pedido.Lote              = file["CodigoDeLote"];                                 // Campos[2];                          //Lote
                    Pedido.CantidadPedido    = decimal.Parse(file["UnidadesPedido"].ToString());     // decimal.Parse(Campos[3]);    //Cantidad
                    Pedido.CantidadEntrega   = decimal.Parse(file["UnidadesEntregadas"].ToString()); // int.Parse(Campos[4]);       //Cantidad entregada
                    Pedido.CantidadPendiente = decimal.Parse(file["Diferencia"].ToString());         // decimal.Parse(Campos[5]); //Diferencia
                    Pedido.EstadoPedido      = file["Anticipado"];                                   // Campos[7];             // Estado
                    Pedido.Id_Amarre         = decimal.Parse(file["IDDeLinea"].ToString());          // decimal.Parse(Campos[8]); // Id_Amarre
                    Pedido.TransferidoTabla  = file["CIF"];
                    Pedido.Servicio          = file["NumeroDeAlbaran"];

                    lstPedidos.Add(Pedido);
                }


                lstPedidos = lstPedidos.OrderBy(x => x.NroPedido).ToList();

                foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos)
                {
                    try
                    {
                        WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient();
                        objWmsInsert.WmsPedidosPendientes_Insertar(idEmpresa, 1, pedido.NroPedido.ToString(), pedido.ID_Item.ToString(), pedido.Lote.ToString(),
                                                                   decimal.Parse(pedido.CantidadPedido.ToString()), decimal.Parse(pedido.CantidadEntrega.ToString()),
                                                                   decimal.Parse(pedido.CantidadPendiente.ToString()),
                                                                   pedido.EstadoPedido.ToString(), int.Parse(pedido.Id_Amarre.ToString()));  //1=SILVESTRE; 2=NEOAGRUM; 6=INATEC

                        //objWmsInsert.WmsPedidosPendientes_UpdateEstilos(idEmpresa, codigoUsuario, pedido.TransferidoTabla, pedido.Servicio);

                        Console.Write("Se registro Op" + pedido.NroPedido + " - " + pedido.Id_Amarre);
                    }
                    catch (Exception ex)
                    {
                        Console.Write("Error: Registrar TXT: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString());
                    }
                }

                Console.Write("Se registro los pedidos consumidos.");
                Console.Write("..:Procesando Guias:..");

                //---------------------------Pedido--------------------------------

                //var lstOpOV = lstPedidos.Select(x => x.NroPedido).Distinct();


                foreach (gsInterfacePedidos_LeerResult pedido in lstPedidos)
                {
                    try
                    {
                        GuiaWCFClient       objGuiaVentaWCF  = new GuiaWCFClient();
                        OrdenVentaWCFClient objOrdenVentaWCF = new OrdenVentaWCFClient();

                        gsOV_BuscarCabeceraResult    objOrdenVentaCab;
                        gsOV_BuscarDetalleResult[]   objOrdenVentaDet      = null;
                        gsGuia_BuscarCabeceraResult  objGuiaVentaCab       = new gsGuia_BuscarCabeceraResult();
                        gsGuia_BuscarDetalleResult[] objGuiaVentaDet       = null;
                        gsGuia_BuscarDetalleResult   objGuiaVentaDetUpdate = null;
                        gsOV_BuscarDetalleResult     objOrdenVenta_Linea   = null;
                        List <gsItem_BuscarResult>   lstProductos          = new List <gsItem_BuscarResult>();
                        gsOV_BuscarImpuestoResult[]  lstImpuestos          = null;
                        GuiaVenta_LotesItemsResult[] lstLotes = null;

                        bool?           bloqueado      = false;
                        string          mensajeBloqueo = null;
                        AgendaWCFClient objAgendaWCFClient;

                        VBG01134Result objAgendaCliente;

                        decimal?lineaCredito = null;
                        decimal?Id_Amarre    = 0;
                        decimal?TC           = 0;


                        int variable = Convert.ToInt32(pedido.NroPedido);

                        if (variable == 23876)
                        {
                            TC = TC;
                        }


                        DateTime?fechaVecimiento = null;

                        Console.Write("OP:" + pedido.NroPedido);
                        Console.Write(" ");


                        objAgendaWCFClient = new AgendaWCFClient();
                        objAgendaCliente   = new VBG01134Result();

                        idOrdenVenta = int.Parse(pedido.NroPedido.ToString());
                        Console.WriteLine("Inicio: objOrdenVentaWCF.OrdenVenta_Buscar_Guia");
                        objOrdenVentaCab = objOrdenVentaWCF.OrdenVenta_Buscar_Guia(idEmpresa, codigoUsuario, idOrdenVenta, ref objOrdenVentaDet, ref lstImpuestos, ref bloqueado, ref mensajeBloqueo);

                        Console.WriteLine("Inicio: objAgendaWCFClient.Agenda_BuscarCliente");
                        objAgendaCliente = objAgendaWCFClient.Agenda_BuscarCliente(idEmpresa, codigoUsuario, objOrdenVentaCab.ID_Agenda,
                                                                                   ref lineaCredito, ref fechaVecimiento, ref TC);
                        Id_Amarre = (decimal)pedido.Id_Amarre;

                        objOrdenVenta_Linea = objOrdenVentaDet.ToList().FindAll(x => x.ID_Amarre == Id_Amarre).Single();

                        int idGuiaOp      = 0;
                        int idGuiaOpLinea = 0;
                        int item_id       = 0;

                        idGuiaOp      = int.Parse(objOrdenVentaCab.OpGuia.ToString());
                        idGuiaOpLinea = int.Parse(objOrdenVenta_Linea.OpGuia.ToString());
                        item_id       = int.Parse(objOrdenVenta_Linea.Item_ID.ToString());

                        if (objOrdenVenta_Linea == null)
                        {
                        }
                        else
                        {
                            if (idGuiaOpLinea > 0)
                            {
                                Console.WriteLine("Inicio: objGuiaVentaWCF.GuiaVenta_Buscar");
                                objGuiaVentaCab = objGuiaVentaWCF.GuiaVenta_Buscar(idEmpresa, codigoUsuario, idGuiaOp, ref objGuiaVentaDet, ref bloqueado, ref mensajeBloqueo);
                            }
                            else
                            {
                                Console.WriteLine("Inicio: GuiaVenta_ObtenerCabecera");
                                objGuiaVentaCab = GuiaVenta_ObtenerCabecera(objOrdenVentaCab, idGuiaOp);
                                Console.WriteLine("Inicio: GuiaVenta_ObtenerDetalle");
                                objGuiaVentaDet = GuiaVenta_ObtenerDetalle(objOrdenVentaCab, objOrdenVentaDet, idEmpresa, codigoUsuario).ToArray();
                            }

                            if (idGuiaOp > 0)
                            {
                                Console.WriteLine("Inicio: objGuiaVentaWCF.GuiaVenta_LotesItemBuscar");
                                lstLotes = objGuiaVentaWCF.GuiaVenta_LotesItemBuscar(idEmpresa, codigoUsuario, int.Parse(idGuiaOp.ToString()), int.Parse(objOrdenVenta_Linea.Item_ID.ToString()));
                            }



                            List <GuiaVenta_LotesItemsResult> LotesUp = new List <GuiaVenta_LotesItemsResult>();
                            if (lstLotes == null)
                            {
                                LotesUp = new List <GuiaVenta_LotesItemsResult>();
                            }
                            else
                            {
                                LotesUp = ((GuiaVenta_LotesItemsResult[])lstLotes).ToList();
                            }
                            Console.WriteLine("Inicio: GuiaVenta_ObtenerDetalle_Update");
                            objGuiaVentaDetUpdate = GuiaVenta_ObtenerDetalle_Update(objGuiaVentaDet, lstPedidos, Id_Amarre, ref LotesUp, item_id);

                            lstLotes = (GuiaVenta_LotesItemsResult[])LotesUp.ToArray();



                            try
                            {
                                int Error = 0;
                                int cont  = 0;
                                WmsWCF.WmsWCFClient objWmsInsert = new WmsWCF.WmsWCFClient();

                                //List<VBG00971Result> Lista_LoteVar = objGuiaVentaWCF.GuiaVenta_BuscarLotesxItem(idEmpresa, 1, int.Parse(pedido.NroPedido), (int)item_id, (int)objGuiaVentaCab.ID_AlmacenAnexo, (int)pedido.Id_Amarre).ToList();

                                //List<VBG00971Result> Lista_LoteVar = dcg.VBG00971(item_id, ID_AlmacenAnexo, "GuiaVenta", 0, "OV", id_amarre).ToList();


                                DataTable dtTabla = new DataTable();
                                blTareo   bl      = new blTareo();
                                Console.WriteLine("Inicio de VBG00971_WMS");
                                //Lista Producción por recibir
                                DataSet ds1 = bl.ListarDataSet(
                                    string.Format(
                                        //"set dateformat DMY\n" +
                                        "set dateformat " + getFormatDate() + "\n" +
                                        "exec " + esquema + "..VBG00971_WMS {0},{1},'GuiaVenta', 0, 'OV',{2},'{3}'",
                                        (int)item_id, (int)objGuiaVentaCab.ID_AlmacenAnexo, pedido.Id_Amarre.ToString(), pedido.Lote.ToString()
                                        )
                                    );
                                //Busca registro de interfaz
                                dtTabla = ds1.Tables[0];
                                dtTabla.Columns.Add("Consumo", typeof(int));
                                Console.WriteLine("Fin de VBG00971_WMS");


                                int Pendiente = 0;
                                Pendiente = Convert.ToInt32(pedido.CantidadEntrega);

                                foreach (DataRow Lote in dtTabla.Rows)//traer solo lotes iguales al lote del kardex
                                {
                                    string strLote = Lote["Lote"].ToString();

                                    if (strLote == pedido.Lote.ToString())
                                    {
                                        int Consumo  = 0;
                                        int CantLote = Convert.ToInt32(Lote[10]);

                                        if (CantLote >= Pendiente)
                                        {
                                            Consumo   = Pendiente;
                                            Pendiente = 0;
                                        }
                                        else
                                        {
                                            Consumo   = CantLote;
                                            Pendiente = Pendiente - CantLote;
                                        }

                                        Lote["Consumo"] = Consumo;
                                        cont++;
                                        if (Pendiente <= 0)
                                        {
                                            break;
                                        }
                                    }
                                }

                                if (cont == 0)
                                {
                                    //objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "No se encuentra Lote para el Item");

                                    DataSet ds11 = bl.ListarDataSet(
                                        string.Format(
                                            "set dateformat DMY\n" +
                                            "exec  " + esquema + "..gsInterfacePedidos_Update '{0}',{1},{2},'{3}'",
                                            pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "'F'", "No se encuentra Lote para el Item"
                                            ));

                                    //dcg.gsInterfacePedidos_Update(Lote, Id_Amarre, transferido, observacion);
                                }
                                else
                                {
                                    try
                                    {
                                        Console.WriteLine("Registrando Guia y moviendo el Inv.");
                                        objGuiaVentaWCF.GuiaVenta_Registrar_wms(idEmpresa, 1, objGuiaVentaCab, objGuiaVentaDetUpdate,
                                                                                decimal.Parse(idGuiaOp.ToString()), lstLotes, EmpresaPT, pedido.Servicio.ToString(), pedido.Lote.ToString(), pedido.Id_Amarre.ToString());

                                        Console.WriteLine("Finalizado");
                                        //DataSet ds13 = bl.ListarDataSet(
                                        // string.Format(
                                        // "set dateformat DMY\n" +
                                        // "exec  " + esquema + "..Cargar_Pedidos_UpdateEstilos '{0}','{1}'",
                                        //   EmpresaPT, pedido.Servicio.ToString()
                                        // ));

                                        //DataSet ds14 = bl.ListarDataSet(
                                        //   string.Format(
                                        //   "set dateformat DMY\n" +
                                        //   "exec  " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'",
                                        //   pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "S", "Se registro correctamente."
                                        //   ));
                                    }
                                    catch (Exception ex)
                                    {
                                        //objWmsInsert.WmsPedidosPendientes_Update(idEmpresa, codigoUsuario, pedido.Lote, (int)pedido.Id_Amarre, "F", "Error, al registrar la Guia.");


                                        //DataSet ds12 = bl.ListarDataSet(
                                        //string.Format(
                                        //"set dateformat DMY\n" +
                                        //"exec  " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'",
                                        //pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "F", "Error: al registrar Guía"
                                        //));

                                        Console.Write("Error al registrar guias: " + ex.Message.ToString());
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                blTareo bl   = new blTareo();
                                DataSet ds15 = bl.ListarDataSet(
                                    string.Format(
                                        "set dateformat DMY\n" +
                                        "exec  " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'",
                                        pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "F", "Error: al registrar Guía"
                                        ));
                                Console.Write("Error al registrar guias: " + ex.Message.ToString());
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        blTareo bl   = new blTareo();
                        DataSet ds16 = bl.ListarDataSet(
                            string.Format(
                                "set dateformat DMY\n" +
                                "exec  " + esquema + "..gsInterfacePedidos_Update '{0}',{1},'{2}','{3}'",
                                pedido.Lote.ToString(), pedido.Id_Amarre.ToString(), "F", "Error: al registrar Guía"
                                ));
                        Console.Write("Error: Registrar Guia: " + pedido.NroPedido.ToString() + "-" + pedido.ID_Item.ToString() + ", " + ex.Message.ToString());
                    }
                }

                ////------------------Mover archivos---------

                //    //MoverArchivos(RutaOrigen, RutaSubmit, file, user, pass);
                ////}
            }
            catch (Exception ex)
            {
                Console.Write("Error: Registrar Guia, " + ex.Message.ToString());
                //MoverArchivos(RutaOrigen, RutaFail, file, user, pass);
            }
            //}
        }