예제 #1
0
        public IActionResult DenyMatch(string user, string title)
        {
            AspNetUsers       activeUser = FindUser();
            List <MatchTable> matches    = db.MatchTable.ToList <MatchTable>();
            MatchTable        newMatch   = new MatchTable();

            foreach (MatchTable match in matches)
            {
                if (match.UserSend == activeUser.Id)
                {
                    if (match.UserSend == user && match.Status != 2)
                    {
                        match.Status = 2;
                        db.SaveChanges();
                        return(Redirect("~/Home/HomePage"));
                    }
                }
            }

            MatchTable Deny = new MatchTable();

            Deny.UserSend = activeUser.Id;
            Deny.UserGet  = user;
            Deny.Status   = 2;
            db.MatchTable.Add(Deny);
            db.SaveChanges();

            ViewData["Search"] = title;

            return(Redirect("~/Home/HomePage"));
        }
예제 #2
0
        private void calculateMatch(Organ r)
        {
            // This will query the recipient wait list with information from the added organ r.
            // Next it will extract the top recipient from the wait list.
            // It will then add the recipient to the match table, intiating the trigger which will prompt the owner if they want to accept the organ.
            // FUTURE: Deal with cases where there is no need for the organ.

            RecipientWaitList waitList = new RecipientWaitList();
            int userID = r.MedicalPersonnelID;

            Medical_Personnel m = (from Medical_Personnel in OrganDonorSystemDB.Medical_Personnel
                                   where Medical_Personnel.medicalPersonnelId == userID
                                   select Medical_Personnel).Single();

            waitList.populateList(r.organType_organtypeID, r.BloodType_BloodTypeID, m.State, m.City);
            if (waitList.getList().Count() > 0)
            {
                Recipient reciever = waitList.getList()[0];

                MatchTable newEntry = new MatchTable();
                newEntry.acceptedOrDeclined             = null;
                newEntry.medicalPersonnelIdForRecipient = reciever.medicalPersonnelID;
                newEntry.organID     = r.OrganID;
                newEntry.organType   = r.organType_organtypeID;
                newEntry.recipientID = reciever.recipentID;


                OrganDonorSystemDB.AddToMatchTables(newEntry);
                OrganDonorSystemDB.SaveChanges();
            }
        }
예제 #3
0
        public IActionResult MatchUsers(string matchUser)
        {
            AspNetUsers       activeUser = FindUser();
            List <MatchTable> matches    = db.MatchTable.ToList <MatchTable>();
            MatchTable        newMatch   = new MatchTable();

            foreach (MatchTable match in matches)
            {
                if (match.UserSend == activeUser.Id)
                {
                    if (match.UserGet == matchUser && (match.Status == 1 | match.Status == 3))
                    {
                        match.Status = 1;
                        db.SaveChanges();
                        return(Redirect("~/Home/HomePage"));
                    }
                }
            }

            newMatch.UserSend = activeUser.Id;
            newMatch.UserGet  = matchUser;
            newMatch.Status   = 1;

            db.MatchTable.Add(newMatch);
            db.SaveChanges();

            return(Redirect("~/Home/HomePage"));
        }
예제 #4
0
 private MatchSerie(int serieNumber, MatchTable table1, MatchTable table2, MatchTable table3, MatchTable table4)
 {
     SerieNumber = serieNumber;
     Table1      = table1;
     Table2      = table2;
     Table3      = table3;
     Table4      = table4;
 }
예제 #5
0
        private static async Task Main(string[] args)
        {
            await DatabaseService.Ensure();

            await SeedHelper.Run();

            Console.WriteLine("Processing table matching....");

StartTableMatching:
            var input = DynamicInputHandler.TakeInput();

            var matchTable = new MatchTable();

            matchTable.SetBatchSize(10);
            MatchTableResponse response;

            try
            {
                response = await matchTable.FindMatch(input.SourceEntity, input.TargetEntity, input.PrimaryKey);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine($"The source and target tables schema may does not match. Starting the matching again... \n\n");
                goto StartTableMatching;
            }


            Console.WriteLine("Added\n---------");
            foreach (var item in response.Added)
            {
                Console.WriteLine($"{item.Message}");
            }

            Console.WriteLine("\nRemoved\n---------");
            foreach (var item in response.Removed)
            {
                Console.WriteLine($"{item.Message}");
            }

            Console.WriteLine("\nChanges\n---------");
            foreach (var item in response.Changes)
            {
                Console.WriteLine($"{item.Message}");
            }

            Console.WriteLine("\n\nFinished table matching....");

            Console.WriteLine("\n\nAre you wish to play with another entities??\n1. Yes \t2. Press any other key to exit.");
            var action = Console.ReadLine();

            if (action == "1" || action?.ToLower() == "yes")
            {
                goto StartTableMatching;
            }
        }
        public ActionResult Accept()
        {
            // This code handles the accepting of an organ.
            int    userID = Int32.Parse(Session["UserName"].ToString());
            int    tID;
            string transcation_id = Request.QueryString["tID"];
            bool   result         = Int32.TryParse(transcation_id, out tID);

            // Update Match Table
            MatchTable update_match = (from MatchTable in OrganDonorSystemDB.MatchTables
                                       where MatchTable.transactionID == tID
                                       select MatchTable).Single();

            update_match.acceptedOrDeclined = 1;

            // Update Organ State
            Organ deliveredOrgan = (from Organ in OrganDonorSystemDB.Organs
                                    where Organ.OrganID == update_match.organID
                                    select Organ).Single();

            deliveredOrgan.available             = false;
            deliveredOrgan.Recipient_RecipientID = update_match.recipientID;

            // Update Recipient State
            Recipient reciever = (from Recipient in OrganDonorSystemDB.Recipients
                                  where Recipient.recipentID == update_match.recipientID
                                  select Recipient).Single();

            reciever.organsOrganID        = deliveredOrgan.OrganID;
            reciever.organTypeOrganTypeID = deliveredOrgan.organType_organtypeID;
            reciever.needsOrgan           = "F";

            // Transplant Complete!
            OrganDonorSystemDB.SaveChanges();

            // Remove Duplicate Matches from the MatchTable. Each Recipient gets one and only one Organ.
            List <MatchTable> duplicate_matches = (from MatchTable in OrganDonorSystemDB.MatchTables
                                                   where MatchTable.recipientID == update_match.recipientID &&
                                                   MatchTable.transactionID != tID
                                                   select MatchTable).ToList();

            for (int i = 0; i < duplicate_matches.Count(); i++)
            {
                OrganDonorSystemDB.MatchTables.DeleteObject(duplicate_matches[i]);
            }
            OrganDonorSystemDB.SaveChanges();

            return(RedirectToAction("Index"));
        }
예제 #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (isEmpty())
            {
                return;
            }
            string winnerName = cmbWinner.GetItemText(this.cmbWinner.SelectedItem);

            foreach (Player player in playerList)
            {
                if (winnerName == player.PlayerName)
                {
                    winner = player;
                    //increment wins via database
                }

                //else set winstreak to 0
            }
            cmbWinner.Items.Clear();
            cmbWinner.SelectedItem = null;
            this.Hide();
            Player p = Database.DatabaseContext.Instance.Player.Where(foundPlayer => foundPlayer.PlayerName == winnerName).First();

            MatchTable table = new MatchTable
            {
                PlayerId   = p.Id,
                GameTypeId = match.MatchType,
                StageId    = match.stageList.Last().Id,
                ItemsId    = 1
            };

            Database.DatabaseContext.Instance.MatchTable.Add(table);
            Database.DatabaseContext.Instance.SaveChanges();

            controller.openRecords(winner, match);
        }
