Sunday, October 17, 2010

Code sample of Microsoft Enterprice Library

Sample userMgnt Class
=====================


#region Update Login Info
public bool UpdateLoginInfo(long uid)
{
try
{
Database db = DatabaseFactory.CreateDatabase(Constants.Database_Connection_Name);
DbCommand dbCommand = db.GetStoredProcCommand(Constants.SP_Update_LoginInfo);
db.AddInParameter(dbCommand, "@UID", DbType.Int64, uid);
db.AddInParameter(dbCommand, "@UserID", DbType.String, this.UserId);
db.AddInParameter(dbCommand, "@Action", DbType.String, this.Action);
db.ExecuteNonQuery(dbCommand);
return true;

}
catch (System.Exception ex)
{
ex.Data.Add("BusinessLayerException", this.GetType().ToString() + ABCErrorMesseges.Error_Seperator + "public bool UpdateLoginInfo()");
throw ex;
return false;
}
}
#endregion


-------------------------------------------------


#region GetAllGroup
//Get All user Groups
public DataSet GetAllGroup()
{
try
{
Database db = DatabaseFactory.CreateDatabase(Constants.Database_Connection_Name);
DbCommand dbCommand = db.GetStoredProcCommand(Constants.SP_Users_GetAlluserGroups);

return db.ExecuteDataSet(dbCommand);
}
catch (System.Exception ex)
{
throw;
}
}
#endregion


-------------------------------------------------------
#region Delete User

public void DeleteUser(int userId)
{
try
{
Database db = DatabaseFactory.CreateDatabase(Constants.Database_Connection_Name);
DbCommand dbCommand = db.GetStoredProcCommand(Constants.SP_Users_Delete);

db.AddInParameter(dbCommand, "@UserId", DbType.Int64, userId);
db.AddInParameter(dbCommand, "@ModifiedBy", DbType.String, this.ModifiedBy);

db.ExecuteNonQuery(dbCommand);
}
catch (System.Exception ex)
{
ex.Data.Add("BusinessLayerException", this.GetType().ToString() + ProjectErrorMesseges.Error_Seperator + "public void DeleteUser(int userId)");
throw ex;
}
}

#endregion

--------------------------------------------


#region add user
public bool addUser(Database db, DbTransaction transaction)
{
bool success = false;
try
{
DbCommand dbCommand = db.GetStoredProcCommand(Projectname.Common.Constants.SP_Users_Insert);
db.AddInParameter(dbCommand, "@UserName", DbType.String, this.UserName);
db.AddInParameter(dbCommand, "@Password", DbType.String, this.Password);
db.AddInParameter(dbCommand, "@Title", DbType.String, this.Title);
db.AddInParameter(dbCommand, "@FirstName", DbType.String, this.FirstName);
db.AddInParameter(dbCommand, "@LastName", DbType.String, this.LastName);
db.AddInParameter(dbCommand, "@ReferenceNumber", DbType.String, this.EmployeeNumber);
db.AddInParameter(dbCommand, "@AddLine1", DbType.String, this.Address1);
db.AddInParameter(dbCommand, "@AddLine2", DbType.String, this.Address2);
db.AddInParameter(dbCommand, "@City", DbType.String, this.City);
db.AddInParameter(dbCommand, "@Zip", DbType.String, this.Zip);
db.AddInParameter(dbCommand, "@State", DbType.String, this.State);
db.AddInParameter(dbCommand, "@Country", DbType.String, this.Country);
db.AddInParameter(dbCommand, "@Email", DbType.String, this.EMail);
db.AddInParameter(dbCommand, "@Designation", DbType.String, this.Designation);
db.AddInParameter(dbCommand, "@MobileNo", DbType.String, this.ContactNumber);
db.AddInParameter(dbCommand, "@RoleId", DbType.Int32, this.RoleId);
db.AddInParameter(dbCommand, "@CreatedBy", DbType.String, this.CreateBy);
db.AddOutParameter(dbCommand,"@UserId", DbType.Int32, 4);
db.AddInParameter(dbCommand, "@IsActive", DbType.Boolean,this.IsActivate);
db.AddInParameter(dbCommand, "@IsSelfRegister", DbType.Boolean, this.IsSelfRegister);


db.ExecuteNonQuery(dbCommand, transaction);

string outUserId = db.GetParameterValue(dbCommand, "@UserId").ToString();
this.UserId = Convert.ToInt32(outUserId);

success = true;
}
catch (System.Exception ex)
{
ex.Data.Add("BusinessLayerException", this.GetType().ToString() + ProjectErrorMesseges.Error_Seperator + "public bool addUser(Database db, DbTransaction transaction)");
throw ex;
return false;
}
return success;

}
#endregion

