public void SendMovementData(Session session) { db.Open(session.DatabaseFilepath); var clientNumber = CheckClientsAndGetNumber(); db.ClearInDB(BMTable.Session); db.ClearInDB(BMTable.Section); db.ClearInDB(BMTable.Tables); db.ClearInDB(BMTable.RoundData); PopulateSessionTable(session); PopulateSectionsAndRoundDataAnd_TablesTables(session, clientNumber); db.SendToDB(BMTable.Session); db.SendToDB(BMTable.Section); db.SendToDB(BMTable.Tables); db.SendToDB(BMTable.RoundData); db.Close(); void PopulateSessionTable(Session _session) { var r1 = db.Data.Session.NewSessionRow(); r1.ID = 1; r1.Name = _session.Name; r1.Date = DateTime.Today; r1.Time = DateTime.Now; r1.ShowInApp = true; r1.GUID = String.Empty; r1.Status = 0; db.Data.Session.AddSessionRow(r1); } BMInput1DataSet.SectionRow AddSectionRow(Section s) { var row = db.Data.Section.NewSectionRow(); row.ID = (short)s.Number; row.Letter = s.Name; row.Tables = (short)s.Movement.TableCount; row.MissingPair = (short)(s.MissingPair?.Number ?? 0); row.Session = 1; row.EWMoveBeforePlay = 0; row.ScoringType = 1; row.Winners = 0; db.Data.Section.AddSectionRow(row); return(row); } void PopulateSectionsAndRoundDataAnd_TablesTables(Session __session, int __clientNumber) { foreach (Section section in __session.Sections) { var sectionRow = AddSectionRow(section); for (int i = 1; i <= section.Movement.TableCount; i++) { AddTablesRow(__clientNumber, sectionRow.ID, i); } for (int t = 0; t < section.Movement.Data.GetLength(0); t++) { for (int r = 0; r < section.Movement.Data.GetLength(1); r++) { AddRoundDataRow(section, sectionRow.ID, t, r); } } } void AddTablesRow(int _clientNumber, short sectionIDinDB, int table) { var r3 = db.Data._Tables.NewTablesRow(); r3.Section = sectionIDinDB; r3._Table = (short)table; r3.ComputerID = (short)_clientNumber; r3.Status = 0; r3.LogOnOff = 2; r3.UpdateFromRound = 0; r3.CurrentBoard = 0; r3.CurrentRound = 0; r3.Group = 0; db.Data._Tables.AddTablesRow(r3); } void AddRoundDataRow(Section section, short sectionIDinDB, int table, int round) { RoundTableData info = section.Movement.Data[table, round]; var r4 = db.Data.RoundData.NewRoundDataRow(); r4.Section = sectionIDinDB; r4._Table = (Int16)info.table; r4.Round = (Int16)info.round; r4.NSPair = (Int16)info.pairNS; r4.EWPair = (Int16)info.pairEW; if (info.UsesCustomBoards) { r4.CustomBoards = info.customBoards; r4.LowBoard = 1; r4.HighBoard = 2; } else { r4.LowBoard = (Int16)(info.boardsLow + section.BoardsShift); r4.HighBoard = (Int16)(info.boardsHigh + section.BoardsShift); r4.CustomBoards = String.Empty; } db.Data.RoundData.AddRoundDataRow(r4); } } }
public Movement Parse(string loadedText, string filePath) { try { string[] lines = loadedText.Split('\n'); string name = lines[1].Trim(); string description = "Giborg.DAT file"; //algorithm state variables bool dataLines = false; int table = 1; bool countingRounds = true; //movement variables int rounds = 0; /* rows = 3 + (17+rounds)tables - 2 * (rows - 1)/(17 + rounds) = tables */ int tables; RoundTableData[,] data = { }; RoundTableData curr; for (int i = 0; i < lines.Length; i++) { if (lines[i].StartsWith("===")) { if (dataLines) { if (countingRounds) { rounds = Int32.Parse(lines[i - 1].Split('|')[0].Trim()); tables = (lines.Length - 1) / (17 + rounds); data = new RoundTableData[tables, rounds]; countingRounds = false; i -= rounds + 1; // Console.WriteLine($"tables:{tables}, rounds:{rounds}"); continue; } table++; } dataLines = !dataLines; } else if (dataLines && !countingRounds) { string[] line = Regex.Replace(lines[i], @"\s+", " ").Split('|'); string[] pairs = line[1].TrimEnd().TrimStart().Split(' '); string[] boards = line[2].Trim().Split('-'); curr = new RoundTableData() { pairNS = (pairs[0] == "--") ? -1 : Int32.Parse(pairs[0]), pairEW = (pairs[1] == "--") ? -1 : Int32.Parse(pairs[1]), boardsLow = Int32.Parse(boards[0]), boardsHigh = Int32.Parse(boards[1]), table = table, round = Int32.Parse(line[0].Trim()) }; data[curr.table - 1, curr.round - 1] = curr; //Console.WriteLine($"Saving TableRoundData of NS:{pairs[0]} EW:{pairs[1]} Boards:{boards[0]}-{boards[1]} to indexes [{table - 1},{ Int32.Parse(line[0].Trim()) - 1}]"); } } return(new Movement(0, data, name, description)); } catch (Exception) { throw; } }