Esempio n. 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                MessageBox.Show("Name Can't be empty");
                return;
            }

            if (txtEmail.Text == "")
            {
                MessageBox.Show("Email Can't be empty");
                return;
            }

            EmployeeInfo employeeInfo = new EmployeeInfo();

            var response = APICalls.AddEmployee(new EmployeeInfo
            {
                email      = txtEmail.Text,
                gender     = drpGender.SelectedItem.ToString(),
                name       = txtName.Text,
                status     = drpStatus.SelectedItem.ToString(),
                created_at = DateTime.Now,
                updated_at = DateTime.Now
            });

            MessageBox.Show("Done " + (response? "Successfully" : "Unsuccessfully"));
        }
        //public SearchForEmployee()
        //{
        //    InitializeComponent();
        //}

        void DoSearch(int page)

        {
            if (chkShowAll.Checked)
            {
                CurrentList = APICalls.GetAllEmployees(page);
            }
            else
            {
                CurrentList = APICalls.SearchForEmployees(txtNameFilter.Text, txtEmailFilter.Text, page);
            }

            grdEmployees.AutoGenerateColumns = false;

            grdEmployees.DataSource = CurrentList.data;
            lblCurrentPage.Text     = CurrentList.meta.pagination.page.ToString() + " Of "
                                      + CurrentList.meta.pagination.pages.ToString();
            CurrentPage = CurrentList.meta.pagination.page;
        }
        private void btnDeleted_Click(object sender, EventArgs e)
        {
            bool response = false;

            if (grdEmployees.Rows.Count > 0)
            {
                foreach (DataGridViewRow selectedemployee in grdEmployees.Rows)
                {
                    bool IsSelected = false;
                    if (bool.TryParse(selectedemployee.Cells["ColumnDelete"].FormattedValue.ToString(), out IsSelected))
                    {
                        if (IsSelected)
                        {
                            response = APICalls.DeleteEmployee(int.Parse(selectedemployee.Cells[0].Value.ToString()));
                        }
                    }
                }
            }

            MessageBox.Show("Done " + (response ? "Successfully" : "Unsuccessfully"));

            DoSearch(CurrentPage);
        }