------------------------------
#region update
public bool update()
{
bool success = false;
try
{
Database db = DatabaseFactory.CreateDatabase(Constants.Database_Connection_Name);
connection = db.CreateConnection();
connection.Open();
transaction = connection.BeginTransaction();

//For Insert User .
DbCommand dbCommand = db.GetStoredProcCommand(Constants.SP_Users_Update);
db.AddInParameter(dbCommand, "@UserId", DbType.Int32, this.UserId);
db.AddInParameter(dbCommand, "@UserName", DbType.String, this.UserName);
db.AddInParameter(dbCommand, "@Password", DbType.String, this.Password);
db.AddInParameter(dbCommand, "@FirstName", DbType.String, this.FirstName);
db.AddInParameter(dbCommand, "@LastName", DbType.String, this.LastName);
db.AddInParameter(dbCommand, "@Email", DbType.String, this.EMail);
db.AddInParameter(dbCommand, "@RoleID", DbType.Int32, this.RoleId);

db.ExecuteNonQuery(dbCommand, transaction);
transaction.Commit();
success = true;
}
catch (System.Exception ex)
{
transaction.Rollback();
throw;
}

finally
{
if ((connection != null) && (connection.State == ConnectionState.Open))
{
connection.Close();
}
}
return success;

}
#endregion

--------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;




namespace ABC.Common
{
public class Constants
{

#region Constants Default Constructor

//This will restrict a Constant class being initialised.
public Constants()
{
}

#endregion

#region Grid Charactor Length
public static readonly string GridCharactorLength = "50";
public static readonly string CON_GridPageSize = System.Configuration.ConfigurationManager.AppSettings["GridPageSize"].ToString();
#endregion

#region Database Connection Name
//Database Connection
public static readonly string Database_Connection_Name = "ABC";

#endregion

#region Common Messeges
public static readonly string MSG_Common_Successfully_saved = "Successfully saved";
public static readonly string MSG_Common_Successfully_updated = "Successfully updated";
public static readonly string MSG_Common_Error_saving = "Error saving.";
public static readonly string MSG_Common_Error_updating = "Error updating.";
#endregion

#region Course Related stored procedures

public static readonly string SP_Course_Insert = "uspInsertCourse";
public static readonly string SP_Course_Update = "uspUpdateCourse";
public static readonly string SP_Course_UpdateforEdit = "uspUpdateCourseforEdit";
#end region
}
}

-------------------------------------
Sample stucture
===============
using System;
using System.Collections.Generic;
using System.Text;


namespace ABC.Common
{
public class Structures
{
public enum YesNo
{
Yes=1,
No=0
}

public enum QuestionType
{
Exact_Match= 1,
MCQ = 2,
True_False= 3,
Short_Answers= 4
}

public enum Tab
{
Tab1 = 0,
Tab2 = 1,
Tab3 = 2,
Tab4 = 3
}
}
}

-----------------------------------------

Sample web config
=================
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"/>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
<sectionGroup name="ajaxNet">
<section name="ajaxSettings" type="AjaxPro.AjaxSettingsSectionHandler,AjaxPro.2" requirePermission="false" restartOnExternalChanges="true"/>
</sectionGroup>
</configSections>
<dataConfiguration defaultDatabase="ABC"/>
<connectionStrings>


