public SSForm(NetworkWarden ward, string filename) { InitializeComponent(); personalSpreadsheet = new Spreadsheet(validAddress, s => s.ToUpper(), "PS6"); this.Text = filename; warden = ward; addressBox.Text = "A1"; // Send the filename to the server Networking.Send(warden, "Connect\t" + filename + "\t\n"); }
/// <summary> /// Begin receiving data from the server. /// /// The first piece of data from the server should be the client ID. /// </summary> /// <param name="ss">The state for this specific socket connection.</param> private void ReceiveStartup(SocketState ss) { StringBuilder sb = ss.sb; String sbStr = sb.ToString(); String[] messageTokens = sbStr.Split(new Char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); this.clientID = int.Parse(messageTokens[0]); Networking.Send(this.server, this.userName + "\n"); this.Invoke((MethodInvoker)(() => { MessageBox.Show(null, "Please open an existing spreadsheet or create a new one using the file menu.", "Use File Menu", MessageBoxButtons.OK, MessageBoxIcon.Information); })); ss.sb.Clear(); ss.callMe = new Action <SocketState>(this.ReceiveData); this.ReceiveData(ss); }
/// <summary> /// deals withe save event under the file menu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void saveToolStripMenuItem_Click(object sender, EventArgs e) { Networking.Send(this.server, "6\t" + this.sheet.GetSavedVersion(this.formName) + "\n"); // Displays a SaveFileDialog so the user can save the Image // assigned to file save. /* * SaveFileDialog saveFileDialog1 = new SaveFileDialog(); * saveFileDialog1.Filter = "sprd files (*.sprd)|*.sprd|All Files (*.*)|*.*"; * saveFileDialog1.Title = "Save a sprd File"; * saveFileDialog1.ShowDialog(); * //file must have a valid name * if (saveFileDialog1.FileName != "") * { * sheet.Save(saveFileDialog1.FileName); * } */ }
/// <summary> /// Send the "DoneTyping" message to the server /// </summary> private void Send_DoneTyping(string address) { if (istyping) { istyping = false; try { Networking.Send(warden, "DoneTyping\t" + warden.ID + "\t" + address.ToString() + "\t\n"); } catch (Exception err) { while (MessageBox.Show("Server is down, application will now close.", "", MessageBoxButtons.OK) == 0) { } Application.Exit(); } } }
/// <summary> /// delas with the load event under the file menu /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loadToolStripMenuItem_Click(object sender, EventArgs e) { //if current spreadsheet has changed, it will ask to save before loading another. /*if (sheet.Changed) * { * DialogResult dialogResult = MessageBox.Show("Do You Want To Save Your Data?", "Save", MessageBoxButtons.YesNo); * //if user selects yes then it executes save method * if (dialogResult == DialogResult.Yes) * { * saveToolStripMenuItem_Click(this, new EventArgs()); * } * }*/ // request list of files from server this.requestOldSpreadsheet = true; Networking.Send(this.server, "0\n"); /* * //opens file dialog box in c: * OpenFileDialog openFileDialog1 = new OpenFileDialog(); * openFileDialog1.InitialDirectory = "c:\\"; * openFileDialog1.Filter = "All Files (*.*)|*.*|sprd files (*.sprd)|*.sprd"; * openFileDialog1.FilterIndex = 2; * openFileDialog1.ShowDialog(); * openFileDialog1.RestoreDirectory = true; * //if no name is valid opens the spreadsheet file. * if (openFileDialog1.FileName != "") * { * sheet = new Spreadsheet(openFileDialog1.FileName, x => true, Normalize, "ps6"); * } * //adds al the items in the spreadsheet file into the spreadsheet grid * char[] alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); * List<char> list = alpha.ToList<char>(); * foreach (string name in sheet.GetNamesOfAllNonemptyCells()) * { * int col = list.IndexOf(char.Parse(name.Substring(0, 1))); * int row = int.Parse(name.Substring(1, 1)); * string value = sheet.GetCellValue(name).ToString(); * spreadsheetPanel1.SetValue(col, row - 1, value); * } */ }
/******************************************************************************************** * Network Comunication Section - Client -> Server ********************************************************************************************/ /// <summary> /// Sends the "Edit" command to the server /// </summary> private void ContentButton_Click(object sender, EventArgs e) { int col, row; spreadsheetPanel1.GetSelection(out col, out row); string address = gridToAddress(col, row); Send_DoneTyping(address); string content = contentBox.Text; personalSpreadsheet.CheckContentsAreValid(content); try { Networking.Send(warden, "Edit\t" + address + "\t" + content + "\t\n"); } catch (Exception err) { while (MessageBox.Show("Server is down, application will now close.", "", MessageBoxButtons.OK) == 0) { } Application.Exit(); } }
private void redoToolStripMenuItem_Click(object sender, EventArgs e) { Networking.Send(this.server, "5\t" + this.docID + "\n"); }
private void renameToolStripMenuItem_Click(object sender, EventArgs e) { temporaryName = Microsoft.VisualBasic.Interaction.InputBox("Enter a name for this spreadsheet", "Rename the Spreadsheet", "Untitled", -1, -1); Networking.Send(this.server, "7\t" + this.sheet.GetSavedVersion(this.formName) + "\t" + temporaryName + "\n"); }
/// <summary> /// deals withe the close item in the file menu dropdown and simply exits /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void closeToolStripMenuItem_Click(object sender, EventArgs e) { Networking.Send(this.server, "9\t" + this.sheet.GetSavedVersion(this.formName) + "\n"); this.Close(); }
/// <summary> /// Creates a new spreadsheet /// </summary> /// <param name="sender"></param> /// <param name="e">event</param> private void newToolStripMenuItem_Click(object sender, EventArgs e) { this.requestNewSpreadsheet = true; Networking.Send(this.server, "0\n"); //NewApplicationContext.getAppContext().RunForm(new Form1()); }
/// <summary> /// Sends the "Undo" command to the server /// </summary> private void undoToolStripMenuItem_Click(object sender, EventArgs e) { Networking.Send(warden, "Undo\t\n"); }