1 / 12

Base de Dados - Sales

Shop Notas de implementação [Exercício da Disciplina de ADAV] http://www.dei.isep.ipp.pt/~jtavares/ADAV/downloads/ADAV_Proj_Rreferencia.pdf. Base de Dados - Sales. Interfaces. Códigos de ‘Status’ – Retorno de alguns métodos // // Definição dos códigos de ‘status’ que poderão ser retornados

erling
Télécharger la présentation

Base de Dados - Sales

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ShopNotas de implementação[Exercício da Disciplina de ADAV]http://www.dei.isep.ipp.pt/~jtavares/ADAV/downloads/ADAV_Proj_Rreferencia.pdf

  2. Base de Dados - Sales

  3. Interfaces • Códigos de ‘Status’ – Retorno de alguns métodos // // Definição dos códigos de ‘status’ que poderão ser retornados // public enum ShopStatusEnum { OK = 1, NOT_OK = 0, INVALID_LOGIN = -1, INVALID_KEY = -2, INVALID_CUSTOMER_ID = -3, INVALID_PRODUCT_ID = -4, INSUFICIENT_STOCK = -5, ERROR = -6 } • User public interface IUser { ShopStatusEnum Validate(string user, string pass); }

  4. Customer public interface ICustomer { // devolve os dados do cliente com um dado id DataSet GetByID(string user, string pass, long clientID); // devolve os dados de todos os clientes cujo nome obedeça ao padrão de pesquisa DataSet FindByName( string user, string pass, string namePattern); // Adiciona um novo cliente e retorna o respectivo ID gerado automaticamente na BD long Add( string user, string pass, string name, string address,string phone, string fax, string email, out ShopStatusEnum status); // actualiza os dados do cliente identificado pelo id ShopStatusEnum Update( string user, string pass, long custumerID, string name, string address, string phone, string fax, string eMail); }

  5. Cliente do componente • Usar DALC Customer // página .aspx de pesquisa … using ShopClassLibrary … string user=…; string pass=…; ICustomer customer=new Customer(); // chamada ao método GetByID da classe Customer.cs DataSet ds = customer.GetByID(user, pass, idcustomer); // método devolve null se não encontrar If ( ds!=null ) …

  6. DAL Classe Customer.cs public DataSet GetByID(string user, string pass, long clientID) { OleDbConnection conn = null; DataSet ds = null; try { // criar objecto de conexão à base de dados e abrir a conexão conn = new OleDbConnection(UtilDB.CONN); conn.Open(); // validar utilizador ShopStatusEnum status = UtilDB.ValidateUser(conn, null, user, pass); if (status != ShopStatusEnum.OK) return null; // efectuar pesquisa ds = UtilDB.GetByID(conn, null, "Customers", "CustomerID", clientID); }

  7. Classe Customer.cs - GetByID (cont.) catch(OleDbException ex) { // tratar a excepção!!!! System.Console.WriteLine("EXCEPÇÃO no método <GetByID> da classe 'Customer': " + ex.Message); } finally { // fechar a conexão if (conn.State == ConnectionState.Open) conn.Close(); } return ds; }

  8. Classe UtilDB.cs static public DataSet GetByID(OleDbConnection conn, OleDbTransaction tx, string table, string keyName, long key) { DataSet ds = null; try { // criar objecto DataSet ds = new DataSet(); // criar um Datadapter para executar o comando e devolver o dataset string sSqlCmd = "Select * From "+ table + " Where "+ keyName + " = "+ key.ToString(); OleDbDataAdapter oAdapter = new OleDbDataAdapter(sSqlCmd, conn); oAdapter.SelectCommand.Transaction = tx; // executar o comando e preencher um Dataset oAdapter.Fill(ds, table); } catch(OleDbException ex) { // tratar a excepção!!!! System.Console.WriteLine("EXCEPÇÃO no método 'UtilDB.GetByID': " + ex.Message); ds = null; } return ds; }

  9. Classe Sale

  10. public class User : IUser { … public ShopStatusEnum Validate(string user, string pass) { return UtilDB.ValidateUser(user, pass); } … // validar Login IUser c = new User(); if (c.Validate(txtUsername.Text, txtPassword.Text) == ShopStatusEnum.OK) public interface IUser { ShopStatusEnum Validate(string user, string pass); }

More Related