<add name="ABC" connectionString="Database=ABC;Server=Server;Integrated Security=false;uid=sa;pwd=allion;" providerName="System.Data.SqlClient"/>
<!--<add name="ABC" connectionString="Database=ABCQA1.2.6;Server=BACKUP-SRV\BACKUP_SRV;Integrated Security=false;uid=sa;pwd=allion;" providerName="System.Data.SqlClient"/>-->

</connectionStrings>

<!--<add name="ABC" connectionString="Database=ABCQA1.2.6;Server=BACKUP-SRV\BACKUP_SRV;Integrated Security=false;uid=sa;pwd=allion;" providerName="System.Data.SqlClient"/>
--><!--<add name="ABC" connectionString="Database=ABC;Server=server;Integrated Security=false;uid=sa;pwd=allion;" providerName="System.Data.SqlClient"/>--><!--
</connectionStrings>-->

<system.web>
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</controls>
<tagMapping>
<add tagType="System.Web.UI.WebControls.CompareValidator" mappedTagType="Sample.Web.UI.Compatibility.CompareValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.CustomValidator" mappedTagType="Sample.Web.UI.Compatibility.CustomValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RangeValidator" mappedTagType="Sample.Web.UI.Compatibility.RangeValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Sample.Web.UI.Compatibility.RegularExpressionValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.RequiredFieldValidator" mappedTagType="Sample.Web.UI.Compatibility.RequiredFieldValidator, Validators, Version=1.0.0.0"/>
<add tagType="System.Web.UI.WebControls.ValidationSummary" mappedTagType="Sample.Web.UI.Compatibility.ValidationSummary, Validators, Version=1.0.0.0"/>
</tagMapping>
</pages>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<!--<add assembly="Microsoft.Web.Services2, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
<add assembly="System.Security, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Services, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<!--<add assembly="Microsoft.Web.Services2, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
<add assembly="System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<!--<add assembly="Microsoft.Web.Services2, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>-->
<add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Web.Extensions.Design, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies>
</compilation>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="en-US"/>
<!--To maximize the uploading data file size from default (4MB) -->
<httpRuntime maxRequestLength="2097151" executionTimeout="60"/>
<!--<sessionState mode="InProc" />-->
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-ISAPI-2.0"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="ScriptResource" verb="GET" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</handlers>
</system.webServer>
<appSettings>
<add key="GridPageSize" value="15"></add>
<add key="MaximumAttachmentNameCharactors" value="40"></add>
<!--Notifications key values area -->
<!-- set SMTP Server name -->
<add key="SmtpServer" value="localhost"></add>
<!-- set SMTP Server name -->
<add key="Port" value="25"></add>

<add key="MaxAttemptsInExam" value="5"/>
</appSettings>
<ajaxNet>
<ajaxSettings>
<urlNamespaceMappings useAssemblyQualifiedName="false" allowListOnly="false">
<!--
Set the attribute useAssemblyQualifiedName to true to enable
use of assemblies placed in the GAC by using the full assembly
qualified name.

To hide internal knowledge of assemblies, classes and namespace
you can override the name of the virtual http endpoints.

<add type="Namespace.Class1,Assembly" path="mypath" />
-->
</urlNamespaceMappings>
<jsonConverters>
<!--
This section can be used to add new IJavaScriptConverters to the
Ajax.NET Professional engine. If you want to disable built-in
converters you can use the remove tag.

<remove type="Namespace.Class1,Assembly"/>
<add type="Namespace.Class2,Assembly"/>

<add type="AjaxPro.BitmapConverter,AjaxPro.2" mimeType="image/jpeg" quality="100"/>
-->
</jsonConverters>
<!--
Set the enabled attribute to true to get Stack, TargetSize and Source
information if an exception has been thrown.
-->
<debug enabled="false"/>
<!--
This is the default configuration used with Ajax.NET Professional. You
can put there your static JavaScript files, or remove the path attribute
to completly disable the files.

