Пример #1
0
        public void LoadRunner()
        {
            using (var db = new MarathonDBEntities1())
            {
                var MarathonCount = db.MarathonTbl.Count();
                var LastMarathon  = db.MarathonTbl.FirstOrDefault(u => u.MarathonId == MarathonCount);

                var RunnerList = (from r in db.Runner
                                  join u in db.User on r.Email equals u.Email
                                  join c in db.Country on r.CountryCode equals c.CountryCode
                                  join reg in db.Registration on r.RunnerId equals reg.RunnerId
                                  join regEvent in db.RegistrationEvent on reg.RegistrationId equals regEvent.RegistrationId
                                  join e in db.Event on regEvent.EventId equals e.EventId
                                  orderby u.FirstName
                                  where e.MarathonId == LastMarathon.MarathonId
                                  select new
                {
                    Id = reg.RegistrationId,
                    Name = u.FirstName + " " + u.LastName + " -" + regEvent.BibNumber + " (" + c.CountryName + ")"
                }).ToList();

                CmbRunners.ItemsSource       = RunnerList;
                CmbRunners.DisplayMemberPath = "Name";
                CmbRunners.SelectedValuePath = "Id";
            }
        }
Пример #2
0
 public string Login()
 {
     try
     {
         using (var db = new MarathonDBEntities1())
         {
             var user = db.User.FirstOrDefault(u => u.Email == TxtLogin.Text && u.Password == PassBox.Password);
             LocalStorage.UserClass.Email     = user.Email;
             LocalStorage.UserClass.FirstName = user.FirstName;
             LocalStorage.UserClass.LastName  = user.LastName;
             if (user.RoleId == "R")
             {
                 LocalStorage.UserClass.RunnerId = user.Runner.FirstOrDefault(u => u.Email == user.Email).RunnerId.ToString();
             }
             if (user != null)
             {
                 return(user.RoleId);
             }
             return(null);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("Неверный логин или пароль");
         return(null);
     }
 }
Пример #3
0
        private void BtnRegister_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (ChkFull.IsChecked == false && ChkHalf.IsChecked == false && ChkSmall.IsChecked == false)
                {
                    MessageBox.Show("Должен быть выбран по крайней мере \n   один вид марафона");
                    return;
                }

                Regex reg = new Regex(@"^\d+");
                if (reg.IsMatch(TxtPayment.Text) == false)
                {
                    MessageBox.Show("Неверная сумма взноса");
                    return;
                }

                using (var db = new MarathonDBEntities1())
                {
                    Registration registration = new Registration
                    {
                        RunnerId             = Convert.ToInt32(LocalStorage.UserClass.RunnerId),
                        RegistrationDateTime = DateTime.Now,
                        RaceKitOptionId      = SelectedId.ToString(),
                        RegistrationStatusId = 1,
                        Cost              = Money,
                        CharityId         = Convert.ToInt32(CmbCharity.SelectedValue),
                        SponsorshipTarget = Convert.ToInt32(TxtPayment.Text)
                    };
                    db.Registration.Add(registration);

                    int LastMarathon = db.MarathonTbl.Count();
                    var RegEvent     = db.Event.Where(u => u.MarathonId == LastMarathon);

                    foreach (var item in EventType)
                    {
                        var EventId             = db.Event.FirstOrDefault(u => u.EventTypeId == item && u.MarathonId == LastMarathon);
                        RegistrationEvent regEv = new RegistrationEvent
                        {
                            RegistrationId = registration.RegistrationId,
                            BibNumber      = null,
                            RaceTime       = null,
                            EventId        = EventId.EventId
                        };
                        db.RegistrationEvent.Add(regEv);
                    }

                    db.SaveChanges();
                    new WinRunnerRegThanks().Show();
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #4
0
 void LoadInfo()
 {
     using (var db = new MarathonDBEntities1())
     {
         checkpoints = db.Checkpoint.ToList();
         int count = db.MarathonTbl.Count();
         lastMarathon = db.MarathonTbl.FirstOrDefault(m => m.MarathonId == count).CityName;
     }
 }
Пример #5
0
 public void LoadCharity()
 {
     using (var db = new MarathonDBEntities1())
     {
         Charities = db.Charity.ToList().OrderBy(u => u.CharityName);
         CmbCharity.ItemsSource       = Charities;
         CmbCharity.DisplayMemberPath = "CharityName";
         CmbCharity.SelectedValuePath = "CharityId";
         CmbCharity.SelectedIndex     = 0;
     }
 }
Пример #6
0
        private void CmbRunners_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int runnerId = Convert.ToInt32(CmbRunners.SelectedValue);

            using (var db = new MarathonDBEntities1())
            {
                var CharityInf = db.Registration.FirstOrDefault(r => r.RunnerId == runnerId);
                CharityInform.CharityName = CharityInf.Charity.CharityName;
                CharityInform.CharityDesc = CharityInf.Charity.CharityDescription;
                LblCharityName.Content    = CharityInf.Charity.CharityName;
            }
        }
Пример #7
0
        public void LoadAll()
        {
            #region Загрузка из базы и вывод инфы о пользователе
            using (var db = new MarathonDBEntities1())
            {
                LblEmail.Content  = LocalStorage.UserClass.Email;
                TxtFirstName.Text = LocalStorage.UserClass.FirstName;
                TxtLastName.Text  = LocalStorage.UserClass.LastName;

                var CountryList = db.Country.AsNoTracking().OrderBy(c => c.CountryName).ToList();
                CmbCountry.ItemsSource       = CountryList;
                CmbCountry.DisplayMemberPath = "CountryName";
                CmbCountry.SelectedValuePath = "CountryCode";

                var Gender = db.Gender.AsNoTracking().ToList();
                CmbGender.ItemsSource       = Gender;
                CmbGender.DisplayMemberPath = "Gender1";
                CmbGender.SelectedValuePath = "Gender1";
                //вывод инфы
                var runnerInf = db.Runner.AsNoTracking().FirstOrDefault(r => r.Email == LocalStorage.UserClass.Email);
                CmbGender.SelectedValue      = runnerInf.Gender;
                DateOfBirthPick.SelectedDate = runnerInf.DateOfBirth;
                CmbCountry.SelectedValue     = runnerInf.CountryCode;

                var user = db.User.AsNoTracking().FirstOrDefault(u => u.Email == LocalStorage.UserClass.Email);

                // Загрузка изображения из бд.
                try
                {
                    var i = new BitmapImage();
                    using (var ms = new MemoryStream(user.Image))
                    {
                        ms.Position = 0;
                        i.BeginInit();
                        i.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                        i.CacheOption   = BitmapCacheOption.OnLoad;
                        i.UriSource     = null;
                        i.StreamSource  = ms;
                        i.EndInit();
                    }
                    i.Freeze();

                    ImgProfile.Source = i;
                }
                catch
                {
                }
            }
            #endregion
        }
Пример #8
0
        public void Load()
        {
            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    int selectedStatus = Convert.ToInt32(CmbStatus.SelectedValue.ToString());
                    var Runners        = (from runner in db.Runner
                                          join user in db.User on runner.Email equals user.Email
                                          join reg in db.Registration on runner.RunnerId equals reg.RunnerId
                                          join regEv in db.RegistrationEvent on reg.RegistrationId equals regEv.RegistrationId
                                          join Ev in db.Event on regEv.EventId equals Ev.EventId
                                          join regStat in db.RegistrationStatus on reg.RegistrationStatusId equals regStat.RegistrationStatusId
                                          where regStat.RegistrationStatusId == selectedStatus && Ev.EventTypeId == CmbDistance.SelectedValue.ToString()
                                          select new
                    {
                        FirstName = user.FirstName,
                        LastName = user.LastName,
                        Email = runner.Email,
                        Status = regStat.RegistrationStatus1,
                        StatusId = regStat.RegistrationStatusId
                    }
                                          ).ToList();

                    #region сортировка

                    switch (CmbSortBy.SelectedValue)
                    {
                    case "1":
                        RunnersList.ItemsSource = Runners.OrderBy(s => s.LastName);
                        break;

                    case "2":
                        RunnersList.ItemsSource = Runners.OrderBy(s => s.FirstName);
                        break;

                    case "3":
                        RunnersList.ItemsSource = Runners.OrderBy(s => s.Email);
                        break;
                    }
                    #endregion

                    LblCount.Content = Runners.Count();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #9
0
        public void Load()
        {
            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    int LastMarathon = db.MarathonTbl.Count();
                    int runnerId     = Convert.ToInt32(LocalStorage.UserClass.RunnerId);
                    var SponsorSh    = (from runner in db.Runner
                                        join reg in db.Registration on runner.RunnerId equals reg.RunnerId
                                        join regEv in db.RegistrationEvent on reg.RegistrationId equals regEv.RegistrationId
                                        join ev in db.Event on regEv.EventId equals ev.EventId
                                        join sp in db.Sponsorship on reg.RegistrationId equals sp.RegistrationId

                                        where runner.RunnerId == runnerId && ev.MarathonId == LastMarathon
                                        select new
                    {
                        regId = reg.RegistrationId,
                        spName = sp.SponsorName,
                        amount = sp.Amount
                    }
                                        ).ToList();
                    if (SponsorSh.Count == 0)
                    {
                        MessageBox.Show("У вас нет спонсоров на текущий марафон");
                        return;
                    }
                    var SponsLst = SponsorSh.Distinct();
                    SponsorsList.ItemsSource = SponsLst;

                    string path       = Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug\\Marathon.exe", "");
                    int    id         = SponsorSh[0].regId;
                    var    charityInf = db.Registration.FirstOrDefault(reg => reg.RegistrationId == id).Charity;
                    LblChName.Content = charityInf.CharityName;
                    LblDesc.Text      = charityInf.CharityDescription;
                    ImgLogo.Source    = new BitmapImage(new Uri(path + "CharityLogos/" + charityInf.CharityLogo));
                    foreach (var item in SponsLst)
                    {
                        Amount += item.amount;
                    }
                    LblCount.Content = "$" + Amount.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #10
0
        public void LoadAll()
        {
            using (var db = new MarathonDBEntities1())
            {
                var CountryList = db.Country.ToList();
                CmbCountry.ItemsSource       = CountryList;
                CmbCountry.DisplayMemberPath = "CountryName";
                CmbCountry.SelectedValuePath = "CountryCode";
                CmbCountry.SelectedIndex     = 0;

                var GenderList = db.Gender.ToList();
                CmbGender.ItemsSource       = GenderList;
                CmbGender.DisplayMemberPath = "Gender1";
                CmbGender.SelectedValuePath = "Gender1";
                CmbGender.SelectedIndex     = 0;
            }
        }
Пример #11
0
        private void LoadData()
        {
            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    var speed = db.Speed.AsNoTracking().ToList();
                    foreach (var sp in speed)
                    {
                        string     way      = Assembly.GetExecutingAssembly().Location.Replace("Marathon.exe", "how long is marathon/");
                        SpeedClass newSpeed = new SpeedClass
                        {
                            Id        = sp.SpeedId,
                            Name      = sp.Name,
                            ImgSource = new BitmapImage(new Uri(way + sp.Image)),
                            Speed     = sp.TopSpeed
                        };
                        speedList.Add(newSpeed);
                    }
                    ListVSpeed.ItemsSource       = speedList;
                    ListVSpeed.SelectedValuePath = "Id";


                    var distances = db.Distance.AsNoTracking().ToList();
                    foreach (var sp in distances)
                    {
                        string        way     = Assembly.GetExecutingAssembly().Location.Replace("Marathon.exe", "how long is marathon/");
                        DistanceClass newDist = new DistanceClass
                        {
                            Id        = sp.DistanceId,
                            Name      = sp.Name,
                            ImgSource = new BitmapImage(new Uri(way + sp.Image)),
                            Distance  = sp.Length
                        };
                        distanceList.Add(newDist);
                    }
                    ListVDistance.ItemsSource       = distanceList;
                    ListVDistance.SelectedValuePath = "Id";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #12
0
 public void LoadAll()
 {
     using (var db = new MarathonDBEntities1())
     {
         var         charities = db.Charity.ToList();
         List <Data> lizt      = new List <Data>();
         string      path      = Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug\\Marathon.exe", "");
         foreach (var charityOrganization in charities)
         {
             Data d = new Data
             {
                 Info      = charityOrganization.CharityName + "\n" + "\n" + charityOrganization.CharityDescription,
                 ImagePath = path + "CharityLogos/" + charityOrganization.CharityLogo
             };
             lizt.Add(d);
         }
         ListCharity.ItemsSource = lizt;
     }
 }
Пример #13
0
        private void Load()
        {
            #region Код загрузки и сортировки данных
            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    var Volunteers = (from vol in db.Volunteer
                                      select new
                    {
                        LastName = vol.LastName,
                        FirstName = vol.FirstName,
                        gender = vol.Gender,
                        country = vol.Country.CountryName
                    }
                                      ).ToList();
                    switch (CmbSortBy.SelectedValue)
                    {
                    case "1":
                        VolunteersList.ItemsSource = Volunteers.OrderBy(v => v.LastName);
                        break;

                    case "2":
                        VolunteersList.ItemsSource = Volunteers.OrderBy(v => v.FirstName);
                        break;

                    case "3":
                        VolunteersList.ItemsSource = Volunteers.OrderBy(v => v.country);
                        break;

                    case "4":
                        VolunteersList.ItemsSource = Volunteers.OrderBy(v => v.gender);
                        break;
                    }
                    LblCount.Content = Volunteers.Count();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            #endregion
        }
Пример #14
0
        public WinRunnersInfoManage()
        {
            InitializeComponent();
            LocalStorage.TimeCalc(LblTime);

            EmailGrid.Visibility = Visibility.Collapsed;
            #region подготовка для сортировки

            List <SortBy> sorts = new List <SortBy>();
            sorts.Add(new SortBy {
                Id = "1", Value = "Фамилия"
            });
            sorts.Add(new SortBy {
                Id = "2", Value = "Имя"
            });
            sorts.Add(new SortBy {
                Id = "3", Value = "Email"
            });
            CmbSortBy.ItemsSource       = sorts;
            CmbSortBy.DisplayMemberPath = "Value";
            CmbSortBy.SelectedValuePath = "Id";
            CmbSortBy.SelectedIndex     = 0;

            using (var db = new MarathonDBEntities1())
            {
                var Status = db.RegistrationStatus.ToList();
                CmbStatus.ItemsSource       = Status;
                CmbStatus.DisplayMemberPath = "RegistrationStatus1";
                CmbStatus.SelectedValuePath = "RegistrationStatusId";


                var Distance = db.EventType.ToList();
                CmbDistance.ItemsSource       = Distance;
                CmbDistance.DisplayMemberPath = "EventTypeName";
                CmbDistance.SelectedValuePath = "EventTypeId";
            }

            #endregion
            CmbStatus.SelectedIndex   = 0;
            CmbDistance.SelectedIndex = 0;
            Load();
        }
Пример #15
0
        private void BtnSaveChanges_Click(object sender, RoutedEventArgs e)
        {
            if (TxtFirstName.Text == "" || TxtLastName.Text == "" || DateOfBirthPick.SelectedDate == null)
            {
                MessageBox.Show("Не все поля заполнены!");
                return;
            }

            #region Проверка пароля.
            if (PasswdBox.Password != "" && PasswdBox.Password != " ")
            {
                Regex reg = new Regex(@"[a-z]");

                if (!reg.IsMatch(PasswdBox.Password))
                {
                    MessageBox.Show("Пароль должен содержать как минимум 1 прописную букву");
                    return;
                }

                reg = new Regex(@"[0-9]");
                if (!reg.IsMatch(PasswdBox.Password))
                {
                    MessageBox.Show("Пароль должен содержать как минимум 1 цифру");
                    return;
                }

                reg = new Regex(@"[!@#$%^]");
                if (!reg.IsMatch(PasswdBox.Password))
                {
                    MessageBox.Show("Пароль должен содержать как минимум один из следующих символов\n !@#$%^");
                    return;
                }
                if (PasswdBox.Password != ConfirmPasswdBox.Password)
                {
                    MessageBox.Show("Пароли не совпадают!");
                    return;
                }
            }
            #endregion

            #region Проверка возраста
            int yearOld = DateTime.Now.Year - Convert.ToInt32(DateOfBirthPick.SelectedDate.Value.Year);
            if (DateTime.Now.DayOfYear < DateOfBirthPick.SelectedDate.Value.DayOfYear)
            {
                yearOld--;
                if (yearOld < 10)
                {
                    MessageBox.Show("Вам должно быть больше 10 лет");
                    return;
                }
            }
            #endregion


            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    //обновление бегуна
                    var updRunner = db.Runner.FirstOrDefault(r => r.Email == LocalStorage.UserClass.Email);
                    updRunner.CountryCode = CmbCountry.SelectedValue.ToString();
                    updRunner.DateOfBirth = DateOfBirthPick.SelectedDate;
                    updRunner.Gender      = CmbGender.SelectedValue.ToString();

                    //обновление юзера
                    var updUser = db.User.FirstOrDefault(u => u.Email == LocalStorage.UserClass.Email);
                    if (PasswdBox.Password != "" && PasswdBox.Password != " ")
                    {
                        updUser.Password = PasswdBox.Password;
                    }
                    updUser.FirstName = TxtFirstName.Text;
                    updUser.LastName  = TxtLastName.Text;

                    if (TxtPhotoFile.Text != "")
                    {
                        Byte[]       img    = null;
                        FileStream   stream = new FileStream(TxtPhotoFile.Text, FileMode.Open, FileAccess.Read);
                        StreamReader read   = new StreamReader(stream);
                        img = new byte[stream.Length - 1];
                        stream.Read(img, 0, (int)stream.Length - 1);
                        updUser.Image = img;
                    }

                    db.SaveChanges();
                    MessageBox.Show("Изменения внесены успешно");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #16
0
        public void LoadResults()
        {
            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    int runnerId = Convert.ToInt32(LocalStorage.UserClass.RunnerId);

                    var RunnerInfo = db.Runner.FirstOrDefault(r => r.RunnerId == runnerId);
                    LblGender.Content = RunnerInfo.Gender;

                    int yearOld = DateTime.Now.Year - Convert.ToInt32(RunnerInfo.DateOfBirth.Value.Year);
                    if (DateTime.Now.DayOfYear < RunnerInfo.DateOfBirth.Value.DayOfYear)
                    {
                        yearOld--;
                    }
                    if (yearOld <= 18)
                    {
                        LblAge.Content = "до 18";
                    }
                    else if (yearOld > 18 && yearOld <= 29)
                    {
                        LblAge.Content = "18 - 29";
                    }
                    else if (yearOld >= 30 && yearOld <= 39)
                    {
                        LblAge.Content = "30 - 39";
                    }
                    if (yearOld >= 40 && yearOld <= 55)
                    {
                        LblAge.Content = "40 - 55";
                    }
                    if (yearOld >= 56 && yearOld <= 70)
                    {
                        LblAge.Content = "56 - 70";
                    }
                    if (yearOld > 70)
                    {
                        LblAge.Content = "больше 70";
                    }


                    #region Проверка кол-ва забегов

                    var ResultsLinq = (from reg in db.Registration
                                       join regEv in db.RegistrationEvent on reg.RegistrationId equals regEv.RegistrationId
                                       join ev in db.Event on regEv.EventId equals ev.EventId
                                       join mthn in db.MarathonTbl on ev.MarathonId equals mthn.MarathonId
                                       join evType in db.EventType on ev.EventTypeId equals evType.EventTypeId
                                       join runner in db.Runner on reg.RunnerId equals runner.RunnerId
                                       orderby regEv.RaceTime
                                       where reg.RunnerId == runnerId && !(regEv.RaceTime == null || regEv.RaceTime == 0)
                                       select new
                    {
                        Marathon = mthn.YearHeld + " " + mthn.Country.CountryName,
                        Distance = evType.EventTypeName,
                        Time = regEv.RaceTime,
                        CummonPlace = "",
                        CategoryPlace = "",
                        Gender = runner.Gender,
                        EventId = ev.EventId,
                        RegisterId = reg.RegistrationId
                    }).ToList();


                    if (ResultsLinq.Count == 0)
                    {
                        MessageBox.Show("Вы еще не соревновались \nУ вас нет результатов");
                        return;
                    }

                    #endregion


                    List <Result> ListResult = new List <Result>();

                    var RegistrIds = RunnerInfo.Registration.Where(reg => reg.RunnerId == runnerId).ToList();
                    var RaceTimes  = db.RegistrationEvent.OrderBy(rt => rt.RaceTime).Where(u => u.RaceTime != 0 || u.RaceTime != null).ToList();

                    int j = 0;
                    foreach (var item in RegistrIds)
                    {
                        var t = RaceTimes.FindAll(u => u.RegistrationId == item.RegistrationId);

                        foreach (var itemT in t)
                        {
                            var CategoryRaceTimes = RaceTimes.Where(u => u.EventId == itemT.EventId).ToList();

                            string i = Convert.ToInt32(RaceTimes.IndexOf(itemT) + 1).ToString();
                            string p = "";
                            foreach (var asd in CategoryRaceTimes)
                            {
                                p = Convert.ToInt32(CategoryRaceTimes.IndexOf(asd) + 1).ToString();
                            }
                            Result res = new Result
                            {
                                Marathon      = ResultsLinq[j].Marathon,
                                Distance      = ResultsLinq[j].Distance,
                                Time          = ResultsLinq[j].Time.ToString(),
                                CummonPlace   = i,
                                CategoryPlace = p
                            };
                            ListResult.Add(res);
                        }


                        j++;
                    }
                    ListResults.ItemsSource = ListResult;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Пример #17
0
        private void BtnLoad_Click(object sender, RoutedEventArgs e)
        {
            string[] volunteersList = File.ReadAllLines(fileName);
            Regex    reg            = new Regex(@"[0-9]");

            try
            {
                using (var db = new MarathonDBEntities1())
                {
                    foreach (var volunteer in volunteersList)
                    {
                        string[] volunteerInfo = volunteer.Split(',');
                        Match    match         = reg.Match(volunteerInfo[0]);
                        if (match.Success)
                        {
                            int id  = Convert.ToInt32(volunteerInfo[0]);
                            var vol = db.Volunteer.FirstOrDefault(v => v.VolunteerId == id);


                            if (volunteerInfo[1] == "" || volunteerInfo[1] == null)
                            {
                                MessageBox.Show("Не указанор имя");
                                return;
                            }
                            if (volunteerInfo[2] == "" || volunteerInfo[2] == null)
                            {
                                MessageBox.Show("Не указана фамилия");
                                return;
                            }
                            if (volunteerInfo[3] == "" || volunteerInfo[3] == null)
                            {
                                MessageBox.Show("не указана страна");
                                return;
                            }
                            if (volunteerInfo[4] == "F")
                            {
                                volunteerInfo[4] = "Female";
                            }
                            else if (volunteerInfo[4] == "M")
                            {
                                volunteerInfo[4] = "Male";
                            }
                            else
                            {
                                MessageBox.Show("В файле указан неверный пол");
                                return;
                            }
                            if (vol == null)
                            {
                                Volunteer vol1 = new Volunteer();
                                vol1.FirstName   = volunteerInfo[1];
                                vol1.LastName    = volunteerInfo[2];
                                vol1.CountryCode = volunteerInfo[3];
                                vol1.Gender      = volunteerInfo[4];
                                db.Volunteer.Add(vol1);
                                newVolunt++;
                            }
                            vol             = new Volunteer();
                            vol.FirstName   = volunteerInfo[1];
                            vol.LastName    = volunteerInfo[2];
                            vol.CountryCode = volunteerInfo[3];
                            vol.Gender      = volunteerInfo[4];
                            updVolunt++;
                            db.SaveChanges();
                        }
                    }
                    MessageBox.Show("Изменения внесены успешно\n" + updVolunt + " волонтеров обновлено\n" + newVolunt + " волонтеров добавлено");
                    newVolunt = 0;
                    updVolunt = 0;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #18
0
        private void BtnPay_Click(object sender, RoutedEventArgs e)
        {
            if (TxtName.Text != "" && TxtName.Text != " " && TxtCardInf.Text != "" && TxtCardInf.Text != " " && Money > 0 && CmbRunners.SelectedIndex > -1)
            {
                try
                {
                    Int32.Parse(TxtMonth.Text);
                    Int32.Parse(TxtYear.Text);
                    Int64.Parse(TxtCardNum.Text);
                    Int32.Parse(TxtCVC.Text);
                }
                catch
                {
                    MessageBox.Show("Поля не заполнены или не верный тип данных");
                    return;
                }

                if (TxtCardNum.Text.Length < 16)
                {
                    MessageBox.Show("Номер карты должен содержать 16 цифр!");
                    return;
                }

                if (Convert.ToInt32(TxtMonth.Text) > 12 || Convert.ToInt32(TxtMonth.Text) < 1)
                {
                    MessageBox.Show("Неверный месяц");
                    return;
                }

                if (Convert.ToInt32(TxtYear.Text) < 2016 || Convert.ToInt32(TxtYear.Text) > 3000)
                {
                    MessageBox.Show("Неверный год");
                    return;
                }

                DateTime startTime = new DateTime(Convert.ToInt32(TxtYear.Text), Convert.ToInt32(TxtMonth.Text), 1);
                DateTime now       = DateTime.Now;
                TimeSpan span      = startTime.Subtract(now);

                if (span.Days <= 0)
                {
                    MessageBox.Show("Карта не активна");
                    return;
                }

                if (TxtCVC.Text.Length < 3)
                {
                    MessageBox.Show("CVC карты должен содержать 3 цифры!");
                    return;
                }

                using (var DataBase = new MarathonDBEntities1())
                {
                    Sponsorship Sponsor = new Sponsorship
                    {
                        SponsorName    = TxtName.Text,
                        RegistrationId = Convert.ToInt32(CmbRunners.SelectedValue),
                        Amount         = Convert.ToDecimal(Money)
                    };

                    DataBase.Sponsorship.Add(Sponsor);
                    DataBase.SaveChanges();
                }

                LocalStorage.SelectedRunnerForSponsorShip.Amount      = Money;
                LocalStorage.SelectedRunnerForSponsorShip.CharityName = CharityInform.CharityName;

                new WinSponsorThanks().Show();
                Close();
            }
            else
            {
                MessageBox.Show("Введены некорректные данные");
                return;
            }
        }
Пример #19
0
        private void BtnRegister_Click(object sender, RoutedEventArgs e)
        {
            User   NewUser   = new User();
            Runner NewRunner = new Runner();

            if (PasswdBox.Password == "" || PasswdBox.Password == " " || ConfirmPasswdBox.Password == "" || ConfirmPasswdBox.Password == " " ||
                TxtFirstName.Text == "" || TxtFirstName.Text == " " || TxtLastName.Text == "" || TxtLastName.Text == " " || BirthOfDatePick.SelectedDate == null)
            {
                MessageBox.Show("Заполнены не все поля!");
                return;
            }

            NewUser.RoleId        = "R";
            NewUser.FirstName     = TxtFirstName.Text;
            NewUser.LastName      = TxtLastName.Text;
            NewRunner.Gender      = CmbGender.SelectedValue.ToString();
            NewRunner.CountryCode = CmbCountry.SelectedValue.ToString();

            #region Проверка Email.
            EmailAddressAttribute emailCheck = new EmailAddressAttribute();
            if (!emailCheck.IsValid(TxtEmail.Text))
            {
                MessageBox.Show("Введен некорректный Email");
                return;
            }

            #endregion
            NewUser.Email   = TxtEmail.Text;
            NewRunner.Email = TxtEmail.Text;

            #region Проверка пароля.
            if (PasswdBox.Password.Length < 6)
            {
                MessageBox.Show("Пароль должен содержать не менее 6 символов");
                return;
            }

            if (ConfirmPasswdBox.Password != PasswdBox.Password)
            {
                MessageBox.Show("Пароли не совпадают");
                return;
            }

            Regex reg = new Regex(@"[a-z]");
            if (!reg.IsMatch(PasswdBox.Password))
            {
                MessageBox.Show("Пароль должен содержать как минимум 1 прописную букву");
                return;
            }

            reg = new Regex(@"[0-9]");
            if (!reg.IsMatch(PasswdBox.Password))
            {
                MessageBox.Show("Пароль должен содержать как минимум 1 цифру");
                return;
            }

            reg = new Regex(@"[!@#$%^]");
            if (!reg.IsMatch(PasswdBox.Password))
            {
                MessageBox.Show("Пароль должен содержать как минимум один из следующих символов\n !@#$%^");
                return;
            }
            #endregion
            NewUser.Password = PasswdBox.Password;

            #region Подсчет возраста.
            int yearOld = DateTime.Now.Year - Convert.ToInt32(BirthOfDatePick.SelectedDate.Value.Year);
            if (DateTime.Now.DayOfYear < BirthOfDatePick.SelectedDate.Value.DayOfYear)
            {
                yearOld--;
                if (yearOld < 10)
                {
                    MessageBox.Show("Вы не можете зарегистрироваться, так как вам меньше 10 лет");
                    return;
                }
            }
            #endregion
            NewRunner.DateOfBirth = Convert.ToDateTime(BirthOfDatePick.SelectedDate);

            #region Сохранение изображения.
            if (LblFileName.Content != "")
            {
                try
                {
                    Byte[]       ImgData = null;
                    FileStream   stream  = new FileStream(LblFileName.Content.ToString(), FileMode.Open, FileAccess.Read);
                    StreamReader read    = new StreamReader(stream);
                    ImgData = new byte[stream.Length - 1];
                    stream.Read(ImgData, 0, (int)stream.Length - 1);

                    NewUser.Image = ImgData;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            #endregion

            using (var DataBase = new MarathonDBEntities1())
            {
                DataBase.User.Add(NewUser);
                DataBase.Runner.Add(NewRunner);
                DataBase.SaveChanges();
            }

            #region Сохранение данных в LocalStorage.
            LocalStorage.UserClass.Email     = TxtEmail.Text;
            LocalStorage.UserClass.FirstName = TxtFirstName.Text;
            LocalStorage.UserClass.LastName  = TxtLastName.Text;
            LocalStorage.UserClass.RunnerId  = NewRunner.RunnerId.ToString();
            #endregion
            new WinRegForTheMarathon().Show();
            Close();
        }
Пример #20
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            #region Проверка заполнения полей

            if (TxtName.Text == "" || TxtName.Text == " ")
            {
                MessageBox.Show("Заполните наименование организации");
                return;
            }
            if (TxtDesc.Text == "" || TxtDesc.Text == " ")
            {
                MessageBox.Show("Заполните описание организации");
                return;
            }
            if (TxtSource.Text == "")
            {
                MessageBox.Show("Установите логотип организации");
                return;
            }

            #endregion

            #region Если создаем организацию

            if (LocalStorage.CharityClass.CharityId == "" || LocalStorage.CharityClass.CharityId == null || LocalStorage.CharityClass.CharityId == " ")
            {
                Charity charity = new Charity();
                charity.CharityName        = TxtName.Text;
                charity.CharityDescription = TxtDesc.Text;
                string[] fileName = TxtSource.Text.Split('\\');
                string   way      = Assembly.GetExecutingAssembly().Location.Replace("bin\\Debug\\Marathon.exe", "CharityLogos\\" + fileName[fileName.Length - 1]);
                File.Copy(TxtSource.Text, way, true);
                charity.CharityLogo = fileName[fileName.Length - 1];
                try
                {
                    using (var db = new MarathonDBEntities1())
                    {
                        db.Charity.Add(charity);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            #endregion

            #region Если редачим существующую организацию

            else
            {
                try
                {
                    using (var db = new MarathonDBEntities1())
                    {
                        var charityOrg = db.Charity.FirstOrDefault(c => c.CharityId.ToString() == LocalStorage.CharityClass.CharityId);
                        charityOrg.CharityName        = TxtName.Text;
                        charityOrg.CharityDescription = TxtDesc.Text;
                        charityOrg.CharityLogo        = LocalStorage.CharityClass.CharityLogo.Replace("CharityLogos/", "");
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
            #endregion
            MessageBox.Show("Изменения внесены успешно!");
        }