void MoverDatos(BO.Models.Suplidores MyComp) { //else if(ctr.Tag == MyComp.COM_DESCRIPCION) foreach (Control ctr in tabPage2.Controls) { if (ctr.Tag == null) { continue; } switch (ctr.Tag.ToString()) { case "SUP_ID": ctr.Text = MyComp.SUP_ID.ToString(); break; case "SUP_CODIGO": ctr.Text = MyComp.SUP_CODIGO.ToString(); break; case "SUP_NOMBRE": ctr.Text = MyComp.SUP_NOMBRE.ToString(); break; case "SUP_ESTADO": ctr.Text = MyComp.SUP_ESTADO.ToString(); break; case "ORI_ID": if (MyComp.ORI_ID != null) { ((ComboBox)ctr).SelectedValue = Convert.ToInt32(MyComp.ORI_ID.ToString()); } else { ((ComboBox)ctr).SelectedValue = -1; } break; } } }
bool SalvarDatos() { bool bRetorno = false; int iId = -1; //CompaniasRecord oCom = new CompaniasRecord(); BO.Models.Suplidores oCom; if (usrbntMant1.bAdiciona == false) { iId = Convert.ToInt32(this.textId.Text); oCom = unitOfWork.SuplidoresRepository.GetByID(iId); } else { oCom = new BO.Models.Suplidores(); } oCom.SUP_NOMBRE = this.txtNombreCorto.Text.ToString(); oCom.SUP_CODIGO = this.txtCodigo.Text.ToString(); oCom.SUP_ESTADO = cmbEstado.Text.ToString(); oCom.ORI_ID = Convert.ToInt32(cmbOrigen.SelectedValue); try { if (usrbntMant1.bAdiciona == false) { unitOfWork.SuplidoresRepository.Update(oCom); } else { unitOfWork.SuplidoresRepository.Insert(oCom); } unitOfWork.Save(); bRetorno = true; usrbntMant1.bExito = true; } catch (System.Data.Entity.Validation.DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { string s = ""; foreach (var ve in eve.ValidationErrors) { s += ve.ErrorMessage + "\n"; } MessageBox.Show("Existen los siguientes errores:" + s, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error); } //throw; } catch (DataException ex) { throw ex; } return(bRetorno); }