private void SaveUNO(string name) { ProjFileStream pfs = new ProjFileStream(name, System.IO.FileMode.Create, System.IO.FileAccess.Write); pfs.WriteBool(showResultsToolStripMenuItem.Checked); pfs.WriteInt(playerCount); for (int i = 0; i < playerCount; i++) { pfs.WriteString(playerNames[i]); } pfs.WriteInt(tabControl1.TabPages.Count); for (int i = 0; i < tabControl1.TabPages.Count; i++) { pfs.WriteString((tabControl1.TabPages[i].Tag as UNOOneGame).UNOStageName); pfs.WriteString((tabControl1.TabPages[i].Tag as UNOOneGame).UNOStageDate); pfs.WriteInt((tabControl1.TabPages[i].Tag as UNOOneGame).RoundsCount); for (int j = 0; j < (tabControl1.TabPages[i].Tag as UNOOneGame).RoundsCount; j++) { for (int k = 0; k < playerCount; k++) { pfs.WriteInt((tabControl1.TabPages[i].Tag as UNOOneGame).GetValue(j, k)); pfs.WriteBool((tabControl1.TabPages[i].Tag as UNOOneGame).GetWinState(j, k)); } } } saved = true; pfs.Close(); }
// Сохранение результатов public void SaveSheet(ProjFileStream pfs, bool templ) { int rc = dataGridView1.Rows.Count; int cc = dataGridView1.Columns.Count; pfs.WriteInt(rc); pfs.WriteInt(cc); for (int i = 1; i < cc - 1; i++) { pfs.WriteString(dataGridView1.Columns[i].HeaderText); } for (int i = 0; i < rc; i++) { pfs.WriteString((string)dataGridView1.Rows[i].Cells[0].Value); for (int j = 1; j < cc - 1; j++) { if (templ) { pfs.WriteInt((int)0); } else { pfs.WriteInt((int)dataGridView1.Rows[i].Cells[j].Value); } } } }
private void LoadingProcess() { ProjFileStream reader = new ProjFileStream(pathToFile, FileMode.Open, FileAccess.Read); resultViewSheet1.LoadSheet(reader); reader.Close(); }
private void SavingProcess() { ProjFileStream writer = new ProjFileStream(pathToFile, FileMode.Create, FileAccess.Write); resultViewSheet1.SaveSheet(writer, false); writer.Close(); saved = true; }
public static void WriteToStream(ProjFileStream writer, SheetColorScheme scheme) { writer.WriteString(scheme.Name); writer.WriteColor(scheme.HeaderBackColor); writer.WriteColor(scheme.ValueBackColor); writer.WriteColor(scheme.TextColor); writer.WriteColor(scheme.SelectedBackColor); writer.WriteColor(scheme.LightingBackColor); writer.WriteColor(scheme.LightingSelectedBackColor); }
public static SheetColorScheme ReadFromStream(ProjFileStream reader) { SheetColorScheme resultScheme = new SheetColorScheme(); resultScheme.Name = reader.ReadString(); resultScheme.HeaderBackColor = reader.ReadColor(); resultScheme.ValueBackColor = reader.ReadColor(); resultScheme.TextColor = reader.ReadColor(); resultScheme.SelectedBackColor = reader.ReadColor(); resultScheme.LightingBackColor = reader.ReadColor(); resultScheme.LightingSelectedBackColor = reader.ReadColor(); return(resultScheme); }
// Сохранение цветовых схем private void ColorSchemesWrite() { string colorFileName = Path.Combine(Application.StartupPath, "Colors"); ProjFileStream writer = new ProjFileStream(colorFileName, FileMode.Create, FileAccess.Write); int cnt = schemes.Count; writer.WriteInt(cnt); for (int i = 0; i < cnt; i++) { SheetColorScheme.WriteToStream(writer, schemes[i]); } writer.Close(); }
// Загрузка цветовых схем private void ColorSchemesRead() { schemes.Clear(); string colorFileName = Path.Combine(Application.StartupPath, "Colors"); if (File.Exists(colorFileName)) { ProjFileStream reader = new ProjFileStream(colorFileName, FileMode.Open, FileAccess.Read); int cnt = reader.ReadInt(); for (int i = 0; i < cnt; i++) { schemes.Add(SheetColorScheme.ReadFromStream(reader)); } reader.Close(); } else { schemes.Add(new SheetColorScheme()); } }
// Template private void MakeTemplate() { tempPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "temp"); if (File.Exists(tempPath)) { ProjFileStream reader = new ProjFileStream(tempPath, FileMode.Open, FileAccess.Read); resultViewSheet1.LoadSheet(reader); } else { for (int i = 0; i < 2; i++) { resultViewSheet1.AddNewRound(("Раунд " + (resultViewSheet1.RoundCount + 1).ToString())); } for (int i = 0; i < 3; i++) { resultViewSheet1.AddNewTeam(string.Format("Team {0}", resultViewSheet1.TeamCount.ToString())); } } }
// Загрузка результатов public void LoadSheet(ProjFileStream pfs) { int rc = pfs.ReadInt(); int cc = pfs.ReadInt(); Clear(); for (int j = 1; j < cc - 1; j++) { AddNewRound(pfs.ReadString()); } for (int i = 0; i < rc; i++) { string name = pfs.ReadString(); AddNewTeam(name); for (int j = 1; j < cc - 1; j++) { dataGridView1.Rows[i].Cells[j].Value = pfs.ReadInt(); } } UpdateResults(); }
private void LoadUNO() { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "*.uno | *.uno"; if (ofd.ShowDialog() == DialogResult.OK) { currentFile = ofd.FileName; ProjFileStream pfs = new ProjFileStream(currentFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); if (tabControl1.TabPages.Count > 0) { tabControl1.TabPages.Clear(); } tabControl1.Visible = true; gameToolStripMenuItem.Enabled = true; showResultsToolStripMenuItem.Checked = pfs.ReadBool(); playerCount = pfs.ReadInt(); tabControl1.Height = UNOOneGame.ColumnHeaderHeight + playerCount * UNOOneGame.RowHeight + UNOOneGame.BottomHeight + tabControl1.ItemSize.Height; for (int i = 0; i < playerCount; i++) { playerNames[i] = pfs.ReadString(); } int stages = pfs.ReadInt(); for (int i = 0; i < stages; i++) { string name = pfs.ReadString(); string date = pfs.ReadString(); tabControl1.TabPages.Add(name); UNOOneGame unoOneGame = new UNOOneGame(); unoOneGame.UNOStageName = name; unoOneGame.UNOStageDate = date; unoOneGame.CreateUNOGame(playerCount, playerNames); unoOneGame.ShowHideResults(!showResultsToolStripMenuItem.Checked); unoOneGame.Dock = DockStyle.Top; unoOneGame.ScrollVisiblityChangeEvent += new EventHandler <ScrollVisiblityEventArgs>(unoOneGame_ScrollVisiblityChangeEvent); unoOneGame.NameChangedEvent += new EventHandler <NameChangedEventArgs>(unoOneGame_NameChangedEvent); tabControl1.TabPages[tabControl1.TabPages.Count - 1].Tag = unoOneGame; tabControl1.TabPages[tabControl1.TabPages.Count - 1].Controls.Add(unoOneGame); if (!roundToolStripMenuItem.Enabled) { roundToolStripMenuItem.Enabled = true; } int roundCount = pfs.ReadInt(); for (int j = 0; j < roundCount; j++) { (tabControl1.TabPages[i].Tag as UNOOneGame).AddRound(playerCount); for (int k = 0; k < playerCount; k++) { (tabControl1.TabPages[i].Tag as UNOOneGame).SetValue(j, k, pfs.ReadInt()); (tabControl1.TabPages[i].Tag as UNOOneGame).SetWinState(j, k, pfs.ReadBool()); } } unoOneGame.RefreshResults(); } pfs.Close(); } }
private void saveAsTemplateToolStripMenuItem_Click(object sender, EventArgs e) { ProjFileStream writer = new ProjFileStream(tempPath, FileMode.Create, FileAccess.Write); resultViewSheet1.SaveSheet(writer, true); }