Click here to Skip to main content
15,880,725 members
Articles / Programming Languages / C#

AccountPlus

Rate me:
Please Sign up or sign in to vote.
4.47/5 (63 votes)
10 Sep 2009LGPL320 min read 239.4K   61.8K   209  
A Complete Account Management System
using System;
using System.Collections.Generic;
using System.Text;
using AccountPlus.DataAccess;
using System.Data;
using AccountPlus.Formatting;


namespace AccountPlus.BusinessLogic
{
    public class Items
    {
        private DBHelper _dbHelper = new DBHelper();

        /// <summary>
        /// Checks whether item with the specified name exists or not
        /// </summary>
        /// <param name="itemName">Item name</param>
        /// <returns>True if item with the specified name exists otherwise false</returns>
        public bool ItemExist(string itemName)
        {            
            string strCount = _dbHelper.ExecuteScalar("SELECT COUNT(*) FROM Item_Details WHERE Item_Name='" + itemName + "' AND IsActive=1").ToString();
            return Convert.ToInt16(strCount) > 0;                
        }

        /// <summary>
        /// Gets Item Id for the specified Item name
        /// </summary>
        /// <param name="itemName">Item Name</param>
        /// <returns>Item Id</returns>
        public string GetItemId(string itemName)
        {            
            string Query = "SELECT Item_Id from Item_Details where Item_Name='" + itemName + "'";
            return _dbHelper.ExecuteScalar(Query).ToString();            
        }
       

        /// <summary>
        /// Adds a new row to the Item_Details table for the specified values
        /// </summary>
        /// <param name="itemName">Item Name</param>
        /// <param name="itemDesc">Item Description</param>
        /// <param name="createdBy">Created By user Id</param>
        /// <param name="createdDate">Created on date</param>
        /// <returns>true if item is created successfully otherwise false</returns>
        public bool AddNewItem(string itemName, string itemDesc, int createdBy, string createdDate)
        {            
            string Query = string.Empty;
            DBParameterCollection paramCollection = new DBParameterCollection();
            paramCollection.Add(new DBParameter("@itemName", itemName));
            paramCollection.Add(new DBParameter("@itemDesc", itemDesc));
            paramCollection.Add(new DBParameter("@createdBy", createdBy));
            paramCollection.Add(new DBParameter("@createdDate", createdDate, System.Data.DbType.DateTime));
            Query = "INSERT INTO Item_Details (Item_Name, Item_Desc, Created_By, Entry_Date,  IsActive) VALUES (";
            Query = Query + "@itemName  , @itemDesc , @createdBy, @createdDate , 1)";
            return  _dbHelper.ExecuteNonQuery(Query, paramCollection) > 0;                        
        }


        /// <summary>
        /// Updates item details for an item of specified itemId and Item details
        /// </summary>
        /// <param name="itemID">Item Id</param>
        /// <param name="itemDesc">Item Description</param>
        /// <param name="entryBy">Item modified by</param>
        /// <param name="entryDate">Item modified date</param>
        /// <returns>true if item is modified successfully otherwise false</returns>
        public bool UpdateItem(int itemID, string itemDesc, string entryBy, string entryDate)
        {            
            string Query = string.Empty;
            DBParameterCollection paramCollection = new DBParameterCollection();            
            paramCollection.Add(new DBParameter("@itemDesc", itemDesc));
            paramCollection.Add(new DBParameter("@entryBy", entryBy));
            paramCollection.Add(new DBParameter("@entryDate", entryDate, System.Data.DbType.DateTime));
            paramCollection.Add(new DBParameter("@itemID", itemID));
            Query = "UPDATE Item_Details SET Item_Desc=@itemDesc , " + 
                "Created_By =@entryBy, Entry_Date = @entryDate " +
                "WHERE Item_Id=@itemID";
            return _dbHelper.ExecuteNonQuery(Query, paramCollection) > 0;                            
        }

        /// <summary>
        /// Gets list of items having specified item name and item description.
        /// Pass String.Empty, String.Empty for fetching all the records i.e. GetItems("", "")
        /// </summary>
        /// <param name="itemName">Item name</param>
        /// <param name="itemDesc">Item description</param>
        /// <returns>Item collection in the form of data table</returns>
        public DataTable GetItems(string itemName, string itemDesc)
        {
            StringBuilder sqlCommand = new StringBuilder("SELECT Item_Id, Item_Name, Item_Desc, IsActive From Item_Details ");
            DBParameterCollection paramCollection = new DBParameterCollection();

            if (itemName != string.Empty)
            {
                sqlCommand.Append(" WHERE Item_Name LIKE @itemName");
                paramCollection.Add(new DBParameter("@itemName", itemName));
            }

            if (itemName != string.Empty && itemDesc != string.Empty)
            {
                sqlCommand.Append(" AND Item_Name LIKE @itemDesc ");
                paramCollection.Add(new DBParameter("@itemDesc", itemDesc));
            }
            else if (itemName == string.Empty && itemDesc != string.Empty)
            {
                sqlCommand.Append(" WHERE Item_Name LIKE @itemDesc");
                paramCollection.Add(new DBParameter("@itemDesc", itemDesc));
            }

            return _dbHelper.ExecuteDataTable(sqlCommand.ToString(), paramCollection);
        }

        /// <summary>
        /// Gets Item description for the specified item id.
        /// </summary>
        /// <param name="itemId">Item id</param>
        /// <returns>Item description</returns>
        public string GetItemDescription(string itemId)
        {
            string sqlCommand = "SELECT Item_Desc From Item_Details Where Item_Id = " + itemId;
            return DataFormat.GetString( _dbHelper.ExecuteScalar(sqlCommand));
        }

    }
}

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, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder Aspirea Technologies Pvt Ltd
India India
• 8 years of experience in IT Industry as a Developer.
• Experience of End-To-End Software Development and Implementation (Entire SDLC i.e Software Development Life Cycle)
• Real time Exposure to Banking, Finance and Energy industry.
• Expertise in distributed application architecture as well as web based applications using Microsoft.NET platform.
• Expertise in database design, SQL programming and SQL performance tuning.
• Expertise in Web Services and WCF Services.
• Experience of Rich Internet Application using Adobe Flex.
• Experience in migration of legacy application to latest technology, migration of VB application to .NET.
• Knowledge of OOPS and Design Concepts.
• Expertise in Agile/ Scrum software development processes.

Specialties
• Languages\ Technologies-
.NET Framework 1.1/2.0/3.0/3.5, C#.NET, VB.NET, ASP.NET, VB6, AJAX, ASP.NET, Adobe Flex 3.0, Web Services, Windows Communication Foundation (WCF), LINQ, SQL Server, Oracle, MySql, MS Access, HTML, XML, JavaScript, C# Script, CSS and XSLT.

• Methodology/ Concepts-
OOPS, Data Structures, Design Concepts and Agile/ Scrum Software Development

Comments and Discussions