예제 #1
0
        public bool AddSecondaryItem(string Name, int Quantity, decimal Cost, int NotificationLevel,
                                     long SupplierID, bool ApplicationKit, bool Mailer)
        {
            DataClasses1DataContext dbContext = new DataClasses1DataContext();

            SecondaryItem secondary = new SecondaryItem
            {
                Name              = Name,
                Quantity          = Quantity,
                Cost              = Cost,
                NotificationLevel = NotificationLevel,
                SupplierID        = SupplierID,
                ApplicationKit    = ApplicationKit,
                Mailer            = Mailer
            };

            dbContext.SecondaryItems.InsertOnSubmit(secondary);

            try
            {
                dbContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine(e.Message, e.StackTrace);
            }

            return(true);
        }
예제 #2
0
        public static bool CheckNotify(Int64 ItemID)
        {
            DataClasses1DataContext dbContext = new DataClasses1DataContext();

            SecondaryItem item = dbContext.SecondaryItems.Where(si => si.ID == ItemID).FirstOrDefault();

            return(item.Quantity <= item.NotificationLevel);
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //check values
            if (!int.TryParse(QuantityTextBox.Text, out int Quantity))
            {
                MessageBox.Show("Item not added. Please enter a whole number for the quantity");
                QuantityTextBox.Text = "0";
                return;
            }

            decimal ItemCost;

            if (!decimal.TryParse(CostTextBox.Text, out ItemCost))
            {
                MessageBox.Show("Item not added. Please enter a valid price as #.## or ##");
                CostTextBox.Text = "0.00";
                return;
            }

            if (TotalRadio.Checked)
            {
                ItemCost = ItemCost / Quantity;
            }

            Supplier supplier = new Supplier();

            if (SupplierTextBox.Text != "")
            {
                supplier.ID = supplier.AddNewSupplier(SupplierTextBox.Text, OrderLinkTextBox.Text);
            }
            else
            {
                //TO DO! For testing only, fix type to be nullable
                supplier.ID = 1;
            }



            SecondaryItem secondary = new SecondaryItem();
            bool          success   = secondary.AddSecondaryItem(NameTextBox.Text, Quantity, ItemCost, Convert.ToInt16(NotificationUpDown.Value), supplier.ID, AppKitBox.Checked, MailerBox.Checked);

            if (success)
            {
                Close();
            }
            else
            {
                MessageBox.Show("An error occurred. This item was not added");
            }
        }
예제 #4
0
        public static bool GetOtherNotify(Int64 SecondaryID)
        {
            DataClasses1DataContext dbContext = new DataClasses1DataContext();

            SecondaryItem secondary = dbContext.SecondaryItems.Where(s => s.ID == SecondaryID).First();

            if (secondary.Quantity <= secondary.NotificationLevel)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #5
0
        public static bool Outgoing(SecondaryItem secondary)
        {
            DataClasses1DataContext dbContext = new DataClasses1DataContext();

            SecondaryItem secondaryItem = dbContext.SecondaryItems.Where(si => si.ID == secondary.ID).FirstOrDefault();

            secondaryItem.Quantity -= secondary.Quantity;

            try
            {
                dbContext.SubmitChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine(e.Message, e.StackTrace);
            }

            return(true);
        }
예제 #6
0
        private void Savebtn_Click(object sender, EventArgs e)
        {
            List <Product> productsInOrder = new List <Product>();

            foreach (DataGridViewRow Row in VinylGridView.Rows)
            {
                if (Row.Cells[0].Value != null)
                {
                    Product vinyl = new Product(Convert.ToInt64(Row.Cells[0].Value),
                                                Convert.ToInt32(Row.Cells[1].Value), Convert.ToInt32(Row.Cells[2].Value),
                                                Convert.ToInt32(Row.Cells[3].Value), Convert.ToInt32(Row.Cells[4].Value));
                    productsInOrder.Add(vinyl);
                }
            }

            List <Sticker> stickersInOrder = new List <Sticker>();

            foreach (DataGridViewRow Row in StickerGridView.Rows)
            {
                if (Row.Cells[0].Value != null)
                {
                    Sticker sticker = new Sticker(Convert.ToInt64(Row.Cells[0].Value), Convert.ToInt32(Row.Cells[1].Value));
                    stickersInOrder.Add(sticker);
                }
            }


            List <SecondaryItem> otherItemsInOrder = new List <SecondaryItem>();

            foreach (DataGridViewRow Row in OtherGridView.Rows)
            {
                if (Row.Cells[0].Value != null)
                {
                    SecondaryItem secondary = new SecondaryItem(Convert.ToInt64(Row.Cells[0].Value), Convert.ToInt32(Row.Cells[1].Value));
                    otherItemsInOrder.Add(secondary);
                }
                if (vinylAppKitCheckBox.Checked)
                {
                    //make an add kit function
                }
            }


            string message = "Vinyl in order = " + productsInOrder.Count.ToString() +
                             "\nStickers in order = " + stickersInOrder.Count.ToString() +
                             "\nOther grid row count = " + otherItemsInOrder.Count.ToString();

            MessageBox.Show(message);


            // Make an order
            DateTime date = dateTimePicker1.Value;

            if (!decimal.TryParse(PriceTBox.Text, out decimal price))
            {
                MessageBox.Show("Please enter a valid order price");
                return;
            }
            Int64 orderID = Order.NewOrder(date, price);

            if (productsInOrder.Any())
            {
                foreach (Product p in productsInOrder)
                {
                    bool   success       = true;
                    double vinylQuantity = Product.GetProductTotal(p);
                    VinylOrderItem.AddToOrder(orderID, p.ID, vinylQuantity);
                    if (p.FullSheet < 1 && p.FullSheet > 0)
                    {
                        success = Product.Outgoing(p, orderID);
                    }
                    else
                    {
                        success = Product.Outgoing(p.ID, vinylQuantity);
                    }

                    if (!success)
                    {
                        MessageBox.Show("There was an error adjusting quantity of {0} vinyl, please double check your stock", p.Color.Name);
                    }

                    if (Product.CheckNotify(p.ID))
                    {
                        MessageBox.Show("You're getting low on {0}", p.Color.Name);
                    }
                }
            }

            if (stickersInOrder.Any())
            {
                foreach (Sticker s in stickersInOrder)
                {
                    StickerOrderItem.AddToOrder(orderID, s.ID, s.Quantity);
                    bool success = Sticker.Outgoing(s.ID, s.Quantity);

                    if (!success)
                    {
                        MessageBox.Show("There was an error adjusting quantity of {0} sticker, please double check your stock", s.Name);
                    }

                    if (Sticker.CheckNotify(s.ID))
                    {
                        MessageBox.Show("You're getting low on {0}", s.Name);
                    }
                }
            }

            if (otherItemsInOrder.Any())
            {
                foreach (SecondaryItem si in otherItemsInOrder)
                {
                    SecondaryOrderItem.AddToOrder(orderID, si.ID, si.Quantity);
                    bool success = SecondaryItem.Outgoing(si);

                    if (!success)
                    {
                        MessageBox.Show("There was an error adjusting quantity of {0} item, please double check your stock", si.Name);
                    }

                    if (SecondaryItem.CheckNotify(si.ID))
                    {
                        MessageBox.Show("You're getting low on {0}", si.Name);
                    }
                }
            }

            if (vinylAppKitCheckBox.Checked == true)
            {
                SecondaryItem.ApplicationKitUsed(orderID, (int)VinylKitCountNumBox.Value);
            }
        }