/// <summary> /// Opens a file if the user chooses, or does nothing if they cancel or exit. /// </summary> private void Open() { OpenFileDialog open = new OpenFileDialog(); open.Filter = "Spreadsheet files (*.ss)|*.ss|All files (*.*)|*.*"; // Set the default filter to *.ss open.FilterIndex = 1; // Open the file chooser open.ShowDialog(); string path = open.FileName; // If user doesn't choose a file if (path == "") return; // Set the file title (filename) and save path string filename = open.SafeFileName; // Try to make a new spreadsheet with the chosen file, then make a new file if // it succeeds. If it is an invalid or corrupt file, then show the message and // don't make the new file. try { SS.Spreadsheet sheet = new SS.Spreadsheet(path, x => true, (string s) => s.ToUpper(), "ps6"); // Start a new spreadsheet with the chosen filename MyApplicationContext.getAppContext().RunForm(new Form1(path, filename, sheet)); } catch (SS.SpreadsheetReadWriteException e) { MessageBox.Show("Invalid or corrupt file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Constructs a new spreadsheet when user clicks open /// and user login is no longer required. /// </summary> public Form1(String ip, String password) { InitializeComponent(); client = new Client(); time = new System.Timers.Timer(); client.IncomingLineEvent += MessageReceived; usrPassword = password; usrIpAddrss = ip; login = new Login.Form1(client, ip, password); spreadsheetPanel1.Hide(); time.Interval = 3000; // Set to 30000 for 30 seconds!! time.Elapsed += new ElapsedEventHandler(time_elapsed); // This could also be done graphically in the designer, as has been // demonstrated in class. spreadsheetPanel1.SelectionChanged += DisplaySelectedCell; spreadsheet = new SS.Spreadsheet(x => true, (string s) => s.ToUpper(), "ps6"); SetTitle(); InsertMode = false; }
/// <summary> /// Constructs a new spreadsheet /// </summary> public Form1(string filename, string save, SS.Spreadsheet sheet) { InitializeComponent(); spreadsheet = sheet; spreadsheetPanel1.SelectionChanged += DisplaySelectedCell; // Initialize all of the non-empty cells HashSet<string> cells = new HashSet<string>(spreadsheet.GetNamesOfAllNonemptyCells()); foreach (string name in cells) DisplayValueInTable(name); spreadsheetPanel1.SetSelection(0, 0); saveFile = filename; titleFile = save; // Perform an initial save Save(); SetTitle(); InsertMode = true; }
private int versionNumber; // Keep track of this spreadsheet's version number #endregion Fields #region Constructors /// <summary> /// Constructs a new spreadsheet /// </summary> public Form1() { InitializeComponent(); //Creates new socket for this specific spreadsheet. client = new Client(); time = new System.Timers.Timer(); client.IncomingLineEvent += MessageReceived; //Creates new login window. login = new Login.Form1(client); login.ClickedCancel += CancelSpreadSheet; // Will close this spreadsheet if user clicks cancel. login.ShowDialog(); //Save the IpAddress and the password so user will not have to input every // time a new spreadsheet is opened. usrPassword = login.getPassword(); usrIpAddrss = login.getIp(); SSEdit = false; //Hide spreadsheet until the login has been verified. spreadsheetPanel1.Hide(); time.Interval = 30000; // Set to 30000 for 30 seconds!! time.Elapsed += new ElapsedEventHandler(time_elapsed); // This could also be done graphically in the designer, as has been // demonstrated in class. spreadsheetPanel1.SelectionChanged += DisplaySelectedCell; spreadsheet = new SS.Spreadsheet(x => true, (string s) => s.ToUpper(), "ps6"); titleFile = "Sheet " + totalSpreadsheets; saveFile = ""; SetTitle(); InsertMode = true; }