segunda-feira, 7 de dezembro de 2020

C++ builder - login e senha IV

O c++ builder da Embarcadero fornece uma ampla
cadeia de controles e de componentes para uso
num form, permitindo a criação de belas janelas
personalizadas de acordo com os conhecimentos
do programador.
Confesso que não conheço todos os componentes
desta incrível IDE, mas na minha opinião não
vejo melhor opção no mercado para quem quer programar
em C/C++ orientado a objetos com janelas para Desktop,
Web ou smartphone.




//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <set>
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
  //---------------------------------------------------------------------------
void __fastcall TForm1::Label_Manual ( TObject *Sender ) {
String str_1 = " C++ BUILDER - LOGIN E SENHA IV ";
//Criando um Label na mão
TStaticText *StaticText1 = new TStaticText ( Form1 );
StaticText1 -> AutoSize = false;
StaticText1 -> Transparent = false;
StaticText1 -> Color = clWhite;
StaticText1 -> Parent = Form1;
StaticText1 -> Font -> Name = "Consolas";
//StaticText1 -> WordWrap = false;
StaticText1 -> Font -> Size = 14;
StaticText1 -> Font-> Style = TFontStyles ( ) << fsBold <<fsItalic;
StaticText1 -> Font -> Color = clRed;
StaticText1 -> Width = 320;
StaticText1 -> Height = 20;
StaticText1 -> Left = 110;
StaticText1 -> Top = 15;
StaticText1 -> Caption = str_1;

Image1 -> Width = 620;
Image1 -> Height = 280;
Image1 -> Left = 10;
Image1 -> Top  = 10;

Image2 -> Width = 62;
Image2 -> Height = 85;
Image2 -> Left = 380;
Image2 -> Top = 190;

Image3 -> Width = 62;
Image3 -> Height = 100;
Image3 -> Left = 380;
Image3 -> Top = 180;

Image4 -> Width = 180;
Image4 -> Height = 100;
Image4 -> Left = 160;
Image4 -> Top = 190;

Panel1 -> Font -> Size = 12;
Panel1 -> Font -> Color = clBlack;
Panel1 -> Color = clYellow;
Panel1 -> Font -> Style = TFontStyles ( ) << fsBold;
Panel1 -> Width = 185;
     Panel1 -> Height = 20;
     Panel1 -> Left = 160;
Panel1 -> Top = 260;

     Edit1 -> SetFocus ( );
     Edit1 -> Font -> Size = 12;
     Edit1 -> Font -> Color = clRed;
     Edit1 -> Font -> Style = TFontStyles ( ) << fsBold << fsItalic;
     Edit1 -> Width = 90;
     Edit1 -> Height = 20;
     Edit1 -> Left = 250;
     Edit1 -> Top = 70;

     //Edit1 -> SetFocus ( );
     Edit2 -> Font -> Size = 12;
     Edit2 -> Font -> Color = clBlack;
Edit2 -> Font -> Style = TFontStyles ( ) << fsBold;
Edit2 -> Width = 90;
     Edit2 -> Height = 20;
Edit2 -> Left = 250;
     Edit2 -> Top = 100;

     //Edit1 -> SetFocus ( );
     Edit3 -> Font -> Size = 12;
     Edit3 -> Font -> Color = clBlack;
Edit3 -> Font -> Style = TFontStyles ( ) << fsBold;
     Edit3 -> Width = 90;
     Edit3 -> Height = 20;
Edit3 -> Left = 250;
     Edit3 -> Top = 130;

    Label1 -> Font -> Size = 12;
Label1 -> Font-> Style = TFontStyles ( ) << fsBold;
//Utilizando o transparent do label em false,
//Podemos colocar uma cor de fundo do texto.
Label1 -> Transparent = false;
Label1 -> Color = clYellow;
Label1 -> Font -> Name = "Tahoma";
Label1 -> Font -> Color = clBlack;
    Label1 -> Width = 130;
    Label1 -> Height = 20;
    Label1 -> Left = 160;
    Label1 -> Top = 70;
    Label1 -> Caption = "Usuário: ";

    Label2 -> Font -> Size = 12;
Label2 -> Font-> Style = TFontStyles ( ) << fsBold;
//Utilizando o transparent do label em false,
//Podemos colocar uma cor de fundo do texto.
Label2 -> Transparent = false;
Label2 -> Color = clYellow;
Label2 -> Font -> Name = "Tahoma";
Label2 -> Font -> Color = clBlack;
    Label2 -> Width = 130;
    Label2 -> Height = 20;
    Label2 -> Left = 160;
    Label2 -> Top = 100;
    Label2 -> Caption = "Senha: ";

    Label3 -> Font -> Size = 12;
Label3 -> Font-> Style = TFontStyles ( ) << fsBold;
//Utilizando o transparent do label em false,
//Podemos colocar uma cor de fundo do texto.
Label3 -> Transparent = false;
Label3 -> Color = clYellow;
Label3 -> Font -> Name = "Tahoma";
Label3 -> Font -> Color = clBlack;
    Label3 -> Width = 130;
    Label3 -> Height = 20;
    Label3 -> Left = 160;
    Label3 -> Top = 130;
Label3 -> Caption = "Confirma: ";

    BitBtn1 -> Font -> Size = 12;
BitBtn1 -> Font -> Color = clBlack;
BitBtn1 -> Font -> Style = TFontStyles ( ) << fsBold;
    BitBtn1 -> Top = 160;
    BitBtn1 -> Left = 160;
    BitBtn1 -> Height = 23;
BitBtn1 -> Width = 60;
BitBtn1 -> Caption = "Login";

    BitBtn2 -> Font -> Size = 12;
BitBtn2 -> Font -> Color = clBlack;
BitBtn2 -> Font -> Style = TFontStyles ( ) << fsBold;
BitBtn2 -> Top = 160;
    BitBtn2 -> Left = 300;
BitBtn2 -> Height = 23;
BitBtn2 -> Width = 40;
BitBtn2 -> Caption = "Sair";

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormShow ( TObject *Sender) {
Label_Manual ( Sender );
Panel1 -> Visible = false;
Image3 -> Visible = false;
}
//---------------------------------------------------------------------------
 //Ajustando os tamanhos do form
void __fastcall TForm1::FormResize ( TObject *Sender ) {
Form1 -> Constraints -> MinHeight = 337;
Form1 -> Constraints -> MinWidth = 535;
Form1 -> Constraints -> MaxHeight = 337;
Form1 -> Constraints -> MaxWidth = 535;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click ( TObject *Sender ) {
   Panel1 -> Visible = true;

   AnsiString str_1 = Edit1 -> Text;
   AnsiString str_2 = Edit2 -> Text;
   AnsiString str_3 = Edit3 -> Text;

   if ( str_1 == "" ) {
Panel1 -> Caption = "Edit1 está vazio ?";
Beep ( 500, 500 );
return;
   }
   if ( str_2 == "" ) {
Panel1 -> Caption = "Edit2 está vazio ?";
Beep ( 500, 500 );
return;
   }
   if ( str_3 == "" ) {
Panel1 -> Caption = "Edit3 está vazio ?";
Beep ( 500, 500 );
return;
   }


    String Usuario_1 = "Samuel";
    String Usuario_2 = Edit1 -> Text;
Boolean Result_1 = SameText ( Usuario_1, Usuario_2 );

    String Senha_1 = Edit2 -> Text;
String Senha_2 = Edit3 -> Text;

    if ( Result_1 == False ) {
//Panel1 -> Font -> Color = clBlue;
Panel1 -> Caption = "Usuário não confere";
        Edit1 -> SetFocus ( );
        Edit1 -> Clear ( );
    } else {
        Boolean Result_2 = SameText ( Senha_1, Senha_2 );
        if ( Result_2 == False ) {
//Panel1 -> Font -> Color = clGreen;
            Panel1 -> Caption = "Senhas desiguais";
            Edit2 -> Clear ( );
            Edit3 -> Clear ( );
            Edit2 -> SetFocus ( );
        } else {
//Panel1 -> Font -> Color = clBlack;
Panel1 -> Caption = "Login efetuado";
Image2 -> Visible = false;
Image3 -> Visible = true;
        }
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click ( TObject *Sender ) {
  Close ( );
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate ( TObject *Sender ) {
TGIFImage *gif = new TGIFImage ( );
gif -> Assign ( Image1 -> Picture );
gif -> Animate = true;
Image1 -> Picture -> Assign ( gif );
}
//---------------------------------------------------------------------------