public static DBgl_UserInfoCollection GetAllItem() { string key = SETTINGS_ALL_KEY; object obj2 = dtpCache.Get(key); if ((obj2 != null)) { return((DBgl_UserInfoCollection)obj2); } DBgl_UserInfoCollection ItemCollection = new DBgl_UserInfoCollection(); Database db = SqlHelper.CreateConnection(SqlHelper.MyConnection); DbCommand dbCommand = db.GetStoredProcCommand("gl_UserInfo_GetAll"); using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { while (dataReader.Read()) { DBgl_UserInfo item = GetItemFromReader(dataReader); ItemCollection.Add(item); } } dtpCache.Max(key, ItemCollection); return(ItemCollection); }
public static DBgl_UserInfoCollection GetItemPagging(int page, int rec, string strSearch, out int TotalRecords) { TotalRecords = 0; DBgl_UserInfoCollection ItemCollection = new DBgl_UserInfoCollection(); Database db = SqlHelper.CreateConnection(SqlHelper.MyConnection); DbCommand dbCommand = db.GetStoredProcCommand("gl_UserInfo_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_UserInfo item = GetItemFromReader(dataReader); ItemCollection.Add(item); } } TotalRecords = Convert.ToInt32(db.GetParameterValue(dbCommand, "@TotalRecords")); return(ItemCollection); }
public static string GetJson(DBgl_UserInfoCollection 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_UserInfo objItem) { jsonWriter.WriteStartObject(); jsonWriter.WritePropertyName("UserInfId"); jsonWriter.WriteValue(objItem.UserInfId.ToString()); jsonWriter.WritePropertyName("UserId"); jsonWriter.WriteValue(objItem.UserId.ToString()); jsonWriter.WritePropertyName("UserName"); jsonWriter.WriteValue(objItem.UserName.ToString()); jsonWriter.WritePropertyName("CreatedDate"); jsonWriter.WriteValue(objItem.CreatedDate.ToString()); jsonWriter.WritePropertyName("Mobile"); jsonWriter.WriteValue(objItem.Mobile.ToString()); jsonWriter.WritePropertyName("CountryId"); jsonWriter.WriteValue(objItem.CountryId.ToString()); //jsonWriter.WritePropertyName("LocationId"); //jsonWriter.WriteValue(objItem.LocationId.ToString()); jsonWriter.WritePropertyName("Address"); jsonWriter.WriteValue(objItem.Address.ToString()); jsonWriter.WritePropertyName("Rating"); jsonWriter.WriteValue(objItem.Rating.ToString()); jsonWriter.WritePropertyName("MyLegs"); jsonWriter.WriteValue(objItem.MyLegs.ToString()); jsonWriter.WritePropertyName("EnjoyLegs"); jsonWriter.WriteValue(objItem.EnjoyLegs.ToString()); jsonWriter.WritePropertyName("Sex"); jsonWriter.WriteValue(objItem.Sex.ToString()); jsonWriter.WritePropertyName("UserImg"); DBtblUser myUser; string img = "no_image.gif"; myUser = DBtblUserManager.GetItemByID(objItem.UserId); if (myUser != null) { img = myUser.ImgUrl; } jsonWriter.WriteValue(img); jsonWriter.WritePropertyName("createdUser"); jsonWriter.WriteValue(objItem.createdUser.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()); }