Click here to Skip to main content
15,893,594 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.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SmartInstitute.Automation.Commands.Framework;
using SmartInstitute.Client.Automation.Commands.Students;
using SmartInstitute;
using SmartInstitute.Client.Automation.Helpers;
using SmartInstitute.Automation.Forms;

#endregion

namespace SmartInstitute.Client.Automation.Documents.StudentDocuments
{
    public partial class StudentAccountsUI : StudentDocumentUIBase
    {
        public StudentAccountsUI()
        {
            InitializeComponent();
        }

        private void LoadStudentProfie()
        {
            Student student = base.Document.StudentModel.Profile;
            // set in the ui
			textBoxStudentID.Text = base.Document.StudentModel.StudentID;
			textBoxStudentName.Text = base.Document.StudentModel.FullName;
        }

        private void StudentAccountsUI_Load(object sender, EventArgs e)
        {
            if (!base.DesignMode)
            {
                LoadStudentProfie();
                LoadAccounts();              
            }
        }
        private AccountCollection _Accounts
        {
            get { return base.Document.StudentModel.Profile.AccountCollection; }
        }

        private void LoadAccounts()
        {
			DoCalculation(base.Document.StudentModel.Profile.AccountCollection);
			this.LoadGrid(base.Document.StudentModel.Profile.AccountCollection);
            
        }

        private void DoCalculation( AccountCollection accounts )
        {
            decimal DebitAmount = 0;
            decimal CreditAmount = 0;
            decimal Balance = 0;
            decimal TotalCharges = 0;
            decimal OtherCharges = 0;
            // foreach record do the calculation
            foreach (Account acc in accounts)
            {
                
                DebitAmount += acc.DebitAmount;
                CreditAmount += acc.CreditAmount;
                // Total Fees
                if (acc.CreditAmount == 0)
                {
                    if (acc.Type == (int)AccountTypeEnum.Assessment )
                    {
                        TotalCharges += acc.DebitAmount;
                        // Total Charges                
                    }
                }
            }           
            Balance = DebitAmount - CreditAmount;

            string formatString = "0.00";

            textBoxDebit.Text = DebitAmount.ToString(formatString);
            textboxBalance.Text = Balance.ToString( formatString );
            textBoxCredit.Text = CreditAmount.ToString( formatString );
            textBoxTotalFee.Text = TotalCharges.ToString(formatString );
            // get the other charges
            OtherCharges = DebitAmount - TotalCharges;
            textBoxOtherCharges.Text = OtherCharges.ToString( formatString );
            // fill the grand Total
            decimal GrandTotal = TotalCharges + OtherCharges;
            textBoxGrandTotal.Text = GrandTotal.ToString( formatString );

        }
        internal class GridColumns
        {
            public const int TRAS_DATE = 0;
            public const int TRAS_DESCRIPTION = 1;
            public const int TRAS_BALANCE = 5;
            public const int DEBIT = 3;
            public const int CREDIT = 4;


        }

