public Boolean ModificarDB_proceso_cerrado(in_Ing_Egr_Inven_Info info, ref string msgs) { try { using (EntitiesInventario Context = new EntitiesInventario()) { in_Ing_Egr_Inven Entity = Context.in_Ing_Egr_Inven.FirstOrDefault(q => q.IdEmpresa == info.IdEmpresa && q.IdSucursal == info.IdSucursal && q.IdMovi_inven_tipo == info.IdMovi_inven_tipo && q.IdNumMovi == info.IdNumMovi); if (Entity != null) { Entity.cm_observacion = info.cm_observacion; Entity.cm_fecha = info.cm_fecha.Date; Entity.CodMoviInven = info.CodMoviInven; Entity.IdMotivo_Inv = info.IdMotivo_Inv; Context.SaveChanges(); foreach (var item in info.listIng_Egr) { if (item.IdEmpresa_inv != null) { in_movi_inve_Info info_movi = new in_movi_inve_Info(); info_movi.IdEmpresa = Convert.ToInt32(item.IdEmpresa_inv); info_movi.IdSucursal = Convert.ToInt32(item.IdSucursal_inv); info_movi.IdBodega = Convert.ToInt32(item.IdBodega_inv); info_movi.IdMovi_inven_tipo = Convert.ToInt32(item.IdMovi_inven_tipo_inv); info_movi.IdNumMovi = Convert.ToDecimal(item.IdNumMovi_inv); info_movi.cm_observacion = info.cm_observacion; info_movi.cm_fecha = info.cm_fecha; info_movi.CodMoviInven = info.CodMoviInven; in_movi_inve_Data data_movi = new in_movi_inve_Data(); data_movi.ModificarDB_proceso_cerrado(info_movi, ref msgs); } else { in_Ing_Egr_Inven_det_Data odata = new in_Ing_Egr_Inven_det_Data(); if (info.IdBodega != null) { item.IdBodega = info.IdBodega; odata.ModificarDB_proceso_cerrado(item); Entity.IdBodega = info.IdBodega; Context.SaveChanges(); } msgs = "Se actualizó la transacción exitosamente."; } } } } return(true); } catch (Exception ex) { string arreglo = ToString(); tb_sis_Log_Error_Vzen_Data oDataLog = new tb_sis_Log_Error_Vzen_Data(); tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now); oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje); mensaje = ex.ToString() + " " + ex.Message; throw new Exception(ex.ToString()); } }
public Boolean GuardarDB(in_Ing_Egr_Inven_Info info, ref decimal IdNumMovi, ref string mensaje) { try { try { using (EntitiesInventario Context = new EntitiesInventario()) { var Address = new in_Ing_Egr_Inven(); Address.IdEmpresa = info.IdEmpresa; Address.IdSucursal = info.IdSucursal; Address.IdBodega = info.IdBodega; Address.IdNumMovi = info.IdNumMovi = GetId(info.IdEmpresa, info.IdSucursal, info.IdMovi_inven_tipo); Address.signo = info.signo; Address.IdMotivo_oc = info.IdMotivo_oc == 0 ? null : info.IdMotivo_oc; Address.IdMotivo_Inv = info.IdMotivo_Inv == 0 ? null : info.IdMotivo_Inv; IdNumMovi = info.IdNumMovi; Address.IdMovi_inven_tipo = info.IdMovi_inven_tipo; Address.CodMoviInven = (info.CodMoviInven == "" || info.CodMoviInven == null) ? IdNumMovi.ToString() : info.CodMoviInven; Address.cm_observacion = (info.cm_observacion == "") ? "" : info.cm_observacion; Address.cm_fecha = info.cm_fecha == null ? DateTime.Now : info.cm_fecha.Date; Address.IdUsuario = info.IdUsuario; Address.Fecha_Transac = DateTime.Now; Address.nom_pc = info.nom_pc; Address.ip = info.ip; Address.Estado = "A"; Address.IdCentroCosto = info.IdCentroCosto; Address.IdCentroCosto_sub_centro_costo = info.IdCentroCosto_sub_centro_costo; Address.IdResponsable = info.IdResponsable; Context.in_Ing_Egr_Inven.Add(Address); Context.SaveChanges(); //Graba Detalle in_Ing_Egr_Inven_det if (info.listIng_Egr.Count() != 0) { int sec = 0; foreach (var item in info.listIng_Egr) { sec = sec + 1; item.IdEmpresa = info.IdEmpresa; item.IdSucursal = info.IdSucursal; item.IdMovi_inven_tipo = info.IdMovi_inven_tipo; if (item.IdBodega == null || item.IdBodega == 0) { item.IdBodega = Convert.ToInt32(info.IdBodega); } item.IdNumMovi = IdNumMovi; item.Secuencia = sec; } in_Ing_Egr_Inven_det_Data odata = new in_Ing_Egr_Inven_det_Data(); odata.GuardarDB(info.listIng_Egr); } mensaje = "Grabación ok.."; } return(true); } catch (DbEntityValidationException ex) { string arreglo = ToString(); tb_sis_Log_Error_Vzen_Data oDataLog = new tb_sis_Log_Error_Vzen_Data(); tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now); oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje); mensaje = ex.ToString() + " " + ex.Message; mensaje = "Error al Grabar" + ex.Message; throw new Exception(ex.ToString()); } } catch (Exception ex) { string arreglo = ToString(); tb_sis_Log_Error_Vzen_Data oDataLog = new tb_sis_Log_Error_Vzen_Data(); tb_sis_Log_Error_Vzen_Info Log_Error_sis = new tb_sis_Log_Error_Vzen_Info(ex.ToString(), "", arreglo, "", "", "", "", "", DateTime.Now); oDataLog.Guardar_Log_Error(Log_Error_sis, ref mensaje); mensaje = ex.ToString() + " " + ex.Message; throw new Exception(ex.ToString()); } }