Listing 4: C# • Implement the Client-Side Business Logic

Taking care of the client-side business logic is relatively straightforward. You use the .NET Framework Windows Forms databind mechanisms to bind properties of the Windows Forms Controls <i>m_cbProducts</i> (ComboBox) and <i>m_lbPrice</i> (Label) to properties of the object <i>m_dtActualProduct</i> that represent the business entity, Product.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinClientConsume_WS_SQLServer2005
{
	public partial class Form1 : Form
	{
		private DataSet m_dsProducts = null;
		private DataTable m_dtActualProduct = 
			null;

		public Form1()
		{
			InitializeComponent();

			this.prvGetProducts();
		}

		private void prvGetProducts()
		{
			eprocurement_purchasingSoapClient 
			objProxy = new 
			eprocurement_purchasingSoapClient();
			object[] arrResult = 
				objProxy.SelectProduct();
			this.m_dsProducts = arrResult[0] 
				as DataSet;

			if (this.m_dsProducts != null)
			{
				this.m_dtActualProduct = 
					this.m_dsProducts.Tables[0];
				this.m_cbProducts.DataSource 
					= this.m_dtActualProduct;
				this.m_cbProducts.DisplayMember = 
					"Name";
				this.m_cbProducts.ValueMember = 
					"ProductID";
				this.m_lbPrice.DataBindings.Add(
					new Binding(
					"Text",
					this.m_dtActualProduct,
					"ListPrice"));
			}
		}

		private void button1_Click(object 
			sender, EventArgs e)
		{
			eprocurement_purchasingSoapClient 
			objProxy = new 
			eprocurement_purchasingSoapClient();

			try
			{
				objProxy.CreatePurchaseOrder( 
				System.Convert.ToInt32(
				this.m_tbEmployeeId.Text.Trim()),
				System.Convert.ToInt32(
				this.m_tbVendorId.Text.Trim()),
				this.m_dtpShipDate.Value,
				System.Convert.ToInt32(
				this.m_cbProducts.SelectedValue),
				System.Convert.ToInt16(
				this.m_tbQuantity.Text.Trim()),
				System.Convert.ToDecimal(
				this.m_lbPrice.Text.Trim()),
				System.Convert.ToDecimal(
				this.m_tbTaxAmount.Text.Trim()),
				System.Convert.ToDecimal(
				this.m_tbFreight.Text.Trim()));
			}

		catch (Exception ex)
		{
		System.Windows.Forms.MessageBox.Show(
			ex.ToString(),"Error 
			MessageBox",MessageBoxButtons.OK,
			MessageBoxIcon.Error);
		}
		}
	}
}
comments powered by Disqus

Featured

Subscribe on YouTube