Click here to Skip to main content
15,881,380 members
Articles / Programming Languages / C#

.NET like Access(V1)

Rate me:
Please Sign up or sign in to vote.
3.20/5 (10 votes)
28 Feb 20067 min read 57.6K   542   40  
Database library for rapid development.
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Configuration;
using System.Xml;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.IO;
namespace DNetLibrary
{
	public enum DateFormat
	{
		StartDayInMonth,LastDayInMonth,Other	 
	}
	/// <summary>
	/// Summary description for Util.
	/// </summary>
	public class UTIL 
	{
		// this Static variable populated with first Session
		
		static public string CurrentDate 
		{
			get 
			{
				return UTIL.DataFormating.ConvertDateToYYYYMMDD(DateTime.Now);
			}
		}
		
		public string TempFolder 
		{
			get 
			{
				return @"C:\Temp\";
			}
		}
		private static string userid;
		static public string SystemUserId 
		{
			get 
			{
				return userid;
			}
			set 
			{
				userid=value;
			}
			
		}
		static public string Version 
		{
			get 
			{
				return 0.ToString();
			}
		}
		
		public static string GetExceptionMessage(Exception ex)
		{
			string st="";
			DNetException dnEx=(ex as DNetException);
			Exception inner;
			if(dnEx!=null)
			{
				inner=dnEx.SourceException;
				if(inner==null)st=dnEx.Message;
				else
				{st=dnEx.Description+" Source of Error: "+inner.Message;}				
				return st;
			}
			st=ex.Message;
			return st;
		}
		sealed public class UI 
		{
//			public static void SetFormCenter(System.Windows.Forms.Form fm) 
//			{
//				System.Drawing.Point p=new Point(0,0);
//		
//				p.X=(Screen.PrimaryScreen.Bounds.Height-fm.Height)/2;
//				p.Y=(Screen.PrimaryScreen.Bounds.Width)/20;
//				fm.Location=p;
//			}
		}
				
		sealed public class DataFormating 
		{
			static  public string ConvertDateToMMDDYYYY(DateTime dateIN) 
			{
				return dateIN.Month.ToString()+"/"+dateIN.Day.ToString()+"/"+dateIN.Year;
			}
		
			static  public DateTime ConvertddmmyyyToDateTime(string sdatetime) 
			{
				string[] list;
				int day ,month,year;
				list=sdatetime.Split('/');
				if(list.Length==3) 
				{
					day =int.Parse(list[0].Trim());
					month=int.Parse(list[1].Trim());
					year=int.Parse(list[2].Trim());
					DateTime dt=new DateTime(year,month,day,0,0,0,0);
					return dt;
				}
				list=sdatetime.Split('-');
				if(list.Length==3) 
				{
					day =int.Parse(list[0].Trim());
					month=int.Parse(list[1].Trim());
					year=int.Parse(list[2].Trim());
					DateTime dt=new DateTime(year,month,day,0,0,0,0);
					return dt;
				}
				return DateTime.MinValue;
			}

			static  public  int FromStringToHash(string st,char separetor,Hashtable ht) 
			{
				string allItems=st;			
				ht.Clear();
				string[] myList=allItems.Split(separetor);
			
				for(int i=0;i<myList.Length;i++) 
				{			
					if(myList[i].Trim()=="")continue;
					string[] internalList=myList[i].Split(':');
				
					if(ht.ContainsKey(internalList[0].Trim())==false)ht[internalList[0].Trim()]=internalList[1].Trim();		
				}// total list			
			
				/* From string to Hash*/ 
				return 0;
			}
		
			static public string ReplaceSpace(string st) 
			{
				return st.Replace(" ","&nbsp;");
			}		
			static public string ConvertDateToYYYYMMDD(DateTime dt) 
			{
				return dt.Year.ToString()+"-"+dt.Month.ToString()+"-"+dt.Day.ToString();
			}
			static public  string ConvertToStandardDateTime(DateTime dt) 
			{
				string day=dt.Day.ToString();
				string month=dt.Month.ToString();
				string year=dt.Year.ToString();
				string hour=dt.Hour.ToString();
				string minute=dt.Hour.ToString();
				string seconds=dt.Second.ToString();
				return year+"-"+month+"-"+day+"  "+hour+":"+minute+":"+seconds;
			}
			static public  void ConvertToDateTime(string sDate,out DateTime dt) 
			{
				dt=DateTime.MinValue;
				try
				{
					dt=Convert.ToDateTime(sDate);
				}
				catch(Exception ee) 
				{
					throw new DNetException(-1,"Invalid DateTime formatt",ee);
				};
				
				return ;
			}
		}// Class data formating
		
