protected void btnFilter_Click(object sender, EventArgs e)
        {
            gvGlance.DataSource = null;
            lblDisplay.Text     = "";
            List <DocumentDetails> documentList = new List <DocumentDetails>();
            ELibraryDocumentBL     docBL        = new ELibraryDocumentBL();
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("Title", typeof(string)));
            dt.Columns.Add(new DataColumn("Author", typeof(string)));
            dt.Columns.Add(new DataColumn("Description", typeof(string)));
            dt.Columns.Add(new DataColumn("Type", typeof(string)));
            dt.Columns.Add(new DataColumn("Price", typeof(string)));
            dt.Columns.Add(new DataColumn("", typeof(Control)));
            dt.Columns.Add(new DataColumn("Path", typeof(string)));
            dt.Columns.Add(new DataColumn("DocumentID", typeof(string)));

            try
            {
                int itemsSelected = 0;
                foreach (ListItem li in chklasideBar.Items)
                {
                    if (li.Selected)
                    {
                        itemsSelected = itemsSelected + 1;
                    }
                }
                if (itemsSelected == 0)
                {
                    throw new ELibraryException("Please select a check box");
                }
                for (int i = 0; i < chklasideBar.Items.Count; i++)
                {
                    List <DocumentDetails> documentDiscList = null;

                    if (chklasideBar.Items[i].Selected)
                    {
                        documentDiscList = null;
                        string discipline = chklasideBar.Items[i].Text;
                        documentDiscList = docBL.ViewDocumentsByDisciplineBL(discipline);
                        if (documentDiscList != null)
                        {
                            foreach (DocumentDetails doc in documentDiscList)
                            {
                                documentList.Add(doc);
                            }
                        }
                    }
                }
                if (documentList.Count > 0)
                {
                    foreach (DocumentDetails doc in documentList)
                    {
                        DataRow dr = dt.NewRow();
                        dr["Title"]       = doc.Title;
                        dr["Author"]      = doc.Author;
                        dr["Type"]        = docBL.GetDocumentTypeBL(doc.DocumentTypeID);
                        dr["Description"] = doc.DocumentDescription;
                        dr["Path"]        = doc.DocumentPath;
                        dr["Price"]       = doc.Price;
                        dr["DocumentID"]  = doc.DocumentID;
                        dt.Rows.Add(dr);
                    }
                    gvGlance.DataSource = dt;
                    gvGlance.DataBind();
                }
            }
            catch (ELibraryException ex)
            {
                ErrorLogging erLog = new ErrorLogging();
                erLog.LogError(ex.Message);
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('Please select atleast one checkbox')", true);
            }
            catch (Exception ex)
            {
                ErrorLogging erLog = new ErrorLogging();
                erLog.LogError(ex.Message);
            }
        }
示例#2
0
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            ELibraryDocumentBL     docBL        = new ELibraryDocumentBL();
            List <DocumentDetails> documentList = null;

            try
            {
                if (cboSearchBy.SelectedItem.Text == "Name")
                {
                    gvSearch.DataSource = null;
                    string name = txtName.Text;
                    if (name == "")
                    {
                        throw new ELibraryException("Please enter the name");
                    }
                    documentList = docBL.ViewDocumentsByNameBL(name);
                    if (documentList != null)
                    {
                        DataTable dt = new DataTable();
                        dt.Columns.Add(new DataColumn("Title", typeof(string)));
                        dt.Columns.Add(new DataColumn("Author", typeof(string)));
                        dt.Columns.Add(new DataColumn("Description", typeof(string)));
                        dt.Columns.Add(new DataColumn("Type", typeof(string)));
                        dt.Columns.Add(new DataColumn("Price", typeof(string)));
                        dt.Columns.Add(new DataColumn("", typeof(Control)));
                        dt.Columns.Add(new DataColumn("Path", typeof(string)));
                        dt.Columns.Add(new DataColumn("DocumentID", typeof(string)));
                        foreach (DocumentDetails doc in documentList)
                        {
                            DataRow dr = dt.NewRow();
                            dr["Title"]       = doc.Title;
                            dr["Author"]      = doc.Author;
                            dr["Type"]        = docBL.GetDocumentTypeBL(doc.DocumentTypeID);
                            dr["Description"] = doc.DocumentDescription;
                            dr["Path"]        = doc.DocumentPath;
                            dr["Price"]       = doc.Price;
                            dr["DocumentID"]  = doc.DocumentID;
                            dt.Rows.Add(dr);
                        }
                        gvSearch.DataSource = dt;
                        gvSearch.DataBind();
                    }
                }
                else if (cboSearchBy.SelectedItem.Text == "Discipline")
                {
                    gvSearch.DataSource = null;
                    string discipline = cboDiscipline.SelectedItem.Text;

                    documentList = docBL.ViewDocumentsByDisciplineBL(discipline);
                    if (documentList != null)
                    {
                        DataTable dt = new DataTable();
                        dt.Columns.Add(new DataColumn("Title", typeof(string)));
                        dt.Columns.Add(new DataColumn("Author", typeof(string)));
                        dt.Columns.Add(new DataColumn("Description", typeof(string)));
                        dt.Columns.Add(new DataColumn("Type", typeof(string)));
                        dt.Columns.Add(new DataColumn("Price", typeof(string)));
                        dt.Columns.Add(new DataColumn("", typeof(Control)));
                        dt.Columns.Add(new DataColumn("Path", typeof(string)));
                        dt.Columns.Add(new DataColumn("DocumentID", typeof(string)));
                        foreach (DocumentDetails doc in documentList)
                        {
                            DataRow dr = dt.NewRow();
                            dr["Title"]       = doc.Title;
                            dr["Author"]      = doc.Author;
                            dr["Type"]        = docBL.GetDocumentTypeBL(doc.DocumentTypeID);
                            dr["Description"] = doc.DocumentDescription;
                            dr["Path"]        = doc.DocumentPath;
                            dr["Price"]       = doc.Price;
                            dr["DocumentID"]  = doc.DocumentID;
                            dt.Rows.Add(dr);
                        }
                        gvSearch.DataSource = dt;
                        gvSearch.DataBind();
                    }
                }
            }
            catch (ELibraryException ex)
            {
                ErrorLogging erLog = new ErrorLogging();
                erLog.LogError(ex.Message);
                lblDisplay.Text = ex.Message;
            }
        }