Пример #1
0
		///<summary>Standard update logic.</summary>
		public static void Update(Supply supp) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),supp);
				return;
			}
			Crud.SupplyCrud.Update(supp);
		}
Пример #2
0
 private void butAdd_Click(object sender,EventArgs e)
 {
     if(comboSupplier.SelectedIndex==-1) {
         MsgBox.Show(this,"Please select a supplier first.");
         return;
     }
     Supply supp=new Supply();
     supp.IsNew=true;
     supp.SupplierNum=ListSupplier[comboSupplier.SelectedIndex].SupplierNum;
     FormSupplyEdit FormS=new FormSupplyEdit();
     FormS.Supp=supp;
     FormS.ListSupplier=ListSupplier;
     FormS.ShowDialog();
     if(FormS.DialogResult!=DialogResult.OK) {
         return;
     }
     long selected=FormS.Supp.SupplyNum;
     int scroll=gridMain.ScrollValue;
     FillGrid();
     gridMain.ScrollValue=scroll;
     for(int i=0;i<listSupply.Count;i++) {
         if(listSupply[i].SupplyNum==selected) {
             gridMain.SetSelected(i,true);
         }
     }
 }
Пример #3
0
		private void FormSupplyOrderItemEdit_Load(object sender,EventArgs e) {
			Supp=Supplies.GetSupply(ItemCur.SupplyNum);
			textSupplier.Text=Suppliers.GetName(ListSupplier,Supp.SupplierNum);
			textCategory.Text=DefC.GetName(DefCat.SupplyCats,Supp.Category);
			textCatalogNumber.Text=Supp.CatalogNumber;
			textDescript.Text=Supp.Descript;
			textQty.Text=ItemCur.Qty.ToString();
			textPrice.Text=ItemCur.Price.ToString("n");
		}
Пример #4
0
 ///<summary>Surround with try-catch.</summary>
 public static void DeleteObject(Supply supp)
 {
     if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
         Meth.GetVoid(MethodBase.GetCurrentMethod(),supp);
         return;
     }
     //validate that not already in use.
     string command="SELECT COUNT(*) FROM supplyorderitem WHERE SupplyNum="+POut.Long(supp.SupplyNum);
     int count=PIn.Int(Db.GetCount(command));
     if(count>0){
         throw new ApplicationException(Lans.g("Supplies","Supply is already in use on an order. Not allowed to delete."));
     }
     Crud.SupplyCrud.Delete(supp.SupplyNum);
 }
Пример #5
0
		private void butDelete_Click(object sender,EventArgs e) {
			if(Supp.IsNew){
				DialogResult=DialogResult.Cancel;
			}
			if(!MsgBox.Show(this,true,"Delete?")){
				return;
			}
			try{
				Supplies.DeleteObject(Supp);
			}
			catch(ApplicationException ex){
				MessageBox.Show(ex.Message);
				return;
			}
			Supp=null;
			DialogResult=DialogResult.OK;
		}
Пример #6
0
		///<summary>Inserts item at corresponding itemOrder. If item order is out of range, item will be placed at beginning or end of category.</summary>
		public static long Insert(Supply supp, int itemOrder) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				supp.SupplyNum=Meth.GetLong(MethodBase.GetCurrentMethod(),supp,itemOrder);
				return supp.SupplyNum;
			}
			string command="";
			if(itemOrder<0) {
				itemOrder=0;
			}
			else {
				command="SELECT MAX(ItemOrder) FROM supply WHERE Category="+POut.Long(supp.Category);
				int itemOrderMax=PIn.Int(Db.GetScalar(command));
				if(itemOrder>itemOrderMax) {
					itemOrder=itemOrderMax+1;
				}
			}
			//Set new item order.
			supp.ItemOrder=itemOrder;
			//move other items
			command="UPDATE supply SET ItemOrder=(ItemOrder+1) WHERE Category="+POut.Long(supp.Category)+" AND ItemOrder>="+POut.Int(supp.ItemOrder);
			Db.NonQ(command);
			//insert and return new supply
			return Crud.SupplyCrud.Insert(supp);
		}
Пример #7
0
		private void FormSupplyEdit_Load(object sender,EventArgs e) {
			textSupplier.Text=Suppliers.GetName(ListSupplier,Supp.SupplierNum);
			SuppOriginal=Supp.Copy();
			for(int i=0;i<DefC.Short[(int)DefCat.SupplyCats].Length;i++){
				comboCategory.Items.Add(DefC.Short[(int)DefCat.SupplyCats][i].ItemName);
				if(Supp.Category==DefC.Short[(int)DefCat.SupplyCats][i].DefNum){
					comboCategory.SelectedIndex=i;
				}
			}
			if(comboCategory.SelectedIndex==-1){
				comboCategory.SelectedIndex=0;//There are no hidden cats, and presence of cats is checked before allowing user to add new.
			}
			categoryInitialVal=Supp.Category;
			textCatalogNumber.Text=Supp.CatalogNumber;
			textDescript.Text=Supp.Descript;
			if(Supp.LevelDesired!=0){
				textLevelDesired.Text=Supp.LevelDesired.ToString();
			}
			if(Supp.Price!=0){
				textPrice.Text=Supp.Price.ToString("n");
			}
			checkIsHidden.Checked=Supp.IsHidden;
			isHiddenInitialVal=Supp.IsHidden;
		}
