Beispiel #1
0
        /*
        private void checkShowShoppingList_Click(object sender,EventArgs e) {
            _listSelectedSupplies.Clear();
            foreach(int index in gridMain.SelectedIndices) {
                _listSelectedSupplies.Add((Supply)gridMain.ListGridRows[index].Tag);
            }
            FillGrid();
        }*/
        private void butUp_Click(object sender,EventArgs e)
        {
            if(textFind.Text!=""){
                MsgBox.Show(this,"Not allowed unless search text is empty.");
                return;
            }
            if(!comboSuppliers.IsAllSelected){
                MsgBox.Show(this,"Not allowed unless All suppliers are selected.");
                return;
            }
            List<int> listSelected=gridMain.SelectedIndices.ToList<int>();
            if(listSelected.Count==0){
                MsgBox.Show(this,"Please select at least one supply, first.");
                return;
            }
            for(int i=1;i<listSelected.Count;i++) {
                if(_listSupplies[listSelected[0]].Category != _listSupplies[listSelected[i]].Category){
                    MsgBox.Show(this,"All selected supplies must be in the same category.");
                    return;
                }
                if(listSelected[i-1]+1 != listSelected[i]){
                    MsgBox.Show(this,"Selection must not have gaps.");//makes my math too hard
                    return;
                }
            }
            if(listSelected[0]==0){
                return;//already at top
            }
            if(_listSupplies[listSelected[0]].Category != _listSupplies[listSelected[0]-1].Category){
                MsgBox.Show(this,"Already at top of category.");
                return;
            }
            //we should only have to move them up one, but there could be hidden supplies that would require moving up more.
            //There can also be hidden supplies that cause gaps in our selected list.
            //After considering many options, the best solution is to move group up one, and then set the item above to the ItemOrder of the bottom in group.

            int countMove=_listSupplies[listSelected[0]].ItemOrder-_listSupplies[listSelected[0]-1].ItemOrder;//example 2-1=1
            //todo: fix gaps caused by hidden supplies

            List<long> listSupplyNums=new List<long>();
            for(int i=0;i<listSelected.Count;i++) {
                listSupplyNums.Add(_listSupplies[listSelected[i]].SupplyNum);
            }
            Supplies.OrderSubtract(listSupplyNums,countMove);
            _listSupplies[listSelected[0]-1].ItemOrder+=listSelected.Count+countMove-1;//Example 0+5+1-1=5, while the 5 selected items moved up to occupy 0 through 4.
            Supplies.Update(_listSupplies[listSelected[0]-1]);
            FillGrid();
            int[] indicesNew=new int[listSelected.Count];
            for(int i=0;i<listSelected.Count;i++){
                indicesNew[i]=listSelected[i]-1;
            }
            gridMain.SetSelected(indicesNew,true);
        }