public string AppName = ConfigurationManager.AppSettings["AppName"]; //"fa114107311259f5f33e70a5d85de34a2499b4401da069af0b1d835cd5ec0d56"; public frmEmployee() { InitializeComponent(); RESTApiHelper.InitializeClient(); btnPrevious.Enabled = false; btnNext.Enabled = false; btnGo.Enabled = false; }
/// <summary> ///Event to handle Employee search by Id and populate the employee details /// </summary> private async void btnIDSearch_Click(object sender, EventArgs e) { try { if (ValidateEmpIDControl((Button)sender)) { string response = await RESTApiHelper.Get(txtEmpID.Text.Trim()); DeserializeJsonforSingleSearch(response); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }
/// <summary> /// Event to handle deleting an employee /// </summary> private async void btnEmpDelete_Click(object sender, EventArgs e) { try { if (ValidateEmpIDControl((Button)sender)) { var response = await RESTApiHelper.Delete(FormJsonString()); LoadCurrentPage(Convert.ToInt32(lblcurrPage.Text)); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }
/// <summary> /// //Call APIHelper to get current page and load datagridview /// </summary> /// <param>current pageno</param> /// <returns></returns> private async void LoadCurrentPage(int currentPage) { try { var response = await RESTApiHelper.GetPage(currentPage.ToString()); JsonResponse jsonparse = JsonConvert.DeserializeObject <JsonResponse>(response); dgvEmployee.DataSource = jsonparse.data; txtPageNo.Text = jsonparse.meta.pagination.page; lblcurrPage.Text = jsonparse.meta.pagination.page; txtTotalRec.Text = jsonparse.meta.pagination.total; lblPages.Text = jsonparse.meta.pagination.pages; if (dgvEmployee.Rows.Count > 0) { LoadControls(0); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }
/// <summary> /// Event to handle updating an employee /// </summary> private async void btnEmpUpdate_Click(object sender, EventArgs e) { try { if (ValidateControls((Button)sender)) { Employee updEmployee = new Employee(); updEmployee.id = txtEmpID.Text.Trim(); updEmployee.name = txtEmpName.Text.Trim(); updEmployee.email = txtEmpEmail.Text.Trim(); updEmployee.gender = cboEmpGender.SelectedItem.ToString(); updEmployee.status = cboEmpStatus.SelectedItem.ToString(); var response = await RESTApiHelper.Put(updEmployee); //FormJsonString()); LoadCurrentPage(Convert.ToInt32(lblcurrPage.Text)); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }
/// <summary> /// Event to handle adding new employee /// </summary> private async void btnEmpAdd_Click(object sender, EventArgs e) { try { if (ValidateControls((Button)sender)) { EmployeeAdd newEmployee = new EmployeeAdd(); newEmployee.name = txtEmpName.Text.Trim(); newEmployee.email = txtEmpEmail.Text.Trim(); newEmployee.gender = cboEmpGender.SelectedItem.ToString(); newEmployee.status = cboEmpStatus.SelectedItem.ToString(); var response = await RESTApiHelper.Post(newEmployee); //DeserializeJsonforSingleSearch(response); LoadCurrentPage(Convert.ToInt32(lblPages.Text)); //ListAllEmployees(); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }
/// <summary> ///Event to handle Employee search by Name and populate the employee details /// </summary> private async void btnNameSearch_Click(object sender, EventArgs e) { try { if (!(txtEmpName.Text.Length > 0)) { txtEmpName.Focus(); MessageBox.Show("Please enter Name", AppName); return; } var response = await RESTApiHelper.Get(txtEmpName.Text.Trim()); var jsonparse = JsonConvert.DeserializeObject <JsonResponse>(response); dgvEmployee.DataSource = jsonparse.data; if (dgvEmployee.Rows.Count > 0) { LoadControls(0); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }
/// <summary> /// //Call APIHelper to get all employees and load datagridview /// </summary> /// <param></param> /// <returns></returns> private async void ListAllEmployees() { try { var response = await RESTApiHelper.GetAll(); JsonResponse jsonparse = JsonConvert.DeserializeObject <JsonResponse>(response); dgvEmployee.DataSource = jsonparse.data; txtPageNo.Text = jsonparse.meta.pagination.page; lblcurrPage.Text = jsonparse.meta.pagination.page; txtTotalRec.Text = jsonparse.meta.pagination.total; lblPages.Text = jsonparse.meta.pagination.pages; if (dgvEmployee.Rows.Count > 0) { btnPrevious.Enabled = false; btnNext.Enabled = true; LoadControls(0); } } catch (Exception ex) { MessageBox.Show(ex.Message, AppName); } }