Example #1
0
        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            label4.Show();
            numericUpDown2.Show();
            radioButton1.Show();
            radioButton2.Show();
            checkBox1.Text           = "Application kit";
            label1.Text              = "Color";
            label2.Text              = "Amount used (sheet)";
            numericUpDown1.Value     = VINYL_DEFAULT_QUANTITY;
            numericUpDown1.Increment = VINYL_INCREMENT;

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

            isVinylOrder = true;
        }
Example #2
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();
        }