private string[] GetStringArr(string p, int HeaderId, string IDKey) { var DHeader = ctx.TfatDesignHeaders.Single(h => h.HeaderRecordKey == HeaderId); var DForms = DHeader.TfatDesignForms.Where(f => f.TabName.ToUpper().Equals("GRID")).OrderBy(f => Math.Abs(Convert.ToDecimal(f.DisplayOrder))); int frmcount = DForms.Count(); string TableName = DHeader.TfatDesignForms.First(f => f.TabName.ToUpper().Equals("GRID")).Fle; object obj = CoreCommon.GetTableObject(TableName); var resultDB = ctx.Set(obj.GetType()).SqlQuery("Select * from [" + TableName + "] Where " + IDKey + " = @ID", new SqlParameter("@ID", p)).ToListAsync().Result; string[] col = new string[frmcount]; foreach (var colfrm in resultDB) { int i = 0; foreach (TfatDesignForm frm in DForms) { col[i] = Convert.ToString(colfrm.GetType().GetProperty(frm.Fld).GetValue(colfrm)); i++; } } return(col); }
public object Get(string sidx, string sord, int page, int rows) { int id = Convert.ToInt32(HttpContext.Current.Request.Url.Segments.Last()); string viewtype = HttpContext.Current.Request.UrlReferrer.Segments.Last(); string querystring = HttpContext.Current.Request.UrlReferrer.Query.ToString(); int childid = Convert.ToInt32(string.IsNullOrEmpty(querystring) ? "0" : querystring.Split(new char[] { '=' }).LastOrDefault()); var DHeader = ctx.TfatDesignHeaders.Single(h => h.HeaderRecordKey == id); var DForms = DHeader.TfatDesignForms.Where(f => f.TabName.ToUpper().Equals("GRID")).OrderBy(f => Math.Abs(Convert.ToDecimal(f.DisplayOrder))); string TableName = DHeader.TfatDesignForms.First(f => f.TabName.ToUpper().Equals("GRID")).Fle; object obj = CoreCommon.GetTableObject(TableName); IEnumerable <object> resultDB = ctx.Set(obj.GetType()) as IEnumerable <object>; string[] IDs = DHeader.IDKey.Split('^'); if (viewtype.ToUpper() != "GRID") { resultDB = from r in resultDB where r.GetType().GetProperty(IDs.First()).GetValue(r).Equals(childid) select r; } if (sord == "desc") { resultDB = from r in resultDB orderby r.GetType().GetProperty(sidx).GetValue(r) descending select r; } else { resultDB = from r in resultDB orderby r.GetType().GetProperty(sidx).GetValue(r) select r; } int count = resultDB.Count(); int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; int totalRecords = count; int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize); var Data = resultDB.Skip(pageIndex * pageSize).Take(pageSize); var result = new { total = totalPages, page = page, records = totalRecords, rows = (from dt in Data select new { i = dt.GetType().GetProperty(IDs.First()).GetValue(dt), cell = GetStringArr(Convert.ToString(dt.GetType().GetProperty(viewtype.ToUpper().Equals("GRID") ? IDs.First() : IDs.Last()).GetValue(dt)), id, (viewtype.ToUpper().Equals("GRID") ? IDs.FirstOrDefault() : IDs.LastOrDefault())) }).ToArray() }; return(result); }