void MoverDatos(BO.Models.Modulos MyComp) { //else if(ctr.Tag == MyComp.COM_DESCRIPCION) foreach (Control ctr in tabPage2.Controls) { if (ctr.Tag == null) { continue; } switch (ctr.Tag.ToString()) { case "MOD_ID": ((TextBox)ctr).Text = MyComp.MOD_ID.ToString(); break; case "MOD_NOMBRE": ((TextBox)ctr).Text = MyComp.MOD_NOMBRE; break; case "MOD_DESCRIPCION": ((TextBox)ctr).Text = MyComp.MOD_DESCRIPCION; break; case "MOD_TIPO": ((ComboBox)ctr).SelectedValue = MyComp.TIPO_ID; break; case "MOD_ESTADO": ((CheckBox)ctr).Checked = MyComp.MOD_ESTADO; break; } } }
bool SalvarDatos() { int iId = -1; bool bRetorno = false; //CompaniasRecord oCom = new CompaniasRecord(); BO.Models.Modulos oCom; if (usrbntMant1.bAdiciona == false) { iId = Convert.ToInt32(this.textId.Text); oCom = unitOfWork.ModulosRepository.GetByID(iId); } else { oCom = new BO.Models.Modulos(); } oCom.TIPO_ID = Convert.ToInt32(this.cmbTipoId.SelectedValue.ToString()); oCom.MOD_NOMBRE = txtNombre.Text; oCom.MOD_DESCRIPCION = txtDescripcion.Text; oCom.MOD_ESTADO = chkEstado.Checked; //oCom.CARGO_ID = textCargoId.Text; try { if (usrbntMant1.bAdiciona == false) { unitOfWork.ModulosRepository.Update(oCom); } else { unitOfWork.ModulosRepository.Insert(oCom); } unitOfWork.Save(); bRetorno = true; usrbntMant1.bExito = true; } catch (System.Data.Entity.Validation.DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { string s = ""; /* * Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", * eve.Entry.Entity.GetType().Name, eve.Entry.State); */ foreach (var ve in eve.ValidationErrors) { s += ve.ErrorMessage + "\n"; /*Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", * ve.PropertyName, ve.ErrorMessage);*/ } MessageBox.Show("Existen los siguientes errores:" + s, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error); } //throw; } catch (DataException ex) { throw ex; } return(bRetorno); }