<scriptReplacements>
<file name="prototype" path="~/ajaxpro/prototype.ashx" />
<file name="core" path="~/ajaxpro/core.ashx" />
<file name="converter" path="~/ajaxpro/converter.ashx" />
</scriptReplacements>
-->
<!-- <encryption cryptType="" keyType="" /> -->
<!--
Set the enabled attribute to true to enable the use of an Ajax.NET Professional
token. This will send a token to the client that will be used to identify if the
requests comes from the same PC.
-->
<token enabled="false" sitePassword="password"/>
<!--
The oldStyle section can be used to enable old styled JavaScript code or
functions that are not used any more.

<oldStyle>
<objectExtendPrototype/>
<appCodeQualifiedFullName/>
<allowNumberBooleanAsString/>
<sessionStateDefaultNone/>
<includeMsPrototype/>
<renderDateTimeAsString/>
<noUtcTime/>
</oldStyle>
-->
</ajaxSettings>
</ajaxNet>
<location path="ajaxpro">
<system.web>
<pages validateRequest="false"/>
<httpHandlers>
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
</httpHandlers>
<!--
If you need to have Ajax.NET Professional methods running on the
login page you may have to enable your own authorization configuration
here.
-->
<!-- SESSION STATE SETTINGS
By default ASP.NET uses cookies to identify which requests belong to a particular session.
If cookies are not available, a session can be tracked by adding a session identifier to the URL.
To disable cookies, set sessionState cookieless="true".

-->
</system.web>
</location>
</configuration>
-----------------------------------------


#region Get UserDetails by userId
public Users GetUserDetailsByUserId(Database db, int UserId)
{
DbCommand dbCommand = db.GetStoredProcCommand(Constants.SP_Users_GetUserByUserId);

db.AddInParameter(dbCommand, "@UserId", DbType.Int32, UserId);


using (IDataReader oDataReader = db.ExecuteReader(dbCommand))
{
try
{
if (oDataReader.Read())
{
//oDataReader["CRFType"] != DBNull.Value ? Convert.ToInt32(oDataReader["CRFType"]) : 0;
//this.UserId = Convert.ToInt32(oDataReader["UserId"]);
this.UserId = oDataReader["UserId"] != DBNull.Value ? Convert.ToInt32(oDataReader["UserId"]) : 0;


this.UserName = oDataReader["UserName"] != DBNull.Value ? Convert.ToString(oDataReader["UserName"]) : "";
this.Password = oDataReader["Password"] != DBNull.Value ? Convert.ToString(oDataReader["Password"]) : "";
this.Title = oDataReader["Title"] != DBNull.Value ? Convert.ToString(oDataReader["Title"]) : "";
this.FirstName = oDataReader["FirstName"] != DBNull.Value ? Convert.ToString(oDataReader["FirstName"]) : "";
this.LastName = oDataReader["LastName"] != DBNull.Value ? Convert.ToString(oDataReader["LastName"]) : "";
this.EmployeeNumber = oDataReader["ReferenceNumber"] != DBNull.Value ? Convert.ToString(oDataReader["ReferenceNumber"]) : "";
this.address1 = oDataReader["AddLine1"] != DBNull.Value ? Convert.ToString(oDataReader["AddLine1"]) : "";
this.address2 = oDataReader["AddLine2"] != DBNull.Value ? Convert.ToString(oDataReader["AddLine2"]) : "";

this.City = oDataReader["City"] != DBNull.Value ? Convert.ToString(oDataReader["City"]) : "";
this.Zip = oDataReader["Zip"] != DBNull.Value ? Convert.ToString(oDataReader["Zip"]) : "";
this.State = oDataReader["State"] != DBNull.Value ? Convert.ToString(oDataReader["State"]) : "";
this.Country = oDataReader["Country"] != DBNull.Value ? Convert.ToString(oDataReader["Country"]) : "";
this.DOB = oDataReader["DateOfBirth"] != DBNull.Value ? Convert.ToDateTime(oDataReader["DateOfBirth"]) : DateTime.MinValue;

this.EMail = oDataReader["Email"] != DBNull.Value ? Convert.ToString(oDataReader["Email"]) : "";
this.Designation = oDataReader["Designation"] != DBNull.Value ? Convert.ToString(oDataReader["Designation"]) : "";
this.ContactNumber = oDataReader["MobileNo"] != DBNull.Value ? Convert.ToString(oDataReader["MobileNo"]) : "";

this.UnitId = oDataReader["UnitId"] != DBNull.Value ? Convert.ToInt32(oDataReader["UnitId"]) : 0;
this.RoleId = oDataReader["RoleId"] != DBNull.Value ? Convert.ToInt32(oDataReader["RoleId"]) : 0;
this.CreateBy = oDataReader["CreatedBy"] != DBNull.Value ? Convert.ToString(oDataReader["CreatedBy"]) : "";

this.CreatedDate = oDataReader["CreatedDate"] != DBNull.Value ? Convert.ToDateTime(oDataReader["CreatedDate"]) : DateTime.MinValue;
this.ModifiedBy = oDataReader["ModifiedBy"] != DBNull.Value ? Convert.ToString(oDataReader["ModifiedBy"]) : "";
this.ModifiedDate = oDataReader["ModifiedDate"] != DBNull.Value ? Convert.ToDateTime(oDataReader["ModifiedDate"]) : DateTime.MinValue;

this.IsActive = Convert.ToBoolean(oDataReader["IsActive"]);

this.IsUserHavingDependendency = oDataReader["IsUserHavingDependendency"] != DBNull.Value ? Convert.ToInt32(oDataReader["IsUserHavingDependendency"]) : 100;

return this;
}
else
{
return null;
}
}
catch (System.Exception ex)
{
ex.Data.Add("BusinessLayerException", this.GetType().ToString() +ABCErrorMesseges.Error_Seperator + "public bool GetUserDetailsByUserId(Database db, int UserId)");
throw ex;
}

}

}


