Monday, 30 September 2013

Handle database value using dynamic data type

Ex:  BranchCode = clsFunctions.HandleDBValue(BranchRow["BranchCode"]);


///
        /// Handle and databaase value like int,string,double,dcimal ect.
        ///
        ///
        ///
        public static dynamic HandleDBValue(object objField)
        {
            dynamic result;
            result = 0;
            if (objField is string)
            {
                result= objField;
            }
            if (objField is int)
            {
                int iResult;
                int.TryParse(objField.ToString(), out iResult);
                result = iResult;
            }
            if (objField is bool)
            {
                bool bResult;
                bool.TryParse(objField.ToString(), out bResult);
                result = bResult;
            }
            if (objField is decimal)
            {
                decimal dResult;
                decimal.TryParse(objField.ToString(), out dResult);
                result = dResult;
            }
            if (objField is double)
            {
                double dblResult;
                double.TryParse(objField.ToString(), out dblResult);
                result = dblResult;
            }
            if (objField is Single)
            {
                Single sResult;
                Single.TryParse(objField.ToString(), out sResult);
                result = sResult;
            }
            return result;
      }

Convert Dataset to XML

      public string ConvertToXml(DataSet ds)
        {
            // This is the final document  
            XmlDocument Data = new XmlDocument();
            // Create a string writer that will write the Xml to a string
            StringWriter stringWriter = new StringWriter();

            // The Xml Text writer acts as a bridge between the xml stream and the text stream
            XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);

            // Now take the Dataset and extract the Xml from it, it will write to the string writer
            ds.WriteXml(xmlTextWriter);

            // Write the Xml out to a string
            return stringWriter.ToString();
        }

Wednesday, 25 September 2013

 Step 1: Remove Cache  when search or initialize
  Cache.Remove("Your Key");

 Step 2:  Initialize Cache
 Cache.Insert("Your Key", , null, DateTime.MaxValue, TimeSpan.FromMinutes(20));

Step 3: Use Cache
For Example

 DataSet dsHis = new DataSet();
                if ((DataSet)Cache["FillVisitStatusHis" + userData.UserID] == null)
                {
                    dsHis = objClinicalDoc.LoadClinicalDocStatusChangeHistory(cdocID, userData.UserID);
                    Cache.Insert("FillVisitStatusHis" + userData.UserID, dsHis, null, DateTime.MaxValue, TimeSpan.FromMinutes(20));
                 
                }
                dsHis = (DataSet)Cache["FillVisitStatusHis" + userData.UserID];
                if(dsHis!=null)
                {
                    if (dsHis.Tables.Count > 0)
                    {
                        if (dsHis.Tables[0].Rows.Count > 0)
                        {
                            divgv.Visible = true;
                        }
                        if (dsHis.Tables[0].Rows.Count > 5)
                        {
                            gvHis.AllowPaging = true;
                        }
                    }
                }

                gvHis.DataSource = dsHis.Tables[0];
                gvHis.DataBind();

function OnlyAlphaNumeric() {
    var keyCode = String.fromCharCode(event.keyCode);
    var letters =/^[a-zA-Z0-9\s.\-]+$/; // /^[a-zA-Z0-9]+$/;
    var result = letters.test(keyCode);
    return result;
}