public DtoLib.Resultado Configuracion_Actualizar_TasaDivisa_ActualizarData(DtoLibSistema.Configuracion.ActualizarTasaDivisa.ActualizarData.Ficha ficha) { var rt = new DtoLib.Resultado(); try { using (var cnn = new sistemaEntities(_cnSist.ConnectionString)) { using (var ts = cnn.Database.BeginTransaction()) { try { var fechaSistema = cnn.Database.SqlQuery <DateTime>("select now()").FirstOrDefault(); var ent = cnn.sistema_configuracion.FirstOrDefault(f => f.codigo == "GLOBAL12"); if (ent == null) { rt.Mensaje = "[ ID ] CONFIGURACION NO ENCONTRADO"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } ent.usuario = ficha.ValorDivisa.ToString(); cnn.SaveChanges(); foreach (var rg in ficha.productosCostoSinDivisa) { var entPrd = cnn.productos.Find(rg.autoPrd); if (entPrd == null) { rt.Mensaje = "[ ID ] Producto, No Encontrado"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } entPrd.divisa = rg.costoDivisa; entPrd.pdf_1 = rg.precioMonedaEnDivisaFull_1; entPrd.pdf_2 = rg.precioMonedaEnDivisaFull_2; entPrd.pdf_3 = rg.precioMonedaEnDivisaFull_3; entPrd.pdf_4 = rg.precioMonedaEnDivisaFull_4; entPrd.pdf_pto = rg.precioMonedaEnDivisaFull_5; cnn.SaveChanges(); var entPrdExt = cnn.productos_ext.Find(rg.autoPrd); if (entPrdExt == null) { rt.Mensaje = "[ ID ] Producto, No Encontrado"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } entPrdExt.pdmf_1 = rg.precioMonedaEnDivisaFull_May_1; entPrdExt.pdmf_2 = rg.precioMonedaEnDivisaFull_May_2; cnn.SaveChanges(); } foreach (var rg in ficha.productosCostoPrecioDivisa) { var p1 = new MySql.Data.MySqlClient.MySqlParameter("@costoProveedor", rg.costoProveedor); var p2 = new MySql.Data.MySqlClient.MySqlParameter("@costoProveedorUnd", rg.costoProveedorUnd); var p3 = new MySql.Data.MySqlClient.MySqlParameter("@costoImportacion", rg.costoImportacion); var p4 = new MySql.Data.MySqlClient.MySqlParameter("@costoImportacionUnd", rg.costoImportacionUnd); var p5 = new MySql.Data.MySqlClient.MySqlParameter("@costoVario", rg.costoVario); var p6 = new MySql.Data.MySqlClient.MySqlParameter("@costoVarioUnd", rg.costoVarioUnd); var p7 = new MySql.Data.MySqlClient.MySqlParameter("@costo", rg.costo); var p8 = new MySql.Data.MySqlClient.MySqlParameter("@costoUnd", rg.costoUnd); var p9 = new MySql.Data.MySqlClient.MySqlParameter("@fecha", fechaSistema.Date); var pa = new MySql.Data.MySqlClient.MySqlParameter("@precio_1", rg.precio_1); var pb = new MySql.Data.MySqlClient.MySqlParameter("@precio_2", rg.precio_2); var pc = new MySql.Data.MySqlClient.MySqlParameter("@precio_3", rg.precio_3); var pd = new MySql.Data.MySqlClient.MySqlParameter("@precio_4", rg.precio_4); var pe = new MySql.Data.MySqlClient.MySqlParameter("@precio_5", rg.precio_5); var pf = new MySql.Data.MySqlClient.MySqlParameter("@auto", rg.autoPrd); var sql = @"update productos set costo_proveedor=@costoProveedor, costo_proveedor_und = @costoProveedorUnd, costo_importacion = @costoImportacion, costo_importacion_und = @costoImportacionUnd, costo_varios = @costoVario, costo_varios_und = @costoVarioUnd, costo = @costo, costo_und = @costoUnd, fecha_ult_costo = @fecha, fecha_cambio = @fecha, precio_1 = @precio_1, precio_2 = @precio_2, precio_3 = @precio_3, precio_4 = @precio_4, precio_pto = @precio_5 where auto=@auto"; var i = cnn.Database.ExecuteSqlCommand(sql, p1, p2, p3, p4, p5, p6, p7, p8, p9, pa, pb, pc, pd, pe, pf); if (i == 0) { rt.Mensaje = "PROBLEMA AL ACTUALIZAR ITEM [" + rg.autoPrd + "]"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } var p11 = new MySql.Data.MySqlClient.MySqlParameter("@precio_may_1", rg.precioMay_1); var p22 = new MySql.Data.MySqlClient.MySqlParameter("@precio_may_2", rg.precioMay_2); var p33 = new MySql.Data.MySqlClient.MySqlParameter("@auto", rg.autoPrd); var sql2 = @"update productos_ext set precio_may_1 = @precio_may_1, precio_may_2 = @precio_may_2 where auto_producto=@auto"; var i2 = cnn.Database.ExecuteSqlCommand(sql2, p11, p22, p33); if (i2 == 0) { rt.Mensaje = "PROBLEMA AL ACTUALIZAR ITEM [" + rg.autoPrd + "]"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } } //foreach (var rg in ficha.productosCostoPrecioDivisa) //{ // var entPrd = cnn.productos.Find(rg.autoPrd); // if (entPrd == null) // { // rt.Mensaje = "[ ID ] Producto, No Encontrado"; // rt.Result = DtoLib.Enumerados.EnumResult.isError; // return rt; // } // entPrd.costo_proveedor = rg.costoProveedor; // entPrd.costo_proveedor_und = rg.costoProveedorUnd; // entPrd.costo_importacion = rg.costoImportacion; // entPrd.costo_importacion_und = rg.costoImportacionUnd; // entPrd.costo_varios = rg.costoVario; // entPrd.costo_varios_und = rg.costoVarioUnd; // entPrd.costo = rg.costo; // entPrd.costo_und = rg.costoUnd; // entPrd.fecha_ult_costo = fechaSistema.Date; // entPrd.fecha_cambio = fechaSistema.Date; // entPrd.precio_1 = rg.precio_1; // entPrd.precio_2 = rg.precio_2; // entPrd.precio_3 = rg.precio_3; // entPrd.precio_4 = rg.precio_4; // entPrd.precio_pto = rg.precio_5; // cnn.SaveChanges(); //} cnn.Configuration.AutoDetectChangesEnabled = false; var lentHist = new List <productos_costos>(); foreach (var rg in ficha.productosCostoPrecioDivisa) { var entHist = new productos_costos() { auto_producto = rg.autoPrd, costo = rg.costo, costo_divisa = rg.costoDivisa, divisa = ficha.ValorDivisa, documento = rg.documento, estacion = ficha.EstacionEquipo, fecha = fechaSistema.Date, hora = fechaSistema.ToShortTimeString(), nota = rg.nota, serie = rg.serie, usuario = ficha.nombreUsuario, }; lentHist.Add(entHist); } cnn.productos_costos.AddRange(lentHist); cnn.SaveChanges(); var lentHist_2 = new List <productos_precios>(); foreach (var rg in ficha.productosPrecioHistorico) { var entHist = new productos_precios() { auto_producto = rg.autoPrd, estacion = ficha.EstacionEquipo, fecha = fechaSistema.Date, hora = fechaSistema.ToShortTimeString(), usuario = ficha.nombreUsuario, nota = rg.nota, precio = rg.precio, precio_id = rg.idPrecio, }; lentHist_2.Add(entHist); } cnn.productos_precios.AddRange(lentHist_2); cnn.SaveChanges(); ts.Commit(); } catch (DbUpdateException ex) { var dbUpdateEx = ex as DbUpdateException; var sqlEx = dbUpdateEx.InnerException; if (sqlEx != null) { var exx = (MySql.Data.MySqlClient.MySqlException)sqlEx.InnerException; if (exx != null) { if (exx.Number == 1451) { rt.Mensaje = "REGISTRO CONTIENE DATA RELACIONADA"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } if (exx.Number == 1062) { rt.Mensaje = exx.Message; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } rt.Mensaje = exx.Message; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } } rt.Mensaje = ex.Message; rt.Result = DtoLib.Enumerados.EnumResult.isError; } finally { cnn.Configuration.AutoDetectChangesEnabled = false; } } } } catch (Exception e) { rt.Mensaje = e.Message; rt.Result = DtoLib.Enumerados.EnumResult.isError; } return(rt); }
public DtoLib.Resultado ReconversionMonetaria_Actualizar(DtoLibSistema.ReconversionMonetaria.Actualizar.Ficha ficha) { var rt = new DtoLib.Resultado(); try { using (var cnn = new sistemaEntities(_cnSist.ConnectionString)) { using (var ts = cnn.Database.BeginTransaction()) { try { var fechaSistema = cnn.Database.SqlQuery <DateTime>("select now()").FirstOrDefault(); var ent = cnn.sistema_configuracion.FirstOrDefault(f => f.codigo == "GLOBAL12"); if (ent == null) { rt.Mensaje = "[ ID ] CONFIGURACION NO ENCONTRADO" + Environment.NewLine + "TASA DIVISA"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } ent.usuario = ficha.tasaDivisa.ToString(); cnn.SaveChanges(); var entTasaPos = cnn.sistema_configuracion.FirstOrDefault(f => f.codigo == "GLOBAL48"); if (entTasaPos == null) { rt.Mensaje = "[ ID ] CONFIGURACION NO ENCONTRADO" + Environment.NewLine + "TASA DIVISA POS"; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } entTasaPos.usuario = ficha.tasaDivisaPos.ToString(); cnn.SaveChanges(); var entRec = new reconversion_monetaria() { fecha = fechaSistema.Date, hora = fechaSistema.ToShortTimeString(), factor_reconversion = ficha.factorReconverion, factor_divisa = ficha.tasaDivisa, usuario = ficha.usuario, codigo_usuario = ficha.codUsuario, idUsuario = ficha.idUsuario, equipo_estacion = ficha.equipoEstacion, items_afectados = ficha.ItemsAfectados, proveedores_afectados = ficha.ProvAfectados, saldos_por_pagar_afectados = ficha.SaldoPorPagarAfectados, }; cnn.reconversion_monetaria.Add(entRec); cnn.SaveChanges(); foreach (var rg in ficha.Producto) { var entPrd = cnn.productos.Find(rg.autoId); if (entPrd == null) { rt.Mensaje = "[ ID ] Producto No Encontrado: " + rg.autoId + Environment.NewLine + rg.nombre; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } entPrd.costo_proveedor = rg.costoPrv; entPrd.costo_proveedor_und = rg.costoPrvUnd; entPrd.costo_promedio = rg.costoProm; entPrd.costo_promedio_und = rg.costoPromUnd; entPrd.costo = rg.costo; entPrd.costo_und = rg.costoUnd; entPrd.fecha_cambio = fechaSistema.Date; entPrd.precio_1 = rg.precio1; entPrd.precio_2 = rg.precio2; entPrd.precio_3 = rg.precio3; entPrd.precio_4 = rg.precio4; entPrd.precio_pto = rg.precio5; cnn.SaveChanges(); } foreach (var rg in ficha.Proveedor) { var entPrv = cnn.proveedores.Find(rg.autoId); if (entPrv == null) { rt.Mensaje = "[ ID ] Proveedor No Encontrado: " + rg.autoId + Environment.NewLine + rg.nombre; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } entPrv.anticipos = rg.anticipos; entPrv.debitos = rg.debitos; entPrv.creditos = rg.creditos; entPrv.saldo = rg.saldo; entPrv.disponible = rg.disponible; cnn.SaveChanges(); } foreach (var rg in ficha.SaldoPorPagar) { var entCxP = cnn.cxp.Find(rg.autoDoc); if (entCxP == null) { rt.Mensaje = "[ ID ] Saldo Por Pagar No Encontrado: " + rg.autoDoc + Environment.NewLine + rg.docNumero; rt.Result = DtoLib.Enumerados.EnumResult.isError; return(rt); } entCxP.importe = rg.importe; entCxP.acumulado = rg.acumulado; entCxP.resta = rg.resta; cnn.SaveChanges(); } cnn.Configuration.AutoDetectChangesEnabled = false; var lentHist = new List <productos_costos>(); foreach (var rg in ficha.HistoricoCosto) { var entHist = new productos_costos() { auto_producto = rg.autoPrd, costo = rg.costo, costo_divisa = rg.costoDivisa, divisa = rg.tasaDivisa, documento = rg.documento, estacion = rg.estacionEquipo, fecha = fechaSistema.Date, hora = fechaSistema.ToShortTimeString(), nota = rg.nota, serie = rg.serie, usuario = rg.usuario, }; lentHist.Add(entHist); } cnn.productos_costos.AddRange(lentHist); cnn.SaveChanges(); var lentHist_2 = new List <productos_precios>(); foreach (var rg in ficha.HistoricoPrecio) { var entHist = new productos_precios() { auto_producto = rg.autoPrd, estacion = rg.estacionEquipo, fecha = fechaSistema.Date, hora = fechaSistema.ToShortTimeString(), usuario = rg.usuario, nota = rg.nota, precio = rg.precio, precio_id = rg.idPrecio, }; lentHist_2.Add(entHist); } cnn.productos_precios.AddRange(lentHist_2); cnn.SaveChanges(); ts.Commit(); } catch (DbEntityValidationException e) { var msg = ""; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { msg += ve.ErrorMessage; } } rt.Mensaje = msg; rt.Result = DtoLib.Enumerados.EnumResult.isError; } catch (System.Data.Entity.Infrastructure.DbUpdateException e) { var msg = ""; foreach (var eve in e.Entries) { //msg += eve.m; foreach (var ve in eve.CurrentValues.PropertyNames) { msg += ve.ToString(); } } rt.Mensaje = msg; rt.Result = DtoLib.Enumerados.EnumResult.isError; } finally { cnn.Configuration.AutoDetectChangesEnabled = false; } } } } catch (Exception e) { rt.Mensaje = e.Message; rt.Result = DtoLib.Enumerados.EnumResult.isError; } return(rt); }
public DtoLib.Resultado CostoProducto_Actualizar(DtoLibInventario.Costo.Editar.Ficha ficha) { var result = new DtoLib.Resultado(); try { using (var cnn = new invEntities(_cnInv.ConnectionString)) { using (var ts = new TransactionScope()) { var fechaSistema = cnn.Database.SqlQuery <DateTime>("select now()").FirstOrDefault(); var entPrd = cnn.productos.Find(ficha.autoProducto); if (entPrd == null) { result.Mensaje = "[ ID ] Producto, No Encontrado"; result.Result = DtoLib.Enumerados.EnumResult.isError; return(result); } entPrd.costo_proveedor = ficha.costoProveedor; entPrd.costo_proveedor_und = ficha.costoProveedorUnd; entPrd.costo_importacion = ficha.costoImportacion; entPrd.costo_importacion_und = ficha.costoImportacionUnd; entPrd.costo_varios = ficha.costoVario; entPrd.costo_varios_und = ficha.costoVarioUnd; entPrd.costo = ficha.costoFinal; entPrd.costo_und = ficha.costoFinalUnd; entPrd.costo_promedio = ficha.costoPromedio; entPrd.costo_promedio_und = ficha.costoPromedioUnd; entPrd.divisa = ficha.costoDivisa; entPrd.fecha_ult_costo = fechaSistema.Date; entPrd.fecha_cambio = fechaSistema.Date; if (ficha.precio != null) { entPrd.precio_1 = ficha.precio.pn1; entPrd.precio_2 = ficha.precio.pn2; entPrd.precio_3 = ficha.precio.pn3; entPrd.precio_4 = ficha.precio.pn4; entPrd.precio_pto = ficha.precio.pn5; entPrd.utilidad_1 = ficha.precio.ut1; entPrd.utilidad_2 = ficha.precio.ut2; entPrd.utilidad_3 = ficha.precio.ut3; entPrd.utilidad_4 = ficha.precio.ut4; entPrd.utilidad_pto = ficha.precio.ut5; } cnn.SaveChanges(); var entHist = new productos_costos() { auto_producto = ficha.autoProducto, costo = ficha.historia.costo, costo_divisa = ficha.historia.divisa, divisa = ficha.historia.tasaCambio, documento = ficha.historia.documento, estacion = ficha.estacion, fecha = fechaSistema.Date, hora = fechaSistema.ToShortTimeString(), nota = ficha.historia.nota, serie = ficha.historia.serie, usuario = ficha.nombreUsuario, }; cnn.productos_costos.Add(entHist); cnn.SaveChanges(); ts.Complete(); } } } catch (DbEntityValidationException e) { var msg = ""; foreach (var eve in e.EntityValidationErrors) { foreach (var ve in eve.ValidationErrors) { msg += ve.ErrorMessage; } } result.Mensaje = msg; result.Result = DtoLib.Enumerados.EnumResult.isError; } catch (System.Data.Entity.Infrastructure.DbUpdateException e) { var msg = ""; foreach (var eve in e.Entries) { //msg += eve.m; foreach (var ve in eve.CurrentValues.PropertyNames) { msg += ve.ToString(); } } result.Mensaje = msg; result.Result = DtoLib.Enumerados.EnumResult.isError; } catch (Exception e) { result.Mensaje = e.Message; result.Result = DtoLib.Enumerados.EnumResult.isError; } return(result); }