Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            _5 f5 = new _5();

            if (!f5.IsDisposed)
            {
                f5.Show();
                Dispose();
            }
        }
Пример #2
0
        public void Register()
        {
            SqlConnectionStringBuilder uacsb = new SqlConnectionStringBuilder();

            uacsb.DataSource         = @"localhost";
            uacsb.InitialCatalog     = "MarathonSkills2016";
            uacsb.IntegratedSecurity = true;
            uacsb.ConnectTimeout     = 30;
            SqlConnection uac   = new SqlConnection(uacsb.ConnectionString);
            SqlCommand    uacom = uac.CreateCommand();

            uacom.CommandText = "SELECT * FROM [MarathonSkills2016].[dbo].[User]";
            SqlDataAdapter uada = new SqlDataAdapter();

            uada.SelectCommand = uacom;
            SqlCommandBuilder uacb = new SqlCommandBuilder(uada);

            uada.DeleteCommand = uacb.GetDeleteCommand();
            uada.InsertCommand = uacb.GetInsertCommand();
            uada.UpdateCommand = uacb.GetUpdateCommand();
            DataTable uadt = new DataTable();

            uada.Fill(uadt);
            foreach (DataRow eaec in uadt.Rows)
            {
                if (eaec["Email"] as string == CurrentUserContext.Email)
                {
                    MessageBox.Show("User with this email already exists!", "MarathonSkills2016", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            DataRow uanr = uadt.NewRow();

            uanr["Email"]     = CurrentUserContext.Email;
            uanr["Password"]  = CurrentUserContext.Password;
            uanr["LastName"]  = CurrentUserContext.LastName;
            uanr["FirstName"] = CurrentUserContext.FirstName;
            uanr["RoleId"]    = CurrentUserContext.RoleId;
            uadt.Rows.Add(uanr);
            uada.Update(uadt);
            SqlConnectionStringBuilder racsb = new SqlConnectionStringBuilder();

            racsb.DataSource         = @"localhost";
            racsb.InitialCatalog     = "MarathonSkills2016";
            racsb.IntegratedSecurity = true;
            racsb.ConnectTimeout     = 30;
            SqlConnection rac   = new SqlConnection(racsb.ConnectionString);
            SqlCommand    racom = rac.CreateCommand();

            racom.CommandText = "SELECT * FROM Runner";
            SqlDataAdapter rada = new SqlDataAdapter();

            rada.SelectCommand = racom;
            SqlCommandBuilder racb = new SqlCommandBuilder(rada);

            rada.DeleteCommand = racb.GetDeleteCommand();
            rada.InsertCommand = racb.GetInsertCommand();
            rada.UpdateCommand = racb.GetUpdateCommand();
            DataTable radt = new DataTable();

            rada.Fill(radt);
            //adding to runner record
            DataRow ranr = radt.NewRow();

            ranr["Email"]       = RunnerCurrentContext.Email;
            ranr["Gender"]      = RunnerCurrentContext.Gender;
            ranr["DateOfBirth"] = RunnerCurrentContext.DOB;
            ranr["CountryCode"] = RunnerCurrentContext.CountryCode;
            ranr["Photo"]       = RunnerCurrentContext.Photo;
            radt.Rows.Add(ranr);
            rada.Update(radt);
            radt.Clear();
            rada.Fill(radt);
            RunnerCurrentContext.RunnerId = (int)radt.Rows[radt.Rows.Count - 1]["RunnerId"];
            MessageBox.Show("Новый бегун успешно зарегистрирован в системе.", "MarathonSkills2016", MessageBoxButtons.OK, MessageBoxIcon.Information);
            _5 f5 = new _5();

            f5.Show();
            Dispose();
        }