|
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(" "," ");
}
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.
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