		sealed public class Validation 
		{			
			public	static bool StartDateGorEEndDate(DateTime sDate,DateTime eDate) 
			{
				if(sDate>eDate) 
				{
					return false;
				}
				else 
				{
					return true;;
				}
			}
		
				
		}
		
		sealed public class Data 
		{
			#region code dictionary
			sealed  public class ObjectStatus 
			{
				public static string Active="ACT";
				public static string InActive="INACT";
				public static string Canceled="CNL";
			}

			#endregion 
			static public void SortDataSet(DataSet dataSet,string fieldName) 
			{
				dataSet.Tables[0].DefaultView.Sort=fieldName;				
				return ;
			}
				
			static public  string RepairStringToSQLServer(string unManagedSQL) 
			{
				unManagedSQL=unManagedSQL.Replace("'","''");
				return unManagedSQL;
			}
			static public string ConnectionString;
			/*class*/}
		sealed public class UserApp 
		{			
			public static string GetFromUserPart(String keyName)
			{
				string s_value="ERROR";
				try
				{
					s_value=System.Configuration.ConfigurationSettings.AppSettings[keyName].Trim();
				}
				catch(Exception ee){s_value=ee.Message;};
				return s_value;
			}
			
				
		}/*UTIL*/
		
	}// Util class
					
	public class Args:System.EventArgs
	{
		public object Val;
		public string Action;
		public Args(object val)
		{
			this.Val=val;
		}
		public Args(string actionName,object val)
		{
			this.Val=val;
			this.Action=actionName;
		}
		public override string ToString()
		{
			return Val.ToString();
		}
		
		
	}
	public class DNetException:System.Exception
	{
		private int no;
		private string description;
		private  Exception sourceException;
		public Exception SourceException
		{
			get
			{
				return sourceException;
			}
			set
			{
				sourceException=value;
			}
		}
		public int No
		{
			get
			{
				return no;
			}
			set
			{
				no=value;
			}
		}

		public string Description
		{
			get
			{
				return description;
			}
			set
			{
				description=value;
			}
		}
		
		public DNetException(int no,string description,Exception source)
		{
			this.no=no;this.description=description;this.sourceException=source;

		}

	}

}// name space

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
Software Developer (Senior) NSW Curriculum & Learning Innovation Centre
Australia Australia
I am a senior developer self taught,
the main study is electronics and communication engineering

I am working as senior programmer in center for learning and innovation
www.cli.nsw.edu.au

I develop Software since 1995 using Delphi with Microsoft SQL Server

before 2000, I didn’t like Microsoft tools and did many projects using all database tools and other programming tools specially Borland C++ Builder, Delphi, Power Builder
And I loved Oracle database for its stability until I was certified as Master in Database Administration from Oracle University.

I tried to work in web programming but I felt that Java is hard and slow in programming, specially I love productivity.

I began worked with .Net since 2001 , and at the same time Microsoft SQL Server 7 was very stable so I switched all my way to Microsoft Tech.
I really respect .Net Platform especially in web applications

I love database Applications too much
And built library with PowerBuilder it was very useful for me and other developers

I have a wide experience due to my work in different companies
But the best experience I like in wireless applications, and web applications.
The best Application I did in my life is Novartis Marketing System 1999 it takes 8 months developing with PowerBuilder and Borland C++, SQL Server
Performance was the key challenge in this Application.
The other 2 applications that I loved Multilingual Project in Scada company in Italy 2000 and SDP Mobile media content platform server for ChinaUnicom 2004
I hope that you enjoy any Article I post.
God bless you.

Comments and Discussions