private void CargarSubCuentas() { try { SBDAEGESEntities _Mod = new SBDAEGESEntities(); var _listObj = (from T in _Mod.USR_ArticuloSubCuenta orderby T.Descripcion select T).ToList(); USR_ArticuloSubCuenta _itemSeleccion = new USR_ArticuloSubCuenta(); //Limpia el combo comboBoxSubCuenta.SuspendLayout(); comboBoxSubCuenta.DataSource = null; comboBoxSubCuenta.Items.Clear(); // Carga el item de Seleccion _itemSeleccion.Descripcion = "<Seleccione una Sub Cuenta>"; _itemSeleccion.subCuenta = 0; _listObj.Insert(0, _itemSeleccion); //Carga el combo comboBoxSubCuenta.DisplayMember = "Descripcion"; comboBoxSubCuenta.ValueMember = "subCuenta"; comboBoxSubCuenta.DataSource = _listObj.ToArray(); comboBoxSubCuenta.SelectedIndex = 0; comboBoxSubCuenta.ResumeLayout(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void toolStripButtonSave_Click(object sender, EventArgs e) { try { if (textBoxDescripSub.Text != string.Empty) { SBDAEGESEntities _Mod = new SBDAEGESEntities(); SBDARSCEntities _ModRsc = new SBDARSCEntities(); USR_ArticuloSubCuenta _sub = new USR_ArticuloSubCuenta { Descripcion = textBoxDescripSub.Text, //esDeProducto = true }; //TABLA EGES if (_cuentaId == 0) { _Mod.USR_ArticuloSubCuenta.Add(_sub); _Mod.SaveChanges(); //ahora grabo en tabla de RSCÇ _ModRsc.USR_ArticuloSubCuenta.Add(_sub); _ModRsc.SaveChanges(); textBoxDescripSub.Text = string.Empty; _cuentaId = 0; TraeSubCuentas(); MessageBox.Show("Sub Cuenta creada correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { _sub.subCuenta = _cuentaId; _Mod.Entry(_sub).State = System.Data.Entity.EntityState.Modified; _Mod.SaveChanges(); //ACTUALIZO EN TABLA RSCÇ _sub.subCuenta = _cuentaId; _ModRsc.Entry(_sub).State = System.Data.Entity.EntityState.Modified; _ModRsc.SaveChanges(); textBoxDescripSub.Text = string.Empty; _cuentaId = 0; TraeSubCuentas(); MessageBox.Show("Sub Cuenta actualizada correctamente", "Mensaje", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("Debe ingresar una descripción", "Alerta", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }