Пример #1
0
    /* request all players of a specific championship from database for a client query */
    public void getChampionshipPlayers(ChampionshipData chmp, bool delay)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel <ICallBack>();

        if (delay)
        {
            ManualResetEvent delayEvent = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(new WaitCallback((_) =>
            {
                sleep();
                delayEvent.Set();
            }));
            delayEvent.WaitOne();
        }

        using (var db = new TTTDataClassesDataContext())
        {
            var          x       = db.PlayerChampionships.Where(pc => pc.ChampionshipId == chmp.Id);
            PlayerData[] players = new PlayerData[x.Count()];
            int          i       = 0;
            foreach (var pc in x)
            {
                players[i++] = getPlayerDataById(pc.PlayerId, db);
            }
            channel.sendPlayers(players, "Q");
        }
    }
Пример #2
0
    private ChampionshipData[] getAllChampionships(int playerId = -1)
    {
        using (var db = new TTTDataClassesDataContext())
        {
            IEnumerable <Championship> x = null;

            if (playerId == -1)
            {
                x = db.Championships;
            }
            else
            {
                var y = db.PlayerChampionships.Where(pc => pc.PlayerId == playerId);
                x = db.Championships.Where(c => y.Any(pc => pc.ChampionshipId == c.Id));
            }

            ChampionshipData[] chmps = new ChampionshipData[x.Count()];
            int i = 0;
            foreach (var c in x)
            {
                chmps[i++] = getChampionshipData(c);
            }
            return(chmps);
        }
    }
Пример #3
0
    /* delete the specific championship from database */
    public void deleteChampionship(ChampionshipData chmp)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel <ICallBack>();

        using (var db = new TTTDataClassesDataContext())
        {
            using (SqlConnection con = new SqlConnection(db.Connection.ConnectionString))
            {
                try
                {
                    bool success = deleteChampionshipDependencies(chmp.Id, db, con);

                    if (!success)
                    {
                        throw new Exception();
                    }

                    string     sql = string.Format("delete from Championships where Id={0}", chmp.Id);;
                    SqlCommand cmd = new SqlCommand(sql, con);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    channel.updateSuccess();
                }
                catch (Exception)
                {
                    channel.updateError("Some error occured while deleting from database");
                }
            }
        }
    }
