private int Ventas(string codigo, string cuenta, int dias) { CredencialesEbay credencialesEbay = new CredencialesEbay(); int ArticuloID = 0; int i = credencialesEbay.Cuentas.IndexOf(cuenta); if (i < 0) { Debug.WriteLine("Funcion Ventas Codigo error IndexOf: " + codigo + " CUenta: " + cuenta); return(0); } cuenta = credencialesEbay.InicialesCuentas[i]; DateTime today = DateTime.Now; DateTime semana = today.AddDays(-1 * dias); try { MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); ArticuloID = dbContextSql.Articulos.Where(w => w.Codigo == codigo).FirstOrDefault().ArticuloID; } catch (Exception e) { Console.WriteLine("B" + e.Message + " " + e.InnerException); } var SiEscandalloDbcontext = new MyEntityModel.ApplicationDbContextSql(); bool SiEscandallo = SiEscandalloDbcontext.SiTieneEscandallo(ArticuloID); int vendidos = 0; if (SiEscandallo == false) { try { MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); vendidos = dbContextSql.Lineas.Where(w => w.ArticuloID == ArticuloID && w.Fecha >= semana && w.Historial.StartsWith(cuenta) && w.Unidades > 0).Sum(s => (int?)s.Unidades) ?? 0; } catch (Exception e) { Console.WriteLine("C " + e.Message + " " + e.InnerException); } return(vendidos); } // Si Escandallo == true else { try { MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); vendidos = dbContextSql.Lineas.Where(w => w.ArticuloCompradoID == ArticuloID && w.Fecha >= semana && w.Historial.StartsWith(cuenta) && w.Unidades > 0).Sum(s => (int?)s.UnidadesArticuloComprado) ?? 0; } catch (Exception e) { Console.WriteLine("C " + e.Message + " " + e.InnerException); } return(vendidos); } }
public static void fnCodigosEsteMaestro(string codigo, List <string> ListaCodigos) { IList <MyEntityModel.Escandallo> Escandallos; MyEntityModel.ApplicationDbContextSql dbContextSQL = new MyEntityModel.ApplicationDbContextSql(); int ArticuloID = FuncionesEbay.fnArticuloID(codigo); if (ArticuloID != 0) { Escandallos = dbContextSQL.Escandallos.Where(w => w.ArticuloID == ArticuloID).ToList(); foreach (var escandallo in Escandallos) { string c = dbContextSQL.Articulos.Where(w => w.ArticuloID == escandallo.DetalleID).FirstOrDefault().Codigo; ListaCodigos.Add(c.Trim()); } } }
public string LeerArticuloEbay(String ArticuloID, string cuenta, string articulo_mio, string codigo) { MyEntityModel.RepuestosDeMovilesDbContext dbContext = new MyEntityModel.RepuestosDeMovilesDbContext(); MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); CredencialesEbay credencialeebay = new CredencialesEbay(); credencialeebay.cuenta = cuenta; ItemType Item; GetItemCall ap = new GetItemCall(credencialeebay.context); ap.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); ap.IncludeItemSpecifics = true; try { Item = ap.GetItem(ArticuloID); } catch (ApiException oApiEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Console.WriteLine("1 " + oApiEx.Message); return(oApiEx.Message); } catch (SdkException oSdkEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Console.WriteLine("2 " + oSdkEx.Message); return(oSdkEx.Message); } catch (Exception oEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Console.WriteLine("3 " + oEx.Message); return(oEx.Message); } EBAY_SEGUIMIENTO ebay_seguimiento = new EBAY_SEGUIMIENTO(); try { ebay_seguimiento = dbContext.EBAY_SEGUIMIENTO.Where(w => w.ARTICULO == Item.ItemID).FirstOrDefault(); } catch (Exception edb) { Console.WriteLine("Error en dbContext " + edb); } if (ebay_seguimiento != null) { ebay_seguimiento.Descripcion = Item.Description; ebay_seguimiento.DISPONIBLES = Item.Quantity - Item.SellingStatus.QuantitySold; ebay_seguimiento.ENVIO = (decimal?)Item.ShippingDetails.ShippingServiceOptions[0].ShippingServiceCost.Value; ebay_seguimiento.IMAGEN_EBAY = Item.PictureDetails.PictureURL[0]; ebay_seguimiento.PRECIO = (decimal?)Item.StartPrice.Value; ebay_seguimiento.SUBTITULO = Item.SubTitle; ebay_seguimiento.TITULO = Item.Title; ebay_seguimiento.VENDIDOS = Item.SellingStatus.QuantitySold; ebay_seguimiento.VENDIDOS_SEMANA = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 7); ebay_seguimiento.VENDIDOS_MES = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 30); ebay_seguimiento.FECHA = DateTime.Now; ebay_seguimiento.PictureURL = string.Join("\t", Item.PictureDetails.PictureURL.ToArray()); dbContext.SaveChanges(); return(""); } else { ebay_seguimiento = new EBAY_SEGUIMIENTO(); ebay_seguimiento.VENDEDOR = Item.Seller.UserID; ebay_seguimiento.ARTICULO = Item.ItemID; ebay_seguimiento.CODIGO = codigo; ebay_seguimiento.TITULO = Item.Title; ebay_seguimiento.SUBTITULO = Item.SubTitle; ebay_seguimiento.Descripcion = Item.Description; ebay_seguimiento.DISPONIBLES = Item.Quantity - Item.SellingStatus.QuantitySold; ebay_seguimiento.ENVIO = (decimal?)Item.ShippingDetails.ShippingServiceOptions[0].ShippingServiceCost.Value; ebay_seguimiento.IMAGEN_EBAY = Item.PictureDetails.PictureURL[0]; ebay_seguimiento.PRECIO = (decimal?)Item.StartPrice.Value; ebay_seguimiento.VENDIDOS = Item.SellingStatus.QuantitySold; ebay_seguimiento.VENDIDOS_SEMANA = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 7); ebay_seguimiento.VENDIDOS_MES = Ventas(ebay_seguimiento.ARTICULO_MIO, ebay_seguimiento.VENDEDOR, 30); ebay_seguimiento.FECHA = DateTime.Now; ebay_seguimiento.PictureURL = string.Join("\t", Item.PictureDetails.PictureURL); dbContext.EBAY_SEGUIMIENTO.Add(ebay_seguimiento); dbContext.SaveChanges(); } return(""); }
public static ItemType LeerArticuloEbay(String ArticuloID, string cuenta) { new Thread(delegate() { fnNotificacion(" Leyendo " + ArticuloID); }).Start(); MyEntityModel.RepuestosDeMovilesDbContext dbContext = new MyEntityModel.RepuestosDeMovilesDbContext(); MyEntityModel.ApplicationDbContextSql dbContextSql = new MyEntityModel.ApplicationDbContextSql(); CredencialesEbay credencialeebay = new CredencialesEbay(); credencialeebay.cuenta = cuenta; ItemType Item; GetItemCall ap = new GetItemCall(credencialeebay.context); ap.DetailLevelList.Add(DetailLevelCodeType.ReturnAll); ap.IncludeItemSpecifics = true; try { Notificacion(ArticuloID, 1); Item = ap.GetItem(ArticuloID); } catch (ApiException oApiEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Debug.WriteLine("1 " + oApiEx.Message); fnGrabarErrorEbayArticulo(ArticuloID, oApiEx.Message); return(null); } catch (SdkException oSdkEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Debug.WriteLine("2 " + oSdkEx.Message); fnGrabarErrorEbayArticulo(ArticuloID, oSdkEx.Message); return(null); } catch (Exception oEx) { // process exception ... pass to caller, implement retry logic here or in caller, whatever you want to do Debug.WriteLine("3 " + oEx.Message); fnGrabarErrorEbayArticulo(ArticuloID, oEx.Message); return(null); } EBAY_SEGUIMIENTO ebay_seguimiento = new EBAY_SEGUIMIENTO(); try { ebay_seguimiento = dbContext.EBAY_SEGUIMIENTO.Where(w => w.ARTICULO == Item.ItemID).FirstOrDefault(); } catch (Exception edb) { Debug.WriteLine("Error en dbContext " + edb); } if (ebay_seguimiento != null) { Debug.WriteLine("Articulo " + ArticuloID + " Leido"); fnCopiarArticuloEbaySeguimiento(Item, ebay_seguimiento); try { dbContext.SaveChanges(); Debug.WriteLine("Articulo " + ArticuloID + " Grabado"); } catch { Debug.WriteLine("Articulo " + ArticuloID + " ****** ERROR AL GRABAR ******"); } } return(Item); }
public static int fnArticuloID(string codigo) { MyEntityModel.ApplicationDbContextSql dbContextSQL = new MyEntityModel.ApplicationDbContextSql(); return(dbContextSQL.Articulos.Where(w => w.Codigo == codigo).FirstOrDefault().ArticuloID); }
private void leer() { MyEntityModel.ApplicationDbContextSql dbContext = new MyEntityModel.ApplicationDbContextSql(); MyEntityModel.RepuestosDeMovilesDbContext dbcontextRepuestos = new MyEntityModel.RepuestosDeMovilesDbContext(); TextFieldParser parser = new TextFieldParser(buttonEditFichero.Text, Encoding.Default); parser.HasFieldsEnclosedInQuotes = true; parser.SetDelimiters(","); string articuloID = ""; string sprecio = ""; string concepto; decimal comision; DateTime fecha; decimal precio; string sfecha, nombreCategoriaRaiz, nombre; long categoria; string[] fields; while (!parser.EndOfData) { fields = parser.ReadFields(); if (fields.Count() == 8) // linea { precio = 0; var values = fields[1].Split(';'); if (values.Count() == 2) // Linea de venta { simpleButtonImportar.Text = articuloID; Application.DoEvents(); articuloID = nombreCategoriaRaiz = ""; categoria = 0; nombre = fields[1]; var values2 = values[1].Split(' '); sprecio = values2[3]; precio = MyEntityModel.FuncionesEbay.fnSpreciodprecio(sprecio); concepto = fields[3]; comision = MyEntityModel.FuncionesEbay.fnSpreciodprecio(fields[4].Split(' ')[0]); articuloID = fields[2]; sfecha = fields[0].Replace("PDT", ""); DateTime.TryParseExact(sfecha.Trim(), "dd-MMM-yy HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out fecha); MyEntityModel.EBAY_SEGUIMIENTO ebay_seguimiento = ebay_seguimiento_lista.Where(w => w.ARTICULO == articuloID).FirstOrDefault(); if (ebay_seguimiento == null) { ebay_seguimiento = dbcontextRepuestos.EBAY_SEGUIMIENTO.Where(w => w.ARTICULO == articuloID).FirstOrDefault(); if (ebay_seguimiento != null) { ebay_seguimiento_lista.Add(ebay_seguimiento); } } if (ebay_seguimiento != null) { categoria = Convert.ToInt64(ebay_seguimiento.PrimaryCategoryID); Categorias categoria_lista = categorias_lista.Where(w => w.categoriaID == categoria).FirstOrDefault(); if (categoria_lista == null) { nombreCategoriaRaiz = MyEntityModel.FuncionesEbay.fnNombreCategoriaRaiz(categoria); categorias_lista.Add(new Categorias { categoriaID = categoria, NombreRaiz = nombreCategoriaRaiz }); } else { nombreCategoriaRaiz = categoria_lista.NombreRaiz; } } MyEntityModel.ComisionesEbay comisionesEbay = new MyEntityModel.ComisionesEbay(); try { comisionesEbay.Articulo = articuloID; comisionesEbay.Categoria = categoria; comisionesEbay.Comision = comision; comisionesEbay.Cuenta = "ofertasparati"; comisionesEbay.Fecha = fecha; comisionesEbay.Nombre = nombre; comisionesEbay.NombreCategoriaRaiz = nombreCategoriaRaiz; comisionesEbay.Precio = precio; if (precio != 0) { comisionesEbay.Porcentaje = decimal.Multiply(100, comision); comisionesEbay.Porcentaje = decimal.Divide(comisionesEbay.Porcentaje, precio); dbContext.comisionesEbay.Add(comisionesEbay); dbContext.SaveChanges(); } } catch (Exception ex) { } } } } parser.Close(); return; }