Пример #1
0
        public Items GetKitComponents(string kitItemNo)
        {
            Items items = new Items();
            try
            {
                using (SqlConnection conn = new SqlConnection(connString))
                using (SqlCommand comm = new SqlCommand("usp_GetKitComponents", conn))
                {
                    comm.CommandType = CommandType.StoredProcedure;

                    comm.Parameters.Clear();
                    comm.Parameters.Add(new SqlParameter("@Kit", kitItemNo));

                    conn.Open();

                    using (SqlDataReader dr = comm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            if (dr.HasRows)
                            {
                                Item item = new Item();
                                item.ItemNo = dr["Component Item No"].ToString();
                                item.Uofm = dr["U of M"].ToString();
                                item.Qty = Convert.ToDecimal(dr["Qty"].ToString());
                                item.ItemType = (ItemType)Convert.ToInt32(dr["Item Type"]);
                                items.Add(item);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            return items;
        }
Пример #2
0
        public Items GetTemplateItems(string templateID, string pricelevel
            , string currency, string uOFm)
        {
            Items items = new Items();
            try
            {
                using (SqlConnection conn = new SqlConnection(connString))
                using (SqlCommand comm = new SqlCommand("usp_GetTemplateItems", conn))
                {
                    comm.CommandType = CommandType.StoredProcedure;

                    comm.Parameters.Clear();
                    comm.Parameters.Add(new SqlParameter("@TemplateID", templateID));

                    conn.Open();

                    using (SqlDataReader dr = comm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Item i = null;
                            decimal qty;

                            i = ItemData.Instance.GetItem(pricelevel, currency
                                , dr["Item no"].ToString(), uOFm);

                            qty = Convert.ToDecimal(dr["Qty"]);

                            if (i != null)
                            {
                                if (qty > 0)
                                {
                                    i.Qty = qty;
                                }

                                if (items != null)
                                {
                                    items.Add(i);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            return items;
        }
Пример #3
0
        public Items GetItems(string level, string currency
            , string uOfM)
        {
            Items items = new Items();
            try
            {
                using (SqlConnection conn = new SqlConnection(connString))

                using (SqlCommand comm = new SqlCommand("usp_GetItemsByLevel", conn))
                {
                    comm.CommandType = CommandType.StoredProcedure;

                    comm.Parameters.Clear();
                    comm.Parameters.Add(new SqlParameter("@UofM", uOfM));
                    comm.Parameters.Add(new SqlParameter("@Currency", currency));
                    comm.Parameters.Add(new SqlParameter("@Level", level));

                    conn.Open();

                    using (SqlDataReader dr = comm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Item item = new Item();

                            item.ItemNo = dr["Item Number"].ToString();
                            item.ItemDescription = dr["Item Description"].ToString();
                            item.ItemClass = dr["Item Class Code"].ToString();
                            item.Uofm = dr["U of M"].ToString();
                            item.Unitprice = Convert.ToDecimal(dr["Unit Price"].ToString());
                            item.ItemType = (ItemType)Convert.ToInt32(dr["Item Type"].ToString());

                            items.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }

            return items;
        }
Пример #4
0
        public Items GetAssessmentItems(string assessmentNo
            , Transaction_Type sopType)
        {
            Items items = new Items();
            try
            {
                using (SqlConnection conn = new SqlConnection(connString))
                using (SqlCommand comm = new SqlCommand("usp_GetAssessmentItems", conn))
                {
                    comm.CommandType = CommandType.StoredProcedure;

                    comm.Parameters.Clear();
                    comm.Parameters.Add(new SqlParameter("@SOPType", (int)sopType));
                    comm.Parameters.Add(new SqlParameter("@Assessment_No", assessmentNo));

                    conn.Open();

                    using (SqlDataReader dr = comm.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            Item i = new Item();
                            i.ItemNo = dr["Item Number"].ToString();
                            i.ItemDescription = dr["Item Description"].ToString();
                            i.Qty = Convert.ToDecimal(dr["Quantity"].ToString());
                            i.Unitprice = Convert.ToDecimal(dr["Unit Price"].ToString());
                            i.ItemClass = dr["Item Class"].ToString();
                            i.Uofm = dr["U of M"].ToString();
                            i.MarkDown = Convert.ToDecimal(dr["Markdown"]);

                            items.Add(i);
                        }
                    }
                }

            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            return items;
        }
Пример #5
0
        private void frmItemLookup_Load(object sender, EventArgs e)
        {
            try
            {
                items = ItemAdapter.Instance.GetItems(level
                    , currency
                    , config["Default_U_of_M"]);

                txtItemNo.Text = itemNumber;
                addItems(itemNumber);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                Prompt.ShowError(ex.Message);
            }
        }
Пример #6
0
        private Items getKitComponents(Item itemKit)
        {
            Items items = new Items();
            Items pricedItems = new Items();

            if (transaction != null)
            {
                if (itemKit.ItemType == ItemType.Kit)
                {
                    items = ItemAdapter.Instance.GetKitComponents(itemKit.ItemNo);

                    foreach (Item item in items)
                    {
                        Item pricedItem;
                        pricedItem = ItemAdapter.Instance.GetItem
                            (transaction.PriceLevel, transaction.CurrencyID
                            , item.ItemNo, item.Uofm);

                        if (pricedItem != null)
                        {
                            //set qty equals qty of the component
                            //in the kit multiplied by the qty of the kit
                            pricedItem.Qty = item.Qty * itemKit.Qty;
                            pricedItem.ComponentOf = itemKit.ItemNo;
                            pricedItems.Add(pricedItem);
                        }
                    }
                }
            }
            return pricedItems;
        }
Пример #7
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;
        }