예제 #1
0
 private void LoadBanks()
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         _BankList = context.BankSet.OrderBy(a => a.Name).ToList();
     }
 }
 private void RollbackRequsitionBatch(RequisitionBatch batch)
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         context.RequisitionBatchRollback(batch.id);
     }
 }
예제 #3
0
        private void CreateReport()
        {
            if (dlgSave.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            byte[] reportData = null;
            try
            {
                var building = cmbBuilding.SelectedItem as Building;
                using (var reportService = ReportServiceClient.CreateInstance())
                {
                    reportData = reportService.InsuranceSchedule(SqlDataHandler.GetConnectionString(), building.ID);
                    if (reportData != null)
                    {
                        File.WriteAllBytes(dlgSave.FileName, reportData);
                        Process.Start(dlgSave.FileName);
                    }
                    else
                    {
                        MessageBox.Show("No data for report.");
                    }
                }
            }
            catch (Exception exp)
            {
                Controller.HandleError(exp);
            }
        }
        public void CreateTournament()
        {
            TournamentModel tournament = new TournamentModel
                                             (TournamentName, IsLeague, HomeAndAway, VictoryPoints, DrawPoints, OfficialScore, EntryFee);

            SqlDataHandler.CreateTournament(tournament);

            foreach (TeamModel team in TournamentTeams)
            {
                tournament.ParticipatingTeams.Add(team);
            }

            RoundLogic.CreateDummyTeams(tournament);

            if (tournament.IsLeague)
            {
                foreach (TeamModel team in tournament.ParticipatingTeams)
                {
                    SqlDataHandler.CreateLeagueParticipant(tournament, team);
                }
            }

            foreach (PrizeModel prize in TournamentPrizes)
            {
                tournament.TournamentPrizes.Add(prize);
                SqlDataHandler.CreatePrize(tournament, prize);
            }

            RoundLogic.CreateRounds(tournament);

            var conductor = Parent as IConductor;

            conductor.ActivateItem(new HomeViewModel());
            //  TODO - activate tournamentView instead of homeView
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (e.RowIndex >= 0)
            {
                var selectedItem = senderGrid.Rows[e.RowIndex].DataBoundItem as MyReminders;
                if (selectedItem != null)
                {
                    using (var context = SqlDataHandler.GetDataContext())
                    {
                        var obj = context.tblReminders.Where(a => a.id == selectedItem.RemID).FirstOrDefault();

                        obj.action = selectedItem.Action;
                        if (selectedItem.Action)
                        {
                            obj.actionDate = DateTime.Now;
                        }
                        else
                        {
                            obj.actionDate = null;
                        }
                        context.SaveChanges();
                    }

                    UpdateRowColours();
                }
            }
        }
예제 #6
0
        public void CreateTeam()
        {
            TeamModel team = new TeamModel(TeamName);

            SqlDataHandler.CreateTeam(team);

            foreach (PlayerModel player in TeamMembers)
            {
                team.TeamMembers.Add(player);
                SqlDataHandler.CreateTeamMembers(team, player);
            }

            if (_tournamentCreationView != null)
            {
                var conductor = Parent as IConductor;
                _tournamentCreationView.TournamentTeams.Add(team);
                conductor.ActivateItem(_tournamentCreationView);
            }
            else
            {
                TeamName = "";
                TeamMembers.Clear();
                ErrorMessage = null;
            }
        }
        private void DisplayManagementPack(ManagementPackPreviewItem item)
        {
            _SelectedItem = item;
            Cursor        = Cursors.WaitCursor;
            try
            {
                Application.DoEvents();

                using (var context = SqlDataHandler.GetDataContext())
                {
                    var dataItem = context.ManagementPackSet.Single(a => a.id == _SelectedItem.Id);
                    tbComments.Text = dataItem.Commments;

                    string tempPDFFile = "";

                    tempPDFFile = Path.GetTempPath();
                    if (!tempPDFFile.EndsWith(@"\"))
                    {
                        tempPDFFile = tempPDFFile + @"\";
                    }

                    tempPDFFile = tempPDFFile + System.Guid.NewGuid().ToString("N") + ".pdf";
                    _SelectedItem.PDFFileName = tempPDFFile;
                    File.WriteAllBytes(_SelectedItem.PDFFileName, dataItem.ReportData);

                    DisplayPDF();
                }
            }
            finally
            {
                Cursor = Cursors.Default;
            }
        }
        private void LoadRequisitions()
        {
            this.Cursor = Cursors.WaitCursor;
            var building = cmbBuilding.SelectedItem as Building;

            try
            {
                _Data = new List <PastelMaintenanceTransaction>();
                using (var reportService = ReportServiceClient.CreateInstance())
                {
                    var items = reportService.MissingMaintenanceRecordsGet(SqlDataHandler.GetConnectionString(), building.ID);
                    if (items == null || items.Length == 0)
                    {
                        Controller.ShowMessage("No transactions found", "Warning");
                    }
                    else
                    {
                        _Data = items.ToList();
                        BindDataGrid();
                    }
                }
            }
            catch (Exception e)
            {
                var settings = dataContext.tblSettings.FirstOrDefault();

                Controller.HandleError("Error loading requisitions, please confirm the ODBC setup for \n" + building.DataPath + "\n as well as \n" + settings.trust + "\n" +
                                       e.Message);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
예제 #9
0
        private byte[] GetAttachment(String fileName, int attachmentType, out int fileID)
        {
            String fileQuery = "SELECT * FROM tblAttachments WHERE fileName = @fileName AND attachmentType = @at";

            Dictionary <String, Object> sqlParms = new Dictionary <string, object>();
            String         status;
            SqlDataHandler dataHandler = new SqlDataHandler();

            sqlParms.Clear();
            sqlParms.Add("@fileName", fileName);
            sqlParms.Add("@at", attachmentType);
            DataSet dsAttachment = dataHandler.GetData(fileQuery, sqlParms, out status);

            if (dsAttachment != null && dsAttachment.Tables.Count > 0 && dsAttachment.Tables[0].Rows.Count > 0)
            {
                byte[] file = (byte[])dsAttachment.Tables[0].Rows[0]["fileContent"];
                fileID = int.Parse(dsAttachment.Tables[0].Rows[0]["id"].ToString());
                return(file);
            }
            else
            {
                fileID = 0;
                return(null);
            }
        }
        private void button3_Click(object sender, EventArgs e)
        {
            if (_SelectedItem == null || String.IsNullOrWhiteSpace(_SelectedItem.PDFFileName))
            {
                Controller.HandleError("Please select an item from the list.", "Validation Error");
                return;
            }

            if (!Controller.AskQuestion("Are you sure you want to set the selected items as published notifying trustrees and without uploading to the website?"))
            {
                return;
            }

            using (var context = SqlDataHandler.GetDataContext())
            {
                var dataItem = context.ManagementPackSet.Single(a => a.id == _SelectedItem.Id);
                _SelectedItem.Processed = true;
                dataItem.Published      = true;
                dataItem.Commments      = tbComments.Text;
                context.SaveChanges();
                BindDataGrid();
                ClosePDF();
                Application.DoEvents();
            }
        }
        private void LoadBreakdown()
        {
            bs.Clear();
            String query = " SELECT u.name, ps.status, ps.actionDate FROM tblPMJobStatus AS ps INNER JOIN tblUsers AS u ON ps.actioned = u.id WHERE (ps.jobID = @jid) ORDER BY ps.actionDate";
            Dictionary <String, Object> sqlParms = new Dictionary <string, object>();

            sqlParms.Add("@jid", jobID);
            SqlDataHandler dh = new SqlDataHandler();
            String         status;
            DataSet        ds = dh.GetData(query, sqlParms, out status);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                DateTime iniDate = DateTime.Now;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    DataRow      dr = ds.Tables[0].Rows[i];
                    jobBreakdown jb = new jobBreakdown
                    {
                        user   = dr["name"].ToString(),
                        status = dr["status"].ToString(),
                        date   = dr["actionDate"].ToString()
                    };
                    jb.delay = i == 0 ? "" : CalcDiff(iniDate, DateTime.Parse(jb.date)).ToString();
                    iniDate  = DateTime.Parse(jb.date);
                    bs.Add(jb);
                }
            }
        }
        private void CreateExcel()
        {
            if (dlgSave.ShowDialog() == DialogResult.OK)
            {
                btnPrint.Enabled = false;
                try
                {
                    using (var reportService = ReportServiceClient.CreateInstance())
                    {
                        try
                        {
                            DateTime dDate      = new DateTime((cmbYear.SelectedItem as IdValue).Id, (cmbMonth.SelectedItem as IdValue).Id, 1);
                            var      idVal      = (cbUserList.SelectedItem as IdValue);
                            var      reportData = reportService.MonthlyReport(SqlDataHandler.GetConnectionString(), dDate, rdCompleted.Checked, idVal != null ? idVal.Id : (int?)null);

                            File.WriteAllBytes(dlgSave.FileName, reportData);
                            Process.Start(dlgSave.FileName);
                        }
                        catch (Exception ex)
                        {
                            Controller.HandleError(ex);

                            Controller.ShowMessage(ex.GetType().ToString());
                        }
                    }
                }
                finally
                {
                    btnPrint.Enabled = true;
                }
            }
        }
        private void dgMonthly_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var selectedItem = senderGrid.Rows[e.RowIndex].DataBoundItem as MonthReport;
                if (selectedItem != null)
                {
                    using (var context = SqlDataHandler.GetDataContext())
                    {
                        var curr = context.tblMonthFins.Where(a => a.id == selectedItem.Id).SingleOrDefault();
                        if (curr != null)
                        {
                            curr.AdditionalComments = selectedItem.AdditionalComments;

                            //future
                            var future = context.tblMonthFins.Where(a => a.buildingID == curr.buildingID && a.findate > curr.findate).ToList();
                            foreach (var item in future)
                            {
                                item.AdditionalComments = selectedItem.AdditionalComments;
                            }

                            context.SaveChanges();
                            Controller.ShowMessage("Comment updated");
                        }
                    }
                }
            }
        }
        private void LoadReminders()
        {
            bsRem.Clear();

            using (var context = SqlDataHandler.GetDataContext())
            {
                var start = DateTime.Today.AddDays(-30);

                var q = from r in context.tblReminders
                        where r.UserId == Controller.user.id &&
                        (r.action == false || r.actionDate == null || r.actionDate > start)
                        select new MyReminders()
                {
                    RemID        = r.id,
                    Building     = r.Building.Building,
                    Customer     = r.customer,
                    ReminderDate = r.remDate,
                    Reminder     = r.remNote,
                    Contacts     = r.Contacts,
                    Phone        = r.Phone,
                    Fax          = r.Fax,
                    Email        = r.Email,
                    Action       = r.action
                };

                bsRem.DataSource = q.OrderBy(a => a.Action).ThenBy(a => a.ReminderDate).ToList();
            }
        }
예제 #15
0
        private void WireUpTournamentOrder()
        {
            if (finishedTournament.IsLeague)
            {
                List <LeagueParticipantModel> leagueParticipants = SqlDataHandler.GetLeagueParticipantsForDisplay(finishedTournament.Id);
                _champion = new TeamModel(leagueParticipants.First().TeamName);
                _runnerUp = new TeamModel(leagueParticipants[1].TeamName);
                _thirdPlaced.Add(new TeamModel(leagueParticipants[2].TeamName));
            }
            else
            {
                RoundModel       finalRound   = finishedTournament.Rounds.Last();
                List <TeamModel> roundWinners = SqlDataHandler.GetRoundWinners(finalRound.Id);

                _champion = roundWinners.First();
                _runnerUp = new TeamModel(finalRound.Games[0].Competitors.Find(team => team.CupRoundWinner == false).TeamName);



                RoundModel                  secondToLastRound = finishedTournament.Rounds[finalRound.RoundNumber - 2];
                List <GameModel>            semiFinalGames    = SqlDataHandler.GetGamesByRound(secondToLastRound);
                List <GameParticipantModel> semiFinalLosers   = new List <GameParticipantModel>();

                foreach (GameModel game in semiFinalGames)
                {
                    semiFinalLosers.Add(game.Competitors.Find(team => team.CupRoundWinner == false));
                }

                _thirdPlaced.Add(new TeamModel(semiFinalLosers[0].TeamName));
                _thirdPlaced.Add(new TeamModel(semiFinalLosers[1].TeamName));
            }
        }
예제 #16
0
        public TournamentSummaryViewModel(TournamentModel selectedTournament)
        {
            finishedTournament                  = selectedTournament;
            finishedTournament.Rounds           = SqlDataHandler.GetRoundsByTournament(finishedTournament.Id);
            finishedTournament.TournamentPrizes = SqlDataHandler.GetDataByTournament <PrizeModel>(selectedTournament.Id, "dbo.SP_GetPrizesByTournament");



            _tournamentName = finishedTournament.TournamentName;
            _trophyTitle    = $"{DateTime.Now.Year} Winner";



            WireUpTournamentOrder();



            WireUpTournamentAwards();



            WireUpHighestScoringGame();



            _participatingTeams = SqlDataHandler.GetTeamsByTournament(finishedTournament);
            _selectedTeam       = _participatingTeams[0];
            _teamMembers        = _selectedTeam.TeamMembers;
        }
 private void CommitRequisitionBatch(RequisitionBatch batch)
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         context.CommitRequisitionBatch(batch.id);
         SendPaymentNotifications(context, batch.id, Controller.user.email);
     }
 }
