Exemplo n.º 1
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.IsHidden != isHiddenInitialVal)
     {
         if (Supp.IsHidden)
         {
             Supp.ItemOrder = 0;
         }
         else
         {
             Supp.ItemOrder = Supplies.GetLastItemOrder(Supp.SupplierNum, Supp.Category) + 1;
         }
     }
     if (Supp.IsNew)
     {
         Supplies.Insert(Supp);
     }
     else
     {
         Supplies.Update(Supp);
     }
     if (Supp.IsHidden != isHiddenInitialVal || Supp.Category != categoryInitialVal)
     {
         List <Supply> listSupply = Supplies.CreateObjects(false, Supp.SupplierNum, "");
         Supplies.CleanupItemOrders(listSupply);
     }
     DialogResult = DialogResult.OK;
 }
Exemplo n.º 2
0
 private void butAdd_Click(object sender,EventArgs e)
 {
     if(Defs.GetDefsForCategory(DefCat.SupplyCats,true).Count==0) {
         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(_listSuppliers.Count==0) {
         MsgBox.Show(this,"No suppliers have been created.  Go to the suppliers window to add suppliers first.");
         return;
     }
     if(comboSuppliers.IsAllSelected || comboSuppliers.SelectedIndices.Count==0){
         MsgBox.Show(this,"Please select one supplier, first.");//because supplier can't ever change, so they need to be looking at just one supplier.
         //an enhancement would be to let them pick a supplier for a new supply, but then not edit.
         return;
     }
     FormSupplyEdit formSupplyEdit=new FormSupplyEdit();
     formSupplyEdit.ListSuppliers=_listSuppliers;
     Supply supply=new Supply();
     //category:
     if(gridMain.SelectedIndices.Length>0){
         supply.Category=_listSupplies[gridMain.SelectedIndices[0]].Category;
     }
     else if(comboCategories.IsAllSelected || comboCategories.SelectedIndices.Count==0){
         supply.Category=((Def)comboCategories.Items.GetObjectAt(0)).DefNum;
     }
     else{
         supply.Category=((Def)comboCategories.Items.GetObjectAt(comboCategories.SelectedIndices[0])).DefNum;
     }
     //supplier:
     supply.SupplierNum=_listSuppliers[comboSuppliers.SelectedIndices[0]].SupplierNum;
     //itemOrder:
     if(gridMain.SelectedIndices.Length>0){
         supply.ItemOrder=_listSupplies[gridMain.SelectedIndices[0]].ItemOrder;
         //even if many items are hidden for various reasons, this works.  Query at bottom of this method blindly moves all the others down.
     }
     else{
         //nothing is selected, so we'll just add it to the end of whatever category we picked above, typically the first category.
         supply.ItemOrder=Supplies.GetLastItemOrder(supply.Category)+1;
         //The query below will then just do nothing because no ItemOrders below
     }
     supply.IsNew=true;
     formSupplyEdit.SupplyCur=supply;
     formSupplyEdit.ShowDialog();
     if(formSupplyEdit.DialogResult!=DialogResult.OK) {
         return;
     }
     //move other item orders down
     Supplies.OrderAddOneGreater(supply.ItemOrder,formSupplyEdit.SupplyCur.Category,formSupplyEdit.SupplyCur.SupplyNum);//example added at 3, so ++ item orders >=3
     int selected=-1;
     if(gridMain.SelectedIndices.Length>0){
         selected=gridMain.SelectedIndices[0];
     }
     FillGrid();
     if(selected!=-1){
         gridMain.SetSelected(selected,true);
         return;
     }
     //none was selected, but we want to select the new item.
     for(int i=0;i<_listSupplies.Count;i++){
         if(_listSupplies[i].SupplyNum==formSupplyEdit.SupplyCur.SupplyNum){
             gridMain.SetSelected(i,true);
             return;
         }
     }
 }