Test Foro de elhacker.net SMF 2.1

Programación => Programación General => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: j0lama en 10 Octubre 2014, 00:44 AM

Título: Ayuda duda C#
Publicado por: j0lama en 10 Octubre 2014, 00:44 AM
Hola buenas, llevo tiempo intentando hacer un login en c# para seriales que cuando se de por valido el serial y el programa se vuelva a ejecutar no me vuelva a salir la ventana de login sino que ya tiene acceso. Alguna ayuda/idea
Un saludo
Título: Re: Ayuda duda C#
Publicado por: Luna71c0 en 10 Octubre 2014, 00:46 AM
Depende que tan profesional quieras ser, podes desde guardar un simple archivo .conf hasta modificar una llave de registro :P
Título: Re: Ayuda duda C#
Publicado por: j0lama en 10 Octubre 2014, 00:50 AM
Algo sencillo que es para un proyecto para el colegio, teniendo en cuenta que de c# se lo básico. ;D
Título: Re: Ayuda duda C#
Publicado por: Eleкtro en 10 Octubre 2014, 10:05 AM
Si no pretendes distribuir la aplicación de forma profesional entonces te sugiero utilizar la infraestructura My.Settings/Properties.Settings.

1. Documéntate:
http://msdn.microsoft.com/en-us/library/aa730869%28v=vs.80%29.aspx

2. Crea una propiedad adecuada a tu propósito:
(http://i.imgur.com/yD0moKI.jpg)

3. Utiliza la propiedad para tus fines:

( Con este ejemplo debería ser suficiente para que entiendas el uso y lo puedas adaptar a tu aplicación. )

Vb.NET:
Código (vbnet) [Seleccionar]
Public Class SerialFormTest

   Private Sub New()

       InitializeComponent()

       Me.CheckSerialStatus()

       Dim serial As String = "0f8fad5b-d9cb-469f-a165-70867728950e"

       If Me.ValidateSerial(serial) Then
           Me.SaveSerial(serial)
           ' Application.Restart()
       End If

   End Sub

   Public Sub CheckSerialStatus()

       If My.Settings.Serial.Equals(Nothing) Then
           MessageBox.Show("No se ha licenciado la aplicación.", Me.Name,
                           MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
           ' Application.Exit()

       Else
           MessageBox.Show("Se ha licenciado la aplicación.", Me.Name,
                           MessageBoxButtons.OK, MessageBoxIcon.Information)

       End If

   End Sub

   Private Function ValidateSerial(ByVal serial As String) As Boolean

       Dim refSerial As Guid
       Return Guid.TryParse(serial, refSerial)

   End Function

   Private Sub SaveSerial(ByVal serial As String)

       With My.Settings
           .Serial = Guid.Parse(serial)
           .Save()
       End With

   End Sub

End Class



C# (conversión al vuelo):
Código (csharp) [Seleccionar]

using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public class SerialFormTest
{


public SerialFormTest()
{
InitializeComponent();

this.CheckSerialStatus();

string serial = "0f8fad5b-d9cb-469f-a165-70867728950e";

if (this.ValidateSerial(serial)) {
this.SaveSerial(serial);
// Application.Restart()
}

}


private void CheckSerialStatus()
{
if (My.Settings.Serial.Equals(null)) {
MessageBox.Show("No se ha licenciado la aplicación.", this.Name, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// Application.Exit()

} else {
MessageBox.Show("Se ha licenciado la aplicación.", this.Name, MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

private bool ValidateSerial(string serial)
{

Guid refSerial = default(Guid);
return Guid.TryParse(serial, refSerial);

}


private void SaveSerial(string serial)
{
var _with1 = My.Settings;
_with1.Serial = Guid.Parse(serial);
_with1.Save();

}

}

//=======================================================
//Service provided by Telerik (www.telerik.com)
//=======================================================


Saludos.