예제 #18
0
        private WebReportData GetBaseData(Building building)
        {
            WebReportData wrd = new WebReportData();

            wrd.building = building.Name;
            wrd.picture  = null;
            var logoData = new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString()).GetBuildingImage(building.ID);

            if (logoData != null)
            {
                using (var memLogo = new MemoryStream(logoData))
                {
                    Image img = Image.FromStream(memLogo);
                    wrd.picture = img;
                }
            }

            //String status;
            //DataSet dsPic = mysql.GetData("SELECT image FROM tt_content WHERE pid = " + building.pid + " AND CType = 'image'", null, out status);
            //if (dsPic != null && dsPic.Tables.Count > 0 && dsPic.Tables[0].Rows.Count > 0)
            //{
            //    String picture = dsPic.Tables[0].Rows[0]["image"].ToString();
            //    Classes.Sftp sftpClient = new Classes.Sftp(String.Empty, true);
            //    sftpClient.WorkingDirectory = "/srv/www/htdocs/uploads/pics";
            //    String thisDirectory = AppDomain.CurrentDomain.BaseDirectory;
            //    String file1 = picture.Replace(Path.GetFileNameWithoutExtension(picture), Path.GetFileNameWithoutExtension(picture) + "_web1");
            //    String tempPath = Path.Combine(thisDirectory, file1);
            //    bool success = sftpClient.Download(tempPath, picture, false, out status);
            //    if (!success)
            //    {
            //        MessageBox.Show(status);
            //        wrd.picture = null;
            //    }
            //    else
            //    {
            //        Image img = Image.FromFile(file1);
            //        wrd.picture = img;
            //    }
            //}
            //else
            //{
            //    wrd.picture = null;
            //}

            List <String> folders   = LoadFolders(building.webFolder);
            List <String> rootFiles = ListFiles(building.webFolder, String.Empty);

            wrd.files.Add("Root", rootFiles);
            foreach (String folder in folders)
            {
                try
                {
                    wrd.files.Add(folder, ListFiles(building.webFolder, folder));
                }
                catch (Exception ex) { Controller.HandleError(ex); }
            }
            return(wrd);
        }
