예제 #1
0
        private void save_Click(object sender, EventArgs e)
        {
            if (!_firstNameClass.testFirstName(first_name_txt.Text))
            {
                return;
            }
            if (!_lastNameClass.testLastName(last_name_txt.Text))
            {
                return;
            }
            if (!_dateOfBirth.testDate(date_of_birth_txt.Text))
            {
                return;
            }
            age_txt_box.Text = _dateOfBirth.getAgeByBirthDate(date_of_birth_txt.Text);
            if (!_phone.testPhoneFormat(phone_txt_box.Text))
            {
                return;
            }
            string query = "SELECT * from credentials where first_name = '" + first_name_txt.Text
                           + "' AND last_name = '" + last_name_txt.Text
                           + "' AND date_of_birth = '" + date_of_birth_txt.Text + "'";

            SqlDataReader reader = Helper_Classes_namespace.DataBaseHelperClass.GlobalPerformQuery(query).ExecuteReader();

            if (reader == null)
            {
                return;
            }
            else if (reader.HasRows)
            {
                query = "UPDATE credentials set first_name = '" + first_name_txt.Text
                        + "' ,last_name = '" + last_name_txt.Text
                        + "' ,date_of_birth = '" + date_of_birth_txt.Text
                        + "' ,phone = '" + phone_txt_box.Text
                        + "' where first_name = '" + first_name_txt.Text
                        + "' AND last_name = '" + last_name_txt.Text
                        + "' AND date_of_birth = '" + date_of_birth_txt.Text + "'";
            }
            else
            {
                query = "INSERT INTO credentials(first_name,last_name,date_of_birth,phone) VALUES('" + first_name_txt.Text + "','" + last_name_txt.Text + "','" + date_of_birth_txt.Text + "','" + phone_txt_box.Text + "')";
            }
            Helper_Classes_namespace.DataBaseHelperClass.ClosePerformQuery();
            Helper_Classes_namespace.DataBaseHelperClass.GlobalPerformQuery(query);
            Helper_Classes_namespace.DataBaseHelperClass.ClosePerformQuery();
            MessageBox.Show(" Field Inserted !!!!!!! ");
            selectAllFromDataSet();
        }
예제 #2
0
        private void save_Click(object sender, EventArgs e)
        {
            if (!_firstNameClass.testFirstName(first_name_txt.Text))
            {
                MessageBox.Show(Helper_Classes_namespace.ErrorMessages.getErrorMessage());
                return;
            }
            if (!_lastNameClass.testLastName(last_name_txt.Text))
            {
                MessageBox.Show(Helper_Classes_namespace.ErrorMessages.getErrorMessage());
                return;
            }

            if (!_dateOfBirth.testDate(date_of_birth_txt.Text))
            {
                MessageBox.Show(Helper_Classes_namespace.ErrorMessages.getErrorMessage());
                return;
            }

            if (!_phone.testPhoneFormat(phone_txt_box.Text))
            {
                MessageBox.Show(Helper_Classes_namespace.ErrorMessages.getErrorMessage());
                return;
            }

            string query = "SELECT * from credentials where first_name = '" + first_name_txt.Text
                           + "' AND last_name = '" + last_name_txt.Text
                           + "' AND date_of_birth = '" + date_of_birth_txt.Text + "'";


            string logEvent = "";

            var response = Helper_Classes_namespace.DataBaseHelperClass.GlobalPerformQuery(query);

            if (response.hasErrors)
            {
                MessageBox.Show(Helper_Classes_namespace.ErrorMessages.getErrorMessage());
                Helper_Classes_namespace.DataBaseHelperClass.ClosePerformQuery();
                return;
            }
            SqlDataReader reader = response.command.ExecuteReader();

            if (reader.HasRows)
            {
                query = "UPDATE credentials set first_name = '" + first_name_txt.Text
                        + "' ,last_name = '" + last_name_txt.Text
                        + "' ,date_of_birth = '" + date_of_birth_txt.Text
                        + "' ,phone = '" + phone_txt_box.Text
                        + "' where first_name = '" + first_name_txt.Text
                        + "' AND last_name = '" + last_name_txt.Text
                        + "' AND date_of_birth = '" + date_of_birth_txt.Text + "'";
                logEvent = "UPDATED \n" + first_name_txt.Text
                           + "\n" + last_name_txt.Text
                           + "\n" + date_of_birth_txt.Text.ToString()
                           + "\n" + phone_txt_box.Text;
            }
            else
            {
                query    = "INSERT INTO credentials(first_name,last_name,date_of_birth,phone) VALUES('" + first_name_txt.Text + "','" + last_name_txt.Text + "','" + date_of_birth_txt.Text + "','" + phone_txt_box.Text + "')";
                logEvent = "INSERTED \n" + first_name_txt.Text
                           + "\n" + last_name_txt.Text
                           + "\n" + date_of_birth_txt.Text.ToString()
                           + "\n" + phone_txt_box.Text;
            }
            eventLogDisplay.AppendText("\n<---------------------->\n");
            eventLogDisplay.AppendText(logEvent);
            Helper_Classes_namespace.PerformWriteToFileAction.writeToLogFile(logEvent.Replace('\n', ' ') + " " + Helper_Classes_namespace.HelperClass.getSystemDateTime().ToLocalTime().ToString());
            Helper_Classes_namespace.DataBaseHelperClass.ClosePerformQuery();
            if (Helper_Classes_namespace.DataBaseHelperClass.GlobalPerformQuery(query) == null)
            {
                MessageBox.Show(Helper_Classes_namespace.ErrorMessages.getErrorMessage());
                Helper_Classes_namespace.DataBaseHelperClass.ClosePerformQuery();
                return;
            }
            Helper_Classes_namespace.DataBaseHelperClass.ClosePerformQuery();
            MessageBox.Show(" Field Inserted !!!!!!! ");
            dataSetView.DataSource = "";
            table = new DataTable();
            table.Columns.Add("Index", typeof(int));
            table.Columns.Add("First Name", typeof(string));
            table.Columns.Add("Last Name", typeof(string));
            table.Columns.Add("Date of Birth", typeof(string));
            table.Columns.Add("Phone", typeof(string));
            table.Rows.Add(0, first_name_txt.Text, last_name_txt.Text, date_of_birth_txt.Text, phone_txt_box.Text).CancelEdit();
            dataSetView.DataSource = table;
        }