예제 #8
0
    private static ResultSeriesReadModel.Table CreateTable(
        IReadOnlyDictionary <string, Player> players,
        MatchTable matchTable)
    {
        ResultSeriesReadModel.Table table = new()
        {
            Score = matchTable.Score,
            Game1 = new ResultSeriesReadModel.Game
            {
                Player =
                    players[matchTable.Game1.Player].Name,
                Pins =
                    matchTable
                    .Game1.Pins,
                Strikes =
                    matchTable
                    .Game1.Strikes,
                Spares =
                    matchTable
                    .Game1.Spares
            },
            Game2 = new ResultSeriesReadModel.Game
            {
                Player =
                    players[matchTable.Game2.Player].Name,
                Pins =
                    matchTable.Game2.Pins,
                Strikes =
                    matchTable.Game2.Strikes,
                Spares =
                    matchTable.Game2.Spares
            }
        };
        return(table);
    }
}
예제 #9
0
        public void LoadData()
        {
            if (this.competitionID < 0)
            {
                return;
            }
            if (this.matchID < 0)
            {
                return;
            }
            if (this.rowID < 0)
            {
                return;
            }
            if (this.allianceColorList.Count != this.teamComboList.Count)
            {
                return;                                                                       // should be same number of items in each
            }
            MySqlConnection connection = new MySqlConnection(Utils.getConnectionString());
            MySqlCommand    cmd;
            bool            connectionAvailable = Utils.openConnection(connection, lblStatus);

            if (connectionAvailable)
            {
                try
                {
                    cmd = connection.CreateCommand();

                    string query = MatchTable.getSelectMatchNumberAndTeamsForID(this.competitionID);
                    //string query = MatchTable.SELECT_MATCH_AND_TEAMS_FROM_ID_PREFIX;
                    //query += MatchTable.SELECT_BLUE1_FOR_ID_PART;
                    //query += MatchTable.COL_BLUE_1 + " AS 'Blue1ID',";
                    //query += MatchTable.SELECT_BLUE2_FOR_ID_PART;
                    //query += MatchTable.COL_BLUE_2 + " AS 'Blue2ID',";
                    //query += MatchTable.SELECT_BLUE3_FOR_ID_PART;
                    //query += MatchTable.COL_BLUE_3 + " AS 'Blue3ID',";
                    //query += MatchTable.SELECT_RED1_FOR_ID_PART;
                    //query += MatchTable.COL_RED_1 + " AS 'Red1ID',";
                    //query += MatchTable.SELECT_RED2_FOR_ID_PART;
                    //query += MatchTable.COL_RED_2 + " AS 'Red2ID',";
                    //query += MatchTable.SELECT_RED3_FOR_ID_PART;
                    //query += MatchTable.COL_RED_3 + " AS 'Red3ID'";
                    //query += MatchTable.FROM_MATCH_FOR_EVENT_ID;
                    //query += this.competitionID;

                    cmd.CommandText = query;

                    MySqlDataAdapter adap = new MySqlDataAdapter(cmd);

                    DataSet ds = new DataSet();
                    adap.Fill(ds);

                    txtMatchNumber.Text = ds.Tables[0].Rows[this.rowID][MatchTable.COLUMN_LABEL_MATCH_NUMBER].ToString();

                    for (int i = 0; i < this.teamComboList.Count; i++)
                    {
                        this.teamComboList[i].SelectedValue = ds.Tables[0].Rows[this.rowID][this.allianceColorList[i]].ToString();
                    }
                }
                catch (MySql.Data.MySqlClient.MySqlException)
                {
                    string message = "Unable to open MySQL connection - check if the database is installed and running!";
                    Console.Out.WriteLine(message);
                    lblStatus.Text = message;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }
        }
예제 #10
0
        public void LoadMatchData()
        {
            if (!CompetitionIDIsValid(this.competitionID))
            {
                return;
            }

            MySqlConnection connection = new MySqlConnection(Utils.getConnectionString());
            MySqlCommand    cmd;
            bool            connectionAvailable = Utils.openConnection(connection, lblStatus);

            if (connectionAvailable)
            {
                try
                {
                    cmd = connection.CreateCommand();

                    string query = MatchTable.getSelectMatchNumberAndTeamsForID(this.competitionID);
                    //string query = MatchTable.SELECT_MATCH_NUMBER_AND_TEAMS_FROM_ID_PREFIX;
                    //query += MatchTable.SELECT_BLUE1_FOR_ID_PART;
                    //query += MatchTable.COL_BLUE_1 + " AS 'Blue1ID',";
                    //query += MatchTable.SELECT_BLUE2_FOR_ID_PART;
                    //query += MatchTable.COL_BLUE_2 + " AS 'Blue2ID',";
                    //query += MatchTable.SELECT_BLUE3_FOR_ID_PART;
                    //query += MatchTable.COL_BLUE_3 + " AS 'Blue3ID',";
                    //query += MatchTable.SELECT_RED1_FOR_ID_PART;
                    //query += MatchTable.COL_RED_1 + " AS 'Red1ID',";
                    //query += MatchTable.SELECT_RED2_FOR_ID_PART;
                    //query += MatchTable.COL_RED_2 + " AS 'Red2ID',";
                    //query += MatchTable.SELECT_RED3_FOR_ID_PART;
                    //query += MatchTable.COL_RED_3 + " AS 'Red3ID'";
                    //query += MatchTable.FROM_MATCH_FOR_EVENT_ID;
                    //query += this.competitionID;

                    cmd.CommandText = query;

                    MySqlDataAdapter adap = new MySqlDataAdapter(cmd);

                    DataSet ds = new DataSet();
                    adap.Fill(ds);
                    gridMatchList.DataSource = ds.Tables[0].DefaultView;
                }
                catch (MySql.Data.MySqlClient.MySqlException)
                {
                    string message = "Unable to open MySQL connection - check if the database is installed and running!";
                    Console.Out.WriteLine(message);
                    lblStatus.Text = message;
                }
                catch (Exception)
                {
                    throw;
                }
                finally
                {
                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }
        }
예제 #11
0
        static void Main(string[] args)
        {
            Program       program = new Program();
            DataTable     InitialTable;
            DataTable     MatchTable;
            List <string> accounts = new List <string>();
            List <string> paths    = new List <string>();
            int           j        = 0;

            optionForm oform = new optionForm();

            oform.ShowDialog();

            string asofstring = oform.asofString;

            string subjectString = oform.subjectString;

            string qtrFolder = oform.statementFolder;

            string csvFile = oform.listFile;

            InitialTable = program.csvToDataTable(csvFile);
            MatchTable   = program.MatcherTable(InitialTable);

            //This loop deletes any entires with a duplicate email from table
            foreach (DataRow r1 in InitialTable.Rows.Cast <DataRow>().ToArray())            // save rows to array
            {
                foreach (DataRow r2 in MatchTable.Rows)
                {
                    if (r1.Field <string>("name") == r2.Field <string>("name"))
                    {
                        r1.Delete();
                        break;                         // break inner loop
                    }
                }
            }

            //This loop creates a mail item for each unique email address
            foreach (DataRow dataRow in InitialTable.Rows)
            {
                string recip       = dataRow["name"].ToString();
                string email       = dataRow["E-mail Address"].ToString();
                string entity      = dataRow["Account Name"].ToString();
                string designation = dataRow["Desig"].ToString();

                if (designation.Length < 5)
                {
                    //makes up for Excel CSV dropping leading zeros
                    designation = "0" + designation;
                }

                program.CreateMailItem(email, recip, entity, program.GetPath(designation, qtrFolder), asofstring, subjectString);
            }

            //Selects destinct names and emails from the CSV using LINQ
            var distinctIds   = MatchTable.AsEnumerable().Select(row => row.Field <string>("Name")).Distinct().ToList();
            var distinctEmail = MatchTable.AsEnumerable().Select(row => row.Field <string>("E-mail Address")).Distinct().ToList();

            foreach (var item in distinctIds)
            {
                string sendName = item;

                accounts.Clear();
                paths.Clear();
                for (int i = 0; i < MatchTable.Rows.Count; i++)
                {
                    string recip       = MatchTable.Rows[i]["name"].ToString();
                    string email       = MatchTable.Rows[i]["E-mail Address"].ToString();
                    string entity      = MatchTable.Rows[i]["Account Name"].ToString();
                    string designation = (MatchTable.Rows[i]["Desig"].ToString());

                    if (designation.Length < 5)
                    {
                        //makes up for Excel CSV dropping leading zeros
                        designation = "0" + designation;
                    }

                    if (item.Equals(recip))
                    {
                        accounts.Add(entity);
                        paths.Add(designation);
                    }

                    if (i == MatchTable.Rows.Count - 1)
                    {
                        string sendEmail = distinctEmail[j];
                        program.CreateMultipleMailItem(sendEmail, sendName, accounts, program.GetPaths(paths, qtrFolder), asofstring, subjectString);
                        j = j + 1;
                    }
                }
            }
            //Signifies the process was successful
            Console.WriteLine("Process Completed. Press any key to exit.");
            Console.ReadKey();
        }
예제 #12
0
        private void SaveData(bool exit)
        {
            MySqlConnection connection = new MySqlConnection(Utils.getConnectionString());
            MySqlCommand    cmd;
            bool            saved = true, validated = true;

            long[]   teamIDs           = new long[] { -1, -1, -1, -1, -1, -1 };
            string[] alliancePositions = new string[] { "Blue1", "Blue2", "Blue3", "Red1", "Red2", "Red3" };

            connection.Open();

            try
            {
                teamIDs[0] = Utils.getLongIDFromComboSelectedValue(cmbBlue1, lblStatus);
                teamIDs[1] = Utils.getLongIDFromComboSelectedValue(cmbBlue2, lblStatus);
                teamIDs[2] = Utils.getLongIDFromComboSelectedValue(cmbBlue3, lblStatus);
                teamIDs[3] = Utils.getLongIDFromComboSelectedValue(cmbRed1, lblStatus);
                teamIDs[4] = Utils.getLongIDFromComboSelectedValue(cmbRed2, lblStatus);
                teamIDs[5] = Utils.getLongIDFromComboSelectedValue(cmbRed3, lblStatus);
            }
            catch (Exception e)
            {
                validated = false;
                Console.Out.WriteLine(e.Message);
            }

            if (validated)
            {
                try
                {
                    cmd             = connection.CreateCommand();
                    cmd.CommandText = MatchTable.getInsertRecordString();

                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_EVENT_ID, this.compID);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_MATCH_COMP_LEVEL, txtMatchType.Text);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_MATCH_NUMBER, int.Parse(txtMatchNumber.Text));
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_MATCH_STATUS, "");

                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_1, teamIDs[3]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_2, teamIDs[4]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_3, teamIDs[5]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_AUTO_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_TELEOP_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_TOTAL_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_QP, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_RED_FOUL_POINTS, 0);

                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_1, teamIDs[0]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_2, teamIDs[1]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_3, teamIDs[2]);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_AUTO_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_TELEOP_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_TOTAL_SCORE, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_QP, 0);
                    cmd.Parameters.AddWithValue("@" + MatchTable.COL_BLUE_FOUL_POINTS, 0);

                    cmd.Parameters.AddWithValue("@" + MatchTable.COLUMN_NAME_MATCH_WINNER, "");
                    cmd.Parameters.AddWithValue("@" + MatchTable.COLUMN_NAME_DRIVE_TEAM_COMMENTS, "");

                    cmd.ExecuteNonQuery();
                    long match_id = cmd.LastInsertedId;
                    //long tablet_id = 0;
                    cmd.Parameters.Clear();

                    cmd.CommandText = TeamMatchTable.INSERT_RECORD;

                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_TEAM_ID, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_MATCH_ID, 0);
                    //cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_EVENT_ID, 0);
                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_POSITION, "");
                    cmd.Parameters.AddWithValue("@" + TeamMatchTable.COL_ALLIANCE, "");

                    for (int tm = 0; tm < teamIDs.Length; tm++)
                    {
                        cmd.Parameters["@" + TeamMatchTable.COL_TEAM_ID].Value  = teamIDs[tm];
                        cmd.Parameters["@" + TeamMatchTable.COL_MATCH_ID].Value = match_id;
                        //cmd.Parameters["@" + TeamMatchTable.COL_EVENT_ID].Value = this.compID;
                        cmd.Parameters["@" + TeamMatchTable.COL_POSITION].Value = (tm % 3) + 1;
                        cmd.Parameters["@" + TeamMatchTable.COL_ALLIANCE].Value = (tm < 3) ? "Blue" : "Red";

                        cmd.ExecuteNonQuery();
                    }
                }
                catch (Exception)
                {
                    saved          = false;
                    lblStatus.Text = "Failed to save data, check that database is active, and verify data is entered correctly";
                    //throw;
                }
                finally
                {
                    if (connection.State == System.Data.ConnectionState.Open)
                    {
                        connection.Close();
                    }
                }
            }

            if (saved)
            {
                if (exit)
                {
                    MatchListForm formObj = (MatchListForm)Application.OpenForms["MatchListForm"];
                    formObj.LoadMatchData();
                    this.Close();
                }
                else
                {
                    txtMatchNumber.Text   = "";
                    txtMatchTime.Text     = "";
                    txtMatchType.Text     = "Qualification";
                    txtMatchLocation.Text = "";
                    cmbBlue1.Text         = "";
                    cmbBlue2.Text         = "";
                    cmbBlue3.Text         = "";
                    cmbRed1.Text          = "";
                    cmbRed2.Text          = "";
                    cmbRed3.Text          = "";
                }
            }
        }