예제 #19
0
        private void dgJobs_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            int            jobID  = int.Parse(e.Row.Cells[0].Value.ToString());
            String         query  = "DELETE FROM tblPMJob WHERE id = " + jobID.ToString();
            SqlDataHandler dh     = new SqlDataHandler();
            String         status = "";

            dh.SetData(query, null, out status);
        }
        public HomeViewModel()
        {
            _existingTournaments = new BindableCollection <TournamentModel>(SqlDataHandler.GetAllData <TournamentModel>("dbo.SP_GetAllTournaments"));

            foreach (TournamentModel tournament in _existingTournaments)
            {
                tournament.Rounds = SqlDataHandler.GetRoundsByTournament(tournament.Id);
            }
        }
예제 #21
0
        private void SaveBuilding()
        {
            building.Name             = txtName.Text;
            building.Abbr             = txtAbbr.Text;
            building.Trust            = txtTrust.Text;
            building.DataPath         = txtPath.Text;
            building.Period           = int.Parse(txtPeriod.Text);
            building.Cash_Book        = txtCash.Text;
            building.Payments         = int.Parse(txtPayment.Text);
            building.Receipts         = int.Parse(txtReceipt.Text);
            building.Journal          = int.Parse(txtJournal.Text);
            building.Centrec_Account  = txtCentrec1.Text;
            building.Centrec_Building = txtCentrec2.Text;
            building.Business_Account = txtBus.Text;
            building.Bank             = txtBank.Text;
            building.PM              = txtPM.Text;
            building.Bank_Name       = txtBankName.Text;
            building.Bank_Acc_Number = txtAccNumber.Text;
            building.Acc_Name        = txtAccName.Text;
            building.Branch_Code     = txtBranch.Text;
            building.Web_Building    = chkWeb.Checked;
            building.letterName      = txtLetter.Text;
            building.addy1           = txtAddress1.Text;
            building.addy2           = txtAddress2.Text;
            building.addy3           = txtAddress3.Text;
            building.addy4           = txtAddress4.Text;
            building.addy5           = txtAddress5.Text;

            Buildings BuildingManager = new Buildings(true);
            String    websafeName     = building.Name.Replace(" ", "_").Replace("/", "_").Replace("\\", "_");

            building.webFolder = websafeName;
            try
            {
                String status = String.Empty;
                if (BuildingManager.Update(building, out status))
                {
                    String newID = "";
                    building.pid = newID;
                    BuildingManager.Update(building, out status);

                    new AstrodonClientPortal(SqlDataHandler.GetClientPortalConnectionString()).SyncBuildingAndClients(building.ID);

                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Building update failed: SV3" + status, "Buildings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Building update failed: SV4" + ex.Message, "Buildings", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 //          CONSTRUCTOR
 public CreateNewTournamentViewModel()
 {
     _tournamentTeams  = new BindableCollection <TeamModel>();
     _tournamentPrizes = new BindableCollection <PrizeModel>();
     _availableTeams   = new BindableCollection <TeamModel>(SqlDataHandler.GetAllData <TeamModel>("dbo.SP_GetAllTeams"));
     TournamentTeams.CollectionChanged += TournamentTeams_CollectionChanged;
     _victoryPoints = 3;
     _drawPoints    = 1;
     _officialScore = 3;
 }
        private void btnSupplierLookup_Click(object sender, EventArgs e)
        {
            if (cmbBuilding.SelectedIndex < 0)
            {
                Controller.HandleError("Please select a building first.", "Validation Error");
                return;
            }
            var building   = cmbBuilding.SelectedItem as Building;
            var buildingId = building.ID;

            using (var context = SqlDataHandler.GetDataContext())
            {
                var frmSupplierLookup = new Astrodon.Forms.frmSupplierLookup(context, buildingId);

                var dialogResult = frmSupplierLookup.ShowDialog();
                var supplier     = frmSupplierLookup.SelectedSupplier;

                if (dialogResult == DialogResult.OK && supplier != null)
                {
                    _Supplier           = supplier;
                    lbSupplierName.Text = _Supplier.CompanyName;


                    var bankDetails = context.SupplierBuildingSet
                                      .Include(a => a.Bank)
                                      .SingleOrDefault(a => a.BuildingId == buildingId && a.SupplierId == _Supplier.id);
                    if (bankDetails == null)
                    {
                        Controller.HandleError("Supplier banking details for this building is not configured.\n" +
                                               "Please capture bank details for this building on the suppier detail screen.", "Validation Error");


                        var frmSupplierDetail = new Astrodon.Forms.frmSupplierDetail(context, _Supplier.id, buildingId);
                        frmSupplierDetail.ShowDialog();

                        bankDetails = context.SupplierBuildingSet
                                      .Include(a => a.Bank)
                                      .SingleOrDefault(a => a.BuildingId == buildingId && a.SupplierId == _Supplier.id);
                        if (bankDetails == null)
                        {
                            _Supplier = null;
                            return;
                        }
                    }

                    lbBankName.Text      = bankDetails.Bank.Name + " (" + bankDetails.BranceCode + ")";
                    lbAccountNumber.Text = bankDetails.AccountNumber;
                    btnSave.Enabled      = true;
                }
                else
                {
                    ClearSupplier();
                }
            }
        }
        private void LoadExistingPack()
        {
            var building = cmbBuilding.SelectedItem as Building;
            var year     = cmbYear.SelectedItem as IdValue;
            var month    = cmbMonth.SelectedItem as IdValue;

            var      dt  = new DateTime(year.Id, month.Id, 1);
            DateTime now = DateTime.Now;

            using (var context = SqlDataHandler.GetDataContext())
            {
                var managementPackReport = context.ManagementPackSet.Include(a => a.Items)
                                           .SingleOrDefault(a => a.BuildingId == building.ID && a.Period == dt);
                if (managementPackReport != null)
                {
                    tbComments.Text = managementPackReport.Commments;

                    _TableOfContents.Clear();
                    foreach (var item in managementPackReport.Items.OrderBy(a => a.Position))
                    {
                        if (item.IsTempFile)
                        {
                            var reportFileName = Path.GetTempFileName();
                            item.Path = reportFileName;
                            File.WriteAllBytes(item.Path, item.FileData);
                        }

                        if (File.Exists(item.Path))
                        {
                            _TableOfContents.Add(new TableOfContentForPdfRecord()
                            {
                                Path         = item.Path,
                                File         = item.File,
                                Description  = item.Description,
                                Description2 = item.Description2,
                                Pages        = item.Pages,
                                Position     = item.Position,
                                FileDate     = item.FileDate,
                                IsTempFile   = item.IsTempFile,
                                IncludeInTOC = true
                            });
                        }
                        else
                        {
                            Controller.ShowMessage("File: " + item.Path + " is missing or does not exist, item skipped.");
                        }
                    }
                }
            }

            if (_TableOfContents != null)
            {
                _TableOfContents = _TableOfContents.OrderBy(a => a.Position).ToList();
            }
        }
 private void LoadBuildings()
 {
     using (var context = SqlDataHandler.GetDataContext())
     {
         buildings = context.tblBuildings.Where(a => a.BuildingFinancialsEnabled &&
                                                a.BuildingDisabled == false &&
                                                (a.FinancialStartDate == null || a.FinancialStartDate <= DateTime.Today) &&
                                                (a.FinancialEndDate == null || a.FinancialEndDate >= DateTime.Today)
                                                ).ToList();
     }
 }
예제 #26
0
        public void CreatePlayer()
        {
            PlayerModel player = new PlayerModel(FirstName, LastName);

            SqlDataHandler.CreatePlayer(player);
            TeamMembers.Add(player);
            ValidateAllData();

            FirstName = null;
            LastName  = null;
        }
예제 #27
0
        private void LoadDefaultValues()
        {
            SqlDataHandler dh            = new SqlDataHandler();
            String         settingsQuery = "SELECT centrec FROM tblSettings";
            String         status;
            DataSet        dsDefault = dh.GetData(settingsQuery, null, out status);

            if (dsDefault != null && dsDefault.Tables.Count > 0 && dsDefault.Tables[0].Rows.Count > 0)
            {
                DataRow dr = dsDefault.Tables[0].Rows[0];
                centrec = dr["centrec"].ToString();
            }
        }
예제 #28
0
        public CupViewModel(TournamentModel selectedTournament)
        {
            CurrentTournament = selectedTournament;

            _tournamentName = CurrentTournament.TournamentName;
            _roundList      = new BindableCollection <RoundModel>(SqlDataHandler.GetRoundsByTournament(CurrentTournament.Id));

            EnterAutomaticResults();

            _selectedRound = _roundList[0];
            _gameList      = new BindableCollection <GameModel>(_selectedRound.Games);
            DisplayRound();
        }
예제 #29
0
        private void UpdateGameAndGameParticipants(GameModel game)
        {
            SqlDataHandler.UpdateGameScoreAndStatus(game);

            if (CurrentTournament.IsLeague)
            {
                SqlDataHandler.UpdateLeagueParticipants(CurrentTournament, game);
            }
            else
            {
                SqlDataHandler.UpdateGameParticipantAsCupRoundWinner(game);
            }
        }
예제 #30
0
        public void ValidateAllData()
        {
            List <string>    errors        = new List <string>();
            List <TeamModel> existingTeams = SqlDataHandler.GetAllData <TeamModel>("dbo.SP_GetAllTeams");
            List <string>    usedNames     = new List <string>();
            string           nameLower     = "";

            if (TeamName != null)
            {
                nameLower = TeamName.ToLower();
            }

            foreach (TeamModel team in existingTeams)
            {
                usedNames.Add(team.TeamName);
            }

            if (usedNames.Contains(TeamName))
            {
                errors.Add($"Team name {TeamName} is already taken.");
            }

            if (String.IsNullOrWhiteSpace(TeamName))
            {
                errors.Add("Team must have a name.");
            }

            if (nameLower.Contains("dummy"))
            {
                errors.Add(@"Team name must not contain word ""dummy"".");
            }

            if (TeamMembers.Count == 0)
            {
                errors.Add("Team must have at least 1 member.");
            }

            bool somethingWrong = usedNames.Contains(TeamName) || String.IsNullOrWhiteSpace(TeamName) ||
                                  nameLower.Contains("dummy") || TeamMembers.Count == 0;

            if (somethingWrong)
            {
                CanCreateTeam = false;
                ErrorMessage  = $"* {string.Join(" ", errors)}";
            }
            else
            {
                CanCreateTeam = true;
                ErrorMessage  = null;
            }
        }