diff --git a/README.md b/README.md index 90ed000..35c6363 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,58 @@ Desenvolver uma aplicação em Delphi que simule um sistema de gerenciamento de - Testes e documentação. Boa sorte com o desafio! Estamos animados para ver o que você pode criar. + + +---------------------------------------------------------------------------- + +## - Solução proposta: + +Foi desenvolvido um sistema para entrada e saida de produtos + +Fluxograma da solução + +![Diagramas técnicos](https://github.com/winaba/desafio-delphi/assets/17182623/9d1b9d47-60ef-4746-9d3c-27ed1d01973f) + + +Composto por: +- telas de Login, +- cadastro de usuario, +- entrada e saida de produtos, +- cadastro de produtos + +Ao abrir o sistema é apresentado a tela de login: + +![Captura de tela 2024-03-09 031242](https://github.com/winaba/desafio-delphi/assets/17182623/e37e77fd-d421-472f-9c55-d029268fbd6e) + + +Caso não possua usuario, é necessario cadastra-lo no botão 'Cadastrar' + +![Captura de tela 2024-03-09 031328](https://github.com/winaba/desafio-delphi/assets/17182623/33e715f1-b734-4fc4-93e8-8e8d57a22e24) + + +Depois de possuir o cadastro e se logar, será apresentado a tela de entrada e saída de prdoutos + +![Captura de tela 2024-03-09 031959](https://github.com/winaba/desafio-delphi/assets/17182623/4ec5fbcb-7ecf-4557-afba-34bc86bdc4f5) + +Caso no momento do cadastro da movimentação o produto não esteja disponivel, clique no botão '+' + +![Captura de tela 2024-03-09 032032](https://github.com/winaba/desafio-delphi/assets/17182623/46ddf955-c97c-406a-b624-931e8849ed45) + + +Configuração + +Para rodar a aplicação é necerio tem um arquivo ini ```config.ini``` configurado no mesmo diretório que o exe + +Exemplo: + +``` +[base] +path=E:\estudos\delphi\desafio_khipo2\desafio-delphi\src\database\desafio_delphi.db +``` +Banco de dados + +O banco de dados utilizado nesta aplicação foi o SQLite + +há exemplos de banco de dados em 'src/database' + + diff --git a/src/database/desafio_delphi.db b/src/database/desafio_delphi.db new file mode 100644 index 0000000..70567a4 Binary files /dev/null and b/src/database/desafio_delphi.db differ diff --git a/src/database/desafio_delphi.db2 b/src/database/desafio_delphi.db2 new file mode 100644 index 0000000..e69de29 diff --git a/src/database/desafio_delphi_bk.db b/src/database/desafio_delphi_bk.db new file mode 100644 index 0000000..70567a4 Binary files /dev/null and b/src/database/desafio_delphi_bk.db differ diff --git "a/src/imagens/Diagramas t\303\251cnicos.jpg" "b/src/imagens/Diagramas t\303\251cnicos.jpg" new file mode 100644 index 0000000..c5178e5 Binary files /dev/null and "b/src/imagens/Diagramas t\303\251cnicos.jpg" differ diff --git a/src/imagens/add_button.png b/src/imagens/add_button.png new file mode 100644 index 0000000..a253c2d Binary files /dev/null and b/src/imagens/add_button.png differ diff --git a/src/model/DAO/desafio.model.dao.connection.dfm b/src/model/DAO/desafio.model.dao.connection.dfm new file mode 100644 index 0000000..672421c --- /dev/null +++ b/src/model/DAO/desafio.model.dao.connection.dfm @@ -0,0 +1,11 @@ +object DMConnection: TDMConnection + Height = 305 + Width = 426 + PixelsPerInch = 120 + object FDConnection1: TFDConnection + Params.Strings = ( + 'DriverID=SQLite') + Left = 160 + Top = 80 + end +end diff --git a/src/model/DAO/desafio.model.dao.connection.pas b/src/model/DAO/desafio.model.dao.connection.pas new file mode 100644 index 0000000..b3601a9 --- /dev/null +++ b/src/model/DAO/desafio.model.dao.connection.pas @@ -0,0 +1,31 @@ +unit desafio.model.dao.connection; + +interface + +uses + System.SysUtils, System.Classes, FireDAC.Stan.Intf, FireDAC.Stan.Option, + FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def, + FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.VCLUI.Wait, + Data.DB, FireDAC.Comp.Client, FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, + FireDAC.Stan.ExprFuncs, FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.Stan.Param, + FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt, FireDAC.Comp.DataSet; + +type + TDMConnection = class(TDataModule) + FDConnection1: TFDConnection; + private + { Private declarations } + public + { Public declarations } + end; + +var + DMConnection: TDMConnection; + +implementation + +{%CLASSGROUP 'Vcl.Controls.TControl'} + +{$R *.dfm} + +end. diff --git a/src/model/implements/desafio.model.implements.connection.pas b/src/model/implements/desafio.model.implements.connection.pas new file mode 100644 index 0000000..d444c87 --- /dev/null +++ b/src/model/implements/desafio.model.implements.connection.pas @@ -0,0 +1,163 @@ +unit desafio.model.implements.connection; + +interface + +uses + desafio.model.interfaces.connection, desafio.model.dao.connection, + FireDAC.Comp.Client, Data.DB, inifiles; + +type + TConnection = class(TInterfacedObject, iConnection) + private + dm : TDMConnection; + FQuery : TFDQuery; + FDataSource : TDataSource; + public + + function sql(aValue : String) : iConnection; + function result : TDataSet; + function datasource : TDataSource; + function query : TFDQuery; + + function open : iConnection; + function close : iConnection; + function exec : iConnection; + function params(aParams : String; aValue : Integer) : iConnection; overload; + function params(aParams : String; aValue : String) : iConnection; overload; + function params(aParams : String; aValue : Currency) : iConnection; overload; + function insert : iConnection; + function cancel : iConnection; + function post : iConnection; + + constructor Create; + destructor Destroy; override; + class function New : iConnection; + end; + +implementation + +uses + System.SysUtils, Vcl.Forms; + +{ TConnection } + +function TConnection.cancel: iConnection; +begin + FQuery.Cancel; + Result := Self; +end; + +function TConnection.close: iConnection; +begin + FQuery.Close; + Result := Self; +end; + +constructor TConnection.Create; + var + iniConf : TIniFile; + vServer, vPath: String; +begin + + iniConf := TIniFile.Create(ExtractFilePath(Application.exeName)+'config.ini'); + try + vPath := iniConf.ReadString('base', 'path', ''); + finally + iniConf.Free; + end; + + dm := TDMConnection.Create(nil); + + dm.FDConnection1.Params.Add('Database='+vPath) ; + + FQuery := TFDQuery.Create(nil); + FQuery.Connection := dm.FDConnection1; + + FDataSource := TDataSource.Create(nil); + FDataSource.DataSet := FQuery; + + +end; + +function TConnection.datasource: TDataSource; +begin + Result := FDataSource; +end; + +destructor TConnection.Destroy; +begin + FDataSource.Free; + FQuery.Free; + dm.Free; + + inherited; +end; + +function TConnection.exec: iConnection; +begin + FQuery.ExecSQL; + Result := Self; +end; + +function TConnection.insert: iConnection; +begin + FQuery.Insert; +end; + +class function TConnection.New: iConnection; +begin + Result := self.Create; +end; + +function TConnection.open: iConnection; +begin + FQuery.Open; + Result := Self; +end; + +function TConnection.params(aParams: String; aValue: Integer): iConnection; +begin + FQuery.ParamByName(aParams).AsInteger := aValue; + Result := self; +end; + +function TConnection.params(aParams: String; aValue: String): iConnection; +begin + FQuery.ParamByName(aParams).AsString := aValue; + Result := self; +end; + + +function TConnection.params(aParams: String; aValue: Currency): iConnection; +begin + FQuery.ParamByName(aParams).AsCurrency := aValue; + Result := self; +end; + +function TConnection.post: iConnection; +begin + FQuery.Post; + Result := Self; +end; + +function TConnection.query: TFDQuery; +begin + result := FQuery; +end; + +function TConnection.result: TDataSet; +begin + Result := FQuery; +end; + +function TConnection.sql(aValue: String): iConnection; +begin + Fquery.Close; + FQuery.SQL.Clear; + FQuery.SQL.Text := aValue; + + Result := Self; +end; + + +end. diff --git a/src/model/implements/desafio.model.implements.orders.pas b/src/model/implements/desafio.model.implements.orders.pas new file mode 100644 index 0000000..67ef812 --- /dev/null +++ b/src/model/implements/desafio.model.implements.orders.pas @@ -0,0 +1,215 @@ +unit desafio.model.implements.orders; + +interface + +uses + desafio.model.interfaces.orders, desafio.model.interfaces.connection, + Data.DB, desafio.model.implements.connection; + + +type + TOrders = class(TInterfacedObject, iOrders) + private + + conn : iConnection; + connView : iConnection; + + FId : Integer; + FProduct : integer; + FTotalValue : Currency; + FTypeMaintenance : Integer; + FCategory : Integer; + + FDateOrder : TDateTime; + + function insert : iOrders; + function cancel : iOrders; + function post(order : iOrders) : iOrders; + + function dataSource : TDataSource; + + function result : TDataSet; + + function searchOrder(aValue : integer) : iOrders; + + function listAllOrders : iOrders; + + function fillObject : iOrders; + + function getId : Integer; + function getTotalValue : Currency; + function getDateOrder : TDateTime; + function getTypeMaintenance : Integer; + function getProduct : Integer; + + procedure setId(aValue : Integer); + procedure setTotalValue(aValue : Currency); + procedure setDateOrder(aValue : TDateTime); + + procedure setTypeMaintenance(aValue : integer); + procedure setProduct(aValue: Integer); + + function viewShowData() : TDataSource; + + public + constructor create; + destructor destroy; override; + class function new : iOrders; + + end; + +implementation + +{ TOrders } + +function TOrders.cancel: iOrders; +begin + conn.result.Cancel; +end; + +constructor TOrders.create; +begin + conn := TConnection.New; +end; + +function TOrders.dataSource: TDataSource; +begin + Result := conn.datasource; +end; + +destructor TOrders.destroy; +begin + //pass + inherited; +end; + +function TOrders.fillObject : iOrders; +begin + FId := conn.result.FieldByName('id').AsInteger; + FProduct := conn.result.FieldByName('product').AsInteger; + FTotalValue := conn.result.FieldByName('total_value').AsCurrency; + FTypeMaintenance := conn.result.FieldByName('type_maintenance').AsInteger; + +end; + +function TOrders.getTotalValue: Currency; +begin + Result := FTotalValue; +end; + +function TOrders.getDateOrder: TDateTime; +begin + Result := FDateOrder; +end; + +function TOrders.getId: Integer; +begin + Result := FId; +end; + +function TOrders.getProduct: Integer; +begin + Result := FProduct; +end; + +function TOrders.getTypeMaintenance: Integer; +begin + Result := FTypeMaintenance; +end; + +function TOrders.insert: iOrders; +begin + conn.result.Insert; + Result := Self; +end; + +function TOrders.listAllOrders: iOrders; +begin + conn.sql('select id, product, quantity, total_value, date_order, type_maintenance '+ + 'from orders') + .open; + + if conn.result.RecordCount > 0 then + begin + fillObject; + end; + + Result := Self; +end; + +class function TOrders.new: iOrders; +begin + Result := self.create; +end; + +function TOrders.post(order : iOrders): iOrders; +begin + conn.result.FieldByName('id').AsInteger := order.getId; + conn.result.FieldByName('total_value').AsCurrency := order.getTotalValue; + conn.result.FieldByName('date_order').AsDateTime := order.getDateOrder; + + conn.result.post; + Result := Self; +end; + +function TOrders.result: TDataSet; +begin + result := conn.result; +end; + +function TOrders.searchOrder(aValue: integer): iOrders; +begin + conn.sql('select id, product, quantity, total_value, date_order '+ + 'from orders where id=:id') + .params('id', aValue) + .open; + + if conn.result.RecordCount > 0 then + begin + FId := conn.result.FieldByName('id').AsInteger; + FTotalValue := conn.result.FieldByName('total_value').AsFloat; + FDateOrder := conn.result.FieldByName('date_order').AsDateTime; + end; + + Result := Self; +end; + +procedure TOrders.setTotalValue(aValue: Currency); +begin + FTotalValue := aValue; +end; + +procedure TOrders.setDateOrder(aValue: TDateTime); +begin + FDateOrder := aValue; +end; + +procedure TOrders.setId(aValue: Integer); +begin + FId := aValue; +end; + +procedure TOrders.setProduct(aValue: Integer); +begin + FProduct := aValue; +end; + +procedure TOrders.setTypeMaintenance(aValue: integer); +begin + FTypeMaintenance := aValue; +end; + +function TOrders.viewShowData: TDataSource; + +begin + connView := TConnection.New; + + connView.sql('select orders.id, trim(products.description) as description, products.sale_price, '+ + 'orders.quantity, orders.total_value, case type_maintenance when 1 THEN "Entrada" ELSE "Saida" END as type_maintenance '+ + 'from orders inner join products on (orders.product=products.id)') + .open; + result := connView.datasource; +end; + +end. + diff --git a/src/model/implements/desafio.model.implements.products.pas b/src/model/implements/desafio.model.implements.products.pas new file mode 100644 index 0000000..43cd762 --- /dev/null +++ b/src/model/implements/desafio.model.implements.products.pas @@ -0,0 +1,248 @@ +unit desafio.model.implements.products; + +interface + +uses + desafio.model.interfaces.products, desafio.model.interfaces.connection, + desafio.model.implements.connection, Data.DB, System.Classes; + +type + TProducts = class(TInterfacedObject, iProducts) + private + conn : iConnection; + + FId : integer; + FDescription : String; + FPriceSell : Currency; + FStorage : Integer; + FCategory: integer; + FPurchasePrice: Currency; + + function dataSource : TDataSource; + function result : TDataSet; + + function searchProducts(aValue : integer) : iProducts; + + function getId : Integer; + function getDescription : String; + function getPriceSell : Currency; + function getPurchasePrice : Currency; + + function getStorage : Double; + function getCategory : Integer; + + procedure setId(aValue : Integer); + procedure setDescription(aValue : String); + procedure setPriceSell(aValue : Currency); + procedure setPurchasePrice(aValue : Currency); + procedure setStorage(aValue : integer); + procedure setCategory(aValue : Integer); + + function listAllProducts: iProducts; + + function fillObject : iProducts; + + function edit(product : iProducts) : iProducts; + + function existProductById(aValue: integer): boolean; + + function strlistAllProducts: string; + + public + + constructor Create; + destructor Destroy; override; + class function New : iProducts; + + end; + +implementation + +uses + System.SysUtils; + +{ TProducts } + +constructor TProducts.Create; +begin + conn := TConnection.New; +end; + +function TProducts.dataSource: TDataSource; +begin + Result := conn.datasource; +end; + +destructor TProducts.Destroy; +begin + //pass + inherited; +end; + +function TProducts.edit(product: iProducts): iProducts; +begin + if existProductById(product.getId) then + begin + conn.sql('update users set '+ + 'description=:description, purchase_price=:purchase_price, '+ + 'sale_price=:sale_price, quantity_stock=:quantity_stock '+ + 'where id=:id ' + ) + .params('id', product.getId) + .params('description', product.getDescription) + .params('purchase_price', product.getPurchasePrice) + .params('sale_price', product.getPriceSell) + .params('quantity_stock', product.getStorage) + .exec; + + searchProducts(product.getId); + end; + + result := self; +end; + +function TProducts.getCategory: Integer; +begin + Result := FCategory; +end; + +function TProducts.getDescription: String; +begin + Result := FDescription; +end; + +function TProducts.getId: Integer; +begin + Result := FId; +end; + +function TProducts.getPriceSell: Currency; +begin + Result := FPriceSell; +end; + +function TProducts.getPurchasePrice: Currency; +begin + Result := FPurchasePrice; +end; + +function TProducts.getStorage: Double; +begin + Result := FStorage; +end; + +class function TProducts.New: iProducts; +begin + result := self.Create; +end; + +function TProducts.result: TDataSet; +begin + result := conn.result; +end; + +function TProducts.searchProducts(aValue: integer): iProducts; +begin + conn.sql('select id, description, purchase_price, sale_price, quantity_stock, category from products where id=:id') + .params('id', aValue) + .open; + + if conn.result.RecordCount > 0 then + begin + fillObject; + end; +end; + +function TProducts.existProductById(aValue: integer): boolean; +begin + conn.sql('select id, description, purchase_price, sale_price, quantity_stock, category from products where id=:id') + .params('id', aValue) + .open; + + result := (conn.result.RecordCount > 0) ; +end; + +function TProducts.fillObject : iProducts; +begin + FId := conn.result.FieldByName('id').AsInteger; + FDescription := conn.result.FieldByName('description').AsString; + FPriceSell := conn.result.FieldByName('sale_price').AsCurrency; + FStorage := conn.result.FieldByName('quantity_stock').AsInteger; + FCategory := conn.result.FieldByName('category').AsInteger; +end; + +procedure TProducts.setCategory(aValue: Integer); +begin + FCategory := aValue; +end; + +procedure TProducts.setDescription(aValue: String); +begin + FDescription := aValue; +end; + +procedure TProducts.setId(aValue: Integer); +begin + FId := aValue; +end; + +procedure TProducts.setPriceSell(aValue: Currency); +begin + FPriceSell := aValue; +end; + +procedure TProducts.setPurchasePrice(aValue: Currency); +begin + FPurchasePrice := aValue; +end; + +procedure TProducts.setStorage(aValue: integer); +begin + FStorage := aValue; +end; + +function TProducts.strlistAllProducts: String; + var + lConn : IConnection; + sProducts : String; +begin + lConn := TConnection.New; + + + lConn.sql('select id, description, purchase_price, sale_price, quantity_stock, category ' + + 'from products') + .open; + + + if lConn.result.RecordCount>0 then + begin + sProducts := ''; + lConn.result.First; + while not lConn.result.Eof do + begin + if trim(sProducts) <> '' then + sProducts := sProducts + ';'; + + sProducts := sProducts + formatFloat('00000',lConn.result.fieldByName('id').AsInteger)+ + '='+ lConn.result.fieldByName('description').AsString; + lConn.result.Next; + end; + + result := sProducts; + end; +end; + +function TProducts.listAllProducts: iProducts; +begin + conn.sql('select id, description, purchase_price, sale_price, quantity_stock, category ' + + 'from products') + .open; + + if conn.result.RecordCount>0 then + fillObject; + + result := self; +end; + +end. + diff --git a/src/model/implements/desafio.model.implements.user.pas b/src/model/implements/desafio.model.implements.user.pas new file mode 100644 index 0000000..f9b19ae --- /dev/null +++ b/src/model/implements/desafio.model.implements.user.pas @@ -0,0 +1,193 @@ +unit desafio.model.implements.user; + +interface + +uses desafio.model.interfaces.user, desafio.model.interfaces.connection, desafio.model.implements.connection; + +type + TUser = class(TInterfacedObject, iUser) + private + conn: iConnection; + + FId: integer; + FName: string; + FEmail: string; + FPassword: string; + + function getId : Integer; + function getName : String; + function getEmail : string; + function getPassword : string; + + procedure setId(aValue : Integer); + procedure setName(aValue : String); + procedure setEmail(aValue : String); + procedure setPassword(aValue : String); + + public + + constructor Create; + destructor Destroy; override; + class function New : iUser; + + function searchUser(aValue: integer): iUser; + function searchUserByEmail(aValue: string) : iUser; + function existUserByEmail(aValue: string): boolean; + function loginUser(aEmail, aPassword : String) : iUser; + function fillObject : iUser; + function insert(user : iUser) : iUser; + + end; + +implementation + +{ TUser } + +constructor TUser.Create; +begin + conn := TConnection.New; +end; + +destructor TUser.Destroy; +begin + //pass + inherited; +end; + + +function TUser.getEmail: string; +begin + Result := FEmail; +end; + +function TUser.getId: Integer; +begin + Result := FId; +end; + +function TUser.getName: String; +begin + Result := FName; +end; + +function TUser.getPassword: string; +begin + Result := FPassword; +end; + +function TUser.insert(user: iUser): iUser; +begin + + if not existUserByEmail(user.getEmail) then + begin + conn.sql('insert into users (name, email, password) '+ + 'values (:name, :email, :password)') + .params('name', user.getName) + .params('email', user.getEmail) + .params('password', user.getPassword) + .exec; + + searchUserByEmail(user.getEmail); + end; + + result := self; +end; + +class function TUser.New: iUser; +begin + result := self.Create; +end; + +procedure TUser.setEmail(aValue: String); +begin + FEmail := aValue; +end; + +procedure TUser.setId(aValue: Integer); +begin + FId := aValue; +end; + +procedure TUser.setName(aValue: String); +begin + FName := aValue; + +end; + +procedure TUser.setPassword(aValue: String); +begin + FPassword := aValue; +end; + +function TUser.searchUser(aValue: integer): iUser; +begin + conn.sql('select id, name, email, password from users where id=:id') + .params('id', aValue) + .open; + + if conn.result.RecordCount > 0 then + begin + FId := conn.result.FieldByName('id').AsInteger; + FName := conn.result.FieldByName('name').AsString; + FEmail := conn.result.FieldByName('email').AsString; + FPassword := conn.result.FieldByName('password').AsString; + end; +end; + +function TUser.searchUserByEmail(aValue: string): iUser; +begin + + FId := 0; + FName := ''; + FEmail := ''; + FPassword := ''; + + conn.sql('select id, name, email, password from users where email=:email') + .params('email', aValue) + .open; + + if conn.result.RecordCount > 0 then + begin + FId := conn.result.FieldByName('id').AsInteger; + FName := conn.result.FieldByName('name').AsString; + FEmail := conn.result.FieldByName('email').AsString; + FPassword := conn.result.FieldByName('password').AsString; + end; +end; + +function TUser.existUserByEmail(aValue: string): boolean; +begin + conn.sql('select id, name, email, password from users where email=:email') + .params('email', aValue) + .open; + + result := (conn.result.RecordCount > 0); +end; + + +function TUser.loginUser(aEmail, aPassword : String): iUser; +begin + result := Nil; + + conn.SQL('select * from users where email=:email and password=:password'); + conn.Params('email', aEmail); + conn.Params('password', aPassword); + conn.Open; + + if not conn.result.IsEmpty then + Result := fillObject; +end; + +function TUser.fillObject: iUser; +begin + Result := TUser.Create; + conn.result.First; + + Result.setId(conn.result.FieldByName('id').AsInteger); + Result.setName(conn.result.FieldByName('name').AsString); + Result.setEmail(conn.result.FieldByName('email').AsString); + Result.setPassword(conn.result.FieldByName('password').AsString); +end; + + +end. diff --git a/src/model/interfaces/desafio.model.interfaces.category.pas b/src/model/interfaces/desafio.model.interfaces.category.pas new file mode 100644 index 0000000..64946ae --- /dev/null +++ b/src/model/interfaces/desafio.model.interfaces.category.pas @@ -0,0 +1,23 @@ +unit desafio.model.interfaces.category; + +interface + +type + +iCategory = interface + + function searchCategory(aValue : integer) : iCategory; + + function getId : Integer; + function getDescription : String; + + procedure setId(aValue : Integer) ; + procedure setDescription(aValue : String) ; + + + end; + + +implementation + +end. diff --git a/src/model/interfaces/desafio.model.interfaces.connection.pas b/src/model/interfaces/desafio.model.interfaces.connection.pas new file mode 100644 index 0000000..6b040c6 --- /dev/null +++ b/src/model/interfaces/desafio.model.interfaces.connection.pas @@ -0,0 +1,29 @@ +unit desafio.model.interfaces.connection; + +interface + + +uses Data.DB, FireDAC.Comp.Client; + +type + iConnection = interface + function sql(aValue : String) : iConnection; + function result : TDataSet; + function datasource : TDataSource; + function query : TFDQuery; + + function open : iConnection; + function close : iConnection; + function exec : iConnection; + function params(aParams : String; aValue : Integer) : iConnection; overload; + function params(aParams : String; aValue : String) : iConnection; overload; + function params(aParams : String; aValue : Currency) : iConnection; overload; + function insert : iConnection; + function cancel : iConnection; + function post : iConnection; + end; + + +implementation + +end. diff --git a/src/model/interfaces/desafio.model.interfaces.order_items.pas b/src/model/interfaces/desafio.model.interfaces.order_items.pas new file mode 100644 index 0000000..ea8d783 --- /dev/null +++ b/src/model/interfaces/desafio.model.interfaces.order_items.pas @@ -0,0 +1,38 @@ +unit desafio.model.interfaces.order_items; + +interface + +uses + Data.DB, FireDAC.Comp.Client; + +type + + iOrder_items = interface + + function dataSource: TDataSource; + + function searchOrder_items(aValue: Integer): iOrder_items; + + function listOrderDetails(dsMaster: TDataSource; + masterFields, indexFieldNames: String): iOrder_items; + + function query: TFDQuery; + + function getId: Integer; + function getIdOrder: Integer; + function getIdProduct: Integer; + function getPriceSell: Currency; + function getQuantity: Integer; + + procedure setId(const Value: Integer); + procedure setIdOrder(const Value: Integer); + procedure setIdProduct(const Value: Integer); + procedure setPriceSell(const Value: Currency); + procedure setQuantity(const Value: Integer); + + end; + + +implementation + +end. diff --git a/src/model/interfaces/desafio.model.interfaces.orders.pas b/src/model/interfaces/desafio.model.interfaces.orders.pas new file mode 100644 index 0000000..57b6d5d --- /dev/null +++ b/src/model/interfaces/desafio.model.interfaces.orders.pas @@ -0,0 +1,44 @@ +unit desafio.model.interfaces.orders; + +interface + +uses + Data.DB; + +type + iOrders = interface + + function insert : iOrders; + function cancel : iOrders; + function post(order : iOrders) : iOrders; + + function dataSource : TDataSource; + + function result : TDataSet; + + function searchOrder(aValue : integer) : iOrders; + + function listAllOrders : iOrders; + + function fillObject : iOrders; + + function getId : Integer; + function getTotalValue : Currency; + function getDateOrder : TDateTime; + function getTypeMaintenance : Integer; + function getProduct : Integer; + + + procedure setId(aValue : Integer); + procedure setTotalValue(aValue : Currency); + procedure setDateOrder(aValue : TDateTime); + procedure setTypeMaintenance(aValue : integer); + procedure setProduct(aValue: Integer); + + function viewShowData: TDataSource; + + end; + +implementation + +end. diff --git a/src/model/interfaces/desafio.model.interfaces.products.pas b/src/model/interfaces/desafio.model.interfaces.products.pas new file mode 100644 index 0000000..95ea580 --- /dev/null +++ b/src/model/interfaces/desafio.model.interfaces.products.pas @@ -0,0 +1,45 @@ +unit desafio.model.interfaces.products; + +interface + +uses + Data.DB, System.Classes; + +type + iProducts = interface + + function dataSource : TDataSource; + function result : TDataSet; + + function searchProducts(aValue : integer) : iProducts; + function listAllProducts: iProducts; + function fillObject : iProducts; + + function getId : Integer; + function getDescription : String; + function getStorage : Double; + function getPriceSell : Currency; + function getPurchasePrice : Currency; + function getCategory : Integer; + + procedure setId(aValue : Integer) ; + procedure setDescription(aValue : String) ; + procedure setStorage(aValue : Integer); + procedure setPriceSell(aValue : Currency) ; + procedure setPurchasePrice(aValue : Currency); + procedure setCategory(aValue : Integer); + + function existProductById(aValue: integer): boolean; + function strlistAllProducts : string; + + + end; + + +implementation + +end. +n + +uses + System.Classes; diff --git a/src/model/interfaces/desafio.model.interfaces.user.pas b/src/model/interfaces/desafio.model.interfaces.user.pas new file mode 100644 index 0000000..06b5efc --- /dev/null +++ b/src/model/interfaces/desafio.model.interfaces.user.pas @@ -0,0 +1,28 @@ +unit desafio.model.interfaces.user; + +interface + +type + + iUser = interface + + function getId : Integer; + function getName : String; + function getEmail : string; + function getPassword : string; + + procedure setId(aValue : Integer); + procedure setName(aValue : String); + procedure setEmail(aValue : String); + procedure setPassword(aValue : String); + + function loginUser(aEmail, aPassword : String) : iUser; + function insert(user : iUser) : iUser; + + end; + + + +implementation + +end. diff --git a/src/prjDesafioDelphi.dpr b/src/prjDesafioDelphi.dpr new file mode 100644 index 0000000..9e6dd88 --- /dev/null +++ b/src/prjDesafioDelphi.dpr @@ -0,0 +1,29 @@ +program prjDesafioDelphi; + +uses + Vcl.Forms, + desafio.view.main in 'view\desafio.view.main.pas' {frmMain}, + desafio.view.login in 'view\desafio.view.login.pas' {frmLogin}, + desafio.model.interfaces.products in 'model\interfaces\desafio.model.interfaces.products.pas', + desafio.model.interfaces.category in 'model\interfaces\desafio.model.interfaces.category.pas', + desafio.model.interfaces.orders in 'model\interfaces\desafio.model.interfaces.orders.pas', + desafio.model.interfaces.connection in 'model\interfaces\desafio.model.interfaces.connection.pas', + desafio.model.interfaces.order_items in 'model\interfaces\desafio.model.interfaces.order_items.pas', + desafio.model.interfaces.user in 'model\interfaces\desafio.model.interfaces.user.pas', + desafio.model.implements.user in 'model\implements\desafio.model.implements.user.pas', + desafio.model.implements.connection in 'model\implements\desafio.model.implements.connection.pas', + desafio.model.dao.connection in 'model\DAO\desafio.model.dao.connection.pas' {DMConnection: TDataModule}, + desafio.view.register.user in 'view\desafio.view.register.user.pas' {frmRegisterUser}, + desafio.model.implements.orders in 'model\implements\desafio.model.implements.orders.pas', + desafio.model.implements.products in 'model\implements\desafio.model.implements.products.pas', + desafio.view.register.product in 'view\desafio.view.register.product.pas' {frmRegisterProduct}; + +{$R *.res} + +begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + ReportMemoryLeaksOnShutdown := true; + Application.CreateForm(TfrmMain, frmMain); + Application.Run; +end. diff --git a/src/prjDesafioDelphi.dproj b/src/prjDesafioDelphi.dproj new file mode 100644 index 0000000..e9d679a --- /dev/null +++ b/src/prjDesafioDelphi.dproj @@ -0,0 +1,999 @@ + + + {B9A98A53-2F7F-46D9-AF0D-664465D7BAA2} + 19.5 + VCL + True + Debug + Win32 + 1 + Application + prjDesafioDelphi.dpr + + + true + + + true + Base + true + + + true + Base + true + + + true + Base + true + + + true + Cfg_1 + true + true + + + true + Base + true + + + true + Cfg_2 + true + true + + + .\$(Platform)\$(Config) + .\$(Platform)\$(Config) + false + false + false + false + false + System;Xml;Data;Datasnap;Web;Soap;Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;$(DCC_Namespace) + $(BDS)\bin\delphi_PROJECTICON.ico + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png + $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png + prjDesafioDelphi + + + soapserver;IndySystem;vclwinx;fmx;vclie;DbxCommonDriver;bindengine;vcldb;IndyIPCommon;VCLRESTComponents;FireDACCommonODBC;FireDACCommonDriver;appanalytics;IndyProtocols;vclx;IndyIPClient;dbxcds;vcledge;vclFireDAC;bindcompvclwinx;bindcomp;FireDACCommon;IndyCore;RESTBackendComponents;bindcompfmx;bindcompdbx;inetdb;rtl;FireDACMySQLDriver;FireDACSqliteDriver;DbxClientDriver;FireDACADSDriver;RESTComponents;soapmidas;DBXSqliteDriver;vcl;vclactnband;IndyIPServer;dsnapxml;fmxFireDAC;dbexpress;dsnapcon;adortl;DBXMySQLDriver;VclSmp;inet;vclimg;vcltouch;FireDACPgDriver;FireDAC;fmxase;inetdbxpress;xmlrtl;tethering;dbrtl;bindcompvcl;dsnap;fmxdae;CloudService;FireDACMSAccDriver;CustomIPTransport;fmxobj;bindcompvclsmp;soaprtl;vcldsnap;DBXInterBaseDriver;FireDACIBDriver;$(DCC_UsePackage) + Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) + Debug + true + CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= + 1033 + $(BDS)\bin\default_app.manifest + + + soapserver;IndySystem;vclwinx;fmx;vclie;DbxCommonDriver;bindengine;vcldb;IndyIPCommon;VCLRESTComponents;FireDACCommonODBC;FireDACCommonDriver;appanalytics;IndyProtocols;vclx;IndyIPClient;dbxcds;vcledge;vclFireDAC;bindcompvclwinx;bindcomp;FireDACCommon;IndyCore;RESTBackendComponents;bindcompfmx;bindcompdbx;inetdb;rtl;FireDACMySQLDriver;FireDACSqliteDriver;DbxClientDriver;FireDACADSDriver;RESTComponents;soapmidas;DBXSqliteDriver;vcl;vclactnband;IndyIPServer;dsnapxml;fmxFireDAC;dbexpress;dsnapcon;adortl;DBXMySQLDriver;VclSmp;inet;vclimg;vcltouch;FireDACPgDriver;FireDAC;fmxase;inetdbxpress;xmlrtl;tethering;dbrtl;bindcompvcl;dsnap;fmxdae;CloudService;FireDACMSAccDriver;CustomIPTransport;fmxobj;bindcompvclsmp;soaprtl;vcldsnap;DBXInterBaseDriver;FireDACIBDriver;$(DCC_UsePackage) + + + DEBUG;$(DCC_Define) + true + false + true + true + true + true + true + + + false + PerMonitorV2 + true + 1033 + + + false + RELEASE;$(DCC_Define) + 0 + 0 + + + PerMonitorV2 + + + + MainSource + + +
frmMain
+ dfm +
+ +
frmLogin
+ dfm +
+ + + + + + + + + +
DMConnection
+ dfm + TDataModule +
+ +
frmRegisterUser
+ dfm +
+ + + +
frmRegisterProduct
+ dfm +
+ + Base + + + Cfg_1 + Base + + + Cfg_2 + Base + +
+ + Delphi.Personality.12 + Application + + + + prjDesafioDelphi.dpr + + + Microsoft Office 2000 Sample Automation Server Wrapper Components + Microsoft Office XP Sample Automation Server Wrapper Components + + + + + + prjDesafioDelphi.exe + true + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + classes + 64 + + + classes + 64 + + + + + res\xml + 1 + + + res\xml + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\armeabi + 1 + + + library\lib\armeabi + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + library\lib\mips + 1 + + + library\lib\mips + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + + + library\lib\armeabi-v7a + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\values-v21 + 1 + + + res\values-v21 + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + res\drawable + 1 + + + res\drawable + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-ldpi + 1 + + + res\drawable-ldpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-mdpi + 1 + + + res\drawable-mdpi + 1 + + + + + res\drawable-hdpi + 1 + + + res\drawable-hdpi + 1 + + + + + res\drawable-xhdpi + 1 + + + res\drawable-xhdpi + 1 + + + + + res\drawable-xxhdpi + 1 + + + res\drawable-xxhdpi + 1 + + + + + res\drawable-xxxhdpi + 1 + + + res\drawable-xxxhdpi + 1 + + + + + res\drawable-small + 1 + + + res\drawable-small + 1 + + + + + res\drawable-normal + 1 + + + res\drawable-normal + 1 + + + + + res\drawable-large + 1 + + + res\drawable-large + 1 + + + + + res\drawable-xlarge + 1 + + + res\drawable-xlarge + 1 + + + + + res\values + 1 + + + res\values + 1 + + + + + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + Contents\MacOS + 1 + .framework + + + Contents\MacOS + 1 + .framework + + + Contents\MacOS + 1 + .framework + + + 0 + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .dll;.bpl + + + + + 1 + .dylib + + + 1 + .dylib + + + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + Contents\MacOS + 1 + .dylib + + + 0 + .bpl + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + Contents\Resources\StartUp\ + 0 + + + Contents\Resources\StartUp\ + 0 + + + Contents\Resources\StartUp\ + 0 + + + 0 + + + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + ..\ + 1 + + + + + Contents + 1 + + + Contents + 1 + + + Contents + 1 + + + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + Contents\Resources + 1 + + + + + library\lib\armeabi-v7a + 1 + + + library\lib\arm64-v8a + 1 + + + 1 + + + 1 + + + 1 + + + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 1 + + + Contents\MacOS + 1 + + + 0 + + + + + library\lib\armeabi-v7a + 1 + + + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF + 1 + + + + + ..\ + 1 + + + ..\ + 1 + + + ..\ + 1 + + + + + 1 + + + 1 + + + 1 + + + + + ..\$(PROJECTNAME).launchscreen + 64 + + + ..\$(PROJECTNAME).launchscreen + 64 + + + + + 1 + + + 1 + + + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + Assets + 1 + + + Assets + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset + 1 + + + + + + + + + + + + + + + + True + False + + + 12 + + + + +
diff --git a/src/view/desafio.view.login.dfm b/src/view/desafio.view.login.dfm new file mode 100644 index 0000000..f6d5c62 --- /dev/null +++ b/src/view/desafio.view.login.dfm @@ -0,0 +1,180 @@ +object frmLogin: TfrmLogin + Left = 0 + Top = 0 + Caption = 'Desafio Delphi - Khipo' + ClientHeight = 390 + ClientWidth = 551 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -12 + Font.Name = 'Segoe UI' + Font.Style = [] + Position = poScreenCenter + TextHeight = 15 + object Panel1: TPanel + Left = 0 + Top = 0 + Width = 551 + Height = 97 + Align = alTop + BevelOuter = bvNone + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 30 + Padding.Top = 30 + Padding.Right = 30 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 0 + ExplicitWidth = 628 + object Label1: TLabel + Left = 30 + Top = 30 + Width = 491 + Height = 23 + Align = alTop + Caption = 'Usu'#225'rio' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + ExplicitWidth = 58 + end + object edEmail: TEdit + Left = 30 + Top = 56 + Width = 491 + Height = 31 + Align = alBottom + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + TabOrder = 0 + Text = 'lauro@gmail.com' + ExplicitTop = 96 + ExplicitWidth = 568 + end + end + object Panel3: TPanel + Left = 0 + Top = 244 + Width = 551 + Height = 146 + Align = alBottom + BevelOuter = bvNone + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 30 + Padding.Top = 30 + Padding.Right = 30 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 2 + ExplicitTop = 296 + ExplicitWidth = 628 + object Button1: TButton + Left = 270 + Top = 30 + Width = 130 + Height = 106 + Align = alRight + Caption = 'Entrar' + TabOrder = 0 + OnClick = Button1Click + ExplicitLeft = 392 + ExplicitTop = 31 + ExplicitHeight = 104 + end + object Button2: TButton + Left = 400 + Top = 30 + Width = 121 + Height = 106 + Align = alRight + Caption = 'Cadastrar' + TabOrder = 1 + OnClick = Button2Click + ExplicitLeft = 464 + ExplicitTop = 31 + ExplicitHeight = 104 + end + object Button3: TButton + Left = 30 + Top = 30 + Width = 122 + Height = 106 + Align = alLeft + Caption = 'Cancelar' + TabOrder = 2 + OnClick = Button3Click + ExplicitLeft = 87 + ExplicitTop = 39 + ExplicitHeight = 104 + end + end + object Panel2: TPanel + Left = 0 + Top = 97 + Width = 551 + Height = 97 + Align = alTop + BevelOuter = bvNone + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 30 + Padding.Top = 30 + Padding.Right = 30 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 1 + ExplicitTop = 8 + ExplicitWidth = 628 + object Label2: TLabel + Left = 30 + Top = 30 + Width = 491 + Height = 23 + Align = alTop + Caption = 'Senha' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + ExplicitWidth = 47 + end + object edPassword: TEdit + Left = 30 + Top = 56 + Width = 491 + Height = 31 + Align = alBottom + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + PasswordChar = '*' + TabOrder = 0 + Text = '123' + ExplicitWidth = 568 + end + end +end diff --git a/src/view/desafio.view.login.pas b/src/view/desafio.view.login.pas new file mode 100644 index 0000000..8abec40 --- /dev/null +++ b/src/view/desafio.view.login.pas @@ -0,0 +1,66 @@ +unit desafio.view.login; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; + +type + TfrmLogin = class(TForm) + Panel1: TPanel; + Panel3: TPanel; + Button1: TButton; + Button2: TButton; + Button3: TButton; + edEmail: TEdit; + Label1: TLabel; + Panel2: TPanel; + Label2: TLabel; + edPassword: TEdit; + procedure Button1Click(Sender: TObject); + procedure Button2Click(Sender: TObject); + procedure Button3Click(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + frmLogin: TfrmLogin; + +implementation + +uses desafio.view.register.user; + +{$R *.dfm} + +procedure TfrmLogin.Button1Click(Sender: TObject); +begin + ModalResult := mrOk; +end; + +procedure TfrmLogin.Button2Click(Sender: TObject); +var + lRegisterUser: TfrmRegisterUser; +begin + lRegisterUser:= TfrmRegisterUser.Create(nil); + try + lRegisterUser.ShowModal; + if lRegisterUser.ModalResult = mrOk then + begin + self.edEmail.Text := lRegisterUser.edtEmail.Text; + self.edPassword.Text := lRegisterUser.edtPassword.Text; + end; + finally + FreeAndNil(lRegisterUser); + end; +end; + +procedure TfrmLogin.Button3Click(Sender: TObject); +begin + close; +end; + +end. diff --git a/src/view/desafio.view.main.dfm b/src/view/desafio.view.main.dfm new file mode 100644 index 0000000..baa713f --- /dev/null +++ b/src/view/desafio.view.main.dfm @@ -0,0 +1,302 @@ +object frmMain: TfrmMain + Left = 0 + Top = 0 + Caption = 'Desafio Delphi - Khipo' + ClientHeight = 503 + ClientWidth = 824 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -12 + Font.Name = 'Segoe UI' + Font.Style = [] + Position = poScreenCenter + OnCreate = FormCreate + TextHeight = 15 + object Panel1: TPanel + Left = 0 + Top = 65 + Width = 824 + Height = 72 + Align = alTop + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 20 + Padding.Right = 10 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 0 + ExplicitWidth = 818 + object Label1: TLabel + Left = 11 + Top = 21 + Width = 167 + Height = 40 + Align = alLeft + Caption = 'Tipo de manuten'#231#227'o: ' + ExplicitHeight = 23 + end + object cbTypeMaintenance: TComboBox + Left = 196 + Top = 21 + Width = 461 + Height = 31 + TabOrder = 0 + Text = '--Tipo de manuten'#231#227'o (Entrada/Sa'#237'da)--' + end + end + object Panel2: TPanel + Left = 0 + Top = 137 + Width = 824 + Height = 63 + Align = alTop + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 20 + Padding.Right = 20 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 1 + ExplicitWidth = 818 + object Panel6: TPanel + Left = 11 + Top = 21 + Width = 185 + Height = 31 + Align = alLeft + BevelOuter = bvNone + TabOrder = 0 + object Label2: TLabel + Left = 0 + Top = 0 + Width = 71 + Height = 31 + Align = alLeft + Caption = 'Produto: ' + ExplicitHeight = 23 + end + end + object Panel7: TPanel + Left = 196 + Top = 21 + Width = 461 + Height = 31 + Align = alLeft + BevelOuter = bvNone + TabOrder = 1 + object btAddProduct: TButton + Left = 417 + Top = 0 + Width = 44 + Height = 31 + Align = alRight + Caption = '+' + TabOrder = 0 + OnClick = btAddProductClick + end + object dbcbProducts: TComboBox + Left = 0 + Top = 0 + Width = 417 + Height = 31 + Align = alClient + TabOrder = 1 + Text = '--Lista de Produtos--' + OnChange = dbcbProductsChange + end + end + object Panel8: TPanel + Left = 657 + Top = 21 + Width = 185 + Height = 31 + Align = alLeft + BevelOuter = bvNone + Padding.Left = 20 + TabOrder = 2 + object lbProductValue: TLabel + Left = 20 + Top = 0 + Width = 70 + Height = 31 + Align = alLeft + Caption = 'R$ 0,00 ' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -20 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + ExplicitHeight = 28 + end + end + end + object Panel3: TPanel + Left = 0 + Top = 0 + Width = 824 + Height = 65 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 20 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 2 + ExplicitWidth = 818 + object DBNavOrders: TDBNavigator + Left = 10 + Top = 20 + Width = 804 + Height = 35 + Align = alClient + TabOrder = 0 + OnClick = DBNavOrdersClick + ExplicitWidth = 798 + end + end + object Panel5: TPanel + Left = 0 + Top = 200 + Width = 824 + Height = 65 + Align = alTop + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 20 + Padding.Right = 10 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 3 + ExplicitWidth = 818 + object Label4: TLabel + Left = 11 + Top = 21 + Width = 94 + Height = 33 + Align = alLeft + Caption = 'Quantidade:' + ExplicitHeight = 23 + end + object dbeQuantity: TDBEdit + Left = 200 + Top = 16 + Width = 121 + Height = 31 + TabOrder = 0 + OnExit = dbeQuantityExit + end + object Panel9: TPanel + Left = 613 + Top = 21 + Width = 200 + Height = 33 + Align = alRight + BevelOuter = bvNone + TabOrder = 1 + ExplicitLeft = 607 + object lbTotalOrder: TLabel + Left = 0 + Top = 0 + Width = 200 + Height = 33 + Align = alClient + Caption = 'Total: R$ ' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -20 + Font.Name = 'Segoe UI' + Font.Style = [] + ParentFont = False + ExplicitWidth = 79 + ExplicitHeight = 28 + end + end + end + object Panel4: TPanel + Left = 0 + Top = 264 + Width = 824 + Height = 239 + Align = alBottom + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 20 + Padding.Right = 10 + Padding.Bottom = 20 + ParentFont = False + TabOrder = 4 + ExplicitTop = 255 + ExplicitWidth = 818 + object Label3: TLabel + Left = 11 + Top = 21 + Width = 802 + Height = 23 + Align = alTop + Caption = 'Historico de transa'#231#245'es:' + ExplicitWidth = 181 + end + object DBGOrders: TDBGrid + Left = 11 + Top = 44 + Width = 802 + Height = 174 + Align = alClient + TabOrder = 0 + TitleFont.Charset = DEFAULT_CHARSET + TitleFont.Color = clWindowText + TitleFont.Height = -17 + TitleFont.Name = 'Segoe UI' + TitleFont.Style = [] + Columns = < + item + Expanded = False + Width = 50 + Visible = True + end + item + Expanded = False + Width = 300 + Visible = True + end + item + Expanded = False + Width = 100 + Visible = True + end + item + Expanded = False + Width = 100 + Visible = True + end + item + Expanded = False + Width = 100 + Visible = True + end + item + Expanded = False + Width = 100 + Visible = True + end> + end + end +end diff --git a/src/view/desafio.view.main.pas b/src/view/desafio.view.main.pas new file mode 100644 index 0000000..66dd262 --- /dev/null +++ b/src/view/desafio.view.main.pas @@ -0,0 +1,291 @@ +unit desafio.view.main; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.DBCtrls, Vcl.ExtCtrls, + Data.DB, Vcl.Grids, Vcl.DBGrids, Vcl.Mask; + +type + TfrmMain = class(TForm) + Panel1: TPanel; + Label1: TLabel; + Panel2: TPanel; + Panel3: TPanel; + DBNavOrders: TDBNavigator; + Panel5: TPanel; + Label4: TLabel; + dbeQuantity: TDBEdit; + Panel4: TPanel; + DBGOrders: TDBGrid; + Panel6: TPanel; + Panel7: TPanel; + Label2: TLabel; + Panel8: TPanel; + lbProductValue: TLabel; + btAddProduct: TButton; + dbcbProducts: TComboBox; + cbTypeMaintenance: TComboBox; + Panel9: TPanel; + lbTotalOrder: TLabel; + Label3: TLabel; + procedure FormCreate(Sender: TObject); + procedure btAddProductClick(Sender: TObject); + procedure DBNavOrdersClick(Sender: TObject; Button: TNavigateBtn); + procedure dbcbProductsChange(Sender: TObject); + procedure dbeQuantityExit(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + + function userValidation(aEmail, aPassword: String): Boolean; + procedure fillComboProducts; + procedure setRowComboProduct(idProduct: Integer); + + function priceSetProduct(idProduct : integer) : Currency; + procedure updateValuesInScreen(); + end; + +var + frmMain: TfrmMain; + +implementation + +uses desafio.view.login, desafio.model.interfaces.user, desafio.model.implements.user, + desafio.model.interfaces.orders, desafio.model.implements.orders, + desafio.model.interfaces.products, desafio.model.implements.products, + desafio.view.register.product; + +var + lUser : iUser; + lOrders : iOrders; + lProducts : iProducts; + + +{$R *.dfm} + +procedure TfrmMain.btAddProductClick(Sender: TObject); + var + lRegisterProduct: TfrmRegisterProduct; +begin + lRegisterProduct := TfrmRegisterProduct.create(nil); + + try + + lRegisterProduct.ShowModal; + + DBcbProducts.Items.Clear; + DBcbProducts.Items.Delimiter := ';'; + DBcbProducts.Items.StrictDelimiter := true; + DBcbProducts.Items.DelimitedText := lProducts.strlistAllProducts; + + finally + lRegisterProduct.Free; + end; + +end; + +procedure TfrmMain.FormCreate(Sender: TObject); +var + lLogin: TfrmLogin; + loginProcess : boolean; +begin + lLogin := TfrmLogin.create(nil); + try + + loginProcess := true; + + while loginProcess do + begin + + lLogin.ShowModal; + + try + if not (lLogin.ModalResult = mrOk) then + begin + loginProcess := false; + Application.Terminate; + end + else if userValidation(lLogin.edEmail.Text, lLogin.edPassword.Text) then + begin + loginProcess := false; + end + else + showmessage('Usuario não autenticado'); + except + showmessage('Houve um erro, verifique os arquivos de configuração.'); + Application.Terminate; + end; + end; + + if Assigned(lUser) then + begin + if lUser.getId>0 then + begin + + lOrders := TOrders.new; + lProducts := TProducts.new; + + lProducts.listAllProducts; + + lOrders.listAllOrders; + + DBNavOrders.DataSource := lOrders.dataSource; + + cbTypeMaintenance.items.clear; + cbTypeMaintenance.items.Delimiter:= ';'; + cbTypeMaintenance.items.StrictDelimiter := true; + cbTypeMaintenance.Items.DelimitedText := 'Entrada;Saída'; + + fillComboProducts; + + DBGOrders.DataSource := lOrders.viewShowData; + + DBGOrders.Columns[0].FieldName := 'id'; + DBGOrders.Columns[1].FieldName := 'description'; + DBGOrders.Columns[2].FieldName := 'sale_price'; + DBGOrders.Columns[3].FieldName := 'quantity'; + DBGOrders.Columns[4].FieldName := 'total_value'; + DBGOrders.Columns[5].FieldName := 'type_maintenance'; + + DBGOrders.ReadOnly := true; + + dbeQuantity.DataField := 'quantity'; + dbeQuantity.DataSource := lOrders.dataSource; + + cbTypeMaintenance.ItemIndex := lOrders.getTypeMainTenance; + + setRowComboProduct(lOrders.getProduct); + + updateValuesInScreen(); + + end; + end; + + finally + lLogin.Free; + end; + +end; + +procedure TfrmMain.setRowComboProduct(idProduct: Integer); + var + lProductInCombo : iProducts; + idToFind : String; + idFound : Integer; +begin + lProductInCombo := TProducts.New; + lProductInCombo.searchProducts(idProduct) ; + + if lProductInCombo.getId > 0 then + begin + idToFind := formatFloat('00000',lProductInCombo.getId); + + idToFind := idToFind + '=' +lProductInCombo.getDescription; + idFound := DBcbProducts.Items.IndexOf(idToFind); + DBcbProducts.ItemIndex := idFound ; + lbProductValue.Caption := 'R$ '+formatfloat('#,###0.00',lProductInCombo.getPriceSell); + end; + +end; + +procedure TfrmMain.dbcbProductsChange(Sender: TObject); +begin + updateValuesInScreen(); +end; + +procedure TfrmMain.dbeQuantityExit(Sender: TObject); +begin + updateValuesInScreen(); +end; + +procedure TfrmMain.updateValuesInScreen(); + var + iIdProduct : Integer; + lQuantity : Double; + lpriceSetProduct : Currency; +begin + + lQuantity := 0; + + iIdProduct := strToIntDef(copy(dbcbProducts.Text,0,5),0); + + lpriceSetProduct := priceSetProduct(iIdProduct) ; + + lQuantity := strToFloatDef(trim(dbeQuantity.Text),0) ; + + if lQuantity>0 then + lbTotalOrder.caption := 'Total: R$ '+ formatFloat('#,###,##0.00',lpriceSetProduct * lQuantity); + + lbProductValue.Caption := 'R$ '+formatFloat('#,###,##0.00',lpriceSetProduct); +end; + +function TfrmMain.priceSetProduct(idProduct : integer) : Currency; + var + lProductRefreshPrice : iProducts; +begin + lProductRefreshPrice := TProducts.New; + + lProductRefreshPrice.searchProducts(idProduct); + + result := lProductRefreshPrice.getPriceSell; +end; + + +procedure TfrmMain.DBNavOrdersClick(Sender: TObject; Button: TNavigateBtn); +begin + if Button in [nbInsert] then + begin + cbTypeMaintenance.ItemIndex := -1; + dbcbProducts.ItemIndex := -1; + lbProductValue.Caption := 'R$ 0,00'; + lbTotalOrder.Caption := 'Total: R$ 0,00'; + end + else if Button in [nbCancel] then + begin + setRowComboProduct(lOrders.getProduct); + updateValuesInScreen; + end + else if Button in [nbFirst, nbPrior, nbNext, nbLast] then + begin + lOrders.fillObject; + cbTypeMaintenance.ItemIndex := lOrders.getTypeMainTenance-1; + setRowComboProduct(lOrders.getProduct); + updateValuesInScreen; + end + else if Button in [nbPost] then + begin + lOrders.result.Edit; + lOrders.result.FieldByName('type_maintenance').AsInteger := cbTypeMaintenance.ItemIndex+1; + lOrders.result.FieldByName('product').AsInteger := StrToIntDef(copy(dbcbProducts.Text, 0, 5),0); + lOrders.result.FieldByName('total_value').AsCurrency := priceSetProduct(StrToIntDef(copy(dbcbProducts.Text, 0, 5),0))*strtointdef(DBEQUANTITY.Text,0); + lOrders.result.Post; + lOrders.fillObject; + DBGOrders.DataSource := lOrders.viewShowData; + end; + +end; + +procedure TfrmMain.fillComboProducts; +begin + DBcbProducts.Items.Clear; + DBcbProducts.Items.Delimiter := ';'; + DBcbProducts.Items.StrictDelimiter := true; + DBcbProducts.Items.DelimitedText := lProducts.strlistAllProducts; +end; + +function TfrmMain.userValidation(aEmail, aPassword: String): Boolean; +begin + lUser := TUser.new; + + lUser := lUser.LoginUser(aEmail, aPassword); + + if not Assigned(lUser) then + Result := False + else + Result := not lUser.getId.ToString.IsEmpty; +end; + +end. diff --git a/src/view/desafio.view.register.product.dfm b/src/view/desafio.view.register.product.dfm new file mode 100644 index 0000000..c14f301 --- /dev/null +++ b/src/view/desafio.view.register.product.dfm @@ -0,0 +1,245 @@ +object frmRegisterProduct: TfrmRegisterProduct + Left = 0 + Top = 0 + Caption = 'Desafio Delphi - Khipo' + ClientHeight = 442 + ClientWidth = 784 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -12 + Font.Name = 'Segoe UI' + Font.Style = [] + Position = poScreenCenter + OnCreate = FormCreate + TextHeight = 15 + object Panel3: TPanel + Left = 0 + Top = 65 + Width = 784 + Height = 377 + Align = alClient + BevelOuter = bvNone + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 0 + ExplicitWidth = 778 + ExplicitHeight = 368 + object Panel4: TPanel + Left = 10 + Top = 10 + Width = 764 + Height = 87 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 0 + object Label1: TLabel + Left = 10 + Top = 10 + Width = 744 + Height = 23 + Align = alTop + Caption = 'Descri'#231#227'o' + ExplicitWidth = 73 + end + object edDescription: TEdit + Left = 10 + Top = 46 + Width = 744 + Height = 31 + Align = alBottom + TabOrder = 0 + Text = 'edDescription' + OnChange = edDescriptionChange + ExplicitTop = 71 + ExplicitWidth = 738 + end + end + object Panel5: TPanel + AlignWithMargins = True + Left = 10 + Top = 100 + Width = 764 + Height = 89 + Margins.Left = 0 + Margins.Right = 0 + Margins.Bottom = 0 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 1 + ExplicitTop = 156 + ExplicitWidth = 758 + object Panel1: TPanel + Left = 10 + Top = 10 + Width = 279 + Height = 69 + Align = alLeft + BevelOuter = bvNone + Padding.Right = 10 + TabOrder = 0 + object Label2: TLabel + Left = 0 + Top = 0 + Width = 269 + Height = 23 + Align = alTop + Caption = 'Pre'#231'o de compra' + ExplicitWidth = 130 + end + object dbedPurchasePrice: TDBEdit + Left = 0 + Top = 38 + Width = 269 + Height = 31 + Align = alBottom + ImeName = 'Japanese' + TabOrder = 0 + end + end + object Panel7: TPanel + Left = 289 + Top = 10 + Width = 307 + Height = 69 + Align = alLeft + BevelOuter = bvNone + Padding.Right = 10 + TabOrder = 1 + object Label4: TLabel + Left = 0 + Top = 0 + Width = 297 + Height = 23 + Align = alTop + Caption = 'Pre'#231'o de venda' + ExplicitWidth = 118 + end + object dbedSalePrice: TDBEdit + Left = 0 + Top = 38 + Width = 297 + Height = 31 + Align = alBottom + ImeName = 'Japanese' + TabOrder = 0 + end + end + end + object Panel6: TPanel + AlignWithMargins = True + Left = 10 + Top = 192 + Width = 764 + Height = 75 + Margins.Left = 0 + Margins.Right = 0 + Margins.Bottom = 0 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 2 + ExplicitTop = 248 + ExplicitWidth = 758 + object Panel8: TPanel + Left = 289 + Top = 10 + Width = 307 + Height = 55 + Align = alLeft + BevelOuter = bvNone + Padding.Right = 10 + TabOrder = 0 + object Label3: TLabel + Left = 0 + Top = 0 + Width = 297 + Height = 23 + Align = alTop + Caption = 'Categoria' + ExplicitWidth = 74 + end + object dbedCategory: TDBEdit + Left = 0 + Top = 24 + Width = 297 + Height = 31 + Align = alBottom + ImeName = 'Japanese' + TabOrder = 0 + end + end + object Panel9: TPanel + Left = 10 + Top = 10 + Width = 279 + Height = 55 + Align = alLeft + BevelOuter = bvNone + Padding.Right = 10 + TabOrder = 1 + object Label5: TLabel + Left = 0 + Top = 0 + Width = 269 + Height = 23 + Align = alTop + Caption = 'Quantidade' + ExplicitWidth = 90 + end + object dbedQuantity: TDBEdit + Left = 0 + Top = 24 + Width = 269 + Height = 31 + Align = alBottom + ImeName = 'Japanese' + TabOrder = 0 + end + end + end + end + object pNavProducts: TPanel + Left = 0 + Top = 0 + Width = 784 + Height = 65 + Align = alTop + Caption = 'pNavProducts' + Padding.Left = 10 + Padding.Top = 20 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 1 + ExplicitWidth = 778 + object dbNavProducts: TDBNavigator + Left = 11 + Top = 21 + Width = 762 + Height = 33 + Align = alClient + TabOrder = 0 + OnClick = dbNavProductsClick + ExplicitWidth = 756 + end + end +end diff --git a/src/view/desafio.view.register.product.pas b/src/view/desafio.view.register.product.pas new file mode 100644 index 0000000..72afa83 --- /dev/null +++ b/src/view/desafio.view.register.product.pas @@ -0,0 +1,118 @@ +unit desafio.view.register.product; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.DBCtrls, + Vcl.Mask; + +type + TfrmRegisterProduct = class(TForm) + Panel3: TPanel; + Panel4: TPanel; + Label1: TLabel; + Panel5: TPanel; + Panel6: TPanel; + Panel1: TPanel; + Label2: TLabel; + Panel7: TPanel; + Label4: TLabel; + Panel8: TPanel; + Label3: TLabel; + Panel9: TPanel; + Label5: TLabel; + pNavProducts: TPanel; + dbNavProducts: TDBNavigator; + dbedPurchasePrice: TDBEdit; + dbedSalePrice: TDBEdit; + dbedQuantity: TDBEdit; + dbedCategory: TDBEdit; + edDescription: TEdit; + procedure FormCreate(Sender: TObject); + procedure dbNavProductsClick(Sender: TObject; Button: TNavigateBtn); + procedure dbedDescriptionExit(Sender: TObject); + procedure edDescriptionChange(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + frmRegisterProduct: TfrmRegisterProduct; + +implementation + +uses + desafio.model.interfaces.products, desafio.model.implements.products, + Data.DB; + +var + lProducts : iProducts; + +{$R *.dfm} + +procedure TfrmRegisterProduct.dbedDescriptionExit(Sender: TObject); +begin + if dbNavProducts.DataSource.State in [DsBrowse] then + begin + edDescription.Text := lProducts.getDescription; + end +end; + +procedure TfrmRegisterProduct.dbNavProductsClick(Sender: TObject; + Button: TNavigateBtn); +begin + if Button in [nbInsert] then + begin + edDescription.Text := ''; + end + else if Button in [nbCancel] then + begin + edDescription.Text := lProducts.getDescription; + end + else if Button in [nbFirst, nbPrior, nbNext, nbLast] then + begin + lProducts.fillObject; + edDescription.Text := lProducts.getDescription; + end + else if Button in [nbPost] then + begin + + lProducts.result.Edit; + lProducts.result.FieldByName('description').AsString := edDescription.Text; + lProducts.result.Post; + lProducts.fillObject; + end; + + +end; + +procedure TfrmRegisterProduct.edDescriptionChange(Sender: TObject); +begin + lProducts.dataSource.Edit; +end; + +procedure TfrmRegisterProduct.FormCreate(Sender: TObject); +begin + + lProducts := TProducts.New ; + + lProducts.listAllProducts ; + + dbNavProducts.DataSource := lProducts.dataSource; + dbedPurchasePrice.DataSource := lProducts.dataSource; + dbedSalePrice.DataSource := lProducts.dataSource; + dbedQuantity.DataSource := lProducts.dataSource; + dbedCategory.DataSource := lProducts.dataSource; + + dbedPurchasePrice.DataField := 'purchase_price'; + dbedSalePrice.DataField := 'sale_price'; + dbedQuantity.DataField := 'quantity_stock'; + dbedCategory.DataField := 'category'; + + edDescription.Text := lProducts.getDescription; +end; + +end. diff --git a/src/view/desafio.view.register.user.dfm b/src/view/desafio.view.register.user.dfm new file mode 100644 index 0000000..03c5441 --- /dev/null +++ b/src/view/desafio.view.register.user.dfm @@ -0,0 +1,199 @@ +object frmRegisterUser: TfrmRegisterUser + Left = 0 + Top = 0 + Caption = 'Desafio Delphi - Khipo' + ClientHeight = 442 + ClientWidth = 628 + Color = clBtnFace + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -12 + Font.Name = 'Segoe UI' + Font.Style = [] + Position = poScreenCenter + TextHeight = 15 + object Panel2: TPanel + Left = 0 + Top = 336 + Width = 628 + Height = 106 + Align = alBottom + BevelOuter = bvNone + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 0 + object Button1: TButton + Left = 10 + Top = 10 + Width = 158 + Height = 86 + Align = alLeft + Caption = 'Salvar' + TabOrder = 0 + OnClick = Button1Click + ExplicitLeft = 3 + ExplicitTop = 3 + ExplicitHeight = 92 + end + end + object Panel3: TPanel + Left = 0 + Top = 0 + Width = 628 + Height = 336 + Align = alClient + BevelOuter = bvNone + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -17 + Font.Name = 'Segoe UI' + Font.Style = [] + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + ParentFont = False + TabOrder = 1 + ExplicitLeft = 8 + ExplicitTop = 8 + ExplicitWidth = 381 + ExplicitHeight = 174 + object Panel4: TPanel + Left = 10 + Top = 10 + Width = 608 + Height = 75 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 0 + object Label1: TLabel + Left = 10 + Top = 10 + Width = 588 + Height = 23 + Align = alTop + Caption = 'Nome' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 47 + end + object edtName: TEdit + Left = 10 + Top = 36 + Width = 588 + Height = 29 + Align = alBottom + BevelInner = bvNone + BevelOuter = bvNone + Ctl3D = False + ImeName = 'Japanese' + ParentCtl3D = False + TabOrder = 0 + ExplicitLeft = 0 + ExplicitTop = 29 + ExplicitWidth = 608 + end + end + object Panel5: TPanel + AlignWithMargins = True + Left = 10 + Top = 88 + Width = 608 + Height = 75 + Margins.Left = 0 + Margins.Right = 0 + Margins.Bottom = 0 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 1 + object Label2: TLabel + Left = 10 + Top = 10 + Width = 588 + Height = 23 + Align = alTop + Caption = 'E-mail' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 48 + end + object edtemail: TEdit + Left = 10 + Top = 36 + Width = 588 + Height = 29 + Align = alBottom + BevelInner = bvNone + BevelOuter = bvNone + Ctl3D = False + ParentCtl3D = False + TabOrder = 0 + ExplicitLeft = 0 + ExplicitTop = 29 + ExplicitWidth = 608 + end + end + object Panel6: TPanel + AlignWithMargins = True + Left = 10 + Top = 166 + Width = 608 + Height = 75 + Margins.Left = 0 + Margins.Right = 0 + Margins.Bottom = 0 + Align = alTop + BevelOuter = bvNone + Padding.Left = 10 + Padding.Top = 10 + Padding.Right = 10 + Padding.Bottom = 10 + TabOrder = 2 + ExplicitTop = 180 + object Label3: TLabel + Left = 10 + Top = 10 + Width = 588 + Height = 23 + Align = alTop + Caption = 'Senha' + ExplicitLeft = 0 + ExplicitTop = 0 + ExplicitWidth = 47 + end + object edtPassword: TEdit + Left = 10 + Top = 36 + Width = 588 + Height = 29 + Align = alBottom + BevelInner = bvNone + BevelOuter = bvNone + Ctl3D = False + ImeName = 'Japanese' + ParentCtl3D = False + PasswordChar = '*' + TabOrder = 0 + ExplicitLeft = 0 + ExplicitTop = 29 + ExplicitWidth = 608 + end + end + end +end diff --git a/src/view/desafio.view.register.user.pas b/src/view/desafio.view.register.user.pas new file mode 100644 index 0000000..a626932 --- /dev/null +++ b/src/view/desafio.view.register.user.pas @@ -0,0 +1,65 @@ +unit desafio.view.register.user; + +interface + +uses + Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, + Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; + +type + TfrmRegisterUser = class(TForm) + Panel2: TPanel; + Button1: TButton; + Panel3: TPanel; + Panel4: TPanel; + Label1: TLabel; + edtName: TEdit; + Panel5: TPanel; + Label2: TLabel; + edtemail: TEdit; + Panel6: TPanel; + Label3: TLabel; + edtPassword: TEdit; + procedure Button1Click(Sender: TObject); + private + { Private declarations } + public + { Public declarations } + end; + +var + frmRegisterUser: TfrmRegisterUser; + +implementation + +uses + desafio.model.interfaces.user, desafio.model.implements.user; + +{$R *.dfm} + + +procedure TfrmRegisterUser.Button1Click(Sender: TObject); + var + lUser : iUser; + +begin + lUser := TUser.new; + + lUser.setId(0); + lUser.setName(edtName.Text); + lUser.setEmail(edtEmail.Text); + lUser.setPassword(edtPassword.Text); + + lUser.insert(lUser); + + if lUser.getId > 0 then + begin + showmessage('Usuário inserido com sucesso') ; + modalResult := mrOk; + end + else + showmessage('Houve um erro na inserção deste usuário'); + +end; + +end.