//Exit procedure public void Exit() { if (serial != null) { if (serial.IsOpen) { serial.Write("#E#"); serial.Close(); } } dl.CloseFile(); }
//Connect to Microcontroller private void btnMicro_Click(object sender, EventArgs e) { this.Visible = false; //Sets DataLogger file to desktopDirectory dl = new DataLogger.DLProgram(desktopDirectory + "/" + CommonFunctions.FileNameSafe(DateTime.Now.ToLongTimeString())); Main m = new Main("microcontroller", currentDirectory, dl); m.ShowDialog(); dl.CloseFile(); m = null; btnLogin.Enabled = true; btnCreate.Enabled = true; txtUsername.Enabled = true; txtPassword.Enabled = true; this.Visible = true; }
//Logging in to the client private void btnLogin_Click(object sender, EventArgs e) { btnCreate.Enabled = false; btnLogin.Enabled = false; txtUsername.Enabled = false; txtPassword.Enabled = false; bool authorized = false; MySqlConnection conn = new MySqlConnection(); JSch jsch = new JSch(); string host = "secs.oakland.edu"; string user = "******"; string pass = "******"; int sshPort = 22; Session session = jsch.getSession(user, host, sshPort); session.setHost(host); session.setPassword(pass); UserInfo ui = new MyUserInfo(); session.setUserInfo(ui); try { session.connect(); session.setPortForwardingL(3306, "localhost", 3306); } catch (Exception err) { MessageBox.Show(err.Message); txtUsername.Enabled = true; txtPassword.Enabled = true; btnLogin.Enabled = true; btnCreate.Enabled = true; } if (session.isConnected()) { try { string dbhost = "localhost"; string dbuser = "******"; string dbpass = "******"; string dbdatabase = "iafram"; string connStr = String.Format("server={0};user id={1};password={2}; database={3}; pooling=false", dbhost, dbuser, dbpass, dbdatabase); conn = new MySqlConnection(connStr); conn.Open(); conn.ChangeDatabase(dbdatabase); string query = "SELECT COUNT(*) "; query += "FROM cse337_project "; query += "WHERE username = "******" AND password = "******"/" + CommonFunctions.FileNameSafe(DateTime.Now.ToLongTimeString())); Main m = new Main(txtUsername.Text, currentDirectory, dl); m.ShowDialog(); dl.CloseFile(); m = null; btnLogin.Enabled = true; btnCreate.Enabled = true; txtUsername.Enabled = true; txtPassword.Enabled = true; this.Visible = true; } else { MessageBox.Show("Incorrect username/password combination."); btnLogin.Enabled = true; txtUsername.Enabled = true; txtPassword.Enabled = true; } } }