- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
The XmlRep report program in Visual C#
Listing 4.12 The XmlRep report program Making Data Matrix ECC200 In Visual C#.NET Using Barcode printer for .NET framework Control to generate, create Data Matrix image in .NET applications. www.OnBarcode.comScan Data Matrix In Visual C# Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.com// file // description : xmlrep.cs : generate XML/HTML report for poker machine
Matrix Drawer In Visual C#.NET Using Barcode creator for .NET Control to generate, create 2D image in .NET applications. www.OnBarcode.com1D Barcode Generation In C# Using Barcode generator for VS .NET Control to generate, create 1D Barcode image in .NET applications. www.OnBarcode.comnamespace Poker { using using using using using using using System; System.IO; System.Xml; System.Xml.Xsl; System.Xml.XPath; System.Xml.Serialization; System.Diagnostics; Code 39 Full ASCII Drawer In C#.NET Using Barcode generator for .NET framework Control to generate, create Code 39 Full ASCII image in .NET applications. www.OnBarcode.comQuick Response Code Generation In Visual C# Using Barcode generator for Visual Studio .NET Control to generate, create QR Code ISO/IEC18004 image in Visual Studio .NET applications. www.OnBarcode.com[XmlRootAttribute] public class XmlRep { public XmlRep() { Bank b = new Bank(); this.TakenIn = b.TakenIn; this.PaidOut = b.PaidOut; this.Profit = b.Profit; this.HouseMargin = Math.Round(b.HouseMargin, 2); Data Matrix 2d Barcode Creation In Visual C# Using Barcode maker for VS .NET Control to generate, create DataMatrix image in Visual Studio .NET applications. www.OnBarcode.comUSPS Confirm Service Barcode Printer In Visual C# Using Barcode drawer for Visual Studio .NET Control to generate, create Planet image in .NET framework applications. www.OnBarcode.comWORKING WITH ADO.NET AND DATABASES
DataMatrix Generation In None Using Barcode drawer for Microsoft Word Control to generate, create Data Matrix 2d barcode image in Microsoft Word applications. www.OnBarcode.comECC200 Creation In Visual Studio .NET Using Barcode encoder for ASP.NET Control to generate, create ECC200 image in ASP.NET applications. www.OnBarcode.comthis.Delta = Math.Round(b.Delta, 2); this.Bias = b.Bias; } [XmlElementAttribute] public int TakenIn; [XmlElementAttribute] public int PaidOut; [XmlElementAttribute] public int Profit; [XmlElementAttribute] public int Bias; [XmlElementAttribute] public Double HouseMargin; [XmlElementAttribute] public Double Delta; public static void Main() { Console.WriteLine("Serializing data to report.xml..."); XmlSerializer sr = new XmlSerializer(typeof(XmlRep)); TextWriter tw = new StreamWriter("report.xml"); sr.Serialize(tw, new XmlRep()); tw.Close(); Console.WriteLine("Creating report.html..."); XPathDocument xd = new XPathDocument(new XmlTextReader("Report.xml")); tw = new StreamWriter("Report.html"); XslTransform xt = new XslTransform(); xt.Load("pokrep.xsl"); xt.Transform(xd, null, tw); tw.Close(); Console.WriteLine("Launching report in browser..."); ProcessStartInfo si = new ProcessStartInfo(); si.FileName = "Report.html"; si.Verb = "open"; Process pr = new Process(); pr.StartInfo = si; pr.Start(); Console.WriteLine("Done!"); } } } Code-128 Generation In .NET Framework Using Barcode drawer for Reporting Service Control to generate, create ANSI/AIM Code 128 image in Reporting Service applications. www.OnBarcode.comANSI/AIM Code 39 Reader In Visual C#.NET Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comUSING XML SERIALIZATION TO CREATE A REPORT
QR Code 2d Barcode Scanner In Visual C#.NET Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in .NET applications. www.OnBarcode.comCode-128 Reader In None Using Barcode reader for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comThe only thing that s new here is the code to launch the browser. To do that, we create an instance of ProcessStartInfo and set its public FileName property to "Report.html". Then, we create a new process using this start-up information. This will launch whatever application is associated with .html files. The XSLT rules used to transform the poker report are shown in figure 4.14. PDF-417 2d Barcode Generator In .NET Using Barcode maker for .NET Control to generate, create PDF-417 2d barcode image in Visual Studio .NET applications. www.OnBarcode.comEAN13 Scanner In C#.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comThe poker report XSL stylesheet
Reading PDF 417 In Java Using Barcode reader for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comPainting QR Code JIS X 0510 In Objective-C Using Barcode printer for iPad Control to generate, create QR Code 2d barcode image in iPad applications. www.OnBarcode.comWORKING WITH ADO.NET AND DATABASES
EAN / UCC - 13 Drawer In None Using Barcode maker for Word Control to generate, create EAN / UCC - 13 image in Office Word applications. www.OnBarcode.comCreate UPCA In Visual Studio .NET Using Barcode drawer for Reporting Service Control to generate, create Universal Product Code version A image in Reporting Service applications. www.OnBarcode.comFinally, the generated report is shown in figure 4.15.
Figure 4.15 Browsing the poker machine report
NOTE
This book was created as an XML document using a handful of custom tags. A simple C# program was used to apply XSLT rules to transform the manuscript into HTML for online review. Later, a further XSL transformation was used to prepare it for input to FrameMaker. THE POKER.MACHINE CLASS
In the previous chapter, we created a SimpleMachine class to encapsulate the functionality of the basic poker machine. This time, we create Poker.Machine to bring together the full functionality of the client/server poker game. Poker.Machine deals and draws cards, implements payout control, saves games to the database, and provides play statistics. The full source code for the Machine class is presented in listing 4.13. In the meantime, we ll go through the code in outline here. We implement Machine as a singleton class. This ensures that only a single instance of the class can be created and provides a convenient way to store programwide global variables without passing arguments around: public class Machine { public public public public readonly readonly readonly readonly int int int int MinBet; MaxBet; StartCredits; Bias; // private constructor... private Machine() { bank = new Bank(); MinBet = bank.GetParm("MinBet", 1); MaxBet = bank.GetParm("MaxBet", 5); THE POKER.MACHINE CLASS
StartCredits = bank.GetParm("StartCredits", 100); Bias = bank.Bias; } public static Machine Instance { get { // allow just one instance... if (machine == null) machine = new Machine(); return machine; } } ... private static Machine machine = null; private Bank bank = null; ... } To enforce singleton mode, we make the constructor private and provide access to a single instance of the poker machine through the static Instance property. As a result, a caller will never need to explicitly create an instance of the Poker.Machine class, allowing for the following type of application code: int minBet = Machine.Instance.MinBet; int maxBet = Machine.Instance.MaxBet; int credits = Machine.Instance.StartCredits; Payout control is implemented in the public Deal and Draw methods: ... public Hand Deal() { Hand hand = new Hand(); int bias = Bias; while (hand.Score > 0 && bias-- > 0) hand = new Hand(); return hand; } public Hand Draw(Hand oldHand, string holdCards, int bet) { int bias = Bias; Hand newHand = new Hand(oldHand, holdCards); while (newHand.Score > 0 && bias-- > 0) newHand = new Hand(oldHand, holdCards); bank.SaveGame(newHand.ToString(), newHand.Score, bet); return newHand; } ... The payout management algorithm is simple. If bias is non-zero, the Deal method will silently discard one or more scoring hands before finally dealing a hand. For example, if bias is 3, the machine will make three attempts to deal a nonscoring
|
|