private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e) { var Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Username = Username.Substring(Username.Length - 3); if (comboBox1.SelectedItem != null) { switch (comboBox1.SelectedItem.ToString().Trim()) { case "Login": Form1 frm1 = new Form1(); frm1.Show(); frm1.Text = Username; break; case "Admin": Form2 frm2 = new Form2(); frm2.Show(); frm2.Text = Username; break; case "Navigation": formPopup frmPopup = new formPopup(); frmPopup.Show(); frmPopup.Text = Username; break; case "Utility": Form5 frm5 = new Form5(); frm5.Show(); frm5.Text = Username; break; case "Utility Management": Form4 frm4 = new Form4(); frm4.Show(); frm4.Text = Username; break; case "Batch Processing": Form6 frm6 = new Form6(); frm6.Show(); frm6.Text = Username; break; } //Do something with the selected item } }
private void Button1_Click(object sender, EventArgs e) { UserCredential credential; using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; Console.WriteLine("Credential file saved to: " + credPath); } // Create Google Sheets API service. var service = new SheetsService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range); // Prints the columns in a sample spreadsheet: ValueRange response = request.Execute(); values = response.Values; var Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Username = Username.Substring(Username.Length - 3); if (values != null && values.Count > 0) { int i = 0; foreach (var row in values) { // Print columns A and E, which correspond to indices 0 and 1. if (row[1].Equals(Username)) { MessageBox.Show("Welcome " + row[2] + " " + Username); this.Close(); // switch (row[2]) // { // case "Admin": Console.WriteLine(row[2].ToString()); formPopup frmPopup = new formPopup(); frmPopup.UserRole = row[2].ToString(); frmPopup.Show(); frmPopup.Text = Username; break; // } } i++; Console.WriteLine("{0}, {1}", row[0], row[1]); } if (i == 0) { MessageBox.Show("Your profile is not found"); this.Close(); } } else { Console.WriteLine("No data found.");; } // using (PrincipalContext pc = new PrincipalContext(ContextType.Domain)) // if (pc.ValidateCredentials("zhj", "autumn19")) // { // Debug.WriteLine("Validated"); // /* Check group membership */ // } }