De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

NextGenPos Evi FrancisHilde Van Roey Wim SerroyenIgnas Van Tricht David Van EffenLiesbeth Vertommen.

Verwante presentaties


Presentatie over: "NextGenPos Evi FrancisHilde Van Roey Wim SerroyenIgnas Van Tricht David Van EffenLiesbeth Vertommen."— Transcript van de presentatie:

1 NextGenPos Evi FrancisHilde Van Roey Wim SerroyenIgnas Van Tricht David Van EffenLiesbeth Vertommen

2 Inleiding Geautomatiseerde applicatie voor kassasysteem Aankopen samenstellen Flexibiliteit Aanpasbaarheid

3 Context diagram

4 Data flow diagram

5 ERD

6 Use case

7 Het programma

8 Pluggable business rules & Prijsstrategieën

9 [Serializable] public class DiscountSettings { private IDiscountStrategy[] strategies; private static XmlSerializer serializer; [XmlIgnore] public IDiscountStrategy[] Strategies { get { return strategies; } set { strategies = value; } } [XmlElement(Type = typeof(DiscountStrategySerializer))] public DiscountStrategySerializer[] XmlStrategies { get { if (Strategies == null) return null; else { DiscountStrategySerializer[] dss = new DiscountStrategySerializer[Strategies.Length]; for (int i = 0; i < Strategies.Length; i++) { dss[i] = new DiscountStrategySerializer(strategies[i]); } return dss; }

10 public class DiscountStrategySerializer : IXmlSerializable { private IDiscountStrategy strategy; public DiscountStrategySerializer(IDiscountStrategy strategy) { this.strategy = strategy; } public void ReadXml(XmlReader reader) { Type type = Type.GetType(reader.GetAttribute("type")); reader.ReadStartElement(); this.strategy = (IDiscountStrategy)new XmlSerializer(type).Deserialize(reader); reader.ReadEndElement(); } public void WriteXml(XmlWriter writer) { writer.WriteAttributeString("type", strategy.GetType().ToString()); new XmlSerializer(strategy.GetType()).Serialize(writer, strategy); }

11 Bedrag op product 4 Chef Antons Cajun Seasoning

12

13 public class RulesFacade { private static RulesFacade instance; private PluggableRules rules; private RulesFacade() { rules = new PluggableRules().Deserialize(RulesFacade.RulesFile); }... public bool IsInvalid(Sale sale) { foreach (PaymentTypeRule ptr in rules.Rules) { if (ptr.PaymentType == sale.PaidBy.Type) return ptr.IsInvalid(sale); } return false; }... }

14 [System.Xml.Serialization.XmlRoot("PluggableRules")] public class PluggableRules { private Rule[] rules; public PluggableRules() { rules = new Rule[0]; } [System.Xml.Serialization.XmlArray("Rules"), System.Xml.Serialization.XmlArrayItem(typeof(PaymentTypeRule))] public Rule[] Rules { get{return rules;} set{rules = value;} } public void addRule(Rule r) { IList ruleList = this.Rules.ToList (); ruleList.Add(r); this.Rules = ruleList.ToArray (); }

15 public void Serialize(string path) { XmlSerializer serializer = new XmlSerializer(typeof(PluggableRules)); Stream stream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite); serializer.Serialize(stream, this); stream.Close(); } public PluggableRules Deserialize(string path) { TextReader reader = new StreamReader(path); XmlSerializer serializer = new XmlSerializer(typeof(PluggableRules)); PluggableRules myRules = (PluggableRules)serializer.Deserialize(reader); reader.Close(); return myRules; }

16 Cash DirectDebit CreditCard

17 ServiceFactory public class ServiceFactory { private Hashtable services = new Hashtable(); public ServiceFactory() { Add (new AccountingAdapter(new AccountingSystemTest())); Add (new InventoryAdapter(new InventorySystemTest())); } public void Add (T t) where T : IService { services.Add(typeof(T), t); } public T GetService () { return (T)services[typeof(T)]; }

18 ServiceFactory public interface IService {} public interface IAccountingAdapter : IService { /// /// Verwerkt de boekhoudkundige gegevens voor een sale /// void ReportSale(Sale s); }

19 Model - klassendiagram

20 SaleStatus - toestandsdiagram - klassendiagram - code voorbeeld

21 - toestandsdiagram - klassendiagram - code voorbeeld SaleStatus

22 - toestandsdiagram - klassendiagram - code voorbeeld SaleStatus public interface ISaleStatus { double[] addLineItem(Product product, int quantity); void removeLineItem(int indexLine); double getTotal () double getTotalWithoutDiscounts(); double doPayment(PaymentType ptype, double amountReceived); }

23 - toestandsdiagram - klassendiagram - code voorbeeld SaleStatus class Empty : ISaleStatus { Sale sale; private static ILogger log = LogManager.GetLogger(); public Empty(Sale sale) { this.sale = sale; } public double[] addLineItem(Product product, int quantity) { SalesLineItem sli = new SalesLineItem(quantity, product); this.sale.ItemsPurchased.Add(sli); int lineIndex = this.sale.ItemsPurchased.Count - 1; double subTotal = sli.GetSubtotal(); double[] indexAndTotal = new double[2]; indexAndTotal[0] = subTotal; indexAndTotal[1] = lineIndex; log.Message("add product: " + product.Description + " item quantity: " + quantity, LoggerState.INFO); this.sale.SaleStatus = this.sale.Running; return indexAndTotal; }...

24 - klassendiagram - code voorbeeld Discounts

25 - klassendiagram - code voorbeeld Discounts public double getTotal() { IDiscountStrategy currentStrategy =PricingStrategyFactory.Instance.GetCurrentStrategy(); this.totalToPay = currentStrategy.GetTotal(this); log.Message("Total: "+this.totalToPay,Convert.ToInt32(LoggerState.INFO)); return this.totalToPay; }

26 - klassendiagram - code voorbeeld - sequentiediagram Payments

27 - klassendiagram - code voorbeeld - sequentiediagram Payments public abstract class IPaymentTemplate { public Boolean doPayment(double amountToPay, Customer customer) { if (SolvabilityIsQuestioned(amountToPay,customer)) { return checkSolvability(amountToPay,customer); } return true; } public Boolean SolvabilityIsQuestioned(double amountToPay, Customer customer) { return true; } public abstract Boolean checkSolvability (double amountToPay, Customer customer); }

28 - klassendiagram - code voorbeeld - sequentiediagram Payments class CreditCardPayment : IPaymentTemplate { public override Boolean checkSolvability(double amountToPay, Customer customer) { ICreditAuthorizationAdapter icrat = AuthorizationFactory.Instance.createAuthorization(PaymentType.CreditCard); return icrat.isAuthorized(string.Empty, customer.Name, amountToPay); }

29 - klassendiagram - code voorbeeld - sequentiediagram Payments

30 - klassendiagram - code voorbeeld - sequentiediagram Payments

31 Database Controller public Controller() { string connectionString = server=(local)\\SQLEXPRESS; “ + “database=NEXTGENPOS.MDF;Integrated Security=SSPI"; mySqlConnection = new SqlConnection(connectionString); } // dynamische query opbouwer private DataSet genericSelectQueryFunction(string selectString, string returnSetName) { if (selectString.Equals("") || returnSetName.Equals("")) { return new DataSet(); } SqlCommand mySqlCommand = mySqlConnection.CreateCommand(); mySqlCommand.CommandText = selectString; SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter(); mySqlDataAdapter.SelectCommand = mySqlCommand; DataSet myDataSet = new DataSet(); mySqlConnection.Open(); mySqlDataAdapter.Fill(myDataSet, returnSetName); mySqlConnection.Close(); return myDataSet; }

32 public DataSet getProductByName(string name) { string selectString = "select * from product where description like” + '%" + name + "%'"; return genericSelectQueryFunction(selectString, "product"); }

33 public void saleTransaction(int customerId, DateTime saleDateTime, bool complete, double amount, int paymentTypeId, int[,] productIdQuantity) { try { mySqlConnection.Open(); } catch (Exception ex) { Console.WriteLine(ex.Message); } SqlTransaction transaction = null; SqlCommand command = new SqlCommand(); int saleId = 0; try { string insertSaleQueryString = "insert into sale (customer_id,date,complete) values ( “ + customerId + ", '" + saleDateTime + "', '" + complete + "')" + "; select id from sale where id= transaction = mySqlConnection.BeginTransaction(); command.Connection = mySqlConnection; command.CommandText = insertSaleQueryString; command.Transaction = transaction; saleId = (int)command.ExecuteScalar(); catch (Exception ex) { Console.WriteLine(ex.Message); if (transaction != null) { Console.WriteLine("Transactie rollback"); transaction.Rollback(); } mySqlConnection.Close(); }

34 Datafacade public static DatabaseFacade Instance { get { if (null == instance) instance = new DatabaseFacade(); return instance; } }

35 public IList getAllEmployees() { IList eList = new List (); DataSet employees = control.getAllEmployees(); DataTable myDataTable = employees.Tables["employee"]; foreach (DataRow row in myDataTable.Rows) { Employee emp = new Employee(); emp.EmployeeID = int.Parse(row["id"].ToString()); emp.FirstName = row["firstname"].ToString(); emp.LastName = row["lastname"].ToString(); emp.UserName = row["username"].ToString(); emp.IsManager = row["function_id"]. ToString().TrimEnd().Equals("2"); eList.Add(emp); } return eList; }

36 public Customer getCustomerById(int id) { DataSet customerDataSet = control.getCustomerById(id); DataTable myDataTable = customerDataSet.Tables["customer"]; if (myDataTable.Rows.Count == 0) { throw new CustomerNotFoundException("Geen klant gevonden met id " + id); } DataRow temp = myDataTable.Rows[0]; return new Customer(int.Parse(temp["id"].ToString()), temp["name"].ToString(), temp["address"].ToString(), temp["city"].ToString(), System.DateTime.Parse(temp["dob"].ToString()); }

37 Stored procedure

38 Kortingen - Strategy

39 Adapters

40 Voorraadbeheersysteem

41 interface IInventoryAdapter { bool IsInStock(Product p); //is het item in voorraad? int GetNumberInStock(Product p); //aantal items in voorraad void UpdateStock(Sale s); //werk de stock bij met de //items in de sale } public int GetNumberInStock(Product p) { if (p.Description.Equals("Tofu") || p.Description.Equals("Konbu")) return 0; return ; }

42 Boekhoudsysteem

43 public interface IAccountingAdapter { /// Verwerkt de boekhoudkundige gegevens voor een sale void ReportSale(Sale s); } public class AccountingSystemTest { public void UpdateSales(Sale s) { Console.WriteLine("Sale:{0}", s.ToString()); } public void UpdateCommissions(Sale s) { }

44 Authorization service

45 public interface ICreditAuthorizationAdapter { bool isAuthorized(string cardNumber, string customername, double amount); } public class CreditCardAuthorizationServiceTest { public bool isAuthorized(string cardnumber, string customername, double amount) { if ((customername.Equals("Antonio Moreno") || customername.Equals("Yang Wang")) && amount > 0) return false; else if ((customername.Equals("Maria Anders") || customername.Equals("Thomas Hardy")) && amount > 1000) return false; return true; }

46 Logger Design Patterns: Chain of Responsibility pattern Verschillende niveaus (debug/info/fatal) verschillende outputs (console/file/ ) Observer pattern Event logging

47 Observer

48

49 IObservable public interface IObserver { void Notify(object anObject); } public interface IObservable { void Register(IObserver anObserver); void UnRegister(IObserver anObserver); }

50 public class ObservableImpl:IObservable { protected Hashtable _observerContainer=new Hashtable(); public void Register(IObserver anObserver){ _observerContainer.Add(anObserver,anObserver); } public void UnRegister(IObserver anObserver){ _observerContainer.Remove(anObserver); } public void NotifyObservers(object anObject) { foreach(IObserver anObserver in _observerContainer.Keys) { anObserver.Notify(anObject); }

51 Voorbeeld public IList ItemsPurchased { get { return itemsPurchased; } set { base.NotifyObservers(itemsPurchased); itemsPurchased = value; }

52 Chain op responsibility

53

54

55 public enum LoggerState { FATAL = 1, //Fatale error --> hoogste niveau: stuur een naar de persoon die verantwoordelijke is EXCEPT = 3, //Zware fout --> Exceptions ERROR = 5, = 6, // versturen van een INFO = 7, //Notice (opmerking) : schrijf naar een logbestand OBSERVER = 8, //observer logging DEBUG = 10 //Debugging boodschap: schrijf enkel naar de console } Elk type heeft een waarde (=prioriteit of mask):

56 protected ILogger next; public ILogger setNext(ILogger l) { next = l; return l; } protected static ILogger l, l3; protected static OBserverLogger l2; static LogManager() { l = new ConsoleLogger(LoggerState.DEBUG); l3 = l.setNext(new LogFileLogger (LoggerState.INFO,"./logs/logFileInfo")); l2 = new OBserverLogger (LoggerState.OBSERVER, "./logs/logFileObserver"); }

57 public void Message(String msg, LoggerState priority) { if (priority <= mask) { WriteMessage(msg); } if (next != null) { next.Message(msg, priority); } abstract protected void WriteMessage(String msg);

58

59 view Model-view-controller

60 New POSForm() een lijst van de klanten opgehaald een lijst binnengehaald met de gekende producten user met succes is geauthenticeerd, zal er worden nagegaan of deze user admin rechten heeft.

61 Hoe vullen we een component ‘combobox’ met de lijst van onze klanten? we hebben een klasse Bind de properties id en name de methode override String ToString()

62 Sequence diagram de lijst met klanten, verkregen door de DatabaseFacade omzetten van customer lijst naar een lijst van Bind objecten lijst van bind objecten wordt aan een BindingSource gelinked.

63

64 Sale ticket een ticket geeft een overzicht van sale de producten, subtotalen, kortingen op producten, globale kortingen de velden die in een ticket zijn instelbaar, doormiddel van een XML config bestand Vb. item in xml:

65

66 Sequence diagram: de communicatie tussen het POSForm en de controller, die uiteindelijk met het model Register communiceert

67 Sequence diagram: de communicatie bij aanmaak van een ticket. Een ticket wordt ingesteld wanneer de methode setFlatList (de lijst van flatLineItems) of setFlatTotal (een flatLineItem) worden aan- geroepen.


Download ppt "NextGenPos Evi FrancisHilde Van Roey Wim SerroyenIgnas Van Tricht David Van EffenLiesbeth Vertommen."

Verwante presentaties


Ads door Google