Example #1
0
        //TODO: don't allow a mandatory item to be deleted/edited
        private void btnDeleteItem_Click(object sender, EventArgs e)
        {
            bool   deleteItem = false;
            string itemNo     = lstItems.SelectedItems[0].Text;

            if (!transaction.Items.GetItem(itemNo).ItemClass.Equals(config["Miscellaneous_Fee"]) &&
                !transaction.Items.GetItem(itemNo).ItemClass.Equals(config["Direct_Cost"]) &&
                !transaction.Items.GetItem(itemNo).ItemNo.StartsWith(config["Unit_Item_Prefix"]))
            {
                deleteItem = true;
            }
            else
            {
                Prompt.ShowError("You cannot delete this item.");
            }

            if (deleteItem)
            {
                string kitItemNumber = transaction.Items.GetItem(itemNo).ComponentOf;
                if (kitItemNumber != "")
                {
                    using (frmDeleteKit deleteKit = new frmDeleteKit(kitItemNumber))
                    {
                        deleteKit.ShowDialog();

                        if (deleteKit.Response == DeleteKitDialogResult.DeleteComponent)
                        {
                            transaction.Items.Delete(transaction.Items.GetItem(itemNo));
                        }
                        else if (deleteKit.Response == DeleteKitDialogResult.DeleteAll)
                        {
                            Items kitItems = new Items();
                            kitItems = ItemAdapter.Instance.GetKitComponents(kitItemNumber);

                            for (int j = transaction.Items.Count - 1; j >= 0; j--)
                            {
                                Item tempItem = null, trxItem = null;
                                trxItem  = transaction.Items.GetItem(j);
                                tempItem = kitItems.GetItem(trxItem.ItemNo);

                                if (tempItem != null) //trx line item exists in kit components
                                {
                                    if (trxItem.Qty > tempItem.Qty)
                                    {
                                        transaction.Items.GetItem(j).Qty = trxItem.Qty - tempItem.Qty;
                                    }
                                    else if (trxItem.Qty < tempItem.Qty)
                                    {
                                        transaction.Items.Delete(transaction.Items.GetItem(j));
                                        log.Error(String.Format
                                                      ("{0} {1} Qty of item is less than the Qty being deleted."
                                                      , transaction.DocumentNumber, trxItem.ItemNo));
                                    }
                                    else if (trxItem.Qty == tempItem.Qty)
                                    {
                                        transaction.Items.Delete(transaction.Items.GetItem(j));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    transaction.Items.Delete(transaction.Items.GetItem(itemNo));
                }
            }

            populateDetails();
            populateTotals();

            txtItemNo.Clear();
            txtItemDescription.Clear();
            txtQty.Clear();
            txtUnitPrice.Clear();
            txtMarkdown.Clear();
            btnSaveItem.Enabled   = false;
            btnDeleteItem.Enabled = false;
        }
Example #2
0
        //TODO: don't allow a mandatory item to be deleted/edited
        private void btnDeleteItem_Click(object sender, EventArgs e)
        {
            bool deleteItem = false;
            string itemNo = lstItems.SelectedItems[0].Text;

            if (!transaction.Items.GetItem(itemNo).ItemClass.Equals(config["Miscellaneous_Fee"])
            && !transaction.Items.GetItem(itemNo).ItemClass.Equals(config["Direct_Cost"])
            && !transaction.Items.GetItem(itemNo).ItemNo.StartsWith(config["Unit_Item_Prefix"]))
            {
                deleteItem = true;
            }
            else
            {
                Prompt.ShowError("You cannot delete this item.");
            }

            if (deleteItem)
            {
                string kitItemNumber = transaction.Items.GetItem(itemNo).ComponentOf;
                if (kitItemNumber != "")
                {
                    using (frmDeleteKit deleteKit = new frmDeleteKit(kitItemNumber))
                    {
                        deleteKit.ShowDialog();

                        if (deleteKit.Response == DeleteKitDialogResult.DeleteComponent)
                        {
                            transaction.Items.Delete(transaction.Items.GetItem(itemNo));
                        }
                        else if (deleteKit.Response == DeleteKitDialogResult.DeleteAll)
                        {
                            Items kitItems = new Items();
                            kitItems = ItemAdapter.Instance.GetKitComponents(kitItemNumber);

                            for (int j = transaction.Items.Count - 1; j >= 0; j--)
                            {
                                Item tempItem = null, trxItem = null;
                                trxItem = transaction.Items.GetItem(j);
                                tempItem = kitItems.GetItem(trxItem.ItemNo);

                                if (tempItem != null) //trx line item exists in kit components
                                {
                                    if (trxItem.Qty > tempItem.Qty)
                                    {
                                        transaction.Items.GetItem(j).Qty = trxItem.Qty - tempItem.Qty;
                                    }
                                    else if (trxItem.Qty < tempItem.Qty)
                                    {
                                        transaction.Items.Delete(transaction.Items.GetItem(j));
                                        log.Error(String.Format
                                            ("{0} {1} Qty of item is less than the Qty being deleted."
                                            , transaction.DocumentNumber, trxItem.ItemNo));
                                    }
                                    else if (trxItem.Qty == tempItem.Qty)
                                    {
                                        transaction.Items.Delete(transaction.Items.GetItem(j));
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    transaction.Items.Delete(transaction.Items.GetItem(itemNo));
                }
            }

            populateDetails();
            populateTotals();

            txtItemNo.Clear();
            txtItemDescription.Clear();
            txtQty.Clear();
            txtUnitPrice.Clear();
            txtMarkdown.Clear();
            btnSaveItem.Enabled = false;
            btnDeleteItem.Enabled = false;
        }