Cookies using Javascript
Hi all,
Today , I was working on my project and I was required to work on the cookies in the client side. Infact , I have to read and write cookie from both client side and server side. For server side it was easy to read , write and expire the cookie but I need to work bit hard in javascript for the same.
Now, I will tell you the method I wrote to read, create and expire the cookie.
//Creating Cookie
function CreateCookie(cookieName,value,hrs)
{
if (hrs)
{
var date = new Date();
date.setTime(date.getTime()+(hrs*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else
var expires = "";
document.cookie = cookieName+"="+value+expires+"; path=/";
}
//Reading Cookie Value
function ReadCookie(cookieName) {
var nameEQ = cookieName + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
//Deleting Cookie
function EraseCookie(cookieName) {
createCookie(cookieName,"",-10);
}
I hope the method I wrote are self explanatory .
But if you still have any issue, please feel free to contact/reply me.
Thanks
Arvind-Ramp
Happy Programming
Wednesday, March 4, 2009
Tuesday, March 3, 2009
Working with Wilson ORmapper
Working With Wilson ORMapper
Hello ,
I am working on a project and using wilson ORMapper to communicate with the database. I faced lot of problems as I didn’t find any the proper document about how to work with ORMapper. Then I thought that after learning I would prepare a very brief document to show how to write the method to communicate with the database using ORMapper. Here are some of the method :
Updating a record.
public static User UpdateUser(IContext context, User user)
{
Global.Manager.StartTracking(user, InitialState.Updated);
Global.Manager.PersistChanges(user, PersistDepth.SingleObject);
return user;
}
Adding New Record
public static User CreateUser(IContext context, User user)
{
Global.Manager.StartTracking(user, InitialState.Inserted);
Global.Manager.PersistChanges(user, PersistDepth.SingleObject);
return user;
}
Getting Record by iD.
public static User GetUserByID(IContext context, int userID)
{
OPathQuery query = new OPathQuery("ID = ?");
return Global.Manager.GetObject(query, userID);
}
Getting collection Object of record.
public static Collection GetUsers (IContext context)
{
if (userStatus == Constants.All)
{
OPathQuery query = new OPathQuery("");
return Global.Manager.GetCollection(query);
}
}
Calling Stored Procedure using Stored Procedure
public static DataSet GetTransferDetails(IContext context, int siteID, int roomID)
{
DataSet dataSet;
SelectProcedure spTransferDetails = new SelectProcedure(null, GetTransferDetails");
spTransferDetails.AddParameter("@siteID", siteID);
spTransferDetails.AddParameter("@departmentID", departmentID); spTransferDetails.AddParameter("@roomID", roomID);
dataSet = Global.Manager.GetDataSet(spTransferDetails);
return dataSet;
}
Executing SQL query in ORMapper
public DataSet GetUserRecordHistory(int userID, string emailID)
{
string sql = String.Format("select UserName,[Time],SiteID,RoleID from User where userID = {0} and emailID = {1} Order By Time DESC", userID, emailID);
return Global.Manager.GetDataSet(sql);
}
Passing Multiple Parameter to the ORMapper query
public Product GetProduct(int manufacturerID, int productCategoryID, int productTypeID,string productName , string length, string diameter, string primaryFeature, string secondaryFeature, string otherFeature)
{
OPathQuery query = new OPathQuery("CategoryID = ? and ManufacturerID = ? and TypeID = ? and Name = ? and Length = ? and Diameter = ? and PrimaryFeature = ? and SecondaryFeature = ? and OtherFeature = ? and IsActive = 1");
return Global.Manager.GetObject(query, productCategoryID, manufacturerID, productTypeID, productName, length, diameter, primaryFeature, secondaryFeature , otherFeature);
}
Using Transaction In ORMAPPER
public static List AddProductandBarcode(IContext context, List productbarcodes)
{
Product product = null;
BarCode barcode = null;
Transaction transaction = null;
List savedProducts = new List();
try
{
transaction = Global.Manager.BeginTransaction();
foreach (ProductBarcode productBarcode in productbarcodes)
{
product = productBarcode.ProductObject;
barcode = productBarcode.BarcodeObject;
Global.Manager.StartTracking(product, InitialState.Inserted);
transaction.PersistChanges(product, PersistDepth.SingleObject);
barcode.ProductID = product.ID;
Global.Manager.StartTracking(barcode, InitialState.Inserted);
transaction.PersistChanges(barcode, PersistDepth.SingleObject);
savedProducts.Add(product);
transaction.Commit();
return savedProducts;
}
catch { transaction.Rollback(); return null; }
finally { transaction.Dispose(); }
}
Sorting Result using ORMapper
public string sortExp = "Name";
public Collection GetSites(IContext context)
{
Collection sites = null;
OPathQuery query = new OPathQuery("",sortExp);
sites = Global.Manager.GetCollection(query);
return sites;
}
Getting single Result/Execute Scalar
public static string GetTimeZoneBySiteID(int siteID)
{
string queryString = string.Format("select timezone from SiteTimeZone tz where s.SiteID = {0}", siteID);
return Global.Manager.ExecuteScalar(queryString);
}
Parameterized query in ORmapper
public static DataSet GetCaseInfo(IContext context, int siteID, DateTime dateTime)
{
DataSet dataSet = null;
string queryString = string.Format(@"select timezone,Time from SiteTimeZone tz where s.SiteID = @siteName and Time=@Time", whereString);
SelectProcedure selectProcedure = new SelectProcedure(null, queryString);
selectProcedure.AddParameter("@SiteID", siteID);
selectProcedure.AddParameter("@Time ", dateTime);
dataSet = Global.Manager.GetDataSet(selectProcedure);
return dataSet;
}
Hope u understood the methods i have written. i dont think these method need any further explanation.
if u have any query , feel free to contact/reply me .
hope to see to again.
-Thanks
Arvind - Ramp
Happy Programming
Hello ,
I am working on a project and using wilson ORMapper to communicate with the database. I faced lot of problems as I didn’t find any the proper document about how to work with ORMapper. Then I thought that after learning I would prepare a very brief document to show how to write the method to communicate with the database using ORMapper. Here are some of the method :
Updating a record.
public static User UpdateUser(IContext context, User user)
{
Global.Manager.StartTracking(user, InitialState.Updated);
Global.Manager.PersistChanges(user, PersistDepth.SingleObject);
return user;
}
Adding New Record
public static User CreateUser(IContext context, User user)
{
Global.Manager.StartTracking(user, InitialState.Inserted);
Global.Manager.PersistChanges(user, PersistDepth.SingleObject);
return user;
}
Getting Record by iD.
public static User GetUserByID(IContext context, int userID)
{
OPathQuery
return Global.Manager.GetObject
}
Getting collection Object of record.
public static Collection
{
if (userStatus == Constants.All)
{
OPathQuery
return Global.Manager.GetCollection
}
}
Calling Stored Procedure using Stored Procedure
public static DataSet GetTransferDetails(IContext context, int siteID, int roomID)
{
DataSet dataSet;
SelectProcedure spTransferDetails = new SelectProcedure(null, GetTransferDetails");
spTransferDetails.AddParameter("@siteID", siteID);
spTransferDetails.AddParameter("@departmentID", departmentID); spTransferDetails.AddParameter("@roomID", roomID);
dataSet = Global.Manager.GetDataSet(spTransferDetails);
return dataSet;
}
Executing SQL query in ORMapper
public DataSet GetUserRecordHistory(int userID, string emailID)
{
string sql = String.Format("select UserName,[Time],SiteID,RoleID from User where userID = {0} and emailID = {1} Order By Time DESC", userID, emailID);
return Global.Manager.GetDataSet(sql);
}
Passing Multiple Parameter to the ORMapper query
public Product GetProduct(int manufacturerID, int productCategoryID, int productTypeID,string productName , string length, string diameter, string primaryFeature, string secondaryFeature, string otherFeature)
{
OPathQuery
return Global.Manager.GetObject
}
Using Transaction In ORMAPPER
public static List
{
Product product = null;
BarCode barcode = null;
Transaction transaction = null;
List
try
{
transaction = Global.Manager.BeginTransaction();
foreach (ProductBarcode productBarcode in productbarcodes)
{
product = productBarcode.ProductObject;
barcode = productBarcode.BarcodeObject;
Global.Manager.StartTracking(product, InitialState.Inserted);
transaction.PersistChanges(product, PersistDepth.SingleObject);
barcode.ProductID = product.ID;
Global.Manager.StartTracking(barcode, InitialState.Inserted);
transaction.PersistChanges(barcode, PersistDepth.SingleObject);
savedProducts.Add(product);
transaction.Commit();
return savedProducts;
}
catch { transaction.Rollback(); return null; }
finally { transaction.Dispose(); }
}
Sorting Result using ORMapper
public string sortExp = "Name";
public Collection
{
Collection
OPathQuery
sites = Global.Manager.GetCollection
return sites;
}
Getting single Result/Execute Scalar
public static string GetTimeZoneBySiteID(int siteID)
{
string queryString = string.Format("select timezone from SiteTimeZone tz where s.SiteID = {0}", siteID);
return Global.Manager.ExecuteScalar(queryString);
}
Parameterized query in ORmapper
public static DataSet GetCaseInfo(IContext context, int siteID, DateTime dateTime)
{
DataSet dataSet = null;
string queryString = string.Format(@"select timezone,Time from SiteTimeZone tz where s.SiteID = @siteName and Time=@Time", whereString);
SelectProcedure selectProcedure = new SelectProcedure(null, queryString);
selectProcedure.AddParameter("@SiteID", siteID);
selectProcedure.AddParameter("@Time ", dateTime);
dataSet = Global.Manager.GetDataSet(selectProcedure);
return dataSet;
}
Hope u understood the methods i have written. i dont think these method need any further explanation.
if u have any query , feel free to contact/reply me .
hope to see to again.
-Thanks
Arvind - Ramp
Happy Programming
Subscribe to:
Comments (Atom)