Esempio n. 1
0
        private void changeGrade()
        {
            try
            {
                frmConfirm   confirm = new frmConfirm();
                DialogResult result  = confirm.ShowDialog();
                if (result == DialogResult.Yes)
                {
                    //Update grade in database
                    String[] rows;
                    string   filename = @"..\..\books.txt";
                    using (StreamReader sr = File.OpenText(filename))
                    {
                        rows = Regex.Split(sr.ReadToEnd(), "\r\n");
                    }

                    using (StreamWriter sw = new StreamWriter(filename))
                    {
                        for (int i = 0; i < rows.Length - 1; i++)
                        {
                            if (rows[i].Contains(data[4]))
                            {
                                rows[i] = rows[i].Replace(data[4], cboGrade.Text);
                            }
                            sw.WriteLine(rows[i]);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Please enter a valid email");
                MessageBox.Show(ex.Message); //handles any error
            }
        }
Esempio n. 2
0
        private void changeEmail()
        {
            try
            {
                bool check = IsValidEmail(txtCurrent.Text);
                bool valid = IsValidEmail(txtNew.Text);
                if (txtCurrent.Text != ea || !valid)
                {
                    MessageBox.Show("Invalid Email");
                }
                else
                {
                    frmConfirm   confirm = new frmConfirm();
                    DialogResult result  = confirm.ShowDialog();
                    if (result == DialogResult.Yes)
                    {
                        //Update Email in database
                        String[] rows;
                        string   filename = @"..\..\books.txt";
                        using (StreamReader sr = File.OpenText(filename))
                        {
                            rows = Regex.Split(sr.ReadToEnd(), "\r\n");
                        }
                        bool match = false;
                        using (StreamWriter sw = new StreamWriter(filename))
                        {
                            for (int i = 0; i < (rows.Length - 1); i++)
                            {
                                if (rows[i].Contains(txtCurrent.Text) && !match)
                                {
                                    rows[i] = rows[i].Replace(txtCurrent.Text, txtNew.Text);
                                    match   = true;
                                }
                                sw.WriteLine(rows[i]);
                            }
                        }

                        MessageBox.Show("Email Updated");
                        hideButtons();
                    }
                    else
                    {
                        MessageBox.Show("Email not Updated");
                        hideButtons();
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Please enter a valid email");
                MessageBox.Show(ex.Message); //handles any error
            }
        }
Esempio n. 3
0
        private void changeName()
        {
            try
            {
                if (txtCurrent.Text == "" || txtNew.Text == "")
                {
                    MessageBox.Show("Please fill all fields");
                }
                else
                {
                    frmConfirm   confirm = new frmConfirm();
                    DialogResult result  = confirm.ShowDialog();
                    if (result == DialogResult.Yes)
                    {
                        //Update name in database
                        String[] rows;
                        string   filename = @"..\..\books.txt";
                        using (StreamReader sr = File.OpenText(filename))
                        {
                            rows = Regex.Split(sr.ReadToEnd(), "\r\n");
                        }

                        using (StreamWriter sw = new StreamWriter(filename))
                        {
                            for (int i = 0; i < rows.Length - 1; i++)
                            {
                                if (rows[i].Contains(data[1]))
                                {
                                    rows[i] = rows[i].Replace(data[1], txtCurrent.Text);
                                    rows[i] = rows[i].Replace(data[2], txtNew.Text);
                                }
                                sw.WriteLine(rows[i]);
                            }
                        }
                        MessageBox.Show("Name Changed");
                        hideButtons();
                        lblFirst.Text = txtCurrent.Text;
                        lblLast.Text  = txtNew.Text;
                    }
                    else
                    {
                        MessageBox.Show("Name not updated");
                    }
                }
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Please enter a valid email");
                MessageBox.Show(ex.Message); //handles any error
            }
        }