Example #1
0
        public ItemDaLicenca PesquisarUltimoItemLicenca(long Codigo)
        {
            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("Select Top 1  * from LICENCA_DE_USO_ITEM Where CD_LICENCA = @v1 order by CD_ITEM_LICENCA_DE_USO DESC ", Con);
                Cmd.Parameters.AddWithValue("@v1", Codigo);
                Dr = Cmd.ExecuteReader();
                ItemDaLicenca p = new ItemDaLicenca();

                if (Dr.Read())
                {
                    p.CodigoDoItem        = Convert.ToInt64(Dr["CD_ITEM_LICENCA_DE_USO"]);
                    p.CodigoDaLicenca     = Convert.ToInt64(Dr["CD_LICENCA"]);
                    p.DataDeValidade      = Convert.ToDateTime(Dr["DT_VALIDADE"]);
                    p.Guid                = Convert.ToString(Dr["TX_GUID"]);
                    p.ChaveDeAutenticacao = Convert.ToString(Dr["CH_AUTENTICACAO"]);
                }
                return(p);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao Pesquisar Item da Licenças do Cliente: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }
Example #2
0
        public void SalvarLicenca(long CodLicenca, DateTime DataValidade, string strMarcados)
        {
            ItemDaLicenca i = new ItemDaLicenca();

            //////////////////////////////////////////////////////////////////////
            i.CodigoDaLicenca     = CodLicenca;
            i.DataDeValidade      = DataValidade;
            i.Guid                = "12334567890";
            i.ChaveDeAutenticacao = "0987654321";

            InserirLicenca(i, strMarcados);
            //////////////////////////////////////////////////////////////////////

            ModuloSistema        m     = new ModuloSistema();
            List <ModuloSistema> lista = new List <ModuloSistema>();

            Char delimiter = ',';

            string[] substrings = strMarcados.Split(delimiter);
            int      numero     = 0;

            foreach (var substring in substrings)
            {
                if (int.TryParse(substring, out numero))
                {
                    m = new ModuloSistema();
                    m.CodigoModulo = Convert.ToInt32(substring);
                    m.Liberar      = true;
                    lista.Add(m);
                }
            }

            InserirLicencaModulos(i.CodigoDoItem, lista);
        }
Example #3
0
        public void InserirLicenca(ItemDaLicenca p, string strMarcados)
        {
            Guid g;

            // Create and display the value of two GUIDs.
            g = Guid.NewGuid();

            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("insert into LICENCA_DE_USO_ITEM (CD_LICENCA, DT_VALIDADE, CH_AUTENTICACAO, TX_GUID) values (@v1,@v2,@v3,@v4); SELECT SCOPE_IDENTITY()", Con);
                Cmd.Parameters.AddWithValue("@v1", p.CodigoDaLicenca);
                Cmd.Parameters.AddWithValue("@v2", p.DataDeValidade);
                Cmd.Parameters.AddWithValue("@v4", g);
                clsHash clsh  = new clsHash(SHA512.Create());
                string  teste = clsh.CriptografarSenha(p.CodigoDaLicenca.ToString() + g + strMarcados);
                Cmd.Parameters.AddWithValue("@v3", teste);
                //                Cmd.ExecuteNonQuery();
                p.CodigoDoItem = Convert.ToInt64(Cmd.ExecuteScalar());
            }
            catch (SqlException ex)
            {
                if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error
                {
                    switch (ex.Errors[0].Number)
                    {
                    case 2601:     // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    case 2627:     // Primary key violation
                        throw new DuplicateNameException("Inclusão não Permitida!!! Chave já consta no Banco de Dados. Mensagem :" + ex.Message.ToString(), ex);

                    default:
                        throw new Exception("Erro ao gravar Item da Licença: " + ex.Message.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar Licença: " + ex.Message.ToString());
            }
            finally
            {
                FecharConexao();
            }
        }