// FIND AND SELECT IN LIST PROVIDED DEFAULT ID //------------------------------------------------------------------------------------------------------------ private void FindSelectDefautID(int?DefaultID) { if (DefaultID != null) { foreach (BetterListViewItem item in lstItens) { if (Convert.ToInt32(item.Text) == DefaultID) { item.Selected = true; propEscolha = GetSelectedItem(); } else { item.Selected = false; } } } else { if (lstItens.Items.Count > 0) { lstItens.Items[0].Selected = true; } } }
// INSERT //------------------------------------------------------------------------------------------------------------ public int InsertBanco(objBanco banco) { try { AcessoDados db = new AcessoDados(); //--- clear Params db.LimparParametros(); //--- define Params db.AdicionarParametros("@BancoNome", banco.BancoNome); db.AdicionarParametros("@Sigla", banco.Sigla); db.AdicionarParametros("@Ativo", true); //--- convert null parameters db.ConvertNullParams(); //--- create query string query = db.CreateInsertSQL("tblBancos"); //--- insert return((int)db.ExecutarInsertAndGetID(query)); } catch (Exception ex) { throw ex; } }
// UPDATE //------------------------------------------------------------------------------------------------------------ public bool UpdateBanco(objBanco banco) { try { AcessoDados db = new AcessoDados(); //--- clear Params db.LimparParametros(); //--- define Params db.AdicionarParametros("@IDBanco", banco.IDBanco); db.AdicionarParametros("@BancoNome", banco.BancoNome); db.AdicionarParametros("@Sigla", banco.Sigla); db.AdicionarParametros("@Ativo", banco.Ativo);; //--- convert null parameters db.ConvertNullParams(); //--- create query string query = db.CreateUpdateSQL("tblBancos", "IDBanco"); //--- update db.ExecutarManipulacao(CommandType.Text, query); return(true); } catch (Exception ex) { throw ex; } }
// CONVERT ROW IN CLASS //------------------------------------------------------------------------------------------------------------ public objBanco ConvertRowInClass(DataRow row) { objBanco banco = new objBanco((int)row["IDBanco"]) { }; banco.BancoNome = (string)row["BancoNome"]; banco.Sigla = row["Sigla"] == DBNull.Value ? string.Empty : (string)row["Sigla"]; banco.Ativo = (bool)row["Ativo"]; return(banco); }
private void btnEscolher_Click(object sender, EventArgs e) { objBanco item = GetSelectedItem(); //--- check selected item if (item == null) { AbrirDialog("Favor selecionar um registro para Editar...", "Selecionar Registro", DialogType.OK, DialogIcon.Information); return; } //--- open edit form propEscolha = item; DialogResult = DialogResult.OK; }
private void AtivarDesativar_Click(object sender, EventArgs e) { //--- verifica se existe alguma cell if (dgvListagem.SelectedCells.Count == 0) { return; } //--- Verifica o item objBanco banco = (objBanco)dgvListagem.SelectedCells[0].OwningRow.DataBoundItem; //---pergunta ao usuário var reponse = AbrirDialog($"Deseja realmente {(banco.Ativo ? "DESATIVAR " : "ATIVAR")} esse Banco?\n" + banco.BancoNome.ToUpper(), (banco.Ativo ? "DESATIVAR " : "ATIVAR"), DialogType.SIM_NAO, DialogIcon.Question); if (reponse == DialogResult.No) { return; } //--- altera o valor banco.Ativo = !banco.Ativo; //--- Salvar o Registro try { // --- Ampulheta ON Cursor.Current = Cursors.WaitCursor; bBLL.UpdateBanco(banco); //--- altera a imagem dgvListagem.Refresh(); } catch (Exception ex) { AbrirDialog("Uma exceção ocorreu ao Alterar o registro do Banco..." + "\n" + ex.Message, "Exceção", DialogType.OK, DialogIcon.Exclamation); } finally { // --- Ampulheta OFF Cursor.Current = Cursors.Default; } }
//================================================================================================= // TOOLSTRIP MENU //================================================================================================= #region ATIVAR DESATIVAR MENU private void dgvListagem_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { Control c = (Control)sender; DataGridView.HitTestInfo hit = dgvListagem.HitTest(e.X, e.Y); dgvListagem.ClearSelection(); //---VERIFICAÇÕES NECESSARIAS if (hit.Type != DataGridViewHitTestType.Cell) { return; } // seleciona o ROW dgvListagem.Rows[hit.RowIndex].Cells[0].Selected = true; dgvListagem.Rows[hit.RowIndex].Selected = true; // mostra o MENU ativar e desativar if (dgvListagem.Columns[hit.ColumnIndex].Name == "Ativo") { objBanco banco = (objBanco)dgvListagem.Rows[hit.RowIndex].DataBoundItem; if (banco.Ativo == true) { AtivarToolStripMenuItem.Enabled = false; DesativarToolStripMenuItem.Enabled = true; } else { AtivarToolStripMenuItem.Enabled = true; DesativarToolStripMenuItem.Enabled = false; } // revela menu MenuListagem.Show(c.PointToScreen(e.Location)); } } }
//--- INSERE NOVO ITEM NO TBL BANCO public void ItemAlterar(objBanco banco) { try { //--- Ampulheta ON Cursor = Cursors.WaitCursor; bBLL.UpdateBanco(banco); } catch (Exception ex) { MessageBox.Show("Ocorreu uma exceção ao atualizar o banco/n" + ex.Message, "Exceção", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ex; } finally { //--- Ampulheta OFF Cursor = Cursors.Default; } }
// CONTROL IMAGES OF LIST DATAGRID //------------------------------------------------------------------------------------------------------------ private void dgvListagem_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if (e.ColumnIndex == clnImage.Index) { objBanco item = (objBanco)dgvListagem.Rows[e.RowIndex].DataBoundItem; if (item.IDBanco == null) { e.Value = ImgNew; } else { if (item.Ativo) { e.Value = ImgAtivo; } else { e.Value = ImgInativo; } } } }
//--- INSERE NOVO ITEM NO TBL BANCO public int ItemInserir(objBanco banco) { try { //--- Ampulheta ON Cursor = Cursors.WaitCursor; int newID = bBLL.InsertBanco(banco); banco.IDBanco = newID; return(newID); } catch (Exception ex) { MessageBox.Show("Ocorreu uma exceção ao inserir um novo banco\n" + ex.Message, "Exceção", MessageBoxButtons.OK, MessageBoxIcon.Error); throw ex; } finally { //--- Ampulheta OFF Cursor = Cursors.Default; } }