Exemple #1
0
        private void btnUpdateIM_Click(object sender, EventArgs e)
        {
            this.Hide();

            //AdminFunc admin = new AdminFunc();
            //admin.Hide();

            InventoryUp frm2 = new InventoryUp();

            frm2.ShowDialog();

            //opens the inventory update form, also hides this form to prevent corruptions of the text file
            //just in case the user updates data from this form and also on the inventory update form
        }
Exemple #2
0
        private void btnupdateIU_Click(object sender, EventArgs e)
        {
            string commaspacecheck = ", ";
            int    quantityparse;
            double priceparse;
            double discountparse;

            if (cmbIU.SelectedIndex == -1) //checks if the current index is at -1, if it is an error message shows, the program also has multiple safety measures in place
            {                              //regarding inputing an item without an item code
                MessageBox.Show("Please enter a correct code");
            }
            else
            {
                if (Convert.ToString(txtNameIU.Text).Contains(commaspacecheck))
                {
                    MessageBox.Show("Please check the syntax of the Item name.");
                }
                else if (Convert.ToString(txtclrIU.Text).Contains(commaspacecheck))
                {
                    MessageBox.Show("Please check the syntax of the Color of the product");
                }
                else if (!int.TryParse(txtQtyIU.Text, out quantityparse))
                {
                    MessageBox.Show("Please check if quantity is a numeric value without decimal points.");
                }
                else if (!double.TryParse(txtprcIU.Text, out priceparse))
                {
                    MessageBox.Show("Please check if Price set is a numeric value");
                }
                else if (!double.TryParse(txtdiscIU.Text, out discountparse) || discountparse > 100)
                {
                    MessageBox.Show("Please check if Discount set is a numeric value");
                }
                else
                {
                    string olddetail = Convert.ToString(lblNameIU.Text) + ", " + Convert.ToString(lblcodeIU.Text) + ", " + Convert.ToString(lblqtyIU.Text)
                                       + ", " + Convert.ToString(lblcolIU.Text) + ", " + Convert.ToString(lblprcIU.Text) + ", " + Convert.ToString(lbldiscIU.Text);

                    string newdetail = Convert.ToString(txtNameIU.Text) + ", " + Convert.ToString(lblcodeIU.Text) + ", " + Convert.ToString(txtQtyIU.Text)
                                       + ", " + Convert.ToString(txtclrIU.Text) + ", " + Convert.ToString(txtprcIU.Text) + ", " + Convert.ToString(txtdiscIU.Text);

                    StreamReader sr = new StreamReader(@".\InventoryList.txt");

                    string itemdetail = sr.ReadToEnd();
                    sr.Close();
                    itemdetail = Regex.Replace(itemdetail, olddetail, newdetail); //regex updates the text file, the best part about it; if it doesn't find the old item
                                                                                  //to be updated, it does not commit the updtate preventing hassles regarding fixing the text file.
                    StreamWriter sw = new StreamWriter(@".\InventoryList.txt");
                    sw.Write(itemdetail);
                    sw.Close();

                    string updatemessage = "Item " + Convert.ToString(lblcodeIU.Text) + " has been updated";

                    MessageBox.Show(updatemessage);

                    //AdminFunc admin = new AdminFunc();
                    //admin.Close();

                    InventoryUp up = new InventoryUp();
                    this.Hide();
                    up.Show();
                }
            }
        }