public IList <viewPaidDetail> GetList(string query, Sort sort, int page, int start, int limit, ref int totalRecords, ref string errMsg, int PayVendorId) { limit = limit + start; SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); throw; }; string wherepage = (page != 0) ? String.Format("row>{0} and row<={1} ", start, limit) : "1=1"; string where = (PayVendorId > 0) ? string.Format("a.PayVendorId = {0}", PayVendorId) : "1=1"; if (!string.IsNullOrEmpty(query)) { string fieldName = "a.InvoiceNum"; where += (!string.IsNullOrEmpty(where) ? " and " : "") + EnumExtension.generateLikeWhere(query, fieldName); } // Handle Order string order = "DetailId"; string direction = "ASC"; if (!string.IsNullOrWhiteSpace(sort.property)) { order = sort.property; direction = sort.direction; } string sql = @"WITH qData AS ( SELECT a.* FROM viewPaidDetails a WHERE {0} ) SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY {2} {3}) as row, IsNull((select count(*) from qData),0) as TotalRecords FROM qData ) a WHERE {1} ORDER BY row"; sql = String.Format(sql, where, wherepage, order, direction); SqlDataAdapter da = new SqlDataAdapter(sql, oConn); DataSet ds = new DataSet(); try { da.Fill(ds); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); errMsg = ex.Message; return(null); } ConnManager.CloseConn(oConn); DataTable dt; dt = ds.Tables[0]; totalRecords = dt.Rows.Count; if (totalRecords > 0) { IList <viewPaidDetail> data = EnumExtension.ToList <viewPaidDetail>(dt); totalRecords = Convert.ToInt32(dt.Rows[0]["TotalRecords"]); return(data); } else { return(null); } }
public IList <GeneralCharge> GetList(FieldFilters fieldFilters, string query, Sort sort, int page, int start, int limit, ref int totalRecords) { limit = limit + start; SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); throw; }; string wherepage = (page != 0) ? String.Format("row>{0} and row<={1} ", start, limit) : "1=1"; string where = "1=1"; #region Field Filters if (fieldFilters.fields != null && fieldFilters.fields.Count > 0) { foreach (var item in fieldFilters.fields) { string value = item.value; string name = item.name; if (item.type == "string" || item.type == "date") { value = "'" + value + "'"; } if (item.type == "date") { name = String.Format("CAST({0} as DATE)", name); } where += String.Format(" AND {0} = {1}", name, value); } } #endregion Field Filters if (!string.IsNullOrEmpty(query)) { string fieldName = "GChargeId"; where += (!string.IsNullOrEmpty(where) ? " and " : "") + EnumExtension.generateLikeWhere(query, fieldName); } // Handle Order string order = "GChargeId"; string direction = "ASC"; if (!string.IsNullOrWhiteSpace(sort.property)) { order = sort.property; direction = sort.direction; } string sql = @"WITH qData AS ( SELECT *, ROW_NUMBER() OVER (ORDER BY {2} {3}) as row FROM vGeneralCharges WHERE {0} ) SELECT {4} *, t5.TotalRecords FROM qData INNER JOIN ((select TOP 1 row as TotalRecords from qData order by row desc)) as t5 on 1=1 WHERE {1} ORDER BY row "; where = (where.StartsWith("1=1 AND ")) ? where.Replace("1=1 AND ", "") : where; string topLimit = ((@limit > 0) ? String.Format(" TOP {0} ", @limit) : ""); sql = String.Format(sql, where, wherepage, order, direction, topLimit); SqlDataAdapter da = new SqlDataAdapter(sql, oConn); DataSet ds = new DataSet(); try { da.Fill(ds); } catch (Exception ex) { ConnManager.CloseConn(oConn); LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); throw; } ConnManager.CloseConn(oConn); DataTable dt; dt = ds.Tables[0]; totalRecords = dt.Rows.Count; if (totalRecords > 0) { IList <GeneralCharge> data = EnumExtension.ToList <GeneralCharge>(dt); totalRecords = Convert.ToInt32(dt.Rows[0]["TotalRecords"]); return(data); } else { return(null); } }
public IList <Vendor> GetList(bool onlyWithBalance, string query, Sort sort, int page, int start, int limit, ref int totalRecords, ref string errMsg) { limit = limit + start; SqlConnection oConn = null; try { oConn = ConnManager.OpenConn(); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); throw; }; string wherepage = (page != 0) ? String.Format("row>{0} and row<={1} ", start, limit) : "1=1"; string where = (onlyWithBalance) ? "dbo.fn_GetVendorBalance(a.VendorId, 0) <> 0 " : "1=1";; if (!string.IsNullOrEmpty(query)) { string fieldName = "a.VendorName+' '+ISNULL(b.BrokerName,'')"; where += (!string.IsNullOrEmpty(where) ? " and " : "") + EnumExtension.generateLikeWhere(query, fieldName); } // Handle Order string order = "VendorName"; string direction = "ASC"; if (!string.IsNullOrWhiteSpace(sort.property)) { order = sort.property; direction = sort.direction; //order = (sort.property == "x_VendorBalance") ? "dbo.fn_GetVendorBalance(a.VendorId, 0)" : order; } string sql = @"WITH qData AS ( SELECT a.*, dbo.fn_GetVendorBalance(a.VendorId, 0) as x_VendorBalance, b.BrokerName FROM Vendors a LEFT JOIN Brokers b ON a.BrokerId = b.BrokerId WHERE {0} ) SELECT * FROM ( SELECT a.*, ROW_NUMBER() OVER (ORDER BY {2} {3}) as row, b.TotalRecords, b.x_GrandTotalBalance FROM qData a LEFT OUTER JOIN (select count(*) as TotalRecords,sum(x_VendorBalance) as x_GrandTotalBalance from qData) as b ON 1=1 ) a WHERE {1} ORDER BY row"; sql = String.Format(sql, where, wherepage, order, direction); SqlDataAdapter da = new SqlDataAdapter(sql, oConn); DataSet ds = new DataSet(); try { da.Fill(ds); } catch (Exception ex) { LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message); errMsg = ex.Message; return(null); } ConnManager.CloseConn(oConn); DataTable dt; dt = ds.Tables[0]; totalRecords = dt.Rows.Count; if (totalRecords > 0) { IList <Vendor> data = EnumExtension.ToList <Vendor>(dt); totalRecords = Convert.ToInt32(dt.Rows[0]["TotalRecords"]); return(data); } else { return(null); } }