/// <summary> /// Link the Delivery and the stock and update the stock. Also add the ComicDelivery for the amounds. /// </summary> /// <param name="dDelivery">DDelivery to use.</param> private void LinkStockToDelivery(DDelivery dDelivery) { using (var command = context.CreateCommand()) { command.AddParameter("delivery_Id", dDelivery.Id); int i = 0; foreach (var comicPair in dDelivery.OrderComics) { command.CommandText = @"Select Stock.ID From Stock " + $"where Stock.ComicID = @comic_Id{i};"; command.AddParameter($"Comic_Id{i}", comicPair.Key.Id); int StockID = (int)command.ExecuteScalar(); command.CommandText = @"insert into DeliveriesComics (DeliveryID, StockID, AmountDelivered) " + $"values (@delivery_Id, @stock_Id{i}, @amount{i});"; command.AddParameter($"stock_Id{i}", StockID); command.AddParameter($"amount{i}", comicPair.Value); command.ExecuteNonQuery(); command.CommandText = @"UPDATE Stock " + $"SET Stock.Stock += @amount{i} " + $"WHERE Stock.ID = @stock_Id{i};"; command.ExecuteNonQuery(); i++; } } }
public static string Eliminar(int idVenta) { DDelivery Obj = new DDelivery(); Obj.IdVenta = idVenta; return(Obj.EliminarVentaDelivery(Obj)); }
/// <summary> /// Sets the id for each comic ordered. /// </summary> /// <param name="toAdd">Delivery contraining no id.</param> private void SetComicIds(DDelivery toAdd) { using (var command = context.CreateCommand()) { int i = 0; foreach (var comic in toAdd.OrderComics.Keys) { command.CommandText = @$ "Select * From Series Where Series.name = @name{i}"; command.AddParameter($"name{i}", comic.Series.Name); int?seriesId = (int?)command.ExecuteScalar(); if (seriesId == null) { throw new DataException($"Series {comic.Series.Name} is not in the database"); } command.CommandText = @$ "Select * From Comics Where Comics.Title = @title{i} AND Comics.SeriesNr = @series_Nr{i} OR @series_Nr{i} IS NULL AND Comics.Series_ID = @series_Id{i};"; command.AddParameter($"title{i}", comic.Title); command.AddParameter($"series_Nr{i}", comic.SeriesNumber); command.AddParameter($"series_Id{i}", seriesId); int?id = (int?)command.ExecuteScalar(); if (id == null) { throw new DataException($"Comic {comic.Title} is not in the database"); } comic.Id = (int)id; i++; } } }
public static string Editar(int idVenta, string estado) { DDelivery Obj = new DDelivery(); Obj.IdVenta = idVenta; Obj.Estado = estado; return(Obj.EditarEstadoDelivery(Obj)); }
public void AddDelivery(Delivery delivery) { DDelivery toAdd = Mapper.toDDelivery(delivery); SetComicIds(toAdd); AddDDelivery(toAdd); LinkStockToDelivery(toAdd); }
public static string InsertarPedidoDelivery(int?idCliente, int?idMesa, DateTime fecha, string estado, string formaPago, decimal descuento, int idTrabajador, string modo, int nroCaja, string tipoCompr, decimal vuelto, string estadoD, DataTable dtDetalle, decimal total, decimal pagaCon, string repartidor, decimal dctoInd, DateTime fechaEntrega, decimal adelanto, int idTrabajador_Cobro, string obs, string motivo, string cliente, string telefono, string tipoCliente, decimal saldo) { DVenta Obj = new DVenta(); Obj.IdCliente = idCliente; Obj.IdMesa = idMesa; Obj.Fecha = fecha; Obj.Estado = estado; Obj.FormaPago = formaPago; Obj.Descuento = descuento; Obj.IdTrabajador = idTrabajador; Obj.Modo = modo; Obj.NroCaja = nroCaja; Obj.FechaEntrega = fechaEntrega; Obj.Adelanto = adelanto; Obj.IdTrabajador_Cobro = idTrabajador_Cobro; Obj.Obs = obs; Obj.Motivo = motivo; Obj.Cliente = cliente; Obj.Telefono = telefono; Obj.TipoCliente = tipoCliente; Obj.Saldo = saldo; List <DDetalleVenta> detalles = new List <DDetalleVenta>(); foreach (DataRow row in dtDetalle.Rows) { DDetalleVenta detalle = new DDetalleVenta(); detalle.IdProducto = Convert.ToInt32(row["Cod"].ToString()); detalle.Kilogramos = Convert.ToDecimal(row["Kg"].ToString()); detalle.Unidad = Convert.ToDecimal(row["NroUnid"].ToString()); detalle.PrecioVenta = Convert.ToDecimal(row["Precio_Un"].ToString()); detalle.Descuento = Convert.ToDecimal(row["Descuento"].ToString()); detalle.Nota = row["Nota"].ToString(); detalle.Tipo = row["Tipo"].ToString(); detalle.Barra = row["Barra"].ToString(); detalle.Estado = row["Estado"].ToString(); detalles.Add(detalle); } DDelivery Obj1 = new DDelivery(); Obj1.TipoCompr = tipoCompr; Obj1.Vuelto = vuelto; Obj1.Estado = estadoD; Obj1.Total = total; Obj1.PagaCon = pagaCon; Obj1.Repartidor = repartidor; Obj1.DctoInd = dctoInd; return(Obj.InsertarPedidoDelivery(Obj, detalles, Obj1)); }
/// <summary> /// Add the info of a DDelivery to the databse. /// </summary> /// <param name="dDelivery">DDelivery to add.</param> private void AddDDelivery(DDelivery dDelivery) { using (var command = context.CreateCommand()) { command.CommandText = $@"Insert into Deliveries (DeliveryDate, Date) " + "values (@deliveryDate ,@date) " + "SELECT CAST(scope_identity() AS int);"; command.AddParameter("date", dDelivery.Date.ToString()); command.AddParameter("deliveryDate", dDelivery.DeliveryDate.ToString()); dDelivery.Id = (int)command.ExecuteScalar(); } }