Click here to Skip to main content
15,897,334 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 243.4K   61.8K   209  
A Complete Account Management System
using System;
using System.Collections.Generic;
using System.Text;

namespace AccountPlus.Formatting
{
    public static class DataFormat
    {
        public static string DateToDB(string date)
        {
            DateTime dt = Convert.ToDateTime(date);
            return dt.ToString("MMddyyyy");
        }

        public static string GetDBDate(string date)
        {
            return GetDateTime(date).ToShortDateString();
        }

        public static string GetDBDate(object date)
        {
            return GetDateTime(date).ToShortDateString();
        }

        public static string GetDBDate(DateTime date)
        {
            return date.ToShortDateString();
        }

        public static string GetCurrentDate()
        {
            DateTime dt = System.DateTime.Now;
            return dt.ToString("MMddyyyy");
        }

        public static string DateToDisp(string date)
        {
            string[] dateString = new string[3];
            DateTime dt = Convert.ToDateTime(date);
            dateString = dt.ToString("dd MMM yyyy").Split(Convert.ToChar(" "));
            return dateString[0] + " " + dateString[1] + ", " + dateString[2];
        }

        public static string GetDateFromDBDate(string date)
        {
            string dateReturn = string.Empty;
            if (date.Trim().Length < 8)
                date = "0" + date.Trim();

            string month = date.Substring(0, 2);
            string date1 = date.Substring(2, 2);
            string year = date.Substring(4);
            dateReturn = month + "/" + date1 + "/" + year ;

            dateReturn = DateToDisp(dateReturn);
            return dateReturn;
        }

        public static string GetMonth(string date)
        {
            string dateToDB = DateToDB(date);
            return dateToDB.Substring(0, 2);
        }

        public static string GetYear(string date)
        {
            string dateToDB = DateToDB(date);
            return dateToDB.Substring(4, 4);
        }

        public static string GetDate(string date)
        {
            string dateToDB = DateToDB(date);
            return dateToDB.Substring(2, 2);
        }

        #region Core Formatting Metods
        public static bool IsValidDate(string date)
        {
            bool retValue = false;
            DateTime result = new DateTime();
           if (DateTime.TryParse(date, out result))            
                retValue = true;

            return retValue;
        }

        public static bool IsValidDate(object date)
        {
            bool retValue = false;
            DateTime result = new DateTime();
            
            if (date != null)
            {
                if (DateTime.TryParse(date.ToString(), out result))
                    retValue = true;
            }
            
            return retValue;
        }

        public static DateTime GetDateTime(string date)
        {            
            DateTime retValue = new DateTime();
            if (IsValidDate(date))
                retValue = Convert.ToDateTime(date);
            
            return retValue;
        }

        public static DateTime GetDateTime(object date)
        {
            DateTime retValue = new DateTime();
            if (IsValidDate(date))
                retValue = Convert.ToDateTime(date);

            return retValue;
        }


        public static bool IsNumeric(object value)
        {
            bool retValue = false;
            
            if (value != null)            
                retValue = IsNumeric (value.ToString());
            
            return retValue;
        }

        public static bool IsNumeric(string value)
        {
            bool retValue = false;
            double result = 0;
            if (value != null)
                retValue = double.TryParse(value, out result);

            return retValue;
        }


        public static bool IsInteger(object value)
        {
            bool retValue = false;

            if (value != null)
                retValue = IsInteger(value.ToString());

            return retValue;
        }

        public static bool IsInteger(string value)
        {
            bool retValue = false;
            int result = 0;
            if (value != null)
                retValue = int.TryParse(value, out result);

            return retValue;
        }

        public static bool IsBoolean(string value)
        {
            bool retValue = false;
            bool result = false ;
            if (value != null)
                retValue = Boolean.TryParse(value, out result);

            return retValue;
        }


        public static bool IsBoolean(object value)
        {
            bool retValue = false;
            
            if (value != null)
                retValue = IsBoolean(value.ToString());

            return retValue;
        }

        public static string GetString(object value)
        {
            string retValue = string.Empty;
            if (value != null)
                retValue = value.ToString();

            return retValue;
        }


        public static int GetInteger(object value)
        {
            int retValue = 0;

            if (IsInteger(value))
                retValue = Convert.ToInt16(value);

            return retValue;
        }


        public static int GetInteger(string value)
        {
            int retValue = 0;

            if (IsInteger(value))
                retValue = Convert.ToInt16(value);

            return retValue;
        }

        public static double GetDouble(object value)
        {
            double retValue = 0;

            if (IsNumeric(value))
                retValue = Convert.ToDouble(value);

            return retValue;
        }


        public static double GetDouble(string value)
        {
            double retValue = 0;

            if (IsNumeric(value))
                retValue = Convert.ToDouble(value);

            return retValue;
        }

        public static bool GetBoolean(object value)
        {
            bool retValue = false;

            if (IsBoolean(value))
                retValue = Convert.ToBoolean(value);

            return retValue;
        }


        public static bool GetBoolean(string value)
        {
            bool retValue = false;

            if (IsBoolean(value))
                retValue = Convert.ToBoolean(value);

            return retValue;
        }


        #endregion

    }
}

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