Exemple #1
0
        public bool saveCurrencyType(currencies_types currencyType, bool isNew)
        {
            // Validating
            string errors = validate(currencyType);

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

            // End validtion

            if (isNew)
            {
                entities.currencies_types.Add(currencyType);
            }

            entities.SaveChanges();
            loadCurrenciesTypes("");
            return(true);
        }
        private void setCurrency(int currencyId)
        {
            int index = -1;

            for (int x = 0; x < currencies.Count; x++)
            {
                if (currencies[x].id == currencyId)
                {
                    index = x;
                    break;
                }
            }

            if (index == -1)
            {
                currencies_types currency = (from em in entities.currencies_types
                                             where em.id == currencyId
                                             select em).First();

                currencies.Add(currency);
                index = (currencies.Count - 1);
            }

            cbCurrency.SelectedIndex = index;
        }
Exemple #3
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = null;

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

            if (row != null)
            {
                int id = Int32.Parse(row.Cells[0].Value.ToString());
                currencies_types currencyType = (from em in entities.currencies_types
                                                 where em.id == id
                                                 select em).First();

                if (currencyType == null)
                {
                    MessageBox.Show(
                        "El Tipo de Moneda seleccionado no existe",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    loadCurrenciesTypes("");
                }
                else
                {
                    TipoMoneda tipoMoneda = TipoMoneda.getInstance();
                    tipoMoneda.setCurrencyType(currencyType);
                    tipoMoneda.Show();
                    tipoMoneda.Focus();
                }
            }
        }
        public void setCurrencyType(currencies_types currencyType)
        {
            this.currencyType = currencyType;

            // Fill with attributes
            txtDescription.Text  = currencyType.description;
            txtExchangeRate.Text = currencyType.exchange_rate.ToString();

            if (currencyType.state)
            {
                rbActive.Checked = true;
            }
            else
            {
                rbInactive.Checked = true;
            }
        }
Exemple #5
0
        private string validate(currencies_types currency)
        {
            StringBuilder sb = new StringBuilder();

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

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

            if (currency.exchange_rate <= 0)
            {
                sb.Append("- El campo tasa de cambio es obligatorio y debe ser mayor que 0\n");
            }

            return(sb.ToString());
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool saved = false;

            if (currencyType == null)
            {
                Decimal exchangeRate = 0;
                Decimal.TryParse(txtExchangeRate.Text, out exchangeRate);
                currencies_types newCurrencyType = new currencies_types {
                    description   = txtDescription.Text,
                    exchange_rate = exchangeRate,
                    state         = rbActive.Checked
                };
                saved = MnjTipoMoneda.getInstance().saveCurrencyType(newCurrencyType, true);
            }
            else
            {
                Decimal exchangeRate = 0;
                Decimal.TryParse(txtExchangeRate.Text, out exchangeRate);
                currencyType.description   = txtDescription.Text;
                currencyType.exchange_rate = exchangeRate;
                currencyType.state         = rbActive.Checked;
                saved = MnjTipoMoneda.getInstance().saveCurrencyType(currencyType, false);
            }

            if (saved)
            {
                MessageBox.Show(
                    "Datos almacenados con éxito",
                    "Información",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information
                    );
                this.Close();
            }
        }
Exemple #7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = null;

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

            if (row != null)
            {
                int id = Int32.Parse(row.Cells[0].Value.ToString());
                currencies_types currencyType = (from em in entities.currencies_types
                                                 where em.id == id
                                                 select em).First();

                if (currencyType == null)
                {
                    MessageBox.Show(
                        "El Tipo de Moneda seleccionado no existe",
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                        );
                    loadCurrenciesTypes("");
                }
                else
                {
                    DialogResult deleteIt = MessageBox.Show(
                        "¿Estás seguro que quieres eliminar este tipo de moneda?",
                        "Confirmar",
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question
                        );

                    if (deleteIt == DialogResult.Yes)
                    {
                        entities.currencies_types.Remove(currencyType);
                        try
                        {
                            entities.SaveChanges();

                            MessageBox.Show(
                                "¡Tipo de Moneda eliminada con éxito!",
                                "Información",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information
                                );
                        }
                        catch (Exception ex) {
                            MessageBox.Show(
                                "¡Este tipo de moneda se encuentra en uso!",
                                "Error",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                                );
                            ConnectionDB.getInstance().resetConnection();
                        }
                    }
                    loadCurrenciesTypes("");
                }
            }
        }