Beispiel #1
0
        public MessageClass()
        {
            Client client = new Client();
            client.IncomingLineEvent += MessageReceived;

            //Create a new login window and set its client to this client.
            login = new Login.Form1();
            login.setClient(client);

            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);

            // Start an application context and run one form inside it
            //MyApplicationContext appContext = MyApplicationContext.getAppContext();
            Application.Run(login);

            //Create new available file window.
            af = new AvailableFiles.Form1();
            af.setClient(client);
            //Application.Run(af);

            spreadsheet = new SpreadsheetGUI.Form1();
        }
Beispiel #2
0
        /// <summary>
        /// Method called when a new message has been received by the server.
        /// </summary>
        /// <param name="line"></param>
        /// <param name="e"></param>
        private void MessageReceived(String line, Exception e)
        {
            if (ReferenceEquals(line, null) || line == "") {
                if (e is SocketException) {
                    serverClosed = true;
                    MessageBox.Show("Server has closed.  Please try again later.",
                        "Message",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    if (this.InvokeRequired) {
                        CloseSSCallback d = new CloseSSCallback(CloseSS);
                        this.Invoke(d, new object[] { });
                    } else {
                        CloseSS();
                    }
                    return;
                }
                return;
            }

            string[] lineReceived = Regex.Split(line, esc.ToString());

            string protocol = lineReceived[0];

            //INVALID\n
            if (protocol.Equals("INVALID")) {
                login.LoginError();
                login = new Login.Form1(client);
                login.ShowDialog();
            }
                //FILELIST[esc]list_of_existing_filenames\n ( each name delimited by [esc])
            else if (protocol.Equals("FILELIST")) {
                availableFile = new AvailableFiles.Form1(client);
                availableFile.ClickedCancel += CancelSpreadSheet;

                //Add the items to the list of items you can open
                availableFile.AddSS(lineReceived);

                //Run the files available prompt window.
                availableFile.ShowDialog();

                NameOfSS = availableFile.getSSName();

                //Shows the spreadsheet again after the user has picked to open
                // a new spreadsheet or to open an exsisting spreadsheet.
                if (this.InvokeRequired) {
                    ShowSSCallback d = new ShowSSCallback(ShowSS);
                    this.Invoke(d, new object[] { });
                } else {
                    spreadsheetPanel1.Show();
                }
                availableFile.Focus();

                time.Start();

                SetTitle();

            }
                //UPDATE[esc]current_version[esc]cell_name1[esc]cell_content1[esc]cell_name2[esc]…\n
                  //SYNC[esc]current_version[esc]cell_name[esc]cell_content…\n
            else if (protocol.Equals("UPDATE") || protocol.Equals("SYNC")) {
                Dictionary<string, string> cells = new Dictionary<string, string>();
                String cellName = ""; String cellCont = "";
                try {
                    int currentVersion = Convert.ToInt32(lineReceived[1]);

                    //If the last command sent to server was an edit to the spreadsheet and
                    // the version + 1 doesn't equal to the version send back by the server demand a Resync to server.
                    if (SSEdit && (versionNumber + 1) != currentVersion) {
                        //Must resync with the server.
                        client.SendMessage("RESYNC\n");
                        SSEdit = false;
                        return;
                    }
                    versionNumber = currentVersion;
                } catch {
                    //TODO:Handle this properly.
                    MessageBox.Show(
                    "Error",
                    "Protocol was not sent properly. No version number was sent",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                    return;
                }
                //Go through the array and place the cellName in the correct container
                // and do the same with the content of that cell.
                for (int i = 2; i < lineReceived.Length; i++) {
                    if (i % 2 == 0) {
                        //It is a cell name
                        cellName = lineReceived[i];
                        i++;
                    }
                    if ((i % 2) == 1 && i < lineReceived.Length) {
                        //It is the contents of the cell.
                        cellCont = lineReceived[i];
                    }
                    cells.Add(cellName, cellCont);
                }
                Update(cells);

                SSEdit = false;
            } else if (protocol.Equals("SAVED")) {
                //TODO: what to do when the saved command is received.
                MessageBox.Show("File Successfully Saved",
                          "Saved",
                          MessageBoxButtons.OK,
                          MessageBoxIcon.Information);
                return;
            }
                //ERROR[esc]error_message\n
              else if (protocol.Equals("ERROR")) {
                MessageBox.Show(lineReceived[1],
                           "Message",
                           MessageBoxButtons.OK,
                           MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #3
0
        /// <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;
        }
Beispiel #4
0
        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;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string zh = comboBox1.Text;
            string mm = textBox1.Text;

            if (zh.Trim() == "")
            {
                MessageBox.Show("用户名不能为空!");
            }
            else if (mm.Trim() == "")
            {
                MessageBox.Show("密码不能为空!");
            }
            else
            {
                if (zz == 3)
                {
                    string sql = @"update LoginInfo
                                set status = '0'
                                ,unlockTime = DATEADD(HH,24,GETDATE())
                                where login='******'";
                    int    rs  = db.DonIntsdf(sql);
                    if (rs == 1)
                    {
                        MessageBox.Show("登录失败三次,账号已锁定!");
                    }
                    zz = 0;
                }
                else
                {
                    string sql = @"select count(*) from LoginInfo 
                               where login='******' and unlockTime>GETDATE()";
                    int    rs  = db.Login(sql);
                    if (rs == 1)
                    {
                        MessageBox.Show("账号已锁定,无法登录!");
                    }
                    else
                    {
                        string sql2 = @"select count(*) from LoginInfo 
                               where login='******' and pass='******'";
                        int    rs2  = db.Login(sql2);
                        if (rs2 == 0)
                        {
                            MessageBox.Show("登录失败!密码错误,您还有" + (3 - zz - 1) + "次机会");
                            zz++;
                        }
                        else if (textBox2.Text.Trim() == jieguo.ToString())
                        {
                            string sql3 = @"update LoginInfo
                                set status = '1'
                                ,unlockTime = null
                                where login='******'";
                            db.DonIntsdf(sql3);
                            Login.Form1 open = new Login.Form1();
                            open.Show();
                            MessageBox.Show(comboBox1.Text + "欢迎您登陆成功");
                            StaticPropertiesOfClasses.Id  = zh;
                            StaticPropertiesOfClasses.pwd = mm;
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("验证码不正确");
                        }
                    }
                }
            }
        }
Beispiel #6
0
 private void button1_Click(object sender, EventArgs e)
 {
     this.Hide();
     Form1 loginform = new Form1();
     loginform.Show();
 }