public static DBgl_CountryCollection GetAllItem() { string key = SETTINGS_ALL_KEY; object obj2 = dtpCache.Get(key); if ((obj2 != null)) { return((DBgl_CountryCollection)obj2); } DBgl_CountryCollection ItemCollection = new DBgl_CountryCollection(); Database db = SqlHelper.CreateConnection(SqlHelper.MyConnection); DbCommand dbCommand = db.GetStoredProcCommand("gl_Country_GetAll"); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DBgl_Country item = GetItemFromReader(dataReader); ItemCollection.Add(item); } } dtpCache.Max(key, ItemCollection); return(ItemCollection); }
public static string GetJson(DBgl_CountryCollection itemCollection) { StringBuilder builder = new StringBuilder(); if (itemCollection.Count > 0) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); using (JsonWriter jsonWriter = new JsonTextWriter(sw)) { jsonWriter.Formatting = Formatting.Indented; jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("results"); jsonWriter.WriteStartArray(); itemCollection.ForEach(delegate(DBgl_Country objItem) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("CountryID"); jsonWriter.WriteValue(objItem.CountryID.ToString()); jsonWriter.WritePropertyName("CountryName"); jsonWriter.WriteValue(objItem.CountryName.ToString()); jsonWriter.WritePropertyName("isPublished"); jsonWriter.WriteValue(objItem.isPublished.ToString()); jsonWriter.WritePropertyName("Orders"); jsonWriter.WriteValue(objItem.Orders.ToString()); jsonWriter.WritePropertyName("ImgUrl"); jsonWriter.WriteValue(objItem.ImgUrl.ToString()); jsonWriter.WritePropertyName("Description"); jsonWriter.WriteValue(objItem.Description.ToString()); jsonWriter.WritePropertyName("Code"); jsonWriter.WriteValue(objItem.Code.ToString()); jsonWriter.WriteEndObject(); }); jsonWriter.WriteEndArray(); jsonWriter.WriteEndObject(); builder.AppendLine(sw.ToString()); } } else { // builder.AppendLine(@"{""results"":[{""id"":""-1"",""myvalue"":""" + MainFunction.ngonngu("gl.nodata") + @"""}]}"); } return(builder.ToString()); }
public static DBgl_CountryCollection GetItemPagging(int page, int rec, string strSearch, out int TotalRecords) { TotalRecords = 0; DBgl_CountryCollection ItemCollection = new DBgl_CountryCollection(); Database db = SqlHelper.CreateConnection(SqlHelper.MyConnection); DbCommand dbCommand = db.GetStoredProcCommand("gl_Country_Paging"); db.AddInParameter(dbCommand, "Page", DbType.Int32, page); db.AddInParameter(dbCommand, "RecsPerPage", DbType.Int32, rec); db.AddInParameter(dbCommand, "SearchValue", DbType.String, strSearch); db.AddOutParameter(dbCommand, "TotalRecords", DbType.Int32, 0); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DBgl_Country item = GetItemFromReader(dataReader); ItemCollection.Add(item); } } TotalRecords = Convert.ToInt32(db.GetParameterValue(dbCommand, "@TotalRecords")); return(ItemCollection); }