///<summary>Fixes all ItemOrders for a category where a duplicate was found. Includes IsHidden so that it works for both hidden and unhidden.</summary> private void FixItemOrders(long category) { List<long> listCategories=new List<long>(); listCategories.Add(category); List<Supply> listSuppliesCat=Supplies.GetList(null,true,"",listCategories); for(int i=0;i<listSuppliesCat.Count;i++){ if(listSuppliesCat[i].ItemOrder!=i){ listSuppliesCat[i].ItemOrder=i; Supplies.Update(listSuppliesCat[i]); } } }
private void FillGrid(bool refresh=true) { List<long> listSupplierNums=null; if(IsSelectMode){ listSupplierNums=new List<long>(); listSupplierNums.Add(SelectedSupplierNum); } else if(comboSuppliers.IsAllSelected){ listSupplierNums=null; } else{ listSupplierNums=comboSuppliers.GetListSelected<Supplier>().Select(x=>x.SupplierNum).ToList(); } List<long> listCategories=null; if(!comboCategories.IsAllSelected){ listCategories=comboCategories.GetListSelected<Def>().Select(x=>x.DefNum).ToList(); } if(refresh){ _listSupplies=Supplies.GetList(listSupplierNums,checkShowHidden.Checked,textFind.Text,listCategories); } if(textFind.Text=="" && comboSuppliers.IsAllSelected){ //check orders. Simply look for any two sequential itemOrders that are the same. This indicates fix required for that category. //Works for hidden or not, but won't fire repeatedly unless user is switching back and forth between hidden and unhidden. bool didFix=false; for(int i=1;i<_listSupplies.Count;i++){//starts at 1 if(_listSupplies[i].Category != _listSupplies[i-1].Category){ //if previous item is different category, then we don't need to compare continue; } if(_listSupplies[i].ItemOrder == _listSupplies[i-1].ItemOrder){//duplicate found didFix=true; FixItemOrders(_listSupplies[i].Category); while(i<_listSupplies.Count && _listSupplies[i].Category == _listSupplies[i-1].Category) { i++;//skip ahead to next category } } } if(didFix){ //get list again _listSupplies=Supplies.GetList(listSupplierNums,checkShowHidden.Checked,textFind.Text,listCategories); } } gridMain.BeginUpdate(); gridMain.ListGridColumns.Clear(); GridColumn col=new GridColumn(Lan.g(this,"Category"),130); gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Catalog #"),80); gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Supplier"),100); gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Description"),200); gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Price"),60,HorizontalAlignment.Right); gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Stock"),50,HorizontalAlignment.Center); gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Order"),50,HorizontalAlignment.Center); if(checkEnterQty.Checked){ col.IsEditable=true; } gridMain.ListGridColumns.Add(col); col=new GridColumn(Lan.g(this,"Hidden"),50,HorizontalAlignment.Center); gridMain.ListGridColumns.Add(col); gridMain.ListGridRows.Clear(); GridRow row; for(int i=0;i<_listSupplies.Count;i++) { row=new GridRow(); if(gridMain.ListGridRows.Count==0 || _listSupplies[i].Category != _listSupplies[i-1].Category) { row.Cells.Add(Defs.GetName(DefCat.SupplyCats,_listSupplies[i].Category));//Add the new category header in this row if it doesn't match the previous row's category. } else { row.Cells.Add(""); } row.Cells.Add(_listSupplies[i].CatalogNumber); row.Cells.Add(Suppliers.GetName(_listSuppliers,_listSupplies[i].SupplierNum)); row.Cells.Add(_listSupplies[i].Descript);//_listSupplies[i].ItemOrder.ToString()+" "+_listSupplies[i].Descript); if(_listSupplies[i].Price==0) { row.Cells.Add(""); } else { row.Cells.Add(_listSupplies[i].Price.ToString("n")); } //stock: if(_listSupplies[i].LevelDesired==0) { row.Cells.Add(""); } else { row.Cells.Add(_listSupplies[i].LevelDesired.ToString()); } //order: if(_listSupplies[i].OrderQty==0) { row.Cells.Add(""); } else { row.Cells.Add(_listSupplies[i].OrderQty.ToString()); } //hidden: row.Cells.Add(_listSupplies[i].IsHidden?"X":""); //row.Tag=_listSupplies[i]; gridMain.ListGridRows.Add(row); } gridMain.EndUpdate(); //for(int i=0;i<gridMain.ListGridRows.Count;i++) { // if(_listSelectedSupplies.Contains(((Supply)gridMain.ListGridRows[i].Tag))) { // gridMain.SetSelected(i,true); // } //} }