コード例 #1
0
        private void btnIMUpdate1_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
        }
コード例 #2
0
        private void btnIMupdate2_Click(object sender, EventArgs e)
        {
            {
                string commaspacecheck = ", ";
                int    quantityparse;
                double priceparse;
                double discountparse;

                if (cmbIMcode1.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(txtIMName2.Text).Contains(commaspacecheck))
                    {
                        MessageBox.Show("Please check the syntax of the Item name.");
                    }
                    else if (Convert.ToString(txtIMclr2.Text).Contains(commaspacecheck))
                    {
                        MessageBox.Show("Please check the syntax of the Color of the product");
                    }
                    else if (!int.TryParse(txtIMQty2.Text, out quantityparse))
                    {
                        MessageBox.Show("Please check if quantity is a numeric value without decimal points.");
                    }
                    else if (!double.TryParse(txtIMprc2.Text, out priceparse))
                    {
                        MessageBox.Show("Please check if Price set is a numeric value");
                    }
                    else if (!double.TryParse(txtIMdisc2.Text, out discountparse) || discountparse > 100)
                    {
                        MessageBox.Show("Please check if Discount set is a numeric value");
                    }
                    else
                    {
                        string olddetail = Convert.ToString(lblIMname2.Text) + ", " + Convert.ToString(lblIMcode2.Text) + ", " + Convert.ToString(lblIMqty2.Text)
                                           + ", " + Convert.ToString(lblIMcol2.Text) + ", " + Convert.ToString(lblIMprc2.Text) + ", " + Convert.ToString(lblIMdisc2.Text);

                        string newdetail = Convert.ToString(txtIMName2.Text) + ", " + Convert.ToString(lblIMcode2.Text) + ", " + Convert.ToString(txtIMQty2.Text)
                                           + ", " + Convert.ToString(txtIMclr2.Text) + ", " + Convert.ToString(txtIMprc2.Text) + ", " + Convert.ToString(txtIMdisc2.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(lblIMcode2.Text) + " has been updated";

                        MessageBox.Show(updatemessage);

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

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