Пример #8
0
		///<summary>Insert new item at bottom of category.</summary>
		public static long Insert(Supply supp){
			return Insert(supp, int.MaxValue);
		}
Пример #9
0
		///<summary>Updates item orders only.  One query is run per supply item. If supplyOriginal is null will insert supplyNew.</summary>
		public static void UpdateOrInsertIfNeeded(Supply supplyOriginal,Supply supplyNew) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),supplyOriginal,supplyNew);
				return;
			}
			if(supplyNew.IsNew
				||supplyNew.SupplyNum==0//if for some reason the SupplyNum didn't get set.
				||supplyOriginal==null) 
			{
				Crud.SupplyCrud.Insert(supplyNew);//probably wont happen but I'm not sure.
			}
			else if(supplyOriginal.CatalogNumber!=supplyNew.CatalogNumber
						||supplyOriginal.Category			!=supplyNew.Category
						||supplyOriginal.Descript			!=supplyNew.Descript
						||supplyOriginal.IsHidden			!=supplyNew.IsHidden
						||supplyOriginal.ItemOrder		!=supplyNew.ItemOrder
						||supplyOriginal.LevelDesired	!=supplyNew.LevelDesired
						||supplyOriginal.Price				!=supplyNew.Price
						||supplyOriginal.SupplierNum	!=supplyNew.SupplierNum)
			{
				Crud.SupplyCrud.Update(supplyNew);
			}
			//No update or insert needed.
		}
Пример #10
0
		private void butOK_Click(object sender,EventArgs e) {
			if(IsSelectMode) {
				if(gridMain.SelectedIndices.Length<1) {
					MsgBox.Show(this,"Please select a supply from the list first.");
					return;
				}
				ListSelectedSupplies.Clear();//just in case
				for(int i=0;i<gridMain.SelectedIndices.Length;i++) {
					ListSelectedSupplies.Add(ListSupply[gridMain.SelectedIndices[i]]);
				}
				SelectedSupply = Supplies.GetSupply((long)gridMain.Rows[gridMain.SelectedIndices[0]].Tag);
				DialogResult=DialogResult.OK;
			}
			//saveChangesToDBHelper();//All changes should already be saved to the database
			DialogResult=DialogResult.OK;
		}
Пример #11
0
		///<summary>Used to sort supply list. Returns -1 if sup1 should come before sup2, 0 is they are the same, and 1 is sup2 should come before sup1.</summary>
		private int sortSupplyListByCategoryOrderThenItemOrder(Supply sup1,Supply sup2) {
			int sup1Cat=DefC.GetOrder(DefCat.SupplyCats,sup1.Category);
			int sup2Cat=DefC.GetOrder(DefCat.SupplyCats,sup2.Category);
			if(sup1Cat==sup2Cat) {//Items in same category
				if(sup1.ItemOrder==sup2.ItemOrder) {//same item
					return 0;
				}
				else if(sup1.ItemOrder<sup2.ItemOrder) {
					return -1;
				}
				else {
					return 1;
				}
			}
			else if(sup1Cat<sup2Cat) {
				return -1;
			}
			else {
				return 1;
			}
		}
Пример #12
0
		///<summary>Returns true if item exists in supply order.</summary>
		private bool itemExistsHelper(Supply supply) {
			for(int i=0;i<tableOrderItems.Rows.Count;i++) {
				if((long)tableOrderItems.Rows[i]["SupplyNum"]==supply.SupplyNum) {
					return true;
				}
			}
			return false;
		}
