Click here to Skip to main content
15,893,790 members
Articles / Web Development / ASP.NET

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

Rate me:
Please Sign up or sign in to vote.
4.96/5 (134 votes)
16 Aug 200540 min read 1.2M   3.9K   462  
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
#region Using directives

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

#endregion

namespace SmartInstitute.Automation.Forms
{
    partial class AccountTransactionDialog : FormUIBase
    {
        public delegate void AcceptedHandler();
        public event AcceptedHandler OnAccept;

		// transaction description enum    
		public enum TransactionDesc
		{
			Undefined_Transaction,
			Admission_Payment,
			Adjustment_of_Fees,
			Full_Payment_of_Fees,
			Discounts_Fees,
			Final_Exam_Payment,
			Late_Payment_Fine,
			Midterm_Exam_Payment,
			Partial_Payment_of_Fees,
			Penalty_Dropping_Semester,
			Surcharge_Fee,
			Upon_Enrolment_Payment,
			Convocation_Fees
		}

		private bool _IsInList = false;

		private AccountCollection _Accounts;

		private int _StudentID;

		public int StudentID
		{
			get { return _StudentID; }
			set { _StudentID = value; }
		}

		private Account _Account;

		public Account AccountObject
		{
			set
			{
				_Account = value;
			}
			get
			{
				return _Account;
			}
		}        
        
        
        public AccountTransactionDialog( AccountCollection accounts )        
        {
			this._Accounts = accounts;
            InitializeComponent();
        }

        private void AccountTransactionDialog_Load(object sender, EventArgs e)
        {
            if (!base.DesignMode)
            {
                LoadTransactionDescription();
                if( ViewMode == Mode.Edit )
                {
                    PopulateUIFromObject();
                }
                else if( ViewMode == Mode.New )
                {
                    CreateBlankEntryForm();
                }
                if( radioCash.Checked )
                    groupCheck.Enabled = false;
            }
        }

        private void CreateBlankEntryForm()
        {
        }

        private void PopulateUIFromObject()
        {
            if( _Account.DebitAmount == 0 )
            {
                radioCredited.Checked = true;
                textBoxAmount.Text = _Account.CreditAmount.ToString();
            }
            else
            {
                radioDebited.Checked = true;
                textBoxAmount.Text = _Account.DebitAmount.ToString();
            }
            // set the date
            string paymentDate = _Account.TransactionDate.ToShortDateString();
            dateTimePickerPaymentDate.Text = dateTimePaymentofChecque.Text = paymentDate;
            // if there is no bank name or number available 
            if( _Account.CheckNumber == String.Empty )
            {
                radioCash.Checked = true;
            }
            
            // select the particulars dropdown
            foreach( ParticulasItem item in comboParticulas.Items )
            {
                string particulasText = item.ToString().Split( ' ' )[0];
                if( _Account.TransactionDescription.IndexOf( particulasText.Trim()  ) > 0  )
                {
                    comboParticulas.SelectedItem = item;
                    _IsInList = true;
                    break;
                }
            }
            if( !_IsInList )
            {
                comboParticulas.Text = _Account.TransactionDescription;
            }
        }

        private void LoadTransactionDescription()
        {
            comboParticulas.Items.Clear();
            // get the names
            string [] desciptionNames = Enum.GetNames( typeof( TransactionDesc ) );
            // fill the names
            foreach( string transactionDescription in desciptionNames )
            {
                comboParticulas.Items.Add( new ParticulasItem( transactionDescription.Replace( '_', ' ' ) ) );    
            }
            comboParticulas.SelectedIndex = 0;
        }
        
		internal class ParticulasItem
        {
            private string _Particulas;

            public ParticulasItem( string particulas )
            {
                _Particulas = particulas;
            }

            public override string ToString()
            {
                return _Particulas;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            PerfomTransaction();
            // always 
            if (null != OnAccept)
                OnAccept();     
            // close me
            this.Close();       
        }

        private void PerfomTransaction()
        {
            if (base.ViewMode == Mode.New)
            {
                _Account = new Account();
                _Account.StudentID = _StudentID;
                _Account.TransactionDate = DateTime.Now;
 
                // fill the object from UI
                FillObject();

				this._Accounts.Add(_Account);				
            }
            else if (base.ViewMode == Mode.Edit)
            {
                FillObject();
				this._Accounts.Add(_Account);
            }
        }

        private void FillObject()
        {
            ParticulasItem pItem = ( ParticulasItem ) comboParticulas.SelectedItem;
            // set the particulas
            if( _IsInList )
            {
                _Account.TransactionDescription = pItem.ToString();
            }
            else
            {
                _Account.TransactionDescription = comboParticulas.Text;
            }
            if( radioCheque.Checked )
            {
                _Account.BankName = textBoxBank.Text.Trim();
                _Account.CheckNumber = textBoxChequeNo.Text.Trim();
                _Account.TransactionDate = DateTime.Parse( dateTimePaymentofChecque.Text.Trim() );
            }
            else
            {
                _Account.BankName = String.Empty;
                _Account.ORNumber = textboxOR.Text.Trim();
                _Account.TransactionDate = DateTime.Parse( dateTimePickerPaymentDate.Text.Trim() );
            }
            
            decimal amountEntered = 0;
            decimal.TryParse( textBoxAmount.Text.Trim(), out amountEntered );

            if( radioDebited.Checked )
            {
                _Account.DebitAmount = amountEntered;
                _Account.CreditAmount = 0;
            }
            else
            {
                _Account.CreditAmount = amountEntered;
                _Account.DebitAmount = 0;
            }
            _Account.Type = (int)AccountTypeEnum.Other;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;   
        }

        private void radioCheque_CheckedChanged(object sender, EventArgs e)
        {
            // swith mode
            if( radioCheque.Checked )
            {
                groupCheck.Enabled = true;
            }
            else
            {
                groupCheck.Enabled = false;
            }
        }
 
		private const string INVALID_TEXT = "(N/A)";    
        private void radioCredited_CheckedChanged(object sender, EventArgs e)
        {
            if (radioCredited.Checked)
            {
                textboxOR.Enabled = true;
                textboxOR.Text = String.Empty;
            }
            else
            {
                textboxOR.Enabled = false;
                textboxOR.Text = INVALID_TEXT;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

Comments and Discussions