Example #1
0
        private void Delete()
        {
            if (_IDGRUPOAGENDA == -1)
            {
                MessageBox.Show(ConfigMessage.Default.MsgSelecRegistro);
                tabControlGrupoAgenda.SelectTab(1);
            }
            else
            {
                DialogResult dr = MessageBox.Show(ConfigMessage.Default.MsgDelete,
                                                  ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo);

                if (dr == DialogResult.Yes)
                {
                    try
                    {
                        GRUPOAGENDAPP.Delete(_IDGRUPOAGENDA);
                        Util.ExibirMSg(ConfigMessage.Default.MsgDelete2, "Blue");
                        Entity = null;
                        GetAllGrupoAgenda();
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(ConfigMessage.Default.MsgDeleteErro);
                    }
                }
            }
        }
Example #2
0
        private static GRUPOAGENDAEntity FillEntityObject(ref FbDataReader DataReader)
        {
            GRUPOAGENDAEntity entity = new GRUPOAGENDAEntity();

            FirebirdGetDbData getData = new FirebirdGetDbData();

            entity.IDGRUPOAGENDA   = getData.ConvertDBValueToInt32(DataReader, DataReader.GetOrdinal("IDGRUPOAGENDA"));
            entity.NOMEGRUPOAGENDA = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("NOMEGRUPOAGENDA"));
            entity.OBSERVACAO      = getData.ConvertDBValueToStringNullable(DataReader, DataReader.GetOrdinal("OBSERVACAO"));


            return(entity);
        }
Example #3
0
        private void DataGriewDados_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (GRUPOAGENDAColl.Count > 0)
            {
                int rowindex = e.RowIndex;
                if (rowindex != -1)
                {
                    int CodigoSelect = Convert.ToInt32(GRUPOAGENDAColl[rowindex].IDGRUPOAGENDA);

                    Entity = GRUPOAGENDAPP.Read(CodigoSelect);

                    tabControlGrupoAgenda.SelectTab(0);
                    txtNome.Focus();
                }
            }
        }
Example #4
0
        private void DataGriewDados_KeyDown(object sender, KeyEventArgs e)
        {
            if (GRUPOAGENDAColl.Count > 0)
            {
                //Obter a linha da célula selecionada
                DataGridViewRow linhaAtual = DataGriewDados.CurrentRow;

                //Exibir o índice da linha atual
                int indice       = linhaAtual.Index;
                int CodigoSelect = Convert.ToInt32(GRUPOAGENDAColl[indice].IDGRUPOAGENDA);

                if (e.KeyCode == Keys.Enter)
                {
                    Entity = GRUPOAGENDAPP.Read(CodigoSelect);

                    tabControlGrupoAgenda.SelectTab(0);
                    txtNome.Focus();
                }
                else if (e.KeyCode == Keys.Delete)
                {
                    DialogResult dr = MessageBox.Show(ConfigMessage.Default.MsgDelete,
                                                      ConfigSistema1.Default.NameSytem, MessageBoxButtons.YesNo);

                    if (dr == DialogResult.Yes)
                    {
                        try
                        {
                            GRUPOAGENDAPP.Delete(CodigoSelect);
                            Util.ExibirMSg(ConfigMessage.Default.MsgDelete2, "Blue");
                            GetAllGrupoAgenda();
                        }
                        catch (Exception)
                        {
                            MessageBox.Show(ConfigMessage.Default.MsgDeleteErro);
                        }
                    }
                }
            }
        }
Example #5
0
 private void TSBNovo_Click(object sender, EventArgs e)
 {
     Entity = null;
     tabControlGrupoAgenda.SelectTab(0);
     txtNome.Focus();
 }
Example #6
0
 private void novoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Entity = null;
     tabControlGrupoAgenda.SelectTab(0);
     txtNome.Focus();
 }
Example #7
0
        public GRUPOAGENDAEntity Read(int IDGRUPOAGENDA)
        {
            FbDataReader reader = null;

            try
            {
                //Verificando a existência de um transação aberta
                if (dbTransaction != null)
                {
                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("Rea_GRUPOAGENDA", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("Rea_GRUPOAGENDA", dbCnn);
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                dbCommand.CommandType = CommandType.StoredProcedure;

                dbCommand.Parameters.AddWithValue("@IDGRUPOAGENDA", IDGRUPOAGENDA);                //PrimaryKey


                reader = dbCommand.ExecuteReader();

                GRUPOAGENDAEntity entity = null;
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        entity = FillEntityObject(ref reader);
                    }
                }

                // Deleta reader
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }

                // Fecha conexão
                if (dbTransaction == null)
                {
                    dbCommand.Transaction.Commit();
                    if (dbCnn.State == ConnectionState.Open)
                    {
                        dbCnn.Close();
                    }
                }

                return(entity);
            }
            catch (Exception ex)
            {
                // Deleta reader
                if (reader != null)
                {
                    reader.Close();
                    reader.Dispose();
                }

                if (dbTransaction != null)
                {
                    this.RollbackTransaction();
                }
                else
                {
                    if (dbCommand.Transaction != null)
                    {
                        dbCommand.Transaction.Rollback();
                    }
                    if (dbCnn.State == ConnectionState.Open)
                    {
                        dbCnn.Close();
                    }
                }

                throw ex;
            }
        }
Example #8
0
        public int Save(GRUPOAGENDAEntity Entity)
        {
            int result = 0;

            try
            {
                //Verificando a existência de um transação aberta
                if (dbTransaction != null)
                {
                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("Sav_GRUPOAGENDA", dbCnn);
                    dbCommand.Transaction = ((FbTransaction)(dbTransaction));
                }
                else
                {
                    if (dbCnn == null)
                    {
                        dbCnn = ((FbConnection)GetConnectionDB());
                    }

                    if (dbCnn.State == ConnectionState.Closed)
                    {
                        dbCnn.Open();
                    }

                    dbCommand             = new FbCommand("Sav_GRUPOAGENDA", dbCnn);
                    dbCommand.Transaction = dbCnn.BeginTransaction(IsolationLevel.ReadCommitted);
                }

                dbCommand.CommandType = CommandType.StoredProcedure;


                if (Entity.IDGRUPOAGENDA != -1)
                {
                    dbCommand.Parameters.AddWithValue("@IDGRUPOAGENDA", Entity.IDGRUPOAGENDA); //PrimaryKey
                }
                else
                {
                    dbCommand.Parameters.AddWithValue("@IDGRUPOAGENDA", DBNull.Value);         //PrimaryKey
                }
                dbCommand.Parameters.AddWithValue("@NOMEGRUPOAGENDA", Entity.NOMEGRUPOAGENDA); //Coluna
                dbCommand.Parameters.AddWithValue("@OBSERVACAO", Entity.OBSERVACAO);           //Coluna



                //Retorno da Procedure
                FbParameter returnValue;
                returnValue = dbCommand.CreateParameter();

                dbCommand.Parameters["@IDGRUPOAGENDA"].Direction = ParameterDirection.InputOutput;


                //Executando consulta
                dbCommand.ExecuteNonQuery();

                result = int.Parse(dbCommand.Parameters["@IDGRUPOAGENDA"].Value.ToString());


                if (dbTransaction == null)
                {
                    dbCommand.Transaction.Commit();
                    dbCnn.Close();
                }
            }
            catch (Exception ex)
            {
                if (dbTransaction != null)
                {
                    this.RollbackTransaction();
                }
                else
                {
                    if (dbCommand.Transaction != null)
                    {
                        dbCommand.Transaction.Rollback();
                    }
                    if (dbCnn.State == ConnectionState.Open)
                    {
                        dbCnn.Close();
                    }
                }

                throw ex;
            }

            return(result);
        }