public bool saveAccountType(account_types accountType, bool isNew) { // Validation string errors = validate(accountType); if (errors.Length > 0) { MessageBox.Show( errors, "Error de validación", MessageBoxButtons.OK, MessageBoxIcon.Error ); return(false); } if (isNew) { entities.account_types.Add(accountType); } entities.SaveChanges(); loadAccountTypes(""); return(true); }
private void btnSave_Click(object sender, EventArgs e) { bool saved = false; if (accountType == null) { account_types newAccountType = new account_types { description = txtDescription.Text, type = cbType.Text, state = rbActive.Checked }; saved = MnjTipoCuenta.getInstance().saveAccountType(newAccountType, true); } else { accountType.description = txtDescription.Text; accountType.type = cbType.Text; accountType.state = rbActive.Checked; saved = MnjTipoCuenta.getInstance().saveAccountType(accountType, false); } if (saved) { MessageBox.Show( "Datos almacenados con éxito", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information ); this.Close(); } }
private String validate(account_types accountType) { StringBuilder sb = new StringBuilder(); foreach (var prop in accountType.GetType().GetProperties()) { if (prop.PropertyType == typeof(string)) { prop.SetValue(accountType, ((string)prop.GetValue(accountType)).Trim()); } } if (accountType.description.Length == 0) { sb.Append("- El campo descripción es obligatorio\n"); } return(sb.ToString()); }
public void setTipoCuenta(account_types accountType) { this.accountType = accountType; // Fill fields txtDescription.Text = accountType.description; cbType.Text = accountType.type; if (accountType.state) { rbActive.Checked = true; rbInactive.Checked = false; } else { rbInactive.Checked = true; rbActive.Checked = false; } // End fill fields }
private void btnDelete_Click(object sender, EventArgs e) { DataGridViewRow row = null; if (dgvAccountTypes.SelectedRows.Count == 1) { row = dgvAccountTypes.SelectedRows[0]; } else if (dgvAccountTypes.SelectedCells.Count == 1) { int i = dgvAccountTypes.SelectedCells[0].RowIndex; row = dgvAccountTypes.Rows[i]; } else { MessageBox.Show( "Debe seleccionar solo 1 tipo de cuenta a eliminar", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information ); } if (row != null) { int id = Int32.Parse(row.Cells[0].Value.ToString()); account_types accountType = (from em in entities.account_types where em.id == id select em).First(); if (accountType == null) { MessageBox.Show( "Tipo de Cuenta no encontrada", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information ); } else { DialogResult deleteIt = MessageBox.Show( "¿Estás seguro que quieres eliminar este tipo de cuenta?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Question ); if (deleteIt == DialogResult.Yes) { entities.account_types.Remove(accountType); try { entities.SaveChanges(); MessageBox.Show( "Tipo de Cuenta eliminada con éxito", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information ); loadAccountTypes(""); } catch (Exception ex) { MessageBox.Show( "¡Este Tipo de Cuenta se encuentra en uso!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error ); ConnectionDB.getInstance().resetConnection(); } } } } }