private void LoadCourses(int deptId)
        {
            try
            {
                List <CourseViewModel> data = deptId == 0 ?  _courseRepo.GetAllCourses() : _courseRepo.GetAllDepartmentCourses(deptId);

                if (data != null)
                {
                    grdData.DataSource = data;
                    if (grdData.Rows.Count > 0)
                    {
                        grdData.Columns["Id"].Visible = false;
                    }
                    else
                    {
                        //var dt = new DataTable();
                        //grdData.Columns.Clear();
                        //dt.Columns.Add("Message", typeof(string));
                        //dt.Rows.Add("No items found");
                        //grdData.DataSource = dt;
                        // MessageBox.Show(this, "No record found", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    repData = data.ConvertToDataTable();  //save records in datatable for searching, export etc
                    Base.ResizeGrid(ref grdData);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        private void LoadData()
        {
            try
            {
                _levelId = comboLevel.SelectedValue.ToString() == Base.IdForSelectAll ? "" : comboLevel.SelectedValue.ToString();
                _deptId  = comboDept.SelectedValue.ToString() == Base.IdForSelectAll ? "" : comboDept.SelectedValue.ToString();

                var data = _repo.GetAllCourses(_deptId, _levelId);
                if (data != null && data.Count > 0)
                {
                    dataGrid.DataSource                        = data;
                    dataGrid.Columns["Id"].Visible             = false;
                    dataGrid.Columns["CourseTitle"].HeaderText = "Course Title";
                    dataGrid.Columns["CourseCode"].HeaderText  = "Course Code";
                }
                else
                {
                    _noItems = true;
                    var dt = new DataTable();
                    dataGrid.Columns.Clear();
                    dt.Columns.Add("Message", typeof(string));
                    dt.Rows.Add("No record found");
                    dataGrid.DataSource = dt;
                }

                _gridData = data.ConvertToDataTable(); //save records in datatable for searching, export etc
                Base.AddLinksToGrid(ref dataGrid, new List <string>
                {
                    "Edit",
                    "Delete"
                }, _noItems); //add edit,delete icon
            }
            catch (Exception e)
            {
                MessageBox.Show(this, e.Message, "Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }