Esempio n. 1
0
 //mostrar valores no formulario
 private void ShowValues(Library.Setor setor)
 {
     this.codigoTB.Text    = string.Format("{0}", setor.Id);
     this.nomeTB.Text      = setor.Nome;
     this.descricaoTB.Text = setor.Descricao;
     //setor.DataCadastro;
 }
Esempio n. 2
0
        static public void Update(Library.Setor setor)
        {
            SqlConnection conexao = null;

            try
            {
                conexao = new SqlConnection(global::Connection.Connection.String());

                SqlCommand comando = conexao.CreateCommand();

                comando.CommandText = "UPDATE Setor SET nome = @nome, descricao = @descricao, dataCadastro = @dataCadastro WHERE (id= " + setor.Id + ")";
                comando.Parameters.AddWithValue("@nome", setor.Nome);
                comando.Parameters.AddWithValue("@descricao", setor.Descricao);
                comando.Parameters.AddWithValue("@dataCadastro", setor.DataCadastro);

                conexao.Open();

                comando.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
            }
        }
Esempio n. 3
0
        static public void Save(Library.Setor setor)
        {
            SqlConnection conexao = null;

            try
            {
                conexao = new SqlConnection(global::Connection.Connection.String());

                SqlCommand comando = conexao.CreateCommand();

                comando.CommandText = "INSERT INTO Setor (nome, descricao, dataCadastro) VALUES (@nome, @descricao, @dataCadastro)"
                                      + "SELECT CAST(scope_identity() AS bigint)";

                comando.Parameters.AddWithValue("@nome", setor.Nome);
                comando.Parameters.AddWithValue("@descricao", setor.Descricao);
                comando.Parameters.AddWithValue("@dataCadastro", setor.DataCadastro);

                conexao.Open();

                //comando.ExecuteNonQuery();
                setor.Id = (long)comando.ExecuteScalar();
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
            }
        }
Esempio n. 4
0
        private void excluirButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            this.InputDisabler(false);
            /************BEGIN************/
            //achando idSetor selecionado na grid
            Library.Setor setor = null;
            for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
            {
                setor = Library.SetorBD.FindById((long)this.dataGridView1.SelectedRows[i].Cells["idDGVTBC"].Value);
            }
            if (MessageBox.Show(this.fstSetorDeletarMsg, this.fstSetorDeletarMsgTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                //se não tiver selecionado mostra mensagem se estiver deleta e atualiza formulario
                if (dataGridView1.SelectedRows.Count != 1)
                {
                    MessageBox.Show(this.fstSetorDeletarNoSelected);
                }
                else
                {
                    Library.SetorBD.Delete(setor);
                    this.RefreshForm();
                }
            }

            /*************END*************/
            this.Modo   = "Excluir";
            this.Cursor = Cursors.Default;
        }
Esempio n. 5
0
        //atualizar objeto setor com valores do formulario
        private Library.Setor UpdateSetorFromForm()
        {
            Library.Setor setorTemp = this.setor;

            //setorTemp.Id = ;
            setorTemp.Nome      = this.nomeTB.Text;
            setorTemp.Descricao = this.descricaoTB.Text;
            //setorTemp.DataCadastro = DateTime.Now;

            return(setorTemp);
        }
Esempio n. 6
0
        private void salvarButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            /************BEGIN************/
            if (this.ValidateForm())
            {
                this.MenuDisabler(true, false, false, false, false);
                this.InputDisabler(false);


                if (this.modo == "Cadastrar")
                {
                    //criando um setor com valores do formulário
                    this.setor = this.ReturnSetorFromForm();
                    //salvando setor
                    Library.SetorBD.Save(this.setor);
                    //this.dataGridView1.Rows.Add(this.setor.Id, this.setor.Nome, this.setor.DataCadastro);
                }
                else
                {
                    this.setor = this.UpdateSetorFromForm();
                    //atualizando setor
                    Library.SetorBD.Update(this.setor);

                    //foreach (DataGridViewRow d in dataGridView1.Rows)
                    //{
                    //    if ((long)d.Cells[0].Value == this.setor.Id)
                    //    {
                    //        d.Cells[0].Value = this.setor.Id;
                    //        d.Cells[1].Value = this.setor.Nome;
                    //        d.Cells[2].Value = this.setor.DataCadastro;
                    //    }
                    //}
                }



                //atualizando formulário
                RefreshForm();
                RefreshChilds();


                this.Modo = "Salvar";
            }
            else
            {
                //mensagem de erro
            }
            /*************END*************/
            this.Cursor = Cursors.Default;
        }
Esempio n. 7
0
 private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
 {
     this.Cursor = Cursors.WaitCursor;
     this.MenuDisabler(true, true, false, false, true);
     this.InputDisabler(false);
     this.Modo = "Selecionar";
     /************BEGIN************/
     if (dataGridView1.SelectedRows.Count == 1)
     {
         //achando idCargo selecionado na grid
         long idSetor = (long)this.dataGridView1.SelectedRows[0].Cells["idDGVTBC"].Value;
         //mostrando cargo selecionado no formulario
         this.setor = Library.SetorBD.FindById(idSetor);
         this.ShowValues(setor);
     }
     /*************END*************/
     this.Cursor = Cursors.Default;
 }
Esempio n. 8
0
        static public Library.Setor FindById(long idSetor)
        {
            SqlConnection  conexao = null;
            SqlDataAdapter dap     = null;
            DataSet        ds      = null;

            Library.Setor setor = null;
            try
            {
                conexao = new SqlConnection(global::Connection.Connection.String());

                dap = new SqlDataAdapter("SELECT * FROM Setor WHERE id='" + idSetor + "'", conexao);

                ds = new DataSet();

                dap.Fill(ds, "Setor");

                if (ds.Tables["Setor"].Rows.Count == 1)
                {
                    //throw new ApplicationException("DataSet está vazio!");
                    setor              = new Setor();
                    setor.Id           = (long)ds.Tables["Setor"].Rows[0]["id"];
                    setor.Nome         = ds.Tables["Setor"].Rows[0]["nome"].ToString();
                    setor.Descricao    = ds.Tables["Setor"].Rows[0]["descricao"].ToString();
                    setor.DataCadastro = (DateTime)ds.Tables["Setor"].Rows[0]["dataCadastro"];
                }
                return(setor);
            }
            catch (SqlException ex)
            {
                Library.Diagnostics.Logger.Error(ex);;
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);;
            }
            finally
            {
                conexao.Close();
                dap.Dispose();
                ds.Dispose();
            }
            return(null);
        }
Esempio n. 9
0
        private void editarButton_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            this.MenuDisabler(true, false, true, true, false);
            this.InputDisabler(true);
            /************BEGIN************/
            //achando idSetor selecionado na grid
            long idSetor = 0;

            for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
            {
                idSetor = (long)this.dataGridView1.SelectedRows[i].Cells["idDGVTBC"].Value;
            }
            //mostrando setor selecionado no formulario
            this.setor = Library.SetorBD.FindSetorById(idSetor);
            this.ShowValues(this.setor);
            /*************END*************/
            this.Modo   = "Editar";
            this.Cursor = Cursors.Default;
        }
Esempio n. 10
0
        static public void Delete(Library.Setor setor)
        {
            SqlConnection conexao = null;

            try
            {
                conexao = new SqlConnection(global::Connection.Connection.String());
                SqlCommand comando = conexao.CreateCommand();

                comando.CommandText = "DELETE FROM Setor WHERE id='" + setor.Id + "'";

                conexao.Open();
                comando.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Library.Diagnostics.Logger.Error(ex);
            }
            finally
            {
                conexao.Close();
            }
        }