Пример #1
0
        public static void viewFormat(int id, ScmStockItem item, ScmView gui)
        {
            string status_msg;

            if (item.stockQty == 0)
            {
                status_msg = "Out of Stock";
                gui.listView1.Items[id].BackColor = Color.LightPink;
            }
            else if (item.stockQty < 1.25f * item.stockMin)
            {
                status_msg = "Stock Low";
                gui.listView1.Items[id].BackColor = Color.Yellow;
            }
            else if (item.stockQty <= item.stockMax)
            {
                status_msg = "In Stock";
            }
            else
            {
                status_msg = "Surplus";
                gui.listView1.Items[id].BackColor = Color.Yellow;
            }

            gui.listView1.Items[id].SubItems.Add(status_msg);
        }
Пример #2
0
        private void BackButton_Click(object sender, EventArgs e)
        {
            Button temp_button = (Button)sender;

            switch (temp_button.Name)
            {
            case "BackButton":
                Program.MainForm.Show();

                //Tells garbage collector this temporary form object will not be used again
                this.Dispose();
                break;

            case "AddButton":
                //Display validation message and return if invalid data exists
                if (missingCode)
                {
                    MessageBox.Show("Please enter a product code"); return;
                }
                ;
                if (missingName)
                {
                    MessageBox.Show("Please enter a product name"); return;
                }
                ;
                if (invalidPrice)
                {
                    MessageBox.Show("Please enter a valid price"); return;
                }
                ;
                if (invalidQty)
                {
                    MessageBox.Show("Please enter a valid quantity"); return;
                }
                ;
                if (invalidMin)
                {
                    MessageBox.Show("Please enter a valid minimum quantity"); return;
                }
                ;
                if (invalidMax)
                {
                    MessageBox.Show("Please enter a valid maximum quantity"); return;
                }
                ;

                ScmStockItem temp_item = new ScmStockItem(itemCode, itemName, itemPrice, itemDate, itemQty, itemMin, itemMax);
                ScmEventMediator.OnStockAdded(temp_item, new EventArgs());
                break;
            }
        }
Пример #3
0
        public static void addStock(ScmStockItem item)
        {
            initDb(); //I never assume the database exists
            XDocument db = XDocument.Load(dbName);

            //Add a new item as a child of the root element 'StockTable'
            //We use the stock ID as the sole attribute of the new child for easy searching
            XElement temp_item = new XElement(item.stockId);

            //We add a child node for each attribute
            //This is an easily readable way to ensure we don't excessively nest nodes
            temp_item.Add(new XElement("stockName", item.stockName));
            temp_item.Add(new XElement("stockPrice", item.stockPrice));
            temp_item.Add(new XElement("stockQty", item.stockQty));
            temp_item.Add(new XElement("stockDate", item.stockDate));
            temp_item.Add(new XElement("stockMin", item.stockMin));
            temp_item.Add(new XElement("stockMax", item.stockMax));

            db.Root.Add(temp_item);

            db.Save(dbName);
        }
Пример #4
0
        public static List <ScmStockItem> readStock()
        {
            initDb();
            XDocument db = XDocument.Load(dbName);

            List <ScmStockItem> stock_list = new List <ScmStockItem>();
            ScmStockItem        temp_item;

            foreach (XElement node in db.Root.Elements())
            {
                temp_item = new ScmStockItem(
                    node.Name.ToString(),
                    node.Element("stockName").Value,
                    float.Parse(node.Element("stockPrice").Value),
                    DateTime.Parse(node.Element("stockDate").Value),
                    int.Parse(node.Element("stockQty").Value),
                    int.Parse(node.Element("stockMin").Value),
                    int.Parse(node.Element("stockMax").Value)
                    );
                stock_list.Add(temp_item);
            }

            return(stock_list);
        }
Пример #5
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     submission = new ScmStockItem(itemCode, itemName, itemPrice, itemDate, itemQty, itemMin, itemMax);
     StockAdded(this, new EventArgs());
 }