// Collection of code snippets by Arne Vajhøj // (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) using System; using System.Drawing; using System.Linq; using System.Windows.Forms; using Order.Backend; namespace Order.Frontend { public class LookupOrderForm : Form { private Label oidlbl; private TextBox oid; private Button find; private Label status; private Label cinfo; private Label oinfo; private DataGridView lines; public LookupOrderForm() { SuspendLayout(); ClientSize = new Size(500, 500); Text = "Lookup Order"; oidlbl = new Label(); oidlbl.Text = "Order id:"; oidlbl.Location = new Point(50, 50); Controls.Add(oidlbl); oid = new TextBox(); oid.Size = new Size(75, 25); oid.Location = new Point(150, 50); Controls.Add(oid); find = new Button(); find.Text = "Find"; find.Location = new Point(250, 50); find.Click += LookupOrder; Controls.Add(find); status = new Label(); status.Text = ""; status.Size = new Size(300, 50); status.Location = new Point(50, 100); Controls.Add(status); cinfo = new Label(); cinfo.Size = new Size(300, 50); cinfo.Location = new Point(50,150); Controls.Add(cinfo); oinfo = new Label(); oinfo.Size = new Size(300, 50); oinfo.Location = new Point(50,200); Controls.Add(oinfo); lines = new DataGridView(); lines.Size = new Size(400, 150); lines.Location = new Point(50, 250); lines.ReadOnly = true; lines.ScrollBars = ScrollBars.None; lines.ColumnHeadersVisible = false; lines.RowHeadersVisible = false; Controls.Add(lines); ResumeLayout(false); } void LookupOrder(object sender, EventArgs e) { Persister p = new Persister(); Order.Backend.Order o = p.LookupOrder(int.Parse(oid.Text)); if(o != null) { status.Text = ""; cinfo.Text = o.Customer.Name + ", " + o.Customer.Address; oinfo.Text = o.OrderDate.ToString("yyyy-MM-dd") + " $" + o.TotalPrice + " " + o.Status; lines.DataSource = o.Lines.Select(ol => new { Product = ol.Product.Name, Quantity = ol.Quantity, Price = ol.Product.Price, TotalPrice = ol.TotalPrice }).ToList(); } else { status.Text = "Order id does not exist"; } } } }