//changement d'onglet private async void TabMenu_Selecting(object sender, TabControlCancelEventArgs e) { var selectedTab = this.TabMenu.SelectedTab.Controls; switch (selectedTab.Owner.Name) { case "tabPage1": this.B_ClientGridSource.DataSource = await Communication.GetClients(); break; case "tabPage2": this.B_ProductGridSource.DataSource = await Communication.GetProducts(); break; case "tabPage3": this.B_EmployeeGridSource.DataSource = await Communication.GetEmployees(); break; default: MessageBox.Show("Invalid tab name: selectedTab.Owner.Name"); break; } //MessageBox.Show("Index selected: " + e.TabPage.Name); }
private async void buttonUpdateEmployee_Click(object sender, EventArgs e) { if (this.selectedRow != null && this.selectedRow.Cells[0].Value != null && (Int32)this.selectedRow.Cells[0].Value != -1) { var coucou = this.selectedRow.Cells; try { var response = await Communication.UpdateEmployee(new Mapping.Employee() { lastName = coucou[1].Value.ToString(), firstName = coucou[2].Value.ToString(), phone = coucou[3].Value.ToString(), service = coucou[4].Value.ToString(), }); if (response != null && response.id != -1) { this.B_EmployeeGridSource.DataSource = await Communication.GetEmployees(); this.textBoxEmployeeFamilyName.Clear(); this.textBoxEmployeeName.Clear(); this.textBoxEmployeePhone.Clear(); this.textBoxEmployeeService.Clear(); this.dataGridViewEmployee.ClearSelection(); } else { MessageBox.Show("Could not update Employee", "Updating Employee", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show("Fatal Error: " + ex.Message, "Updating Employee", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { //MessageBox.Show("Please select a row before trying to edit.", "Cell error", MessageBoxButtons.OK, MessageBoxIcon.Information); } }