        private void LoadGrid( AccountCollection accounts )
        {
            dataGridAccouns.Rows.Clear();
            // styles
            DataGridViewCellStyle validBalanceStyle = new DataGridViewCellStyle( dataGridAccouns.DefaultCellStyle );
            validBalanceStyle.ForeColor = Color.Green;
            validBalanceStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
     
            DataGridViewCellStyle  negativeBalanceStyle = new DataGridViewCellStyle( dataGridAccouns.DefaultCellStyle );
            negativeBalanceStyle.ForeColor = Color.Red;
            negativeBalanceStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

            DataGridViewCellStyle totalFeeStyle = new DataGridViewCellStyle( dataGridAccouns.DefaultCellStyle );
            totalFeeStyle.BackColor = Color.LightGray;

            DataGridViewCellStyle alignment = new DataGridViewCellStyle(dataGridAccouns.DefaultCellStyle);
            alignment.Alignment = DataGridViewContentAlignment.MiddleRight;
            // end style
            //dataGridAccouns.r
            foreach( Account acc in accounts )
            {
                string transactionDate = acc.TransactionDate.ToString( "MM/dd/yyyy" );
                string transactionDescription = acc.TransactionDescription;

              
                int newRowIndex =  dataGridAccouns.Rows.Add( transactionDate,
                                                             transactionDescription,
                                                             acc.DebitAmount,
                                                             acc.CreditAmount,
                                                             acc.Balance );

                DataGridViewRow newRow = dataGridAccouns.Rows[newRowIndex];
              
                //newRow.Cells[ GridColumns.TRAS_DESCRIPTION ].Style.ApplyStyle( transactionStyle );               
               
                
                if( acc.Type == (int)AccountTypeEnum.Assessment )
                {
                    
                    newRow.DefaultCellStyle.ApplyStyle( totalFeeStyle );
                    // set the back color of other two column
                    negativeBalanceStyle.BackColor = Color.LightGray;
                    validBalanceStyle.BackColor = Color.LightGray;
                    
                    alignment.BackColor = Color.LightGray;
                    // apply right now
                    newRow.Cells[GridColumns.TRAS_BALANCE].Style.ApplyStyle(alignment);
                }
                else if (acc.Type != (int)AccountTypeEnum.Assessment)
                {
                    alignment.BackColor = Color.White;
                    negativeBalanceStyle.BackColor = Color.White;
                    validBalanceStyle.BackColor = Color.White;

                    if (acc.Balance <= 0)
                    {
                        newRow.Cells[GridColumns.TRAS_BALANCE].Style.ApplyStyle(negativeBalanceStyle);
                    }
                    else
                    {
                        newRow.Cells[GridColumns.TRAS_BALANCE].Style.ApplyStyle(validBalanceStyle);
                    }
                }
                // apply the style
                newRow.Cells[GridColumns.DEBIT].Style.ApplyStyle(alignment);
                newRow.Cells[GridColumns.CREDIT].Style.ApplyStyle(alignment);
                
                // each row represents each account entity
                newRow.Tag = acc;
                newRow.DefaultCellStyle.WrapMode = DataGridViewTriState.True;               
               
            }// end foreach
            dataGridAccouns.AutoResizeRows();
        }// end method
        private void addToolStripButton_Click(object sender, EventArgs e)
        {
            LoadAddDialog();
        }

        private void LoadAddDialog()
        {
			using (AccountTransactionDialog accDialog = new AccountTransactionDialog(base.Document.StudentModel.Profile.AccountCollection))
            {
                accDialog.ViewMode = AccountTransactionDialog.Mode.New;
                accDialog.StudentID = base.Document.StudentModel.Profile.ID;
                // show the dialog
                accDialog.OnAccept += new AccountTransactionDialog.AcceptedHandler( accDialog_OnAccept );
                accDialog.ShowDialog( this );
            }
        }
        private void editToolStripButton_Click(object sender, EventArgs e)
        {
            LoadEditDialog();
        }

        private void LoadEditDialog()
        {
			using (AccountTransactionDialog accDialog = new AccountTransactionDialog(base.Document.StudentModel.Profile.AccountCollection))
            {
                foreach( DataGridViewRow row in dataGridAccouns.SelectedRows )
                {
                    // set the account Object
                    Account account = row.Tag as Account;
                    if (account != null)
                    {
                        accDialog.AccountObject = account;

                        // set the mode                   
                        accDialog.ViewMode = AccountTransactionDialog.Mode.Edit;
                        // show the dialog
                        accDialog.OnAccept += new AccountTransactionDialog.AcceptedHandler(accDialog_OnAccept);
                        accDialog.ShowDialog(this);
                    }
                }
            }
        }

        private void dataGridAccouns_SelectionChanged(object sender, EventArgs e)
        {
            
            foreach( DataGridViewRow row in dataGridAccouns.SelectedRows )
            {
                Account account = row.Tag as Account;
                if (account != null)
                {
                    if (account.Type == (int)AccountTypeEnum.Assessment)
                    {
                        editToolStripButton.Enabled = false;
                        deleteToolStripButton.Enabled = false;
                    }
                    else
                    {
                        editToolStripButton.Enabled = true;
                        deleteToolStripButton.Enabled = true;
                    }
                }
            }
         
        }
        private void accDialog_OnAccept()
        {
            // refresh the grid and load history again 
            LoadAccounts();
        }

        private void refreshButton_Click(object sender, EventArgs e)
        {
            LoadAccounts();
        }

        private void deleteToolStripButton_Click(object sender, EventArgs e)
        {
            DialogResult result =   MessageBox.Show(this, "Are you sure you want to DELETE this transaction", "Notice",MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (result == DialogResult.Cancel)
                return;

            foreach (DataGridViewRow row in dataGridAccouns.SelectedRows)
            {
                Account acc =  row.Tag as Account;
				acc.MarkToDelete();
            }// end foreach

			this.LoadAccounts();
        }
    }
}

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