public static List <ArticulosEnEscandallo> fnArticulosEnEscandallo(string codigo) { ApplicationDbContextSql dbContextSQL = new ApplicationDbContextSql(); int articuloID = dbContextSQL.Articulos.Where(w => w.Codigo == codigo.Trim()).FirstOrDefault().ArticuloID; return(fnArticulosEnEscandallo(articuloID)); }
public static List <ArticulosEnEscandallo> fnArticulosEnEscandallo(int articuloID) { List <ArticulosEnEscandallo> articulosEnEscandallo = new List <ArticulosEnEscandallo>(); ApplicationDbContextSql dbContext = new ApplicationDbContextSql(); List <Escandallo> escandallos = dbContext.Escandallos.Where(w => w.ArticuloID == articuloID).ToList(); foreach (Escandallo escandallo in escandallos) { try { Articulo articulo = dbContext.Articulos.Where(w => w.ArticuloID == escandallo.DetalleID).FirstOrDefault(); articulosEnEscandallo.Add(new ArticulosEnEscandallo { Nombre = articulo.Nombre, ArticuloId = escandallo.DetalleID, Codigo = articulo.Codigo.Trim(), PesoNeto = articulo.PesoNeto, PesoBruto = articulo.PesoBruto, Costo = articulo.Costo, Imprimir = escandallo.Imprimir, Precio = escandallo.Precio, Unidades = escandallo.Unidades }); } catch { Debug.WriteLine("Error en el escandallo del artículoID " + articuloID.ToString()); } } if (articulosEnEscandallo.Count == 0) { Articulo articulo = dbContext.Articulos.Where(w => w.ArticuloID == articuloID).FirstOrDefault(); articulosEnEscandallo.Add(new ArticulosEnEscandallo { Nombre = articulo.Nombre, ArticuloId = articuloID, Codigo = articulo.Codigo.Trim(), PesoNeto = articulo.PesoNeto, PesoBruto = articulo.PesoBruto, Costo = articulo.Costo, Imprimir = SiNo.Si, Precio = SiNo.Si, Unidades = 1 }); } return(articulosEnEscandallo); }
public static List <ArticulosEnEscandallo> fnArticulosEnEscandalloEbay(string articuloEbayID) { int articuloID = 0; try { RepuestosDeMovilesDbContext dbContext = new RepuestosDeMovilesDbContext(); string codigo = dbContext.EBAY_SEGUIMIENTO.Where(w => w.ARTICULO == articuloEbayID).FirstOrDefault().ARTICULO_MIO.Trim(); ApplicationDbContextSql dbContextSQL = new ApplicationDbContextSql(); articuloID = dbContextSQL.Articulos.Where(w => w.Codigo == codigo).FirstOrDefault().ArticuloID; } catch { } if (articuloID > 0) { return(fnArticulosEnEscandallo(articuloID)); } else { return(null); } }
private void GrabarOrderItems(List <OrderItem> orderItems, Order order) { bool nuevo; // return; ApplicationDbContextSql dbContext = new ApplicationDbContextSql(); var transaction = dbContext.Database.BeginTransaction(IsolationLevel.RepeatableRead); foreach (OrderItem item in orderItems) { AmazonOrderLinea amazonOrderLinea = dbContext.amazonorderLineas.Where(w => w.AmazonOrderLineaID == item.OrderItemId).FirstOrDefault(); if (amazonOrderLinea == null) { nuevo = true; amazonOrderLinea = new AmazonOrderLinea(); } else { nuevo = false; } amazonOrderLinea.OrderItemId = item.OrderItemId; amazonOrderLinea.AmazonOrderID = order.AmazonOrderId; amazonOrderLinea.AmazonOrderLineaID = item.OrderItemId; if (item.IsSetASIN()) { amazonOrderLinea.Asin = item.ASIN; } amazonOrderLinea.Cuenta = order.SellerOrderId; if (item.IsSetItemPrice()) { amazonOrderLinea.ItemPriceAmount = FuncionesEbay.fnSpreciodprecio(item.ItemPrice.Amount); amazonOrderLinea.ItemPriceCurrencyCode = item.ItemPrice.CurrencyCode; } if (item.IsSetQuantityOrdered()) { amazonOrderLinea.QuantityOrdered = item.QuantityOrdered; } if (item.IsSetQuantityShipped()) { amazonOrderLinea.QuantityShipped = item.QuantityShipped; } if (item.IsSetSellerSKU()) { amazonOrderLinea.SellerSKU = item.SellerSKU; } if (item.IsSetShippingPrice()) { amazonOrderLinea.ShippingPriceAmount = FuncionesEbay.fnSpreciodprecio(item.ShippingPrice.Amount); amazonOrderLinea.ShippingPriceCurrencyCode = item.ShippingPrice.CurrencyCode; } if (item.IsSetTitle()) { amazonOrderLinea.Title = item.Title; } if (nuevo) { dbContext.amazonorderLineas.Add(amazonOrderLinea); } } try { dbContext.SaveChanges(); transaction.Commit(); dbContext.Dispose(); } catch (Exception e) { } }
private void GrabarOrder(Order order, string cuenta) { bool nuevo = false; // return; ApplicationDbContextSql dbContext = new ApplicationDbContextSql(); var transaction = dbContext.Database.BeginTransaction(IsolationLevel.RepeatableRead); AmazonOrder amazonOrder = dbContext.amazonorders.Where(w => w.AmazonOrderID == order.AmazonOrderId).FirstOrDefault(); if (amazonOrder == null) { amazonOrder = new AmazonOrder(); nuevo = true; } amazonOrder.AmazonOrderID = order.AmazonOrderId; if (order.IsSetBuyerEmail()) { amazonOrder.BuyerEmail = order.BuyerEmail; } if (order.IsSetBuyerName()) { amazonOrder.BuyerName = order.BuyerName; } amazonOrder.Cuenta = cuenta; if (order.IsSetEarliestDeliveryDate()) { amazonOrder.EarliestDeliveryDate = order.EarliestDeliveryDate; } if (order.IsSetEarliestShipDate()) { amazonOrder.EarliestShipDate = order.EarliestShipDate; } if (order.IsSetFulfillmentChannel()) { amazonOrder.fulfillmentChannel = order.FulfillmentChannel; } if (order.IsSetIsPremiumOrder()) { amazonOrder.IsPremiumOrder = order.IsPremiumOrder; } if (order.IsSetIsPrime()) { amazonOrder.IsPrime = order.IsPrime; } if (order.IsSetLastUpdateDate()) { amazonOrder.lastUpdateDate = order.LastUpdateDate; } if (order.IsSetLatestDeliveryDate()) { amazonOrder.LatestDeliveryDate = order.LatestDeliveryDate; } if (order.IsSetLatestShipDate()) { amazonOrder.LatestShipDate = order.LatestShipDate; } if (order.IsSetMarketplaceId()) { amazonOrder.MarketplaceId = order.MarketplaceId; } if (order.IsSetNumberOfItemsShipped()) { amazonOrder.NumberOfItemsShipped = order.NumberOfItemsShipped; } if (order.IsSetNumberOfItemsUnshipped()) { amazonOrder.NumberOfItemsUnshipped = order.NumberOfItemsUnshipped; } if (order.IsSetOrderChannel()) { amazonOrder.orderChannel = order.OrderChannel; } if (order.IsSetOrderTotal()) { amazonOrder.OrderTotalAmount = FuncionesEbay.fnSpreciodprecio(order.OrderTotal.Amount); amazonOrder.OrderTotalCurrencyCode = order.OrderTotal.CurrencyCode; } if (order.IsSetOrderType()) { amazonOrder.OrderType = order.OrderType; } if (order.IsSetPaymentMethod()) { amazonOrder.PaymentMethod = order.PaymentMethod; } if (order.IsSetPurchaseDate()) { amazonOrder.purchaseDate = order.PurchaseDate; } if (order.IsSetOrderChannel()) { amazonOrder.salesChannel = order.SalesChannel; } if (order.IsSetSellerOrderId()) { amazonOrder.SellerOrderID = order.SellerOrderId; } if (order.IsSetShipmentServiceLevelCategory()) { amazonOrder.ShipmentServiceLevelCategory = order.ShipmentServiceLevelCategory; } if (order.IsSetShippedByAmazonTFM()) { amazonOrder.ShippedByAmazonTFM = order.ShippedByAmazonTFM; } if (order.IsSetShippingAddress()) { amazonOrder.ShippingAddressAddressLine1 = order.ShippingAddress.AddressLine1; amazonOrder.ShippingAddressAddressLine2 = order.ShippingAddress.AddressLine2; amazonOrder.ShippingAddressAddressLine3 = order.ShippingAddress.AddressLine3; amazonOrder.ShippingAddressCity = order.ShippingAddress.City; amazonOrder.ShippingAddressCountryCode = order.ShippingAddress.CountryCode; amazonOrder.ShippingAddressDistrict = order.ShippingAddress.District; amazonOrder.ShippingAddressName = order.ShippingAddress.Name; amazonOrder.ShippingAddressPhone = order.ShippingAddress.Phone; amazonOrder.ShippingAddressPostalCode = order.ShippingAddress.PostalCode; amazonOrder.ShippingAddressStateOrRegion = order.ShippingAddress.StateOrRegion; } if (order.IsSetShipServiceLevel()) { amazonOrder.shipServiceLevel = order.ShipServiceLevel; } if (nuevo) { dbContext.amazonorders.Add(amazonOrder); } dbContext.SaveChanges(); transaction.Commit(); dbContext.Dispose(); }
public ArticulosUserControl() { InitializeComponent(); this.Dock = DockStyle.Fill; this.HandleDestroyed += handleDestroyed; if (File.Exists("Layouts\\Articulos\\gridViewArticulos.xml")) { gridViewArticulos.RestoreLayoutFromXml("Layouts\\Articulos\\gridViewArticulos.xml"); } if (File.Exists("Layouts\\Articulos\\layout.xml")) { layoutControl1.RestoreLayoutFromXml("Layouts\\Articulos\\layout.xml"); } RegistryKey reg = Registry.CurrentUser.OpenSubKey("\\SOFTWARE\\Rajotero\\Articulos", true); if (reg == null) { reg = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Rajotero\\Articulos"); } if (reg != null) { radioGroupRajotero.SelectedIndex = (int)reg.GetValue("Rajotero", 0); radioGroupEscandallo.SelectedIndex = (int)reg.GetValue("Escandallo", 0); radioGroupActivos.SelectedIndex = (int)reg.GetValue("Activo", 0); textEditPalabras.Text = (string)reg.GetValue("Palabras", ""); textEditDelEnvio.Text = (string)reg.GetValue("Envio", ""); } if (File.Exists("Layouts\\Articulos\\gridViewCompras.xml")) { gridViewCompras.RestoreLayoutFromXml("Layouts\\Articulos\\gridViewCompras.xml"); } MyEntityModel.ApplicationDbContextSql dbContext = new MyEntityModel.ApplicationDbContextSql(); dbContext.TipoArticulos.Load(); repositoryItemLookUpEditTipoArticulo1.DataSource = dbContext.TipoArticulos.Local.ToBindingList(); repositoryItemLookUpEditTipoArticulo1.DisplayMember = "Nombre"; repositoryItemLookUpEditTipoArticulo1.ValueMember = "TipoArticuloID"; FechaActualizacionTotalesArticulo(); GridColumn colStock = new GridColumn(); colStock.FieldName = "Stock"; colStock.Caption = "Stock"; colStock.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; gridViewArticulos.Columns.Add(colStock); colStock.VisibleIndex = 0; colUnidadesRecibidas.FieldName = "UnidadesRecibidas"; colUnidadesRecibidas.Caption = "UnidadesRecibidas"; colUnidadesRecibidas.UnboundType = DevExpress.Data.UnboundColumnType.Decimal; gridViewArticulos.Columns.Add(colUnidadesRecibidas); colUnidadesRecibidas.VisibleIndex = 0; LoadSource(); // Prevent the focused cell from being highlighted. gridViewArticulos.OptionsSelection.EnableAppearanceFocusedCell = false; // Draw a dotted focus rectangle around the entire row. gridViewArticulos.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.RowFocus; CredencialesEbay credenciales = new CredencialesEbay(); foreach (string cuenta in credenciales.Cuentas) { LayoutControlItem item1 = layoutControlCuentas.Root.AddItem(); item1.Name = "Ebay " + cuenta; item1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom; item1.MaxSize = new Size(205, 30); ComboBoxEdit comboBoxEdit1 = new DevExpress.XtraEditors.ComboBoxEdit(); comboBoxEdit1.Name = "Ebay " + cuenta; comboBoxEdit1.Properties.Items.AddRange(new object[] { "Todos", "Publicados", "Sin publicar" }); comboBoxEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; comboBoxEdit1.Properties.PopupFormSize = new Size(50, comboBoxEdit1.Properties.PopupFormSize.Height); comboBoxEdit1.Size = new Size(50, comboBoxEdit1.Properties.PopupFormSize.Height); comboBoxEdit1.SelectedIndex = (int)reg.GetValue(comboBoxEdit1.Name, 0); item1.Control = comboBoxEdit1; } foreach (string cuenta in Global.CuentasAmazon) { LayoutControlItem item1 = layoutControlCuentas.Root.AddItem(); item1.Name = "Amazon " + cuenta; item1.SizeConstraintsType = DevExpress.XtraLayout.SizeConstraintsType.Custom; item1.MaxSize = new Size(205, 30); ComboBoxEdit comboBoxEdit1 = new DevExpress.XtraEditors.ComboBoxEdit(); comboBoxEdit1.Name = "Amazon " + cuenta; comboBoxEdit1.Properties.Items.AddRange(new object[] { "Todos", "Publicados", "Sin publicar" }); comboBoxEdit1.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor; comboBoxEdit1.Properties.PopupFormSize = new Size(50, comboBoxEdit1.Properties.PopupFormSize.Height); comboBoxEdit1.Size = new Size(50, comboBoxEdit1.Properties.PopupFormSize.Height); comboBoxEdit1.SelectedIndex = (int)reg.GetValue(comboBoxEdit1.Name, 0); item1.Control = comboBoxEdit1; } }
private void ButtonFechaActualizacionTotalesArticulo_Click(object sender, EventArgs e) { var dataContext = new MyEntityModel.ApplicationDbContextSql(); string sql; ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando ArticuloComprado"; Application.DoEvents(); sql = "UPDATE lineas SET ArticuloCompradoID = (SELECT ArticuloId FROM Articulos a WHERE a.Codigo = ArticuloComprado)"; dataContext.Database.ExecuteSqlCommand(sql); ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Vendidos - 1"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET vendidos = (" + "SELECT SUM(unidades) from lineas l WHERE l.ArticuloID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ({0}) " + ")", Global.TiposVentasSQL); dataContext.Database.ExecuteSqlCommand(sql); ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Comprados - 1"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET comprados = (" + "SELECT SUM(unidades) from lineas l WHERE l.ArticuloID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ('B')" + ")"); dataContext.Database.ExecuteSqlCommand(sql); DateTime Siete = DateTime.Now.AddDays(-7); var parameters = new List <SqlParameter> { new SqlParameter { ParameterName = "@Fecha", SqlDbType = SqlDbType.DateTime, Value = Siete } }; ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Vendidos Semana - 1"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET vendidossiete = (" + "SELECT SUM(unidades) from lineas l WHERE l.ArticuloID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ({0}) and l.fecha >= @Fecha" + ")", Global.TiposVentasSQL); dataContext.Database.ExecuteSqlCommand(sql, new SqlParameter { ParameterName = "@Fecha", SqlDbType = SqlDbType.DateTime, Value = Siete }); DateTime Treinta = DateTime.Now.AddDays(-30); ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Vendidos Mes - 1"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET vendidostreinta = (" + "SELECT SUM(unidades) from lineas l WHERE l.ArticuloID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ({0}) and l.fecha >= @Fecha" + " AND ((SELECT COUNT(*) FROM Escandallo e WHERE e.ArticuloID = Articulos.ArticuloID) = 0)" + ")", Global.TiposVentasSQL); dataContext.Database.ExecuteSqlCommand(sql, new SqlParameter { ParameterName = "@Fecha", SqlDbType = SqlDbType.DateTime, Value = Treinta }); ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Vendidos - 2"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET vendidos = (" + "SELECT SUM(UnidadesArticuloComprado) from lineas l WHERE l.ArticuloCompradoID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ({0}) " + " )" + " WHERE ((SELECT COUNT(*) FROM Escandallo e WHERE e.ArticuloID = Articulos.ArticuloID) > 0)", Global.TiposVentasSQL); dataContext.Database.ExecuteSqlCommand(sql); ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Vendidos Semana - 2"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET vendidossiete = (" + "SELECT SUM(unidades) from lineas l WHERE l.ArticuloCompradoID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ({0}) and l.fecha >= @Fecha" + " )" + " WHERE ((SELECT COUNT(*) FROM Escandallo e WHERE e.ArticuloID = Articulos.ArticuloID) > 0)", Global.TiposVentasSQL); dataContext.Database.ExecuteSqlCommand(sql, new SqlParameter { ParameterName = "Fecha", SqlDbType = SqlDbType.DateTime, Value = Siete }); ButtonFechaActualizacionTotalesArticulo.Text = "Actualizando Vendidos Mes - 2"; Application.DoEvents(); sql = string.Format("UPDATE articulos SET vendidostreinta = (" + "SELECT SUM(unidades) from lineas l WHERE l.ArticuloCompradoID = articulos.ArticuloID AND SUBSTRING(l.Tipo, 3, 1) IN ({0}) and l.fecha >= @Fecha" + " )" + " WHERE ((SELECT COUNT(*) FROM Escandallo e WHERE e.ArticuloID = Articulos.ArticuloID) > 0)", Global.TiposVentasSQL); dataContext.Database.ExecuteSqlCommand(sql, new SqlParameter { ParameterName = "Fecha", SqlDbType = SqlDbType.DateTime, Value = Treinta }); MyEntityModel.Datos datos = dataContext.datos.FirstOrDefault(); if (datos == null) { datos = new MyEntityModel.Datos(); datos.FechaActualizacionTotalesArticulo = DateTime.Now; dataContext.datos.Add(datos); } else { datos.FechaActualizacionTotalesArticulo = DateTime.Now; } dataContext.SaveChanges(); FechaActualizacionTotalesArticulo(); }
private void LoadSource() { var dataContextArticulos = new MyEntityModel.ApplicationDbContextSql(); string were = " Select * from Articulos where ArticuloID > 0 "; string lista = ""; var dataContextRajotero = new MyEntityModel.RajoteroDbContext(); var dataContextRepuestos = new MyEntityModel.RepuestosDeMovilesDbContext(); if (radioGroupRajotero.SelectedIndex != 0) { var a = dataContextRajotero.ps_product.Where(w => w.reference.Trim() != "").Select(s => s.reference.Trim()).ToList(); lista = "'" + String.Join("','", a) + "'"; } if (radioGroupRajotero.SelectedIndex == 1) // Publicados en rajotero { were += " and Codigo in (" + lista + ") "; } if (radioGroupRajotero.SelectedIndex == 2) // Sin Publicar en rajotero { were += " and Codigo not in (" + lista + ") "; } if (radioGroupEscandallo.SelectedIndex == 1) // Con Escandallo { were += " and ArticuloID in (Select ArticuloID from Escandallo) "; } if (radioGroupEscandallo.SelectedIndex == 2) // Sin Escandallo { were += " and ArticuloID not in (Select ArticuloID from Escandallo) "; } if (radioGroupActivos.SelectedIndex == 1) { were += " and Activo = 1 "; } if (radioGroupActivos.SelectedIndex == 2) { were += " and Activo = 0 "; } foreach (DevExpress.XtraEditors.ComboBoxEdit comboBoxEdit in layoutControlCuentas.Controls.OfType <DevExpress.XtraEditors.ComboBoxEdit>()) { if (comboBoxEdit.Name.Contains("Ebay")) { string cuenta = comboBoxEdit.Name.Split(' ')[1]; if (comboBoxEdit.Text != "Todos") { List <string> codigos = dataContextRepuestos.EBAY_SEGUIMIENTO.Where(w => w.VENDEDOR == cuenta).Select(s => s.ARTICULO_MIO.Trim()).ToList(); lista = "'" + String.Join("','", codigos) + "'"; if (comboBoxEdit.Text == "Publicados") { were += " and Codigo in (" + lista + ") "; } if (comboBoxEdit.Text == "Sin publicar") { were += " and Codigo not in (" + lista + ") "; } } } } if (textEditDelEnvio.Text.Trim() != "") { int NumeroEnvio = 0; try { NumeroEnvio = Convert.ToInt16(textEditDelEnvio.Text); } catch { } if (NumeroEnvio != 0) { MyEntityModel.RepuestosDeMovilesDbContext dbContextRepuestos = new MyEntityModel.RepuestosDeMovilesDbContext(); var a = dbContextRepuestos.L_ENVIOS.Where(w => w.CABECERA == NumeroEnvio).Select(s => s.ARTICULO).ToList(); string listaEnvio = "'" + String.Join("','", a) + "'"; if (listaEnvio.Trim() != "") { were += " and Codigo in (" + listaEnvio + ") "; } colUnidadesRecibidas.Visible = true; } else { colUnidadesRecibidas.Visible = false; } } var palabras = textEditPalabras.Text.Split(' '); foreach (string palabra in palabras) { if (palabra.FirstOrDefault() == '-') { var p = palabra.Remove(0, 1); were += " AND nombre not like '%" + p + "%' "; } else { were += " AND nombre like '%" + palabra + "%' "; } } IList <MyEntityModel.Articulo> articulos = dataContextArticulos.Database.SqlQuery <MyEntityModel.Articulo>(were).ToList(); gridControlArticulos.DataSource = articulos; layoutControlGroupFiltros.Text = "Articulos Encontrados " + articulos.Count.ToString(); }