/// <summary> /// Metodo el cual esta mostrando los datos generales de las venta /// </summary> public static void printFooter() { DataTable dtFooter = new DataTable(); //Agregando las columnas al data table dtFooter.Columns.AddRange(new DataColumn[] { new DataColumn("TIPO_PAGO", typeof(string)), new DataColumn("CANTIDAD_ARTICULOS", typeof(int)), new DataColumn("SUBTOTAL", typeof(string)), new DataColumn("IVA", typeof(string)), new DataColumn("TOTAL", typeof(string)) }); // e ir ingresando los a las filas segun la columna los datos guardados en las variables staticas var row = dtFooter.NewRow(); row["TIPO_PAGO"] = "EFECTIVO"; row["CANTIDAD_ARTICULOS"] = quantityOfItems; row["SUBTOTAL"] = "$ " + subtotal; row["IVA"] = "$ " + iva; row["TOTAL"] = "$ " + total; dtFooter.Rows.Add(row); //Clase para imprimir el data table en forma de tabla ExtensionDataTable.PrintToConsole(dtFooter); }
/// <summary> /// Metodo que realiza la logia de la venta /// </summary> /// <param name="dt">Data table el cual guardara los datos de la venta</param> public static void Ventas(DataTable dt) { Console.Clear(); Product p = new Product(); string CodBar = string.Empty; int resp, otherP; Console.WriteLine("================================================================================================="); Console.WriteLine(" ||\t\t\t\t\t\t!!!VENTAS¡¡¡\t\t\t\t\t\t||"); Console.WriteLine("================================================================================================="); do { Console.Clear(); Console.Write("\nCodigo de Barras:"); CodBar = Console.ReadLine(); // Mandar a llamar el metodo para encontrar el producto por medio del codigo de barras findProdoductByBarCode(CodBar, dt); // Clase el cual estara imprimiendo el data table enforma de tabla ExtensionDataTable.PrintToConsole(dt); Console.WriteLine("\n"); //Metodo que esta mostrando el data table con los datos generales de la venta printFooter(); Console.WriteLine("\nDeseas Comprar otro Articulo?\n" + "1.- Si\n" + "2.- No"); resp = Convert.ToInt32(Console.ReadLine()); if (resp > 2 || resp < 1) { Console.WriteLine("\t !!Porfavor Ingresa una de las Respuestas Mostradas¡¡"); } } while (resp == 1); if (resp == 2) { Console.Clear(); string msgError = string.Empty; // Objeto de la clase venta para guardar los datos Sale sale = new Sale(); sale.Sucursal = "Apodaca Centro"; sale.Fecha = DateTime.Now; sale.Importe = total; sale.QuantityOfItems = quantityOfItems; sale.Caja = "Default"; // Llamar al metodo que valida si la insercion de la tabla venta fue realizada msgError = BusinessLogicLayer.SaleBLL.insertSale(sale); if (string.IsNullOrEmpty(msgError)) { //Obtener el Ultimo registro actualizado de la Clase SALE int saleId = BusinessLogicLayer.SaleBLL.getLastRegister(); //Validar si obtuvimos una id de la clase Sale if (saleId > 0) { // Foreach que recore el data table con los detalles del producto a comprar foreach (DataRow row in dt.Rows) { //Objeto de la entidad DetalleVenta para guardar los datos DetalleVenta detalleVenta = new DetalleVenta(); // Pasar los datos del data table al objeto detalleVenta.IdVenta = saleId; detalleVenta.IdProducto = Convert.ToInt32(BusinessLogicLayer.ProductBLL.getProductIdByCodeBar(row["Codigo_Barras"].ToString())); detalleVenta.Cantidad = Convert.ToInt32(row["CANTIDAD"].ToString()); detalleVenta.Importe = Convert.ToDouble(row["Precio_Unitario"].ToString()); // Guardar los datos a variables staticas para poder hacer la modificacion de la resta de cantidad // segun los producto comprado string codBar = row["Codigo_Barras"].ToString(); int quantity = Convert.ToInt32(row["CANTIDAD"].ToString()); //Una ves Agregado los datos al objeto detalleventa entonces se van a insertar a la tabla // Llamar el metodo a validar la insercion de los datos en la clase DetalleVenta bool isCheked = BusinessLogicLayer.DetalleVentaBLL.insertDetalleVenta(detalleVenta); // Metodo para Modifcar la nueva cantidad de la clase Product BusinessLogicLayer.ProductBLL.modifyQuantityOfItems(codBar, quantity); if (isCheked) { Console.Clear(); Console.WriteLine("\n\tGRACIAS POR SU COMPRA, VUELVA PRONTO"); Console.ReadLine(); } } } } else { Console.WriteLine(msgError); Console.ReadLine(); } } }