Пример #13
0
		private void butAdd_Click(object sender,EventArgs e) {
			if(DefC.Short[(int)DefCat.SupplyCats].Length==0) {//No supply categories have been entered, not allowed to enter supply
				MsgBox.Show(this,"No supply categories have been created.  Go to the supply inventory window, select categories, and enter at least one supply category first.");
				return;
			}
			if(comboSupplier.SelectedIndex < 1) {//Includes no items or the ALL item being selected
				MsgBox.Show(this,"Please select a supplier first.");
				return;
			}
			Supply supp=new Supply();
			supp.IsNew=true;
			supp.SupplierNum=ListSupplier[comboSupplier.SelectedIndex-1].SupplierNum;//Selected index -1 to account for ALL being at the top of the list.
			if(gridMain.GetSelectedIndex()>-1){
				supp.Category=ListSupply[gridMain.GetSelectedIndex()].Category;
				supp.ItemOrder=ListSupply[gridMain.GetSelectedIndex()].ItemOrder;
			}
			FormSupplyEdit FormS=new FormSupplyEdit();
			FormS.Supp=supp;
			FormS.ListSupplier=ListSupplier;
			FormS.ShowDialog();//inserts supply in DB if needed.  Item order will be at selected index or end of category.
			if(FormS.DialogResult!=DialogResult.OK) {
				return;
			}
			//update listSupplyAll to reflect changes made to DB.
			ListSupplyAll=Supplies.GetAll();
			//int scroll=gridMain.ScrollValue;
			SelectedGridItems.Clear();
			SelectedGridItems.Add(FormS.Supp.SupplyNum);
			FillGrid();
			//gridMain.ScrollValue=scroll;
		}
Пример #14
0
 ///<summary>Insert new item at bottom of category.</summary>
 public static long Insert(Supply supp)
 {
     return(Insert(supp, int.MaxValue));
 }
Пример #15
0
		private void butOK_Click(object sender,EventArgs e) {
			if(textLevelDesired.errorProvider1.GetError(textLevelDesired)!=""
				|| textPrice.errorProvider1.GetError(textPrice)!="")
			{
				MsgBox.Show(this,"Please fix data entry errors first.");
				return;
			}
			if(textDescript.Text==""){
				MsgBox.Show(this,"Please enter a description.");
				return;
			}
			Supp.Category=DefC.Short[(int)DefCat.SupplyCats][comboCategory.SelectedIndex].DefNum;
			Supp.CatalogNumber=textCatalogNumber.Text;
			Supp.Descript=textDescript.Text;
			Supp.LevelDesired=PIn.Float(textLevelDesired.Text);
			Supp.Price=PIn.Double(textPrice.Text);
			Supp.IsHidden=checkIsHidden.Checked;
			if(Supp.Category!=categoryInitialVal) {
				Supp.ItemOrder=int.MaxValue;//changed categories, new or existing, move to bottom of new category.
			}
			if(Supp.IsNew) {
				Supp=Supplies.GetSupply(Supplies.Insert(Supp,Supp.ItemOrder));//insert Supp and update with PK and item order from DB.
			}
			else {
				Supplies.Update(SuppOriginal,Supp);
			}
			DialogResult=DialogResult.OK;
		}
Пример #16
0
 ///<summary></summary>
 public static long Insert(Supply supp)
 {
     if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
         supp.SupplyNum=Meth.GetLong(MethodBase.GetCurrentMethod(),supp);
         return supp.SupplyNum;
     }
     return Crud.SupplyCrud.Insert(supp);
 }
Пример #17
0
		///<summary>Updates and also fixes item order issues that may arise from changing categories.</summary>
		public static void Update(Supply suppOld, Supply suppNew) {
			if(RemotingClient.RemotingRole==RemotingRole.ClientWeb) {
				Meth.GetVoid(MethodBase.GetCurrentMethod(),suppOld,suppNew);
				return;
			}
			string command="";
			if(suppNew.ItemOrder<0 || suppNew.ItemOrder==int.MaxValue) {
				command="SELECT MAX(ItemOrder) FROM supply WHERE Category="+POut.Long(suppNew.Category);
				int itemOrderMax=PIn.Int(Db.GetScalar(command));
				if(suppNew.ItemOrder>itemOrderMax) {
					suppNew.ItemOrder=itemOrderMax+1;
				}
			}
			//move other items
			if(suppNew.Category==suppOld.Category) {//move within same category
				command="UPDATE supply SET ItemOrder=(ItemOrder+1)"
				+" WHERE Category="+POut.Long(suppNew.Category)
				+" AND ItemOrder>="+POut.Int(suppNew.ItemOrder)
				+" AND ItemOrder<="+POut.Int(suppOld.ItemOrder);
				Db.NonQ(command);//may have overlapping item orders until suppNew is updated at the end of this function.
			}
			else {//move between categories
				//Move all item orders down one form the old list
				command="UPDATE supply SET ItemOrder=(ItemOrder-1)"
				+" WHERE Category="+POut.Long(suppOld.Category)
				+" AND ItemOrder>="+POut.Int(suppOld.ItemOrder);
				Db.NonQ(command);
				//Assuming item order is correct adjust new list item orders
				command="UPDATE supply SET ItemOrder=(ItemOrder+1)"
				+" WHERE Category="+POut.Long(suppNew.Category)
				+" AND ItemOrder>="+POut.Int(suppNew.ItemOrder);
				Db.NonQ(command);
			}
			Crud.SupplyCrud.Update(suppNew);
		}
Пример #18
0
		private void gridMain_CellDoubleClick(object sender,ODGridClickEventArgs e) {
			SelectedGridItems.Clear();
			foreach(int index in gridMain.SelectedIndices) {
				SelectedGridItems.Add(ListSupply[index].SupplyNum);
			}
			if(IsSelectMode) {
				SelectedSupply = Supplies.GetSupply((long)gridMain.Rows[e.Row].Tag);
				ListSelectedSupplies.Clear();//just in case
				for(int i=0;i<gridMain.SelectedIndices.Length;i++) {
					ListSelectedSupplies.Add(ListSupply[gridMain.SelectedIndices[i]]);
				}				
				DialogResult = DialogResult.OK;
				return;
			}
			//Supply supplyCached=Supplies.GetSupply((long)gridMain.Rows[e.Row].Tag);
			FormSupplyEdit FormS=new FormSupplyEdit();
			FormS.Supp=Supplies.GetSupply((long)gridMain.Rows[e.Row].Tag);//works with sorting
			FormS.ListSupplier=ListSupplier;
			FormS.ShowDialog();
			if(FormS.DialogResult!=DialogResult.OK) {
				return;	
			}
			ListSupplyAll=Supplies.GetAll();
			int scroll=gridMain.ScrollValue;
			FillGrid();
			gridMain.ScrollValue=scroll;
		}
Пример #19
0
 private void butNewSupply_Click(object sender,EventArgs e)
 {
     if(listSupplier.Count==0) {
         MsgBox.Show(this,"Please add suppliers first.  Use the menu at the top of this window.");
         return;
     }
     if(DefC.Short[(int)DefCat.SupplyCats].Length==0) {
         MsgBox.Show(this,"Please add supply categories first.  Use the menu at the top of this window.");
         return;
     }
     if(comboSupplier.SelectedIndex==-1) {
         MsgBox.Show(this,"Please select a supplier first.");
         return;
     }
     Supply supp=new Supply();
     supp.IsNew=true;
     supp.SupplierNum=listSupplier[comboSupplier.SelectedIndex].SupplierNum;
     FormSupplyEdit FormS=new FormSupplyEdit();
     FormS.Supp=supp;
     FormS.ListSupplier=listSupplier;
     FormS.ShowDialog();
     if(FormS.DialogResult!=DialogResult.OK) {
         return;
     }
     long selected=FormS.Supp.SupplyNum;
     int scroll=gridSupplyMain.ScrollValue;
     FillGridSupplyMain();
     gridSupplyMain.ScrollValue=scroll;
     for(int i=0;i<listSupply.Count;i++) {
         if(listSupply[i].SupplyNum==selected) {
             gridSupplyMain.SetSelected(i,true);
         }
     }
 }
Пример #20
0
		///<summary>Sets item orders appropriately. Does not reorder list, and does not repaint/refill grid.</summary>
		private void moveItemOrderHelper(Supply supply,int newItemOrder) {
			if(supply.ItemOrder>newItemOrder) {//moving item up, itterate down through list
				for(int i=0;i<ListSupplyAll.Count;i++) {
					if(ListSupplyAll[i].Category!=supply.Category) {
						continue;//wrong category
					}
					if(ListSupplyAll[i].SupplyNum==supply.SupplyNum) {
						ListSupplyAll[i].ItemOrder=newItemOrder;//set item order of this supply.
						continue;
					}
					if(ListSupplyAll[i].ItemOrder>=newItemOrder && ListSupplyAll[i].ItemOrder<supply.ItemOrder) {//all items between newItemOrder and oldItemOrder
						ListSupplyAll[i].ItemOrder++;
					}
				}
			}
			else {//moving item down, itterate up through list
				for(int i=ListSupplyAll.Count-1;i>=0;i--) {
					if(ListSupplyAll[i].Category!=supply.Category) {
						continue;//wrong category
					}
					if(ListSupplyAll[i].SupplyNum==supply.SupplyNum) {
						ListSupplyAll[i].ItemOrder=newItemOrder;//set item order of this supply.
						continue;
					}
					if(ListSupplyAll[i].ItemOrder<=newItemOrder && ListSupplyAll[i].ItemOrder>supply.ItemOrder) {//all items between newItemOrder and oldItemOrder
						ListSupplyAll[i].ItemOrder--;
					}
				}
			}
			//ListSupplyAll has correct itemOrder values, which we need to copy to listSupply without changing the actual order of ListSupply.
			for(int i=0;i<ListSupply.Count;i++){
				for(int j=0;j<ListSupplyAll.Count;j++) {
					if(ListSupply[i].SupplyNum!=ListSupplyAll[j].SupplyNum) {
						continue;
					}
					ListSupply[i]=ListSupplyAll[j];//update order and category.
				}
			}
		}