Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 The Warehouse Program. 2 A console program. Listens for connect requests from the call center program. Accepts connection. Reads message. Order ID Prints.

Similar presentations


Presentation on theme: "1 The Warehouse Program. 2 A console program. Listens for connect requests from the call center program. Accepts connection. Reads message. Order ID Prints."— Presentation transcript:

1 1 The Warehouse Program

2 2 A console program. Listens for connect requests from the call center program. Accepts connection. Reads message. Order ID Prints picklist Instructions for a packer. Similar to invoice, but no prices.

3 3 Getting Started Create a new C# Console Application. Northwind_Warehouse Start by getting username and password for database connection string. Don’t show password on the screen! Note: No namespace declarations.

4 4 Get_Connection_Info using System; using System.Text; class Program { public static string Username; public static string Password; static void Get_Connection_Info() { Console.Write("User name: "); Username = Console.ReadLine(); Console.Write("Password:"); ConsoleColor saved_color = Console.ForegroundColor; Console.ForegroundColor = Console.BackgroundColor; Password = Console.ReadLine(); Console.ForegroundColor = saved_color; }

5 5 Get_Connection_Info static void Main(string[] args) { Console.WriteLine("Northwind Traders Warehouse Program starting\n"); Get_Connection_Info(); Console.WriteLine(); Console.WriteLine(Username + " " + Password); Console.ReadLine(); }

6 6 Signing In

7 7 Process Network Messages Code copied from TCP Echo Server with some modifications http://www.cse.usf.edu/~turnerr/Software_Systems_Development/ Downloads/2011_04_28_Northwind_Warehouse/Process_Network_ Messages.cs http://www.cse.usf.edu/~turnerr/Software_Systems_Development/ Downloads/2011_04_28_Northwind_Warehouse/Process_Network_ Messages.cs Add usings: using System.Net; using System.Net.Sockets; Convert main() into Process_Network_Messages()

8 8 Process_Network_Messages static string Process_Network_Messages() { String Order_ID = ""; const int BUFSIZE = 32; int servPort = 7; TcpListener listener = null; try { listener = new TcpListener(IPAddress.Any, servPort); listener.Start(); } catch (SocketException se) { Console.WriteLine(se.ErrorCode + ": " + se.Message); Console.ReadLine(); Environment.Exit(se.ErrorCode); }

9 9 Process_Network_Messages byte[] rcvBuffer = new byte[BUFSIZE]; int bytesRcvd; TcpClient client = null; NetworkStream netStream = null; while (true) { Console.WriteLine("Waiting for orders\n"); Order_ID = ""; try { client = listener.AcceptTcpClient(); netStream = client.GetStream(); bytesRcvd = netStream.Read(rcvBuffer, 0, rcvBuffer.Length); while (bytesRcvd > 0) { Order_ID += Encoding.ASCII.GetString(rcvBuffer, 0, bytesRcvd); bytesRcvd = netStream.Read(rcvBuffer, 0, rcvBuffer.Length); } netStream.Close(); client.Close(); }

10 10 Process_Network_Messages catch (Exception e) { Console.WriteLine(e.Message); if (netStream != null) { netStream.Close(); } Console.ReadLine(); } print_picklist(Order_ID); }

11 11 print_picklist() Stub static void print_picklist(string order_id) { Console.WriteLine("Order ID: " + order_id); }

12 12 Program.cs static void Main(string[] args) { Console.WriteLine("Northwind Traders Warehouse Program starting\n"); Get_Connection_Info(); Console.WriteLine(); //Console.WriteLine(Username + " " + Password); Process_Network_Messages(); Console.ReadLine(); } Build and run.

13 13 Client Program Modify Call Center program to send a message to the warehouse whenever a new order is added to the database Just send Order IDs. TCP Echo Client code modified for this purpose. http://www.cse.usf.edu/~turnerr/Software_Systems_Development/ Downloads/2011_04_28_Northwind_Warehouse http://www.cse.usf.edu/~turnerr/Software_Systems_Development/ Downloads/2011_04_28_Northwind_Warehouse File Network_IO.cs

14 14 Network_IO.cs using System; using System.Text; using System.IO; using System.Net.Sockets; static public class Network_IO { static public void Notify_Warehouse(int Order_ID) { string server = "127.1.1.1"; byte[] byteBuffer; int servPort = 7; TcpClient client = null; NetworkStream netStream = null;

15 15 Network_IO.cs string msg = Order_ID.ToString(); byteBuffer = Encoding.ASCII.GetBytes(msg); try { client = new TcpClient(server, servPort); netStream = client.GetStream(); netStream.Write(byteBuffer, 0, byteBuffer.Length); } catch (Exception e) { Console.WriteLine("Error sending message to warehouse\n"); Console.WriteLine(e.Message); } finally { if (netStream != null) { netStream.Close(); } if (client != null) { client.Close(); }

16 16 Order_Entry_Form.cs Add to Submit Order event handler After writing Order Details to the database Network_IO.Notify_Warehouse(order.OrderId);

17 17 Call Center Communicating with Warehouse

18 18 What else? We need the entity classes from the Call Center program in the warehouse program: Order Order_Detail Product Database_Class Customer Customer_DB Some must be modified to get their information from the database rather than just writing to the database.

19 19 What else? Class Picklist Gets order info for a specified Order ID Using the entity classes Prints the picklist Modified version of code from Project 8 that prints invoices. Download complete program: File Warehouse.zip

20 20 Observations We are using a console application to do stuff that is normally done only in Windows forms applications. Note declaration of PrintDocument Picklist.cs line 19 Normally in generated code. Initialization code to instantiate the PrintDocument and hook up the event handler. Picklist.cs lines 23 - 25 (In Constructor) Normally done by generated code, the InitializeComponent() method called from the Form constructor.

21 21 Observations PrintPage event handler had to be manually entered into the source file. Couldn't double click on an icon and get Visual Studio to set it up automatically. Had to manually add some references to the project: System.Drawing System.Windows.Forms Visual Studio doesn't expect these to be used in a Console application.

22 22 Warehouse Program Build and run

23 23 Call Center Communicating with Warehouse

24 24 A Picklist End of Presentation


Download ppt "1 The Warehouse Program. 2 A console program. Listens for connect requests from the call center program. Accepts connection. Reads message. Order ID Prints."

Similar presentations


Ads by Google