public void setCuentaContable(countables_accounts countableAccount)
        {
            this.countableAccount = countableAccount;
            loadMayorAccount(countableAccount.level);
            txtDescription.Text           = countableAccount.description;
            chkbAllowTransactions.Checked = countableAccount.allow_transaction;
            cbLevel.SelectedIndex         = countableAccount.level - 1;

            for (int x = 0; x < cbMajorAccount.Items.Count; x++)
            {
                countables_accounts tempCountableAccount =
                    (countables_accounts)cbMajorAccount.Items[x];

                if (tempCountableAccount.id == countableAccount.account_major)
                {
                    cbMajorAccount.SelectedIndex = x;
                    break;
                }
            }

            if (countableAccount.state)
            {
                rbActive.Checked   = true;
                rbInactive.Checked = false;
            }
            else
            {
                rbActive.Checked   = false;
                rbInactive.Checked = true;
            }
        }
Exemplo n.º 2
0
        public bool saveAccountCountable(countables_accounts accountCountable, bool isNew)
        {
            // Validation
            string errors = validate(accountCountable);

            if (errors.Length > 0)
            {
                MessageBox.Show(
                    errors,
                    "Error de validación",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                return(false);
            }

            if (isNew)
            {
                entities.countables_accounts.Add(accountCountable);
            }

            try
            {
                entities.SaveChanges();

                MessageBox.Show(
                    "¡Cambios guardados con éxito!",
                    "Información",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );

                loadCountablesAccounts("");
                return(true);
            }
            catch (Exception ex) {
                MessageBox.Show(
                    "¡No se pudo guardar los cambios!",
                    "Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error
                    );

                loadCountablesAccounts("");
                return(false);
            }
        }
Exemplo n.º 3
0
        private void btnFilter_Click(object sender, EventArgs e)
        {
            String account = "";
            countables_accounts cAccount = ((countables_accounts)cbAccounts.SelectedItem);

            if (cAccount.id != 0)
            {
                account = cAccount.description;
            }

            DateTime dateFrom = new DateTime(dtFrom.Value.Year, dtFrom.Value.Month, dtFrom.Value.Day);
            DateTime dateTo   = new DateTime(dtTo.Value.Year, dtTo.Value.Month, dtTo.Value.Day);

            dateTo = dateTo.AddMilliseconds(-1);
            dateTo = dateTo.AddDays(1);
            loadMovements(account, txtDescription.Text, dateFrom, dateTo);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool saved = false;

            if (countableAccount == null)
            {
                countables_accounts newCountableAccount = new countables_accounts
                {
                    description       = txtDescription.Text,
                    account_type      = ((account_types)cbType.SelectedItem).id,
                    allow_transaction = chkbAllowTransactions.Checked,
                    level             = (int)cbLevel.SelectedItem,
                    balance           = 0,
                    state             = rbActive.Checked
                };

                if (newCountableAccount.level != 1)
                {
                    newCountableAccount.account_major = ((countables_accounts)cbMajorAccount.SelectedItem).id;
                }

                saved = MnjCuentaContable.getInstance().saveAccountCountable(newCountableAccount, true);
            }
            else
            {
                countableAccount.description       = txtDescription.Text;
                countableAccount.account_type      = ((account_types)cbType.SelectedItem).id;
                countableAccount.allow_transaction = chkbAllowTransactions.Checked;
                countableAccount.level             = (int)cbLevel.SelectedItem;
                countableAccount.state             = rbActive.Checked;

                if (countableAccount.level != 1)
                {
                    countableAccount.account_major = ((countables_accounts)cbMajorAccount.SelectedItem).id;
                }

                saved = MnjCuentaContable.getInstance().saveAccountCountable(countableAccount, false);
            }

            if (saved)
            {
                this.Close();
            }
        }
Exemplo n.º 5
0
        public String validate(countables_accounts countableAccount)
        {
            StringBuilder sb = new StringBuilder();

            foreach (var prop in countableAccount.GetType().GetProperties())
            {
                if (prop.PropertyType == typeof(string))
                {
                    prop.SetValue(countableAccount, ((string)prop.GetValue(countableAccount)).Trim());
                }
            }

            if (countableAccount.description.Length == 0)
            {
                sb.Append("- El campo descripción es obligatorio\n");
            }

            if (countableAccount.level > 1 && countableAccount.account_major == null)
            {
                sb.Append("El campo cuenta mayor es obligatorio\n");
            }
            return(sb.ToString());
        }
Exemplo n.º 6
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = null;

            if (dgvCountablesAccounts.SelectedRows.Count == 1)
            {
                row = dgvCountablesAccounts.SelectedRows[0];
            }
            else if (dgvCountablesAccounts.SelectedCells.Count == 1)
            {
                int i = dgvCountablesAccounts.SelectedCells[0].RowIndex;
                row = dgvCountablesAccounts.Rows[i];
            }
            else
            {
                MessageBox.Show(
                    "Debe seleccionar solo 1 tipo de cuenta a modificar",
                    "Información",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
            }

            if (row != null)
            {
                int                 id               = Int32.Parse(row.Cells[0].Value.ToString());
                CuentaContable      cuentaContable   = CuentaContable.getInstance();
                countables_accounts countableAccount =
                    (from em in entities.countables_accounts
                     where em.id == id
                     select em).First();

                cuentaContable.setCuentaContable(countableAccount);
                cuentaContable.ShowDialog(this);
                cuentaContable.Focus();
            }
        }
Exemplo n.º 7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = null;

            if (dgvCountablesAccounts.SelectedRows.Count == 1)
            {
                row = dgvCountablesAccounts.SelectedRows[0];
            }
            else if (dgvCountablesAccounts.SelectedCells.Count == 1)
            {
                int i = dgvCountablesAccounts.SelectedCells[0].RowIndex;
                row = dgvCountablesAccounts.Rows[i];
            }
            else
            {
                MessageBox.Show(
                    "Debe seleccionar solo 1 tipo de cuenta a modificar",
                    "Información",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
            }

            if (row != null)
            {
                DialogResult deleteIt = MessageBox.Show(
                    "¿Estás seguro de eliminar esta cuenta?",
                    "Confirmar",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Question
                    );

                if (deleteIt == DialogResult.Yes)
                {
                    int id = Int32.Parse(row.Cells[0].Value.ToString());
                    countables_accounts countableAccount =
                        (from em in entities.countables_accounts
                         where em.id == id
                         select em).First();

                    if (countableAccount == null)
                    {
                        MessageBox.Show(
                            "¡Cuenta no encontrada!",
                            "Información",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information
                            );
                    }
                    else
                    {
                        try
                        {
                            entities.countables_accounts.Remove(countableAccount);
                            entities.SaveChanges();

                            MessageBox.Show(
                                "¡Cuenta Eliminada con éxito!",
                                "Información",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information
                                );

                            loadCountablesAccounts("");
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(
                                "La cuenta no pudo ser eliminada porque se encuentra en uso",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                                );
                            ConnectionDB.getInstance().resetConnection();
                        }
                    }
                }
            }
        }