Пример #4
0
        private void deleteSingleRow()
        {
            int row = ctrl.getSelectedRow();

            if (row == -1)
            {
                MessageBox.Show("No row is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (queryObjects is PlayerData[])
            {
                PlayerData player = ((PlayerData)queryObjects[row]);
                if (player.Id == 1)
                {
                    MessageBox.Show("Deletion of Server's user is not allowed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    mainForm.getClient().deletePlayer(player);
                }
            }
            else if (queryObjects is ChampionshipData[])
            {
                ChampionshipData chmp = ((ChampionshipData)queryObjects[row]);
                mainForm.getClient().deleteChampionship(chmp);
            }
        }
Пример #5
0
        private ChampionshipData getChampionshipFromFields()
        {
            ChampionshipData champ = new ChampionshipData();

            champ.City      = (tbCity.Text.Length > 0) ? tbCity.Text : null;
            champ.StartDate = dtpStartDate.Value;
            if (cbHasEnded.Checked)
            {
                champ.EndDate = dtpEndDate.Value;
            }
            else
            {
                champ.EndDate = null;
            }
            if (cbPicture.Checked && picPath != null)
            {
                var uri = new System.Uri(picPath);
                champ.Picture = uri.AbsoluteUri;
            }
            else
            {
                champ.Picture = null;
            }
            return(champ);
        }
 public void setChampionshipsList(ChampionshipData[] chmps)
 {
     this.championships = chmps;
     for (var i = 0; i < chmps.Length; i++)
     {
         clbChampionships.Items.Add(mainForm.championshipString(chmps[i]));
     }
 }
Пример #7
0
    private bool isPlayerRegisteredToChamp(PlayerData player, ChampionshipData champ, TTTDataClassesDataContext db)
    {
        var x =
            from pc in db.PlayerChampionships
            where pc.PlayerId == player.Id && pc.ChampionshipId == champ.Id
            select pc;

        return(x.Count() > 0);
    }
Пример #8
0
 public void setChampionshipsQuery(ChampionshipData[] chmps)
 {
     this.queryObjects = chmps;
     string[] titles = { "Id", "City", "StartDate", "EndDate", "Picture" };
     string[] types = { "int", "char", "datetime", "datetime", "image" };
     bool[] readOnly = { true, false, false, false, false };
     bool[] nullable = { false, false, false, true, true };
     ctrl = new QueryControl(queryObjects, titles, types, readOnly, nullable);
     tableElementHost.Child = ctrl;
     ctrl.setSelectionType(cbDelType.SelectedIndex == 1);
 }
Пример #9
0
    private ChampionshipData getChampionshipData(Championship c)
    {
        ChampionshipData champ = new ChampionshipData();

        champ.Id        = c.Id;
        champ.City      = c.City;
        champ.StartDate = c.StartDate;
        if (c.EndDate.HasValue)
        {
            champ.EndDate = c.EndDate;
        }
        champ.Picture = c.Picture;
        return(champ);
    }
Пример #10
0
 private void btnSubmit_Click(object sender, EventArgs e)
 {
     valid = true;
     this.ValidateChildren();
     if (valid)
     {
         btnSubmit.Enabled = false;
         btnCancel.Enabled = false;
         ChampionshipData champ = getChampionshipFromFields();
         mainForm.getClient().registerNewChampionship(champ);
     }
     else
     {
         MessageBox.Show("Some fields are missing or invalid", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Пример #11
0
        private ChampionshipData[] getSelectedChamps()
        {
            if (clbChampionships.CheckedIndices.Count < 1)
            {
                return(null);
            }

            ChampionshipData[] chmps = new ChampionshipData[clbChampionships.CheckedIndices.Count];
            int i = 0;

            foreach (var j in clbChampionships.CheckedIndices.Cast <int>().ToArray())
            {
                chmps[i++] = championships[j];
            }
            return(chmps);
        }
Пример #12
0
        public ChampionshipPanel(MainForm ParentForm)
            : base(325, 600, "Championships", ParentForm, Properties.Resources.Championships)
        {
            InitialiseControls();
            AddControls();

            DataController = new ChampionshipData(PointScoringSystem.Post2009, true, Session.Race);
            DataController.ChampionshipsModified += DataController_ChampionshipsModified;
            DataController.DriverDeltasUpdated   += DataController_DriverDeltasUpdated;
            DataController.TeamDeltasUpdated     += DataController_TeamDeltasUpdated;
            DataController.ComparisonCleared     += DataController_ComparisonCleared;
            DataController.SessionChanged        += DataController_SessionChanged;

            UpdateDriverPoints(DataController.Statistic);

            SetPanelProperties(DockTypes.Right, AutosizeTypes.AutoHeight, FillStyles.FullHeight, this.Size);
        }
Пример #13
0
    /* register new championship to database */
    public void registerNewChampionship(ChampionshipData champ)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel <ICallBack>();

        using (var db = new TTTDataClassesDataContext())
        {
            using (SqlConnection con = new SqlConnection(db.Connection.ConnectionString))
            {
                string sql;

                if (champ.EndDate == null)
                {
                    sql = string.Format("Insert into Championships(City, StartDate, Picture) "
                                        + "values('{0}', '{1}', '{2}')", champ.City, champ.StartDate, champ.Picture);
                }
                else
                {
                    sql = string.Format("Insert into Championships(City, StartDate, EndDate, Picture) "
                                        + "values('{0}', '{1}', '{2}', '{3}')", champ.City, champ.StartDate, champ.EndDate, champ.Picture);
                }

                SqlCommand cmd = new SqlCommand(sql, con);
                try
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    channel.showNewChampSuccess();
                }
                catch (Exception e)
                {
                    channel.showException(e);
                }
            }
        }
    }
Пример #14
0
    private ChampionshipData[] getAllChampionships(int playerId = -1)
    {
        using (var db = new TTTDataClassesDataContext())
        {
            IEnumerable<Championship> x = null;

            if (playerId == -1)
                x = db.Championships;
            else
            {
                var y = db.PlayerChampionships.Where(pc => pc.PlayerId == playerId);
                x = db.Championships.Where(c => y.Any(pc => pc.ChampionshipId == c.Id));
            }

            ChampionshipData[] chmps = new ChampionshipData[x.Count()];
            int i = 0;
            foreach (var c in x)
            {
                chmps[i++] = getChampionshipData(c);
            }
            return chmps;
        }
    }
Пример #15
0
    /* register new championship to database */
    public void registerNewChampionship(ChampionshipData champ)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel<ICallBack>();

        using (var db = new TTTDataClassesDataContext())
        {
            using (SqlConnection con = new SqlConnection(db.Connection.ConnectionString))
            {
                string sql;
                
                if (champ.EndDate == null)
                {
                    sql = string.Format("Insert into Championships(City, StartDate, Picture) "
                     + "values('{0}', '{1}', '{2}')", champ.City, champ.StartDate, champ.Picture);
                }
                else
                {
                    sql = string.Format("Insert into Championships(City, StartDate, EndDate, Picture) "
                     + "values('{0}', '{1}', '{2}', '{3}')", champ.City, champ.StartDate, champ.EndDate, champ.Picture);
                }
                
                SqlCommand cmd = new SqlCommand(sql, con);
                try
                {
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                    channel.showNewChampSuccess();
                }
                catch (Exception e)
                {
                    channel.showException(e);
                }
            }

        }
    }
Пример #16
0
    /* delete the specific championship from database */
    public void deleteChampionship(ChampionshipData chmp)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel<ICallBack>();

        using (var db = new TTTDataClassesDataContext())
        {
            using (SqlConnection con = new SqlConnection(db.Connection.ConnectionString))
            {
                try
                {
                    bool success = deleteChampionshipDependencies(chmp.Id, db, con);

                    if (!success)
                        throw new Exception();

                    string sql = string.Format("delete from Championships where Id={0}", chmp.Id); ;
                    SqlCommand cmd = new SqlCommand(sql, con);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                    channel.updateSuccess();
                }
                catch (Exception)
                {
                    channel.updateError("Some error occured while deleting from database");
                }
            }
        }
    }
Пример #17
0
    /* update the championships database with the changes received in the array */
    public void updateChampionships(ChampionshipData[] chmps)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel<ICallBack>();

        using (var db = new TTTDataClassesDataContext())
        {
            using (SqlConnection con = new SqlConnection(db.Connection.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("", con);
                try
                {
                    con.Open();

                    foreach (var c in chmps)
                    {
                        string sql = "Update Championships SET City='" + c.City + "', StartDate='" + c.StartDate + "'";

                        if (c.EndDate != null)
                            sql += ", EndDate='" + c.EndDate + "'";
                        else
                            sql += ", EndDate=NULL";

                        if (c.Picture != null && c.Picture.Replace(" ", String.Empty).Length > 0)
                            sql += ", Picture='" + c.Picture + "'";
                        else
                            sql += ", Picture=NULL";

                        sql += " where Id=" + c.Id;
                                
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                    }

                    con.Close();

                    channel.updateSuccess();
                }
                catch (Exception)
                {
                    channel.updateError("Some error occured while updating the database");
                }
            }
        }
    }
Пример #18
0
    /* request all players of a specific championship from database for a client query */
    public void getChampionshipPlayers(ChampionshipData chmp, bool delay)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel<ICallBack>();

        if (delay)
        {
            ManualResetEvent delayEvent = new ManualResetEvent(false);
            ThreadPool.QueueUserWorkItem(new WaitCallback((_) =>
            {
                sleep();
                delayEvent.Set();
            }));
            delayEvent.WaitOne();
        }

        using (var db = new TTTDataClassesDataContext())
        {
            var x = db.PlayerChampionships.Where(pc => pc.ChampionshipId == chmp.Id);
            PlayerData[] players = new PlayerData[x.Count()];
            int i = 0;
            foreach (var pc in x)
            {
                players[i++] = getPlayerDataById(pc.PlayerId, db);
            }
            channel.sendPlayers(players, "Q");
        }
    }
Пример #19
0
 public string championshipString(ChampionshipData champ)
 {
     return(champ.Id + " : " + Regex.Replace(champ.City, @"\s+", " ")
            + ": " + champ.StartDate.ToShortDateString());
 }
Пример #20
0
 public string championshipString(ChampionshipData champ)
 {
     return champ.Id + " : " + Regex.Replace(champ.City, @"\s+", " ")
         + ": " + champ.StartDate.ToShortDateString();
 }
Пример #21
0
 private ChampionshipData getChampionshipData(Championship c)
 {
     ChampionshipData champ = new ChampionshipData();
     champ.Id = c.Id;
     champ.City = c.City;
     champ.StartDate = c.StartDate;
     if (c.EndDate.HasValue)
         champ.EndDate = c.EndDate;
     champ.Picture = c.Picture;
     return champ;
 }
        private ChampionshipData[] getSelectedChamps()
        {
            if (clbChampionships.CheckedIndices.Count < 1)
                return null;

            ChampionshipData[] chmps = new ChampionshipData[clbChampionships.CheckedIndices.Count];
            int i = 0;
            foreach (var j in clbChampionships.CheckedIndices.Cast<int>().ToArray())
            {
                chmps[i++] = championships[j];
            }
            return chmps;
        }
Пример #23
0
    private bool isPlayerRegisteredToChamp(PlayerData player, ChampionshipData champ, TTTDataClassesDataContext db)
    {
        var x =
            from pc in db.PlayerChampionships
            where pc.PlayerId == player.Id && pc.ChampionshipId == champ.Id
            select pc;

        return x.Count() > 0;
    }
Пример #24
0
    /* register a player to championship(s) */
    public void registerPlayerToChamp(PlayerData player, ChampionshipData[] chmps)
    {
        ICallBack channel = OperationContext.Current.GetCallbackChannel<ICallBack>();

        if (player == null || chmps == null)
        {
            channel.registerPlayerToChampError("Error: data is corrupted");
            return;
        }

        using (var db = new TTTDataClassesDataContext())
        {
            using (SqlConnection con = new SqlConnection(db.Connection.ConnectionString))
            {
                SqlCommand cmd = new SqlCommand("", con);
                try
                {
                    con.Open();

                    for (var i = 0; i < chmps.Length; i++)
                    {
                        if (!isPlayerRegisteredToChamp(player, chmps[i], db))
                        {
                            cmd.CommandText = string.Format("Insert into PlayerChampionships(PlayerId, ChampionshipId) "
                                + "values({0}, {1})", player.Id, chmps[i].Id);
                            cmd.ExecuteNonQuery();
                        }
                    }

                    con.Close();
                    channel.registerPlayerToChampSuccess();
                }
                catch (Exception e)
                {
                    channel.showException(e);
                }
            }

        }
    }
Пример #25
0
 private ChampionshipData getChampionshipFromFields()
 {
     ChampionshipData champ = new ChampionshipData();
     champ.City = (tbCity.Text.Length > 0) ? tbCity.Text : null;
     champ.StartDate = dtpStartDate.Value;
     if (cbHasEnded.Checked)
         champ.EndDate = dtpEndDate.Value;
     else
         champ.EndDate = null;
     if (cbPicture.Checked && picPath != null)
     {
         var uri = new System.Uri(picPath);
         champ.Picture = uri.AbsoluteUri;
     }
     else
         champ.Picture = null;
     return champ;
 }
Пример #26
0
 public void sendChampionships(ChampionshipData[] chmps, string caller)
 {
     switch (caller)
     {
         case "R":   // register
             if (mainForm.regToChampForm != null)
                 mainForm.regToChampForm.setChampionshipsList(chmps);
             break;
         case "Q":   // query
             if (mainForm.queriesForm != null)
                 mainForm.queriesForm.setChampionshipsQuery(chmps);
             break;
         case "SQ":   // sub query
             if (mainForm.queriesForm != null)
                 mainForm.queriesForm.setSubQueryObjects(chmps);
             break;
     }
 }