private void preencher_terminais()
        {
            ListViewItem item;
            //DBApp db = new DBApp();
            //SqlCommand comm = db.Conn.CreateCommand();

            //comm.CommandText = "SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_IND FROM Terminais ORDER BY TRM_DESCRICAO";
            //SqlDataReader reader = comm.ExecuteReader();

            DBApp         db     = new DBApp();
            SqlDataReader reader = db.getReader("SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_IND FROM Terminais ORDER BY TRM_DESCRICAO");

            listRelogios.Items.Clear();

            while (reader.Read())
            {
                item      = new ListViewItem();
                item.Text = reader["TRM_DESCRICAO"].ToString().Trim();
                item.SubItems.Add(reader["TRM_IP"].ToString().Trim());
                item.SubItems.Add(reader["TRM_PORTA"].ToString().Trim());
                item.SubItems.Add(reader["TRM_IND"].ToString());
                item.ImageIndex = 0;
                listRelogios.Items.Add(item);
            }

            reader.Close();
            db.closeConnection();
        }
        private void RepEdicao_Load(object sender, EventArgs e)
        {
            if (Terminal > 0)
            {
                db = new DBApp();

                //SqlCommand Comm = db.Conn.CreateCommand();
                //Comm.CommandText = "SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_RAZAOSOCIAL, TRM_CNPJ, TRM_CPF, " +
                //                   "TRM_ENDERECO, TRM_NUMERO, TRM_SERIAL FROM Terminais WHERE TRM_IND = " + Terminal.ToString() + " " +
                //                   "ORDER BY TRM_DESCRICAO";
                //SqlDataReader reader = Comm.ExecuteReader();

                SqlDataReader reader = db.getReader("SELECT TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_RAZAOSOCIAL, TRM_CNPJ, TRM_CPF, " +
                                                    "TRM_ENDERECO, TRM_NUMERO, TRM_SERIAL FROM Terminais WHERE TRM_IND = " + Terminal.ToString() + " " +
                                                    "ORDER BY TRM_DESCRICAO");
                reader.Read();

                edDescricao.Text   = reader["TRM_DESCRICAO"].ToString().Trim();
                edIp.Text          = reader["TRM_IP"].ToString().Trim();
                edPorta.Text       = reader["TRM_PORTA"].ToString().Trim();
                edRazaoSocial.Text = reader["TRM_RAZAOSOCIAL"].ToString().Trim();
                edCnpj.Text        = reader["TRM_CNPJ"].ToString().Trim();
                edCpf.Text         = reader["TRM_CPF"].ToString().Trim();
                edEndereco.Text    = reader["TRM_ENDERECO"].ToString().Trim();
                edNumero.Text      = reader["TRM_NUMERO"].ToString().Trim();
                edSerial.Text      = reader["TRM_SERIAL"].ToString().Trim();
                reader.Close();
                db.closeConnection();
            }
            else
            {
                edPorta.Text = Consts.PORTAPADRAO.ToString();
            }
        }
        private void btOk_Click(object sender, EventArgs e)
        {
            //SqlConnection Conn = DB.Connection();
            //SqlCommand Comm = Conn.CreateCommand();

            DBApp db = new DBApp();

            db.openConnection();
            SqlCommand Comm = db.Conn.CreateCommand();

            if (Terminal > 0)
            {
                Comm.CommandText = "UPDATE Terminais SET TRM_DESCRICAO = @DESCRICAO, TRM_IP = @IP, " +
                                   "TRM_PORTA = @PORTA, TRM_GRUPO = @GRUPO, TRM_FABRICANTE = @FABRICANTE, " +
                                   "TRM_RAZAOSOCIAL = @RAZAOSOCIAL, TRM_CNPJ = @CNPJ, TRM_CPF = @CPF, TRM_ENDERECO = @ENDERECO, TRM_NUMERO = @NUMERO, TRM_SERIAL = @SERIAL " +
                                   "WHERE TRM_IND = " + Terminal.ToString();
            }
            else
            {
                Comm.CommandText = "INSERT INTO Terminais (TRM_DESCRICAO, TRM_IP, TRM_PORTA, TRM_GRUPO, " +
                                   "TRM_FABRICANTE, TRM_RAZAOSOCIAL, TRM_CNPJ, TRM_CPF, TRM_ENDERECO, TRM_NUMERO, TRM_SERIAL) VALUES (@DESCRICAO, " +
                                   "@IP, @PORTA, @GRUPO, @FABRICANTE, @RAZAOSOCIAL, @CNPJ, @CPF, @ENDERECO, @NUMERO, @SERIAL)";
            }

            Comm.Parameters.Add(new SqlParameter("@DESCRICAO", edDescricao.Text));
            Comm.Parameters.Add(new SqlParameter("@IP", edIp.Text));
            Comm.Parameters.Add(new SqlParameter("@PORTA", edPorta.Text));
            Comm.Parameters.Add(new SqlParameter("@GRUPO", Grupo));
            Comm.Parameters.Add(new SqlParameter("@FABRICANTE", "TRIX"));

            Comm.Parameters.Add(new SqlParameter("@RAZAOSOCIAL", edRazaoSocial.Text));

            Comm.Parameters.Add(new SqlParameter("@CNPJ", edCnpj.Text));
            Comm.Parameters.Add(new SqlParameter("@CPF", edCpf.Text));

            Comm.Parameters.Add(new SqlParameter("@ENDERECO", edEndereco.Text));
            Comm.Parameters.Add(new SqlParameter("@NUMERO", edNumero.Text));
            Comm.Parameters.Add(new SqlParameter("@SERIAL", edSerial.Text));

            Comm.ExecuteNonQuery();
            db.closeConnection();
            //Conn.Close();

            this.Close();
        }
        private void preencher_funcionarios(int Terminal)
        {
            ListViewItem item;
            DBApp        db = new DBApp();
            //SqlCommand comm = db.Conn.CreateCommand();

            //comm.CommandText = "SELECT FUNC_NOME, CAR_DESCRICAO, CRA_NUMERO, FUNC_PIS, FUNC_IND, " +
            //    "dbo.fn_getdatetime(TRMF_ARMAZENADO_EM) AS TRMF_ARMAZENADO_EM " +
            //    "FROM Funcionarios " +
            //    "LEFT JOIN Cargos ON CAR_IND = FUNC_CARGO " +
            //    "LEFT JOIN Crachas ON CRA_FUNC = FUNC_IND " +
            //    "INNER JOIN TerminaisFuncionarios ON TRMF_FUNC = FUNC_IND " +
            //    "WHERE TRMF_TERMINAL = " + Terminal + " AND FUNC_DT_DEM IS NULL AND FUNC_MARCADO_EXCLUSAO = 0 " +
            //    "ORDER BY FUNC_NOME";
            //SqlDataReader reader = comm.ExecuteReader();

            SqlDataReader reader = db.getReader("SELECT FUNC_NOME, CAR_DESCRICAO, CRA_NUMERO, FUNC_PIS, FUNC_IND, " +
                                                "dbo.fn_getdatetime(TRMF_ARMAZENADO_EM) AS TRMF_ARMAZENADO_EM " +
                                                "FROM Funcionarios " +
                                                "LEFT JOIN Cargos ON CAR_IND = FUNC_CARGO " +
                                                "LEFT JOIN Crachas ON CRA_FUNC = FUNC_IND " +
                                                "INNER JOIN TerminaisFuncionarios ON TRMF_FUNC = FUNC_IND " +
                                                "WHERE TRMF_TERMINAL = " + Terminal + " AND FUNC_DT_DEM IS NULL AND FUNC_MARCADO_EXCLUSAO = 0 " +
                                                "ORDER BY FUNC_NOME");

            listFuncionarios.Items.Clear();

            while (reader.Read())
            {
                item      = new ListViewItem();
                item.Text = reader["FUNC_NOME"].ToString().Trim();
                item.SubItems.Add(reader["CAR_DESCRICAO"].ToString().Trim());
                item.SubItems.Add(reader["CRA_NUMERO"].ToString());
                item.SubItems.Add(reader["FUNC_PIS"].ToString().Trim());
                item.SubItems.Add(reader["FUNC_IND"].ToString());
                item.SubItems.Add(reader["TRMF_ARMAZENADO_EM"].ToString());
                listFuncionarios.Items.Add(item);
            }

            reader.Close();
            db.closeConnection();
        }