예제 #1
0
        private void buttonCadastrarRestaurante_Click(object sender, EventArgs e)
        {
            Classes.Restaurante r;
            try
            {
                string restNome          = textBoxNomeHotel.Text;
                string restCategoria     = comboBoxCategoriaRestaurante.SelectedItem.ToString();
                string restEspecialidade = textBoxEspecialidadeRestaurante.Text;
                maskedTextBoxContatoRestaurante.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                string restContato = maskedTextBoxContatoRestaurante.Text;
                maskedTextBoxContatoRestaurante.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                maskedTextBoxPreco.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; // tira a formatação
                float restPreco = float.Parse(maskedTextBoxPreco.Text.ToString()) / 100;
                maskedTextBoxPreco.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                string restEndTipo = comboBoxEndTipoRestaurante.SelectedItem.ToString();
                string restEndLog  = textBoxEndLogradouroRestaurante.Text;
                string restEndNum  = textBoxEndNumeroRestaurante.Text;
                string restComp;
                try
                {
                    restComp = textBoxEndComplementoRestaurante.Text;
                }
                catch (NullReferenceException)
                {
                    restComp = "";
                }
                string restEndBairro = textBoxEndBairroRestaurante.Text;
                maskedTextBoxEndCepRestaurante.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                string restEndCep = maskedTextBoxEndCepRestaurante.Text;
                maskedTextBoxEndCepRestaurante.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                int restCid = int.Parse(comboBoxEndCidadeRestaurante.SelectedValue.ToString());
                if (restCid == 0)
                {
                    throw new InvalidSelectValue("CidadeID must be different of 0");
                }

                r = new Classes.Restaurante(0, restNome, restCategoria, restEspecialidade, restPreco, restContato, restEndTipo, restEndLog, restEndNum, restComp, restEndBairro, restEndCep, restCid);
                if (adapter.adicionarRestaurante(r))
                {
                    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);
            }
        }
예제 #2
0
        private void buttonEditar_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; });
                textBoxIdRestaurante.Enabled = false;
                buttonEditar.Text            = "Salvar";
                editar = !editar;
            }
            else
            {
                Classes.Restaurante r;

                try
                {
                    int    restID            = int.Parse(textBoxIdRestaurante.Text);
                    string restNome          = textBoxNomeRestaurante.Text;
                    string restCategoria     = comboBoxCategoriaRestaurante.SelectedItem.ToString();
                    string restEspecialidade = textBoxEspecialidadeRestaurante.Text;
                    maskedTextBoxContatoRestaurante.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                    string restContato = maskedTextBoxContatoRestaurante.Text;
                    maskedTextBoxContatoRestaurante.TextMaskFormat    = MaskFormat.IncludePromptAndLiterals;
                    maskedTextBoxPrecoMedioRestaurante.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; // tira a formatação
                    float restPreco = 0;
                    try
                    {
                        restPreco = float.Parse(maskedTextBoxPrecoMedioRestaurante.Text.ToString()) / 100;
                    }
                    catch (FormatException)
                    {
                        //MessageBox.Show("Verifique se os campos estão preenchidos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        throw new NullReferenceException("PREÇO");
                    }
                    maskedTextBoxPrecoMedioRestaurante.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                    string restEndTipo = comboBoxEndTipoRestaurante.SelectedItem.ToString();
                    string restEndLog  = textBoxEndLogradouroRestaurante.Text;
                    string restEndNum  = textBoxEndNumeroRestaurante.Text;
                    string restComp;
                    try
                    {
                        restComp = textBoxEndComplementoRestaurante.Text;
                    }
                    catch (NullReferenceException)
                    {
                        restComp = "";
                    }
                    string restEndBairro = textBoxEndBairroRestaurante.Text;
                    maskedTextBoxEndCepRestaurante.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
                    string restEndCep = maskedTextBoxEndCepRestaurante.Text;
                    maskedTextBoxEndCepRestaurante.TextMaskFormat = MaskFormat.IncludePromptAndLiterals;
                    int restCid = int.Parse(comboBoxEndCidadeRestaurante.SelectedValue.ToString());
                    if (restCid == 0)
                    {
                        throw new InvalidSelectValue("CidadeID must be different of 0");
                    }

                    r = new Classes.Restaurante(restID, restNome, restCategoria, restEspecialidade, restPreco, restContato, restEndTipo, restEndLog, restEndNum, restComp, restEndBairro, restEndCep, restCid);
                    if (adapter.atualizarRestaurante(r))
                    {
                        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;
                                        }
                                 });
                        buttonEditar.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);
                }
            }
        }