public void UpdateBrandCategoryDisplaySequence(int brandId, SortAction action) { System.Data.Common.DbCommand storedProcCommand = this.database.GetStoredProcCommand("cp_BrandCategory_DisplaySequence"); this.database.AddInParameter(storedProcCommand, "BrandId", System.Data.DbType.Int32, brandId); this.database.AddInParameter(storedProcCommand, "Sort", System.Data.DbType.Int32, action); this.database.ExecuteNonQuery(storedProcCommand); }
static string BuildTopQuery(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields) { string str = string.IsNullOrEmpty(sortBy) ? pk : sortBy; string str2 = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); string str3 = string.IsNullOrEmpty(filter) ? "" : ("AND " + filter); StringBuilder builder = new StringBuilder(); builder.AppendFormat("SELECT TOP {0} {1} FROM {2} ", pageSize.ToString(CultureInfo.InvariantCulture), selectFields, table); if (pageIndex == 1) { builder.AppendFormat("{0} ORDER BY {1} {2}", str2, str, sortOrder.ToString()); } else { int num = (pageIndex - 1) * pageSize; if (sortOrder == SortAction.Asc) { builder.AppendFormat("WHERE {0} > (SELECT MAX({0}) FROM (SELECT TOP {1} {0} FROM {2} {3} ORDER BY {0} ASC) AS TMP) {4} ORDER BY {0} ASC", new object[] { str, num, table, str2, str3 }); } else { builder.AppendFormat("WHERE {0} < (SELECT MIN({0}) FROM (SELECT TOP {1} {0} FROM {2} {3} ORDER BY {0} DESC) AS TMP) {4} ORDER BY {0} DESC", new object[] { str, num, table, str2, str3 }); } } if (isCount) { builder.AppendFormat(";SELECT COUNT({0}) FROM {1} {2}", str, table, str2); } return(builder.ToString()); }
public static string BuildRownumberQuery(string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize) { StringBuilder stringBuilder = new StringBuilder(); string text = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); if (partitionSize > 0) { stringBuilder.AppendFormat("SELECT TOP {0} {1}, ROW_NUMBER() OVER (ORDER BY ", partitionSize.ToString(CultureInfo.InvariantCulture), selectFields); } else { stringBuilder.AppendFormat("SELECT {0} , ROW_NUMBER() OVER (ORDER BY ", selectFields); } stringBuilder.AppendFormat("{0} {1}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, sortOrder.ToString()); stringBuilder.AppendFormat(") AS RowNumber FROM {0} {1}", table, text); stringBuilder.Insert(0, "SELECT * FROM (").Append(") T WHERE T.RowNumber BETWEEN @StartNumber AND @EndNumber"); string text2 = ""; if (!string.IsNullOrEmpty(sortBy)) { if (sortBy.IndexOf(",") > 0) { text2 = sortBy.Substring(0, sortBy.IndexOf(",")); } else { text2 = sortBy; } } if (isCount && partitionSize == 0) { stringBuilder.AppendFormat(";SELECT COUNT(0) FROM {1} {2}", string.IsNullOrEmpty(text2) ? pk : text2, table, text); } return(stringBuilder.ToString()); }
private bool LoadPreviousTags() { const bool EMPTY_CURRENT_TAGS = false; for (int i = 0; i < doneActions.Count; i++) { SortAction action = doneActions.ElementAt(i); //Search through doneActions for the most recent "Move" action that will have the previously used tags in it. if (action.GetType() == typeof(Move)) { if (EMPTY_CURRENT_TAGS) { while (EnabledTags.Count > 0) { EnabledTags.Clear(); } } /*for (int t = 0; t < (action as Move).tags.Length; t++) * { * EnabledTags.Add((action as Move).tags[t]); * }*/ EnabledTags.AddRange((action as Move).tags); // The most recent move action was found and the tags were loaded. return(true); } } // No recent move action was found and no tags were loaded. return(false); }
private static string BuildRownumberQuery(string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize, bool isAdmin) { if (!isAdmin) { if (!String.IsNullOrEmpty(sortBy)) { if (sortBy.Equals("DisplaySequence") && table.Equals("vw_Ecshop_BrowseProductList p")) { sortBy = "Fraction"; } } } StringBuilder stringBuilder = new StringBuilder(); string text = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); if (partitionSize > 0) { stringBuilder.AppendFormat("SELECT TOP {0} {1}, ROW_NUMBER() OVER (ORDER BY ", partitionSize.ToString(CultureInfo.InvariantCulture), selectFields); } else { stringBuilder.AppendFormat("SELECT {0} , ROW_NUMBER() OVER (ORDER BY ", selectFields); } stringBuilder.AppendFormat("{0} {1}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, sortOrder.ToString()); stringBuilder.AppendFormat(") AS RowNumber FROM {0} {1}", table, text); stringBuilder.Insert(0, "SELECT * FROM (").Append(") T WHERE T.RowNumber BETWEEN @StartNumber AND @EndNumber"); if (isCount && partitionSize == 0) { stringBuilder.AppendFormat(";SELECT COUNT({0}) FROM {1} {2}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, table, text); } return(stringBuilder.ToString()); }
public void SortSubFolders(SortAction sortAction, ref PGFolderComparer defaultcomparer) { PGFolderComparer comparer = PGFolderComparer.GetComparerBySortAction(sortAction, defaultcomparer); SubFolders.Sort(comparer); defaultcomparer = comparer; }
private static string CteRownumberQuery(string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize) { StringBuilder builder = new StringBuilder(); string str = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); if (partitionSize > 0) { builder.AppendFormat("SELECT TOP {0} {1}, ROW_NUMBER() OVER (ORDER BY ", partitionSize.ToString(CultureInfo.InvariantCulture), selectFields); } else { builder.AppendFormat("SELECT {0} , ROW_NUMBER() OVER (ORDER BY ", selectFields); } builder.AppendFormat("{0} {1}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, sortOrder.ToString()); builder.AppendFormat(") AS RowNumber FROM {0} {1}", table, str); builder.Insert(0, "SELECT * FROM (").Append(") T WHERE T.RowNumber BETWEEN @StartNumber AND @EndNumber ORDER BY sortStr"); if (isCount && (partitionSize == 0)) { builder.AppendFormat(@";with cte as(select convert(nvarchar(50), UserID) as sortStr,* from vw_aspnet_Chanels where ParentID=0 or ParentID is null union all select convert(nvarchar(50),convert(nvarchar(6), isnull(a.ParentID,0))+'-'+convert(nvarchar(6),isnull(a.UserID,0))) as sortStr,a.* from vw_aspnet_Chanels a join cte b on a.ParentID=b.UserID) SELECT COUNT({0}) FROM cte {1}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, str); } return(builder.ToString()); }
/// <summary> /// 初始化绑定商品数据 /// </summary> /// <param name="sortBy"></param> /// <param name="sortOrder"></param> private void BindProducts(string sortBy, SortAction sortOrder) { this.LoadParameters(); PurchaseOrderItemQuery purchaseOrderItemQuery = new PurchaseOrderItemQuery { POId = this.POId, PageSize = this.pager.PageSize, PageIndex = this.pager.PageIndex, SortOrder = sortOrder, SortBy = sortBy, ProductName = this.productsName, BarCode = this.barCode, }; Globals.EntityCoding(purchaseOrderItemQuery, true); DbQueryResult purchaseOrder = PurchaseOrderHelper.GetPurchaseOrderItemList(purchaseOrderItemQuery); this.rpPOItem.DataSource = purchaseOrder.Data; this.rpPOItem.DataBind(); //获取采购单总数量,采购单总金额(最上面或者最底下加整个明细的加总) DataSet ds = PurchaseOrderHelper.GetPOTotalQuyAndAmount(this.POId); //ExpectQuantity,OriginalCurrencyTotalPrice,TotalSalePrice if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0) { lblTotal.Text = string.Format("合计:采购单总数量:{0}; 采购单原币总金额:{1}; 采购单销售总金额:{2};", ds.Tables[0].Rows[0][0], ds.Tables[0].Rows[0][1], ds.Tables[0].Rows[0][2]); } this.pager1.TotalRecords = (this.pager.TotalRecords = purchaseOrder.TotalRecords); }
public static PGFolderComparer GetComparerBySortAction(SortAction sortAction, PGFolderComparer inheritComparer) { PGFolderComparer comparer = new PGFolderComparer(); if (sortAction == SortAction.NameASC) { comparer = new PGFolderNameASCComparer(); } else if (sortAction == SortAction.NameDESC) { comparer = new PGFolderNameDESCComparer(); } else if (sortAction == SortAction.DateTimeASC) { comparer = new PGFolderDateASCComparer(); } else if (sortAction == SortAction.DateTimeDESC) { comparer = new PGFolderDateDESCComparer(); } else if (sortAction == SortAction.CustomOrderProperty) { comparer = new PGFolderOrderComparer(); } else if (sortAction == SortAction.Inherit) { comparer = inheritComparer; } else { throw new Exception("Comparer not found"); } return(comparer); }
public SortSettings() { this.AutoSortByPrimaryKey = true; this.InitialSortColumn = ""; this.InitialSortDirection = SortDirection.Asc; this.SortIconsPosition = SortIconsPosition.Vertical; this.SortAction = SortAction.ClickOnHeader; }
public void SortPaymentMode(int modeId, SortAction action) { DbCommand storedProcCommand = this.database.GetStoredProcCommand("sp_Pay_PaymentMode_Sequence"); this.database.AddInParameter(storedProcCommand, "ModeId", DbType.Int32, modeId); this.database.AddInParameter(storedProcCommand, "Sort", DbType.Int32, (int)action); this.database.ExecuteNonQuery(storedProcCommand); }
private void DoAction(SortAction action) { action.Do(); doneActions.Push(action); undoneActions.Clear(); form.ValidateChildren(); }
/// <summary> /// 初始化绑定商品数据 /// </summary> /// <param name="sortBy"></param> /// <param name="sortOrder"></param> private void BindProducts(string sortBy, SortAction sortOrder) { DbQueryResult purchaseOrder = this.GetData(sortBy, sortOrder); this.rpPO.DataSource = purchaseOrder.Data; this.rpPO.DataBind(); this.pager1.TotalRecords = (this.pager.TotalRecords = purchaseOrder.TotalRecords); }
public void UpdateBrandCategoryDisplaySequence(int brandId, SortAction action) { // not found "cp_BrandCategory_DisplaySequence" store procedure DbCommand storedProcCommand = this.database.GetStoredProcCommand("cp_BrandCategory_DisplaySequence"); this.database.AddInParameter(storedProcCommand, "BrandId", DbType.Int32, brandId); this.database.AddInParameter(storedProcCommand, "Sort", DbType.Int32, action); this.database.ExecuteNonQuery(storedProcCommand); }
private void BindData(string creTime, SortAction sortAction) { DbQueryResult purchaseOrder = this.GetData(creTime, sortAction); this.rpPO.DataSource = purchaseOrder.Data; this.rpPO.DataBind(); this.pager1.TotalRecords = (this.pager.TotalRecords = purchaseOrder.TotalRecords); }
public void SortPaymentMode(int modeId, SortAction action) { //MySqlParameter[] parameters = { // new MySqlParameter("?ModeId",MySqlDbType.Int32), // new MySqlParameter("?Sort",MySqlDbType.Int32) // }; //parameters[0].Value = modeId; //parameters[1].Value = (int)action; //DbHelperMySQL.RunProcedure("sp_Pay_PaymentMode_Sequence", parameters); }
public void SortPaymentMode(int modeId, SortAction action) { //SqlParameter[] parameters = { // new SqlParameter("@ModeId",SqlDbType.Int), // new SqlParameter("@Sort",SqlDbType.Int) // }; //parameters[0].Value = modeId; //parameters[1].Value = (int)action; //DBHelper.DefaultDBHelper.RunProcedure("sp_Pay_PaymentMode_Sequence", parameters); }
public virtual IList <T> Gets <T>(string sortBy, SortAction sortOrder, int?maxNum = default(int?)) where T : new() { Type typeFromHandle = typeof(T); List <T> list = new List <T>(); TableNameAttribute tableNameAttribute = (TableNameAttribute)Attribute.GetCustomAttribute(typeFromHandle, typeof(TableNameAttribute)); string text = "SELECT"; if (maxNum.HasValue) { text = text + " TOP " + maxNum.Value; } text = text + " * FROM " + tableNameAttribute.TableName + " ORDER BY " + sortBy + " " + sortOrder.ToString(); DbCommand sqlStringCommand = this.database.GetSqlStringCommand(text); using (IDataReader dataReader = this.database.ExecuteReader(sqlStringCommand)) { while (dataReader.Read()) { T val = new T(); int fieldCount = dataReader.FieldCount; for (int i = 0; i < fieldCount; i++) { if (((IDataRecord)dataReader)[i] != DBNull.Value) { PropertyInfo property = typeFromHandle.GetProperty(dataReader.GetName(i), BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Public | BindingFlags.GetProperty); if (property != (PropertyInfo)null) { Type type = property.PropertyType; if (type.IsGenericType && type.GetGenericTypeDefinition().Equals(typeof(Nullable <>))) { NullableConverter nullableConverter = new NullableConverter(type); type = nullableConverter.UnderlyingType; } if (type.IsEnum) { object value = Enum.ToObject(type, ((IDataRecord)dataReader)[i]); property.SetValue(val, value, null); } else { object obj = Convert.ChangeType(((IDataRecord)dataReader)[i], type); if (type.Equals(typeof(string)) && obj == null) { obj = string.Empty; } property.SetValue(val, obj, null); } } } } list.Add(val); } } return(list); }
public IList <ShippersInfo> GetShippersBySupplierId(int supplierId, SortAction sortOrder) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("SELECT * FROM Hishop_Shippers where SupplierId={0} ", supplierId); stringBuilder.AppendFormat(" ORDER BY ShipperId {0}", sortOrder); DbCommand sqlStringCommand = base.database.GetSqlStringCommand(stringBuilder.ToString()); using (IDataReader objReader = base.database.ExecuteReader(sqlStringCommand)) { return(DataHelper.ReaderToList <ShippersInfo>(objReader)); } }
void grdProducts_Sorting(object sender, GridViewSortEventArgs e) { string sort = e.SortExpression; SortAction sortOrder = grdProducts.SortOrder.ToLower() == "asc" ? SortAction.Asc : SortAction.Desc; this.sortBy = sort; this.sortOrder = grdProducts.SortOrder; this.hidSortOrder.Value = this.sortOrder; this.hidSortBy.Value = this.sortBy; this.ReloadProductOnSales(true); //绑定排序数据 //this.BindProducts(sort, sortOrder); }
private void BindProducts(string sortBy, SortAction sortOrder) { this.LoadParameters(); ProductQuery productQuery = new ProductQuery { Keywords = this.productName, ProductCode = this.productCode, CategoryId = this.categoryId, PageSize = this.pager.PageSize, PageIndex = this.pager.PageIndex, SortOrder = sortOrder, SortBy = sortBy, StartDate = this.startDate, BrandId = this.dropBrandList.SelectedValue.HasValue ? this.dropBrandList.SelectedValue : null, TagId = this.dropTagList.SelectedValue.HasValue ? this.dropTagList.SelectedValue : null, TypeId = this.typeId, SaleStatus = this.saleStatus, EndDate = this.endDate, ImportSourceId = this.ddlImportSourceType.SelectedValue.HasValue ? this.ddlImportSourceType.SelectedValue : null, SupplierId = this.ddlSupplier.SelectedValue.HasValue ? this.ddlSupplier.SelectedValue : null, TemplateId = this.ddlShipping.SelectedValue.HasValue ? this.ddlShipping.SelectedValue : null, IsApproved = this.IsApproved }; if (this.categoryId.HasValue) { productQuery.MaiCategoryPath = CatalogHelper.GetCategory(this.categoryId.Value).Path; } Globals.EntityCoding(productQuery, true); DbQueryResult products = ProductHelper.GetProductsAdmin(productQuery); this.grdProducts.DataSource = products.Data; this.grdProducts.DataBind(); // this.grdProducts.SortDirection = SortDirection.Ascending; this.txtSearchText.Text = productQuery.Keywords; this.txtSKU.Text = productQuery.ProductCode; this.dropCategories.SelectedValue = productQuery.CategoryId; this.dropType.SelectedValue = productQuery.TypeId; this.ddlImportSourceType.SelectedValue = productQuery.ImportSourceId; this.ddlSupplier.SelectedValue = productQuery.SupplierId; this.ddlShipping.SelectedValue = productQuery.TemplateId; if (productQuery.IsApproved.HasValue) { this.dropIsApproved.SelectedValue = productQuery.IsApproved.Value.ToString(); } this.pager1.TotalRecords = (this.pager.TotalRecords = products.TotalRecords); }
/// <summary> /// 排序并返回列表。 /// </summary> public System.Collections.Generic.List <DatabaseSchemaHandler> Sort() { System.Collections.Generic.List <DatabaseSchemaHandler> list = new System.Collections.Generic.List <DatabaseSchemaHandler>(); //foreach(AssemblyRef System.Collections.Generic.Dictionary <string, SortEntry> refOrders = new System.Collections.Generic.Dictionary <string, SortEntry>(); System.Collections.Generic.List <AssemblyRef> all = LinqHelper.ToList(_refs.Values); SortAction action = null; action = (p1, p2) => { foreach (string p11 in p1.refs) { AssemblyRef p12; if (_refs.TryGetValue(p11, out p12)) { if (all.Remove(p12)) { action(p12, p2 * 1000); } } } SortEntry p10 = new SortEntry() { item = p1, order = p2 * (refOrders.Count + 1) }; refOrders.Add(p1.fullName, p10); return(p10); }; while (all.Count > 0) { AssemblyRef item = all[0]; all.RemoveAt(0); action(item, -1); } SortFunc classOrderGetter = (p1) => p1.Attribute.Order + GetClassRef(p1.Attribute.TableName, p1.Attribute.References); foreach (SortEntry p1 in LinqHelper.OrderByDescending(refOrders.Values, p => p.order)) { list.AddRange(p1.item.SortList(classOrderGetter)); } refOrders.Clear(); refOrders = null; all = null; return(list); }
private DbQueryResult GetData(string sortBy, SortAction sortOrder) { this.LoadParameters(); PODeclareListQuery PODeclareListQuery = new PODeclareListQuery { PageSize = this.pager.PageSize, PageIndex = this.pager.PageIndex, SortOrder = sortOrder, SortBy = sortBy, StartDate = this.startDate, EndDate = this.endDate, //POCDStatus = this.POCDStatus, fromID = this.fromID, PONumber = this.poNumber }; Globals.EntityCoding(PODeclareListQuery, true); return(PurchaseOrderHelper.GetPODeclareList(PODeclareListQuery)); }
/// <summary> /// Pop an action from the undoneActions stack and exeucutes it. Returns false if there was no action on the stack to redo. /// </summary> public bool Redo() { if (undoneActions.Count > 0) { SortAction action = undoneActions.Pop(); action.Do(); if (action.Successful) { doneActions.Push(action); } form.ValidateChildren(); return(true); } return(false); }
private static string BuildRownumberQuery(string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize) { StringBuilder builder = new StringBuilder(); string str = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); if (partitionSize > 0) { builder.AppendFormat("SELECT TOP {0} {1}, ROW_NUMBER() OVER (ORDER BY ", partitionSize.ToString(CultureInfo.InvariantCulture), selectFields); } else { builder.AppendFormat("SELECT {0} , ROW_NUMBER() OVER (ORDER BY ", selectFields); } builder.AppendFormat("{0} {1}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, sortOrder.ToString()); builder.AppendFormat(") AS RowNumber FROM {0} {1}", table, str); builder.Insert(0, "SELECT * FROM (").Append(") T WHERE T.RowNumber BETWEEN @StartNumber AND @EndNumber"); if (isCount && (partitionSize == 0)) { builder.AppendFormat(";SELECT COUNT({0}) FROM {1} {2}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, table, str); } return(builder.ToString()); }
public static string BuildNotinQuery(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string key, string filter, string selectFields) { string str = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); string str2 = string.IsNullOrEmpty(filter) ? "" : ("AND " + filter); string str3 = string.IsNullOrEmpty(sortBy) ? "" : ("ORDER BY " + sortBy + " " + sortOrder.ToString()); StringBuilder builder = new StringBuilder(); builder.AppendFormat("SELECT TOP {0} {1} FROM {2} ", pageSize.ToString(CultureInfo.InvariantCulture), selectFields, table); if (pageIndex == 1) { builder.AppendFormat("{0} {1}", str, str3); } else { int num = (pageIndex - 1) * pageSize; builder.AppendFormat("WHERE {0} NOT IN (SELECT TOP {1} {0} FROM {2} {3} {4}) {5} {4}", new object[] { key, num, table, str, str3, str2 }); } if (isCount) { builder.AppendFormat(";SELECT COUNT({0}) FROM {1} {2}", key, table, str); } return builder.ToString(); }
private DbQueryResult GetData(string sortBy, SortAction sortOrder) { this.LoadParameters(); PurchaseOrderQuery purchaseOrderQuery = new PurchaseOrderQuery { PageSize = this.pager.PageSize, PageIndex = this.pager.PageIndex, SortOrder = sortOrder, SortBy = sortBy, StartDate = this.startDate, EndDate = this.endDate, PONumber = this.poNumber, SupplierId = this.supplierId, POStatus = this.Status, HSInOut = this.hsInOut, QPStatus = this.QPStatus, CIStatus = this.CIStatus }; Globals.EntityCoding(purchaseOrderQuery, true); return(PurchaseOrderHelper.GetPurchaseOrderList(purchaseOrderQuery)); }
private void EditSortDescriptions(SortAction a) { var sortDestination = (new SortDescription("Destination.Name", ListSortDirection.Ascending)); var sortDate = (new SortDescription("StartDate", ListSortDirection.Descending)); switch (a) { case SortAction.Add: tripListBox.Items.SortDescriptions.Add(sortDestination); tripListBox.Items.SortDescriptions.Add(sortDate); break; case SortAction.Delete: if (tripListBox.Items.SortDescriptions.Contains(sortDate)) { tripListBox.Items.SortDescriptions.Remove(sortDestination); tripListBox.Items.SortDescriptions.Remove(sortDate); } break; default: break; } }
public static DbQueryResult PagingByRownumber(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize) { if (string.IsNullOrEmpty(table)) { return null; } if (string.IsNullOrEmpty(sortBy) && string.IsNullOrEmpty(pk)) { return null; } if (string.IsNullOrEmpty(selectFields)) { selectFields = "*"; } string query = BuildRownumberQuery(sortBy, sortOrder, isCount, table, pk, filter, selectFields, partitionSize); int num = ((pageIndex - 1) * pageSize) + 1; int num2 = (num + pageSize) - 1; DbQueryResult result = new DbQueryResult(); SqlConnection cn = new SqlConnection(Init.GetConnectionString()); SqlCommand cmd = new SqlCommand(query, cn); cmd.Parameters.Add("@StartNumber", num); cmd.Parameters.Add("@EndNumber", num2); cn.Open(); using (IDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { result.Data = ConverDataReaderToDataTable(reader); if ((isCount && (partitionSize == 0)) && reader.NextResult()) { reader.Read(); result.TotalRecords = reader.GetInt32(0); } } return result; }
public static DbQueryResult PagingByRownumber(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields) { return PagingByRownumber(pageIndex, pageSize, sortBy, sortOrder, isCount, table, pk, filter, selectFields, 0); }
public abstract void UpdateBrandCategoryDisplaySequence(int brandId, SortAction action);
public static DbQueryResult PagingByRownumber(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize) { if (string.IsNullOrEmpty(table)) { return null; } if (string.IsNullOrEmpty(sortBy) && string.IsNullOrEmpty(pk)) { return null; } if (string.IsNullOrEmpty(selectFields)) { selectFields = "*"; } string query = BuildRownumberQuery(sortBy, sortOrder, isCount, table, pk, filter, selectFields, partitionSize); int num = ((pageIndex - 1) * pageSize) + 1; int num2 = (num + pageSize) - 1; DbQueryResult result = new DbQueryResult(); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "StartNumber", DbType.Int32, num); database.AddInParameter(sqlStringCommand, "EndNumber", DbType.Int32, num2); using (IDataReader reader = database.ExecuteReader(sqlStringCommand)) { result.Data = ConverDataReaderToDataTable(reader); if ((isCount && (partitionSize == 0)) && reader.NextResult()) { reader.Read(); result.TotalRecords = reader.GetInt32(0); } } return result; }
public static DbQueryResult PagingByTopsort(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields) { if (string.IsNullOrEmpty(table)) { return null; } if (string.IsNullOrEmpty(sortBy) && string.IsNullOrEmpty(pk)) { return null; } if (string.IsNullOrEmpty(selectFields)) { selectFields = "*"; } string query = BuildTopQuery(pageIndex, pageSize, sortBy, sortOrder, isCount, table, pk, filter, selectFields); DbQueryResult result = new DbQueryResult(); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); using (IDataReader reader = database.ExecuteReader(sqlStringCommand)) { result.Data = ConverDataReaderToDataTable(reader); if (isCount && reader.NextResult()) { reader.Read(); result.TotalRecords = reader.GetInt32(0); } } return result; }
private static string BuildRownumberQuery(string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields, int partitionSize) { StringBuilder builder = new StringBuilder(); string str = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); if (partitionSize > 0) { builder.AppendFormat("SELECT TOP {0} {1}, ROW_NUMBER() OVER (ORDER BY ", partitionSize.ToString(CultureInfo.InvariantCulture), selectFields); } else { builder.AppendFormat("SELECT {0} , ROW_NUMBER() OVER (ORDER BY ", selectFields); } builder.AppendFormat("{0} {1}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, sortOrder.ToString()); builder.AppendFormat(") AS RowNumber FROM {0} {1}", table, str); builder.Insert(0, "SELECT * FROM (").Append(") T WHERE T.RowNumber BETWEEN @StartNumber AND @EndNumber"); if (isCount && (partitionSize == 0)) { builder.AppendFormat(";SELECT COUNT({0}) FROM {1} {2}", string.IsNullOrEmpty(sortBy) ? pk : sortBy, table, str); } return builder.ToString(); }
public static void UpdateBrandCategorieDisplaySequence(int brandId, SortAction action) { new BrandCategoryDao().UpdateBrandCategoryDisplaySequence(brandId, action); }
private static string BuildTopQuery(int pageIndex, int pageSize, string sortBy, SortAction sortOrder, bool isCount, string table, string pk, string filter, string selectFields) { string str = string.IsNullOrEmpty(sortBy) ? pk : sortBy; string str2 = string.IsNullOrEmpty(filter) ? "" : ("WHERE " + filter); string str3 = string.IsNullOrEmpty(filter) ? "" : ("AND " + filter); StringBuilder builder = new StringBuilder(); builder.AppendFormat("SELECT TOP {0} {1} FROM {2} ", pageSize.ToString(CultureInfo.InvariantCulture), selectFields, table); if (pageIndex == 1) { builder.AppendFormat("{0} ORDER BY {1} {2}", str2, str, sortOrder.ToString()); } else { int num = (pageIndex - 1) * pageSize; if (sortOrder == SortAction.Asc) { builder.AppendFormat("WHERE {0} > (SELECT MAX({0}) FROM (SELECT TOP {1} {0} FROM {2} {3} ORDER BY {0} ASC) AS TMP) {4} ORDER BY {0} ASC", new object[] { str, num, table, str2, str3 }); } else { builder.AppendFormat("WHERE {0} < (SELECT MIN({0}) FROM (SELECT TOP {1} {0} FROM {2} {3} ORDER BY {0} DESC) AS TMP) {4} ORDER BY {0} DESC", new object[] { str, num, table, str2, str3 }); } } if (isCount) { builder.AppendFormat(";SELECT COUNT({0}) FROM {1} {2}", str, table, str2); } return builder.ToString(); }
public void UpdateBrandCategoryDisplaySequence(int brandId, SortAction action) { DbCommand storedProcCommand = this.database.GetStoredProcCommand("cp_BrandCategory_DisplaySequence"); this.database.AddInParameter(storedProcCommand, "BrandId", DbType.Int32, brandId); this.database.AddInParameter(storedProcCommand, "Sort", DbType.Int32, action); this.database.ExecuteNonQuery(storedProcCommand); }
public void SortPaymentMode(int modeId, SortAction action) { DbCommand storedProcCommand = this.database.GetStoredProcCommand("sp_Pay_PaymentMode_Sequence"); this.database.AddInParameter(storedProcCommand, "ModeId", DbType.Int32, modeId); this.database.AddInParameter(storedProcCommand, "Sort", DbType.Int32, (int) action); this.database.ExecuteNonQuery(storedProcCommand); }
public static void UpdateBrandCategorieDisplaySequence(int brandId, SortAction action) { ProductProvider.Instance().UpdateBrandCategoryDisplaySequence(brandId, action); }