//Função que exclui telefone private void phoneDelete() { if (Convert.ToInt32(this.dgv_telephones.Rows.Count) == 0) { MessageBox.Show("Não há telefone selecionado para editar!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (Convert.ToInt32(this.dgv_telephones.SelectedRows.Count) > 1) { MessageBox.Show("Selecione apenas uma linha da tabela para editar!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Telephone telephone = new Telephone(); telephone.IdTelefone = Convert.ToInt32(this.dgv_telephones.SelectedRows[0].Cells[0].Value); if (Database.deleteTelephone(telephone)) { MessageBox.Show("Telefone excluído com sucesso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.mtb_telephoneNumber.Focus(); this.dataTableRemoveEmptyColumns("SELECT idTelefone, tipoTelefone AS 'Tipo:', numeroTelefone AS 'Número:' FROM telefone WHERE idFornecedor = " + Globals.idFornecedor); if (this.dgv_telephones.Rows.Count == 0) { this.displayTelephoneSettings(false, 204); } } else { MessageBox.Show("[ERRO] Não foi possível excluir telefone!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//Função que cadastra novo telefone private void newTelephone() { string mtb = this.mtb_telephoneNumber.Text.Trim(); if ((this.cbb_telephoneType.SelectedIndex == -1) || ((this.mtb_telephoneNumber.Text.IndexOf(' ')) != (this.mtb_telephoneNumber.Text.LastIndexOf(' ')))) { MessageBox.Show("Selecione um telefone para atualizar ou preencha os dados corretamente!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (mtb.Trim().Length < 10) { MessageBox.Show("Selecione um telefone para atualizar ou preencha os dados corretamente!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { Telephone telephone = new Telephone(); telephone.IdFornecedor = Globals.idFornecedor; telephone.TipoTelefone = this.cbb_telephoneType.SelectedItem.ToString().Trim(); telephone.NumeroTelefone = this.mtb_telephoneNumber.Text.Trim(); if (Database.newTelephone(telephone)) { MessageBox.Show("Telefone cadastrado com sucesso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.cbb_telephoneType.SelectedIndex = -1; this.cbb_telephoneType.Text = "Tipo do telefone"; this.mtb_telephoneNumber.Clear(); this.dataTableRemoveEmptyColumns("SELECT idTelefone, tipoTelefone AS 'Tipo:', numeroTelefone AS 'Número:' FROM telefone WHERE idFornecedor = " + Globals.idFornecedor); this.displayTelephoneSettings(true, 518); } else { MessageBox.Show("Não foi possível cadastrar telefone!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
//Função que atualiza telefone private void phoneUpdate() { if (Convert.ToInt32(this.dgv_telephones.Rows.Count) == 0) { MessageBox.Show("Não há telefone selecionado para editar!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (Convert.ToInt32(this.dgv_telephones.SelectedRows.Count) > 1) { MessageBox.Show("Selecione apenas uma linha da tabela para editar!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { string mtb = this.mtb_telephoneNumber.Text.Trim(); if ((this.cbb_telephoneType.SelectedIndex == -1) || ((this.mtb_telephoneNumber.Text.IndexOf(' ')) != (this.mtb_telephoneNumber.Text.LastIndexOf(' '))) || (mtb.Trim().Length < 10)) { MessageBox.Show("Selecione um telefone para atualizar ou preencha os dados corretamente!"); } else { Telephone telephone = new Telephone(); telephone.IdTelefone = Convert.ToInt32(this.dgv_telephones.SelectedRows[0].Cells[0].Value); telephone.TipoTelefone = this.cbb_telephoneType.SelectedItem.ToString().Trim(); telephone.NumeroTelefone = this.mtb_telephoneNumber.Text.Trim(); if (Database.updateTelephone(telephone)) { MessageBox.Show("Telefone atualizado com sucesso!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); this.dataTableRemoveEmptyColumns("SELECT idTelefone, tipoTelefone AS 'Tipo:', numeroTelefone AS 'Número:' FROM telefone WHERE idFornecedor = " + Globals.idFornecedor); } else { MessageBox.Show("[ERRO] Não foi possível atualizar telefone!", "", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }