Пример #1
0
        private void btnUpdate_Click_1(object sender, EventArgs e)
        {
            stop = 1;

            if (stop == 1)
            {
                //employee

                //if item not yet approved or denied by the supervisor
                //all fields in item can be changed
                //as long as po request is not closed, employee may add new items to it

                //supervisors can modify po items - quantity, price and location fields but
                //must enter a reason

                if (txtId.Text == "" || txtId.Text == null)
                {
                    MessageBox.Show("You must enter an item id.");
                }

                else
                {
                    ItemService     i = new ItemService();
                    PurchaseService p = new PurchaseService();

                    int id = Convert.ToInt32(txtId.Text);

                    ItemStatusType itemStatus;
                    itemStatus = i.GetItemStatus(id);

                    ApprovalStatus approvalStatus;

                    int POId = p.GetPurchaseOrderByItemId(id);
                    approvalStatus = p.GetPurchaseStatus(POId);



                    if (itemStatus == ItemStatusType.Denied)
                    {
                        MessageBox.Show("This item cannot be updated, the item is denied.");
                    }
                    else if (approvalStatus == ApprovalStatus.Closed)
                    {
                        MessageBox.Show("This purchase order cannot be updated, the order is closed.");
                    }
                    else
                    {
                        if (flag == 0)
                        {
                            PopulateItemObject();

                            if (i.UpdateItems(item))
                            {
                                MessageBox.Show("Item Successfully Updated.");
                                Clear();
                            }
                        }

                        else
                        {
                            PopulateItemObject();
                            if (txtModReason.Text == "" || txtModReason.Text == String.Empty)
                            {
                                MessageBox.Show("You must enter a modification reason.");
                            }
                            else
                            {
                                //check if purchase order belongs to the supervisor modifying
                                int             POID = Convert.ToInt32(txtId.Text);
                                PurchaseService ps   = new PurchaseService();

                                _p = ps.CheckSupervisor(POID);

                                if (_p.Supervisor == _e.Id)
                                {
                                    PopulateItemObject();

                                    if (i.UpdateItems(item))
                                    {
                                        MessageBox.Show("Item Successfully Updated.");
                                        Clear();
                                    }
                                }

                                try
                                {
                                    if (i.UpdateItemsSupervisor(item))
                                    {
                                        String ModificationReason = txtModReason.Text;
                                        //update po mod reason and date
                                        ps.UpdatePOSupervisor(POID, ModificationReason);

                                        MessageBox.Show("Item Successfully Updated.");
                                        Clear();
                                    }
                                }catch (Exception ex)
                                {
                                    MessageBox.Show("You are only permitted to modify the quantity, price, and location fields.");
                                }
                            }
                        }
                    }
                }
            }
        }