#endregion

Tuesday, May 11, 2010

advertisement


Thursday, May 6, 2010

use If, Else in one line

leads.ShipmentDate = View.TxtShipmentDate.Text != "" ? Convert.ToDateTime(View.TxtShipmentDate.Text) : DateTime.MinValue;

Thursday, April 29, 2010

data for mation of data grid

{0:dd-MM-yyyy}

Sunday, April 11, 2010

Generate Random Number between specified range

private int GenerateNewRandomNumber(int min, int max)
{
Random Myrandom = new Random();
return Myrandom.Next(min, max);
}


//To call function
int Myrandom= GenerateNewRandomNumber(5, 20);

Wednesday, April 7, 2010

valuble validation scripts Asp.net C#

Enter atleast 5 characters
^.{5,}$


Please ignore the space character.

^[\S]*$

Wednesday, February 17, 2010

ziping folder using ICSharpCode dll

using ICSharpCode.SharpZipLib.Zip;

private static void ListZipContent(string sFile)
{
ZipFile zip = new ZipFile(File.OpenRead(sFile));
foreach (ZipEntry entry in zip)
{
//Console.WriteLine(entry.Name);
}
}

private static void CompressZip(string sPath, string zipSavingPath)
{
try
{
string zipName = DateTime.Now.ToString("m") + ".zip";
ZipOutputStream zipOut = new ZipOutputStream(File.Create(zipSavingPath + zipName));
//ZipOutputStream zipOut = new ZipOutputStream(File.Create(sPath));
foreach (string fName in Directory.GetFiles(sPath))
{
FileInfo fi = new FileInfo(fName);
ZipEntry entry = new ZipEntry(fi.Name);
FileStream sReader = File.OpenRead(fName);
byte[] buff = new byte[Convert.ToInt32(sReader.Length)];
sReader.Read(buff, 0, (int)sReader.Length);
entry.DateTime = fi.LastWriteTime;
entry.Size = sReader.Length;
sReader.Close();
zipOut.PutNextEntry(entry);
zipOut.Write(buff, 0, buff.Length);
}
zipOut.Finish();
zipOut.Close();
}
catch (Exception ex)
{

}
}