Пример #1
0
        private static bool AddKart(Kart kart)
        {
            string querryString = $"INSERT INTO Kart (Kart, Available, Trans_Id) " +
                                  $"VALUES ('{kart.Name}','{kart.Available}','{kart.TransID}')";

            KartList.KList.Add(kart);

            return(Database.SetQuery(querryString));
        }
Пример #2
0
        /// <summary>
        /// Get direction of the received data.
        /// </summary>
        /// <param name="message"></param>
        private static void GetDirection(string message)
        {
            if (message == "Ping")
            {
                TcpPingTimer.Stop();
                TcpPingTimer.Interval = new TimeSpan(0, 0, 10);
                TcpPingTimer.Start();
                Send("Ping");
            }
            else
            {
                string[] text = message.Split('+');

                switch (text[0])
                {
                case "K":
                    Kart.SendKarts();
                    break;

                case "C":
                    if (Database.Insert("Course", "Course_Name, Course_Id, User_Id, Kart_Id, Date",
                                        $"'{text[1]}','{text[2]}','{text[3]}','{text[4]}','{text[5]}'"))
                    {
                        if (Database.Insert("Laps", "Course_Id, Kart_Id, Time, BestTime ,AbsoluteTime", $"'{text[2]}','{text[4]}','0:00.000','0:00.000','0:00.000'"))
                        {
                            CourseRowList.RefreshList();
                            CourseList.RefreshList();
                            if (LapCollection.LapList.Count(x => x.CourseID == text[2]) > 0)
                            {
                                LapCollection.RefreshList(text[2]);
                            }
                        }
                    }
                    break;

                case "P":
                    if (Database.Insert("CoursePlaces", "user,cart,course_id", $"'{text[1]}','{text[2]}','{text[3]}'"))
                    {
                        log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:New user joined Course: {text[1]} - {text[2]} - {text[3]}");
                    }
                    break;

                case "U":
                    if (Database.Insert("UserStatistics", "User_id,Course_id,Time",
                                        $"'{text[1]}','{text[2]}','{text[3]}'"))
                    {
                        log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:New User Statistic: {text[1]} - {text[2]} - {text[3]}");
                    }
                    break;

                case "R":
                    UserCollection.RefreshList();
                    foreach (User user in UserCollection.UserList)
                    {
                        Send($"R+{user.Email}+{user.Password}+{user.Name}+{user.Surname}+{user.Photo}");
                        log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:Sent user {user.Email} - {user.Name} - {user.Surname}");
                    }
                    break;

                case "Q":
                    if (Database.Insert("Users", "Email,Name,Surname,Password,Image",
                                        $"'{text[1]}','{text[2]}','{text[3]}','{text[4]}','{text[5]}'"))
                    {
                        log.Debug($"[{Settings.GetLine(new StackTrace(true))}]:New User Created: {text[1]} - {text[2]} - {text[3]}");
                    }
                    break;

                default:
                    log.Error($"[{Settings.GetLine(new StackTrace(true))}]:Unknown message: {message}");
                    break;
                }
            }
        }