private void buttonCadastrarMuseu_Click(object sender, EventArgs e) { bool sucess = true; try { string museuNome = textBoxNomeMuseu.Text; maskedTextBoxValorEntradaMuseu.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; float museuPreco = float.Parse(maskedTextBoxValorEntradaMuseu.Text) / 100; maskedTextBoxValorEntradaMuseu.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; string museuNumSalas = textBoxNumeroDeSalasMuseu.Text; DateTime museuFund = monthCalendarFundacaoMuseu.SelectionStart; maskedTextBoxContatoMuseu.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; string contato = maskedTextBoxContatoMuseu.Text; maskedTextBoxContatoMuseu.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; string descricao = textBoxDescricaoMuseu.Text; string endTip = comboBoxEndTipoMuseu.SelectedItem.ToString(); string endLog = textBoxEndLogradouroMuseu.Text; string endNum = textBoxEndNumeroMuseu.Text; string endComp; try { endComp = textBoxEndComplementoMuseu.Text; } catch (NullReferenceException) { endComp = ""; } string endBairro = textBoxEndBairroMuseu.Text; maskedTextBoxEndCepMuseu.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; string endCep = maskedTextBoxEndCepMuseu.Text; maskedTextBoxEndCepMuseu.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; int cidade = int.Parse(comboBoxEndCidadeMuseu.SelectedValue.ToString()); if (cidade == 0) { throw new InvalidSelectValue("CidadeID must be different of 0"); } Classes.Museu m = new Classes.Museu(0, museuFund, museuPreco, museuNumSalas, null, 0, "Museu", museuNome, contato, descricao, endTip, endLog, endNum, endComp, endBairro, endCep, cidade); if (!adapter.adicionarMuseu(m)) { sucess = false; //MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } MySqlDataReader reader = adapter.lastInsertId(); reader.Read(); int museuId = reader.GetInt32(0); foreach (DataRow drow in selecionados.Rows) { int idFundador = int.Parse(drow[0].ToString()); Classes.Fundador fu = new Classes.Fundador(idFundador, null, null, DateTime.Now, false, DateTime.Now, null, null); Classes.Museu mu = new Classes.Museu(museuId, DateTime.Now, 0, null, null, 0, null, null, null, null, null, null, null, null, null, null, 0); if (!adapter.adicionarFundadopor(mu, fu)) { sucess = false; //MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (sucess) { MessageBox.Show("Adicionado!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (NullReferenceException) { MessageBox.Show("Verifique se os campos estão preenchidos corretamente", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click(object sender, EventArgs e) { if (!editar) { groupBox1.Controls.Cast <Control>().ToList() .ForEach(x => { x.Enabled = true; }); groupBox2.Controls.Cast <Control>().ToList() .ForEach(x => { x.Enabled = true; }); textBoxIdIgreja.Enabled = false; button1.Text = "Salvar"; editar = !editar; } else { bool sucess = true; try { string igrejaNome = textBoxNomeIgreja.Text; string igrejaEstilo = textBoxEstiloIgreja.Text; DateTime igrejaFund = monthCalendarFundacaoIgreja.SelectionStart; maskedTextBoxContatoIgreja.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; string contato = maskedTextBoxContatoIgreja.Text; maskedTextBoxContatoIgreja.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; string descricao = textBoxDescricaoIgreja.Text; string endTip = comboBoxEndTipoIgreja.SelectedItem.ToString(); string endLog = textBoxEndLogradouroIgreja.Text; string endNum = textBoxEndNumeroIgreja.Text; string endComp; try { endComp = textBoxEndComplementoIgreja.Text; } catch (NullReferenceException) { endComp = ""; } string endBairro = textBoxEndBairroIgreja.Text; maskedTextBoxEndCepIgreja.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals; string endCep = maskedTextBoxEndCepIgreja.Text; maskedTextBoxEndCepIgreja.TextMaskFormat = MaskFormat.IncludePromptAndLiterals; int cidade = int.Parse(comboBoxEndCidadeIgreja.SelectedValue.ToString()); if (cidade == 0) { throw new InvalidSelectValue("CidadeID must be different of 0"); } int id = int.Parse(textBoxIdIgreja.Text); Classes.Igreja i = new Classes.Igreja(id, igrejaFund, igrejaEstilo, null, 0, "Igreja", igrejaNome, contato, descricao, endTip, endLog, endNum, endComp, endBairro, endCep, cidade); if (!adapter.atualizarIgreja(i)) { sucess = false; //MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } MySqlDataReader reader = adapter.lastInsertId(); reader.Read(); int igrejaId = int.Parse(textBoxIdIgreja.Text); foreach (DataRow drow in selecionados.Rows) { int idFundador = int.Parse(drow[0].ToString()); Classes.Fundador fu = new Classes.Fundador(idFundador, null, null, DateTime.Now, false, DateTime.Now, null, null); Classes.Igreja ig = new Classes.Igreja(igrejaId, DateTime.Now, null, null, 0, null, null, null, null, null, null, null, null, null, null, 0); //if (!adapter.atualizarFundadapor(ig, fu)) //{ //sucess = false; //MessageBox.Show("Falha", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); //} } if (sucess) { MessageBox.Show("Atualizado!", "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); } } }