Exemplo n.º 1
0
        public static bool AddToOrder(Int64 OrderID, Int64 StickerID, int Quantity)
        {
            DataClasses1DataContext dbContext = new DataClasses1DataContext();

            StickerOrderItem stickerOrderItem = new StickerOrderItem(OrderID, StickerID, Quantity);

            dbContext.StickerOrderItems.InsertOnSubmit(stickerOrderItem);

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

            return(true);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            //NicsInventory1DataSet.ColorsDataTable Colors;

            //Add to order tables
            string ColorName  = ColorComboBox.Text;
            int    firstSpace = ColorName.IndexOf(" ");

            ColorName = ColorName.Substring(0, firstSpace);
            //int ColorID = Convert.ToInt32(comboBox5.SelectedValue);
            //MessageBox.Show(boxmessage);

            SqlConnection conn = new SqlConnection(connstr);

            using (conn)
            {
                conn.Open();

                /*using (var cmd = new SqlCommand("SELECT ID FROM Products WHERE VinylType = @VinylType AND ColorID = @ColorID", conn))
                 * {
                 *  cmd.Parameters.AddWithValue("@VinylType", VinylTypeID);
                 *  cmd.Parameters.AddWithValue("@ColorID", ColorID);
                 *
                 *  int result = Convert.ToInt32(cmd.ExecuteScalar());
                 *
                 *  if (result != 0)
                 *  {
                 *      prodID = result;
                 *      MessageBox.Show("Product ID found");
                 *  }
                 *  else
                 *  {
                 *      MessageBox.Show("No Product found.");
                 *  }
                 * }*/

                string  costTextBox = textBox1.Text;
                decimal orderPrice;
                if (!decimal.TryParse(costTextBox, out orderPrice))
                {
                    MessageBox.Show("Order not created. Please enter a valid price as #.## or ##");
                    textBox1.Text = "0.00";
                    return;
                }

                SqlCommand cmdNewOrder = new SqlCommand("spAddOrder", conn);
                cmdNewOrder.CommandType = CommandType.StoredProcedure;

                cmdNewOrder.Parameters.Add(new SqlParameter("@pDate", SqlDbType.DateTime));
                cmdNewOrder.Parameters["@pDate"].Value = dateTimePicker1.Value;

                cmdNewOrder.Parameters.Add(new SqlParameter("@pPrice", SqlDbType.Decimal));
                cmdNewOrder.Parameters["@pPrice"].Value = orderPrice;

                cmdNewOrder.Parameters.Add(new SqlParameter("@pID", SqlDbType.Int));
                cmdNewOrder.Parameters["@pID"].Direction = ParameterDirection.Output;

                try
                {
                    cmdNewOrder.ExecuteNonQuery();
                    this.OrderID = (int)cmdNewOrder.Parameters["@pID"].Value;
                    string boxmessage = "This returned order #" + OrderID;
                    MessageBox.Show(boxmessage);
                }
                catch
                {
                    //NC-14 A simple catch.
                    MessageBox.Show("Order ID was not returned. Order could not be created.");
                }

                if (isVinylOrder)
                {
                    int prodID = Convert.ToInt32(ColorComboBox.SelectedValue);

                    DataClasses1DataContext context = new DataClasses1DataContext();
                    //TO DO -- Add product and quantities to a List object and iterate through

                    VinylOrderItem vinylOrderItem = new VinylOrderItem();
                    vinylOrderItem.ProductID = prodID;
                    vinylOrderItem.OrderID   = OrderID;
                    vinylOrderItem.Quantity  = numericUpDown1.Value;

                    context.VinylOrderItems.InsertOnSubmit(vinylOrderItem);

                    SecondaryOrderItem TransferTape = new SecondaryOrderItem();

                    TransferTape.SecondaryID = GetSecondaryItemID(TransferTapeType);
                    TransferTape.OrderID     = OrderID;
                    TransferTape.Quantity    = numericUpDown2.Value;

                    context.SecondaryOrderItems.InsertOnSubmit(TransferTape);

                    try
                    {
                        context.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                    }

                    bool result = Product.Outgoing(prodID, (double)numericUpDown1.Value);
                    if (!result)
                    {
                        MessageBox.Show("There was a problem decreasing vinyl inventory. Tell your wife she did something wrong");
                    }
                }
                else
                {
                    DataClasses1DataContext context = new DataClasses1DataContext();

                    StickerOrderItem stickerOrderItem = new StickerOrderItem();
                    stickerOrderItem.OrderID   = OrderID;
                    stickerOrderItem.Quantity  = (int)numericUpDown1.Value;
                    stickerOrderItem.StickerID = stickerID;

                    try
                    {
                        context.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        Console.Write(ex.Message);
                    }

                    bool result = Sticker.Outgoing(stickerID, (int)numericUpDown1.Value);
                    if (!result)
                    {
                        MessageBox.Show("There was a problem decreasing sticker inventory. Tell your wife she did something wrong");
                    }

                    if (Sticker.CheckNotify(stickerID))
                    {
                        MessageBox.Show("You're getting low on " + Sticker.GetName(stickerID));
                    }
                }
            }

            //Decrement stock

            textBox3.Clear();
            ScrapLengthTB.Clear();
            ScrapWidthTB.Clear();
            textBox6.Clear();
            textBox1.Text = "0.00";

            checkBox1.Checked = false;
            checkBox5.Checked = false;

            numericUpDown1.Value = VINYL_DEFAULT_QUANTITY;
            numericUpDown2.Value = TRANSFER_TAPE_DEFAULT_QUANTITY;

            ColorComboBox.Show();
            StickerNameCombo.Hide();
        }