private void button1_Click(object sender, EventArgs e)
        {
            if (!editar)
            {
                groupBoxDados.Controls.Cast <Control>().ToList()
                .ForEach(x => { x.Enabled = true; });
                groupBoxEndereço.Controls.Cast <Control>().ToList()
                .ForEach(x => { x.Enabled = true; });
                textBoxIdHotel.Enabled = false;
                button1.Text           = "Salvar";
                editar = !editar;
            }
            else
            {
                try
                {
                    string hRid;
                    if (checkBoxContemRestaurante.Checked)
                    {
                        hRid = comboBoxIdRestauranteHotel.SelectedValue.ToString();
                    }
                    else
                    {
                        hRid = "NULL";
                    }

                    string hNome      = textBoxNomeHotel.Text;
                    string hCategoria = comboBoxCategoriaHotel.SelectedItem.ToString();
                    maskedTextBoxContatoHotel.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                    string hContato = maskedTextBoxContatoHotel.Text;
                    maskedTextBoxContatoHotel.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                    string hEndTipo = comboBoxEndTipoHotel.SelectedItem.ToString();
                    string hEndLog  = textBoxEndLogradouroHotel.Text;
                    string hEndNum  = textBoxEndNumeroHotel.Text;
                    string hEndComp;
                    try
                    {
                        hEndComp = textBoxEndComplementoHotel.Text;
                    }
                    catch (NullReferenceException)
                    {
                        hEndComp = "NULL";
                    }
                    string hEndBairro = textBoxEndBairroHotel.Text;
                    maskedTextBoxEndCepHotel.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                    string hEndCep = maskedTextBoxEndCepHotel.Text;
                    maskedTextBoxEndCepHotel.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                    int hCid = int.Parse(comboBoxEndCidadeHotel.SelectedValue.ToString());
                    if (hCid == 0)
                    {
                        throw new InvalidSelectValue("CidadeID must be different of 0");
                    }
                    int           id = int.Parse(textBoxIdHotel.Text);
                    Classes.Hotel h  = new Classes.Hotel(id, hCid, hRid, hNome, hCategoria, hContato, hEndTipo, hEndLog, hEndNum, hEndComp, hEndBairro, hEndBairro);
                    if (adapter.atualizarHotel(h))
                    {
                        MessageBox.Show("Atualizado!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //this.Close();
                        editar = !editar;
                        groupBoxDados.Controls.Cast <Control>().ToList()
                        .ForEach(x => { if (x.GetType() != typeof(Label))
                                        {
                                            x.Enabled = false;
                                        }
                                 });
                        groupBoxEndereço.Controls.Cast <Control>().ToList()
                        .ForEach(x => { if (x.GetType() != typeof(Label))
                                        {
                                            x.Enabled = false;
                                        }
                                 });
                        button1.Text = "Editar";
                    }
                    else
                    {
                        MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch (NullReferenceException)
                {
                    //Erro ao resgatar valores dos componentes
                    MessageBox.Show("Verifique se os campos estão preenchidos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (InvalidSelectValue)
                {
                    //Tratar se usuario não tenha selecionado uma cidade valida
                    MessageBox.Show("Verifique se os campos estão preenchidos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Пример #2
0
        private void buttonCadastrarHotel_Click(object sender, EventArgs e)
        {
            try
            {
                string hRid;
                if (checkBoxContemRestaurante.Checked)
                {
                    hRid = comboBoxIdRestauranteHotel.SelectedValue.ToString();
                }
                else
                {
                    hRid = "NULL";
                }

                string hNome      = textBoxNomeHotel.Text;
                string hCategoria = comboBoxCategoriaHotel.SelectedItem.ToString();
                maskedTextBoxContatoHotel.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                string hContato = maskedTextBoxContatoHotel.Text;
                maskedTextBoxContatoHotel.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                string hEndTipo = comboBoxEndTipoHotel.SelectedItem.ToString();
                string hEndLog  = textBoxEndLogradouroHotel.Text;
                string hEndNum  = textBoxEndNumeroHotel.Text;
                string hEndComp;
                try
                {
                    hEndComp = textBoxEndComplementoHotel.Text;
                }
                catch (NullReferenceException)
                {
                    hEndComp = "NULL";
                }
                string hEndBairro = textBoxEndBairroHotel.Text;
                maskedTextBoxEndCepHotel.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                string hEndCep = maskedTextBoxEndCepHotel.Text;
                maskedTextBoxEndCepHotel.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                int hCid = int.Parse(comboBoxEndCidadeHotel.SelectedValue.ToString());
                if (hCid == 0)
                {
                    throw new InvalidSelectValue("CidadeID must be different of 0");
                }
                Classes.Hotel h = new Classes.Hotel(0, hCid, hRid, hNome, hCategoria, hContato, hEndTipo, hEndLog, hEndNum, hEndComp, hEndBairro, hEndBairro);
                if (adapter.adicionarHotel(h))
                {
                    MessageBox.Show("Adicionado!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (NullReferenceException)
            {
                //Erro ao resgatar valores dos componentes
                MessageBox.Show("Verifique se os campos estão preenchidos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (InvalidSelectValue)
            {
                //Tratar se usuario não tenha selecionado uma cidade valida
                MessageBox.Show("Verifique se os campos estão preenchidos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }