public void UpdatePrecio(List <Articulos> artList) { try { this.OpenConnection(); foreach (Articulos art in artList) { NpgsqlCommand cmdSave = new NpgsqlCommand("update articulos set " + " precio=@precio where id=@id ", npgsqlConn); cmdSave.Parameters.Add("@id", NpgsqlTypes.NpgsqlDbType.Text).Value = art.ID; cmdSave.Parameters.Add("@precio", NpgsqlTypes.NpgsqlDbType.Double).Value = art.Precio; cmdSave.ExecuteNonQuery(); } } finally { CloseConnection(); //actualizo cuenta corriente abierta para los articulos q aun estan abiertos try { foreach (Articulos art in artList) { VentasAdap vAdap = new VentasAdap(); vAdap.ActualizarPrecioDeCuentasCorrientesConDeuda(art.ID, art.Precio); } } catch { } } }
public void ExportarVentas() { VentasAdap vAdap = new VentasAdap(); Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application(); excel.Application.Workbooks.Add(true); excel.Cells[1, 1] = DateTime.Now.Date; excel.Cells[1, 2] = "VENTAS REALIZADAS EN EL DIA"; excel.Cells[4, 1] = "CLIENTE"; excel.Cells[4, 2] = "NÚMERO DE VENTA"; excel.Cells[4, 3] = "FORMA DE PAGO"; excel.Cells[4, 4] = "TOTAL"; int filas = 5; int columnaP = 1; int columnaC = 2; int columnaT = 4; int columnaF = 3; foreach (Venta v in vAdap.GetFiltroTiempo(DateTime.Now, DateTime.Now)) { excel.Cells[filas + 1, columnaP] = v.Nombre_cliente; excel.Cells[filas + 1, columnaC] = v.Id_Venta; excel.Cells[filas + 1, columnaT] = v.Total.ToString(); excel.Cells[filas + 1, columnaF] = v.FormaPago; filas++; } string subPath = DateTime.Now.Year + "-" + DateTime.Now.Month.ToString() + "\\" + DateTime.Now.Day.ToString() + "\\"; string pathString = System.IO.Path.Combine(@"C:\Ventas", subPath); System.IO.Directory.CreateDirectory(pathString); string fileName = System.IO.Path.GetRandomFileName(); excel.Columns.AutoFit(); excel.Visible = false; string nombre_excel = "Ventas " + DateTime.Now.Day.ToString() + ".xlsx"; if (File.Exists(pathString + nombre_excel) == true) { File.Delete(pathString + nombre_excel); } excel.ActiveWorkbook.Protect("juanlucho"); excel.ActiveWorkbook.Password = "******"; excel.ActiveWorkbook.SaveAs(pathString + nombre_excel); excel.Workbooks.Close(); }