コード例 #1
0
ファイル: Runner.cs プロジェクト: Liromanz/MarathonSkills2016
        private void regMarathonButton_Click(object sender, EventArgs e)
        {
            runnerForm.ActiveForm.Hide();
            eventRegistrationForm form = new eventRegistrationForm();

            form.Show();
        }
コード例 #2
0
        private void registerButton_Click(object sender, EventArgs e) // Нажатие на кнопку "Сохранить", добавление нового пользователя в базу данных + картинка
        {
            string result = checkToAdd();

            if (result == "ОК")
            {
                try
                {
                    connectionSql.Open();

                    command = new SqlCommand($"insert into [dbo].[User] (Email, Password, FirstName, LastName, RoleId) values('{emailTextBox.Text}', '{passwordTextBox.Text}','{nameTextBox.Text.ToUpper()}','{lastNameTextBox.Text.ToUpper()}','R')", connectionSql);
                    command.ExecuteNonQuery();
                    connectionSql.Close();

                    byte[]       image        = null;
                    FileStream   fileStream   = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
                    BinaryReader binaryReader = new BinaryReader(fileStream);
                    image = binaryReader.ReadBytes((int)fileStream.Length);

                    connectionSql.Open();
                    command = new SqlCommand($"insert into [dbo].[Runner] (Email, Gender, DateOfBirth, CountryCode, Image) values('{emailTextBox.Text}','{sexComboBox.Text}', CONVERT(datetime, '{birthDateTimePicker.Value}',4), (select [CountryCode] from [Country] where CountryName = '{countryComboBox.Text}'), @img)", connectionSql);
                    command.Parameters.Add(new SqlParameter("@img", image));
                    command.ExecuteNonQuery();

                    authorizationForm.email = emailTextBox.Text;
                    runnerRegistrationForm.ActiveForm.Hide();
                    eventRegistrationForm form = new eventRegistrationForm();
                    form.Show();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
                finally
                {
                    connectionSql.Close();
                }
            }
            else
            {
                MessageBox.Show(result);
            }
        }
コード例 #3
0
        private void registerButton_Click(object sender, EventArgs e) //изменение всех файлов для внесения их в бд и обновление всех данных в зависимости от email
        {
            string result = checkToAdd();

            if (result == "ОК")
            {
                try
                {
                    connectionSql.Open();

                    string name     = nameTextBox.Text;
                    string lastName = lastNameTextBox.Text;
                    string gender   = sexComboBox.Text;
                    string data     = birthDateTimePicker.Value.ToString();
                    string country  = countryComboBox.SelectedValue.ToString();

                    byte[] image = (byte[])row[6];
                    if (imageLocation != "")
                    {
                        FileStream   fileStream   = new FileStream(imageLocation, FileMode.Open, FileAccess.Read);
                        BinaryReader binaryReader = new BinaryReader(fileStream);
                        image = binaryReader.ReadBytes((int)fileStream.Length);
                    }

                    string password = (string)row[7];
                    if (passwordTextBox.Text != "" || passwordAgainTextBox.Text != "")
                    {
                        string resultPassword = changePassword();
                        if (resultPassword == "ОК")
                        {
                            password = passwordTextBox.Text;
                        }
                        else
                        {
                            MessageBox.Show(resultPassword);
                        }
                    }

                    command = new SqlCommand($"update[dbo].[User] set Password = '******', FirstName = '{name}', LastName = '{lastName}' where Email = '{emailUserLabel.Text}'", connectionSql);
                    command.ExecuteNonQuery();
                    connectionSql.Close();

                    connectionSql.Open();
                    command = new SqlCommand($"update[dbo].[Runner] set Gender = '{gender}', CountryCode = '{country}', DateOfBirth = CONVERT(datetime, '{data}', 4), Image = @img where Email = '{emailUserLabel.Text}'", connectionSql);
                    command.Parameters.Add(new SqlParameter("@img", image));
                    command.ExecuteNonQuery();


                    runnerProfileForm.ActiveForm.Hide();
                    eventRegistrationForm form = new eventRegistrationForm();
                    form.Show();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message);
                }
                finally
                {
                    connectionSql.Close();
                }
            }
            else
            {
                MessageBox.Show(result);
            }
        }