Esempio n. 1
0
        protected void grdResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            HyperLink  hlEdit           = null;
            HyperLink  hlSpeciesResults = null;
            HyperLink  hlAdd            = null;
            LinkButton lnkDelete        = null;
            Label      lblDelete        = null;

            string strUserName = "";

            DataRowView dr = (DataRowView)e.Row.DataItem;

            if (Session["UserName"] != null)
            {
                strUserName = Session["UserName"].ToString();
            }

            int intCurrentUserID = DataProxy.GetUserID(strUserName);

            //JK: No idea why I was doing this - maybe to prevent dups with a previous query's dataset, but causing rows to be hidden in error - commenting out.
            //if (Session["PreviousRow"] != null)
            //    strPreviousRow = Session["PreviousRow"].ToString();

            if (e.Row.RowType == DataControlRowType.Header)
            {
                //Set first column/"Country" header
                e.Row.Cells[0].Text = DataProxy.LoadString("COUNTRYLABEL", strCurrentLanguage);

                //Set second column/"Species" header
                e.Row.Cells[1].Text = DataProxy.LoadString("SPECIESLABEL", strCurrentLanguage);

                //Set third column/"Common Name" header
                e.Row.Cells[2].Text = DataProxy.LoadString("COMMONNAMELABEL", strCurrentLanguage);

                //Set fourth column/"Local Common Name" header
                e.Row.Cells[3].Text = DataProxy.LoadString("LOCALCOMMONNAMELABEL", strCurrentLanguage);

                //Set fifth column/"User Name" header
                e.Row.Cells[4].Text = DataProxy.LoadString("ASSESSEDBYLABEL", strCurrentLanguage);

                //Set fourth column/"Total Assessments" header
                //e.Row.Cells[3].Text = DataProxy.LoadString("TOTALASSESSMENTSLABEL", strCurrentLanguage);
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string strAssessmentID = "";
                int    intSpeciesID    = 0;
                int    intCountryID    = 0;
                int    intAssessUserID = 0;
                int    intAssessmentID = 0;

                if (dr["SpeciesID"] != null)
                {
                    int.TryParse(dr["SpeciesID"].ToString(), out intSpeciesID);
                }

                if (dr["UserID"] != null)
                {
                    int.TryParse(dr["UserID"].ToString(), out intAssessUserID);
                }

                if (dr["CountryID"] != null)
                {
                    int.TryParse(dr["CountryID"].ToString(), out intCountryID);
                }

                if (dr["AssessmentID"] != null)
                {
                    strAssessmentID = dr["AssessmentID"].ToString();
                }

                if (e.Row.FindControl("hlAdd") != null)
                {
                    hlAdd = (HyperLink)e.Row.FindControl("hlAdd");

                    string strURL = "CreateAssessment.aspx?AssessmentID=0" + "&SpeciesID=" +
                                    intSpeciesID.ToString() + "&CountryID=" + intCountryID.ToString();

                    hlAdd.NavigateUrl = strURL;
                    hlAdd.Text        = DataProxy.LoadString("ADDASSESSMENTLABEL", strCurrentLanguage);

                    //Only allow user to add an assessment if they haven't already created one for that country/species combo
                    if (intCurrentUserID == 0)
                    {
                        hlAdd.Visible = true;
                    }
                    else
                    {
                        //Check here if user has an assessment

                        if (intAssessUserID != intCurrentUserID)
                        {
                            if (strAssessmentID != "")
                            {
                                intAssessmentID = Convert.ToInt32(strAssessmentID);
                            }
                            intUserID = DataProxy.GetUserIDForAssessment(intCurrentUserID, intCountryID, intSpeciesID);

                            if (intUserID > 0)
                            {
                                hlAdd.Visible = false;
                            }
                            else
                            {
                                hlAdd.Visible = true;
                            }
                        }
                        else
                        {
                            hlAdd.Visible = false;
                        }
                    }
                }
                if (e.Row.FindControl("lnkDelete") != null)
                {
                    lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
                    if (intCurrentUserID != 0)
                    {
                        if (intAssessUserID == intCurrentUserID)
                        {
                            lnkDelete.Visible = true;
                            int intAssessID = Convert.ToInt32(strAssessmentID);
                            lnkDelete.CommandArgument = intAssessID.ToString();
                            lblDelete = (Label)e.Row.FindControl("lblDelete");
                            if (lblDelete != null)
                            {
                                lblDelete.Text = DataProxy.LoadString("DELETETEXT", strCurrentLanguage);
                            }
                        }
                        else
                        {
                            lnkDelete.Visible = false;
                        }
                    }
                    else
                    {
                        lnkDelete.Visible = false;
                    }
                }

                if (e.Row.FindControl("hlEdit") != null)
                {
                    hlEdit = (HyperLink)e.Row.FindControl("hlEdit");
                    string strURL = "EditAssessment.aspx?AssessmentID=" + strAssessmentID + "&SpeciesID=" +
                                    intSpeciesID.ToString() + "&CountryID=" + intCountryID.ToString();

                    if (intCurrentUserID != 0)
                    {
                        if (intAssessUserID == intCurrentUserID)
                        {
                            hlEdit.Visible     = true;
                            hlEdit.NavigateUrl = strURL;

                            //Check if assessment has been marked 'Completed' and flag appropriately for user
                            int intAssessID = Convert.ToInt32(strAssessmentID);
                            if (DataProxy.CheckAssessmentComplete(intAssessID))
                            {
                                hlEdit.Text = DataProxy.LoadString("EDITASSESSMENTLABEL", strCurrentLanguage);
                            }
                            else
                            {
                                hlEdit.Text = DataProxy.LoadString("EDITINCOMPLETEASSESSMENTLABEL", strCurrentLanguage);
                            }
                        }
                    }
                    else
                    {
                        hlEdit.Visible = false;
                    }
                }

                if (e.Row.FindControl("hlSpeciesResults") != null)
                {
                    hlSpeciesResults = (HyperLink)e.Row.FindControl("hlSpeciesResults");

                    string strURL = "";
                    if (strAssessmentID != "0")
                    {
                        strURL = "AssessmentResults.aspx?AssessmentID=" + strAssessmentID + "&SpeciesID=" +
                                 dr["SpeciesID"].ToString() + "&CountryID=" + dr["CountryID"].ToString();
                    }

                    hlSpeciesResults.NavigateUrl = strURL;
                }
            }
        }
Esempio n. 2
0
        protected void grdResults_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            HyperLink  hlEdit           = null;
            HyperLink  hlArchive        = null;
            HyperLink  hlSpeciesResults = null;
            HyperLink  hlAdd            = null;
            LinkButton lnkDelete        = null;
            Label      lblDelete        = null;
            Label      lblCurStatus     = null;
            Label      lblDateAssessed  = null;


            string strUserName    = "";
            string strPreviousRow = "";

            DataRowView dr = (DataRowView)e.Row.DataItem;

            if (Session["UserName"] != null)
            {
                strUserName = Session["UserName"].ToString();
            }

            int intCurrentUserID = DataProxy.GetUserID(strUserName);

            //JK: No idea why I was doing this - maybe to prevent dups with a previous query's dataset, but causing rows to be hidden in error - commenting out.
            //if (Session["PreviousRow"] != null)
            //    strPreviousRow = Session["PreviousRow"].ToString();

            if (e.Row.RowType == DataControlRowType.Header)
            {
                //Set first column/"Country" header
                e.Row.Cells[0].Text = DataProxy.LoadString("COUNTRYLABEL", strCurrentLanguage);

                //Set second column/"Species" header
                e.Row.Cells[1].Text = DataProxy.LoadString("SPECIESLABEL", strCurrentLanguage);

                //Set third column/"Common Name" header
                e.Row.Cells[2].Text = DataProxy.LoadString("COMMONNAMELABEL", strCurrentLanguage);

                //Set fourth column/"Local Common Name" header
                e.Row.Cells[3].Text = DataProxy.LoadString("LOCALCOMMONNAMELABEL", strCurrentLanguage);

                //Set fifth column/"User Name" header
                e.Row.Cells[4].Text = DataProxy.LoadString("ASSESSEDBYLABEL", strCurrentLanguage);

                //Set sixth column/"Date Assessed" header
                e.Row.Cells[5].Text = DataProxy.LoadString("ASSESSMENTDATELABEL", strCurrentLanguage);

                //Set seventh column/"Status" header
                string strStatus = DataProxy.LoadString("ASSESSMENTSTATUSLABEL", strCurrentLanguage);
                strStatus           = strStatus.Replace(":", "");
                e.Row.Cells[6].Text = strStatus;
            }

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string strAssessmentID = "";
                int    intSpeciesID    = 0;
                int    intCountryID    = 0;
                int    intAssessUserID = 0;
                int    intUserID       = 0;
                int    intAssessmentID = 0;
                string strCurStatus    = "";


                if (dr["SpeciesID"] != null)
                {
                    int.TryParse(dr["SpeciesID"].ToString(), out intSpeciesID);
                }

                if (dr["UserID"] != null)
                {
                    int.TryParse(dr["UserID"].ToString(), out intAssessUserID);
                }

                if (dr["CountryID"] != null)
                {
                    int.TryParse(dr["CountryID"].ToString(), out intCountryID);
                }

                if (dr["AssessmentID"] != null)
                {
                    strAssessmentID = dr["AssessmentID"].ToString();
                }


                if (e.Row.FindControl("lblDateAssessed") != null)
                {
                    DateTime dtDate;
                    string   strDate;

                    lblDateAssessed = (Label)e.Row.FindControl("lblDateAssessed");

                    if (dr["DateCreated"] != null)
                    {
                        if (dr["DateCreated"] != DBNull.Value)
                        {
                            dtDate  = Convert.ToDateTime(dr["DateCreated"]);
                            strDate = dtDate.ToString("dd MMM yyyy");
                            lblDateAssessed.Text = strDate;
                        }
                    }
                }


                if (e.Row.FindControl("lblCurStatus") != null)
                {
                    lblCurStatus = (Label)e.Row.FindControl("lblCurStatus");

                    if (dr["CurStatus"] != null)
                    {
                        strCurStatus = dr["CurStatus"].ToString();
                    }

                    if (strCurStatus != "")
                    {
                        if (strCurStatus == "Draft")
                        {
                            strCurStatus = DataProxy.LoadString("INCOMPLETELABEL", strCurrentLanguage);
                        }
                        else
                        {
                            strCurStatus = DataProxy.LoadString("COMPLETEDLABEL", strCurrentLanguage);
                        }
                    }
                    lblCurStatus.Text = strCurStatus;
                }

                if (e.Row.FindControl("hlAdd") != null)
                {
                    hlAdd = (HyperLink)e.Row.FindControl("hlAdd");

                    string strURL = "CreateAssessment.aspx?AssessmentID=0" + "&SpeciesID=" +
                                    intSpeciesID.ToString() + "&CountryID=" + intCountryID.ToString();

                    hlAdd.NavigateUrl = strURL;
                    hlAdd.Text        = DataProxy.LoadString("ADDASSESSMENTLABEL", strCurrentLanguage);

                    //Only allow user to add an assessment if they haven't already created one for that country/species combo
                    if (intCurrentUserID == 0)
                    {
                        hlAdd.Visible = true;
                    }
                    else
                    {
                        //Check here if user has an assessment

                        if (intAssessUserID != intCurrentUserID)
                        {
                            if (strAssessmentID != "")
                            {
                                intAssessmentID = Convert.ToInt32(strAssessmentID);
                            }
                            intUserID = DataProxy.GetUserIDForAssessment(intCurrentUserID, intCountryID, intSpeciesID);

                            if (strUserRole == "Guest")
                            {
                                hlAdd.Enabled = false;
                            }

                            if (intUserID > 0)
                            {
                                hlAdd.Visible = false;
                            }
                            else
                            {
                                hlAdd.Visible = true;
                            }
                        }
                        else
                        {
                            hlAdd.Visible = false;
                        }
                    }
                }
                if (e.Row.FindControl("lnkDelete") != null)
                {
                    lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
                    if (intCurrentUserID != 0)
                    {
                        //jan 2018 - add Delete option for Admin users logged in as well...
                        if (intAssessUserID == intCurrentUserID || (strUserRole == "Admin" && intAssessUserID != 0))
                        {
                            lnkDelete.Visible = true;

                            if (strUserRole == "Guest")
                            {
                                lnkDelete.Enabled = false;
                            }

                            int intAssessID = Convert.ToInt32(strAssessmentID);
                            lnkDelete.CommandArgument = intAssessID.ToString();
                            lblDelete = (Label)e.Row.FindControl("lblDelete");
                            if (lblDelete != null)
                            {
                                lblDelete.Text = DataProxy.LoadString("DELETETEXT", strCurrentLanguage);
                            }
                        }
                        else
                        {
                            lnkDelete.Visible = false;
                        }
                    }
                    else
                    {
                        lnkDelete.Visible = false;
                    }
                }

                if (e.Row.FindControl("hlEdit") != null)
                {
                    hlEdit = (HyperLink)e.Row.FindControl("hlEdit");
                    string strURL = "EditAssessment.aspx?AssessmentID=" + strAssessmentID + "&SpeciesID=" +
                                    intSpeciesID.ToString() + "&CountryID=" + intCountryID.ToString();

                    bool isFacilitator = false;
                    int  intAssessID   = Convert.ToInt32(strAssessmentID);

                    if (intCurrentUserID != 0)
                    {
                        //Add logic to this for Facilitators who can now edit the assessment
                        DataTable dtCurUser = DataProxy.GetUserInfo(intCurrentUserID);
                        if (dtCurUser != null)
                        {
                            if (dtCurUser.Rows.Count > 0)
                            {
                                DataRow drUser        = dtCurUser.Rows[0];
                                int     intUserTypeID = Convert.ToInt16(drUser["UserTypeID"]);
                                string  userType      = DataProxy.GetUserType(intUserTypeID);
                                if (userType.ToUpper() == "FACILITATOR")
                                {
                                    isFacilitator = true;
                                }
                            }
                        }

                        if (intAssessUserID == intCurrentUserID || isFacilitator)
                        {
                            hlEdit.Visible = true;

                            if (strUserRole == "Guest")
                            {
                                hlEdit.Enabled = false;
                            }

                            if (isFacilitator)
                            {
                                hlEdit.Text = DataProxy.LoadString("EDITTEXT", strCurrentLanguage);
                                strURL     += "&FEdit=Y";
                                if (strAssessmentID == "0")
                                {
                                    hlEdit.Visible = false;
                                }

                                //Set Archive assessments
                                hlArchive = (HyperLink)e.Row.FindControl("hlArchive");
                                if (DataProxy.CheckAssessmentComplete(intAssessID))
                                {
                                    hlArchive.Visible = true;
                                    string strMessage = "";
                                    if (DataProxy.CheckAssessmentArchived(intAssessID))
                                    {
                                        strMessage = DataProxy.LoadString("CONFIRMUNARCHIVE", strCurrentLanguage);

                                        hlArchive.Text = DataProxy.LoadString("ARCHIVETEXT", strCurrentLanguage);
                                        hlArchive.Attributes["onclick"] = String.Format("return confirm('{0}');", strMessage);
                                        hlArchive.NavigateUrl           = "SearchAll.aspx?ArchiveAssessID=" + strAssessmentID + "&Archive=N";
                                    }
                                    else
                                    {
                                        //Assessment not set to Archived - show icon
                                        strMessage = DataProxy.LoadString("CONFIRMARCHIVE", strCurrentLanguage);

                                        hlArchive.ImageUrl = @"\images\Archive icon.png";
                                        hlArchive.Attributes["onclick"] = String.Format("return confirm('{0}');", strMessage);
                                        hlArchive.NavigateUrl           = "SearchAll.aspx?ArchiveAssessID=" + strAssessmentID + "&Archive=Y";
                                    }
                                }
                            }
                            else
                            {
                                //Check if assessment has been marked 'Completed' and flag appropriately for user
                                if (DataProxy.CheckAssessmentComplete(intAssessID))
                                {
                                    hlEdit.Text = DataProxy.LoadString("EDITASSESSMENTLABEL", strCurrentLanguage);
                                }
                                else
                                {
                                    hlEdit.Text = DataProxy.LoadString("EDITINCOMPLETEASSESSMENTLABEL", strCurrentLanguage);
                                }
                            }

                            hlEdit.NavigateUrl = strURL;
                        }
                    }
                    else
                    {
                        hlEdit.Visible = false;
                    }
                    //OLD LOGIC
                    //if (strUserName != "")
                    //    //strAssessmentID = DataProxy.GetAssessmentIDForUser(Convert.ToInt32(dr["SpeciesID"]), Convert.ToInt32(dr["CountryID"]), strUserName);
                    //    strAssessmentID = dr["AssessmentIDUser"].ToString();


                    //if (strUserName != "")
                    //{
                    //    if (strUserName.ToUpper() == dr["UserName"].ToString().ToUpper() && strAssessmentID != "0")
                    //    {
                    //        hlEdit.Visible = true;
                    //        hlEdit.NavigateUrl = strURL;
                    //        hlEdit.Text = DataProxy.LoadString("EDITASSESSMENTLABEL", strCurrentLanguage);
                    //    }
                    //}
                    //else
                    //    hlEdit.Visible = false;
                    //END OLD LOGIC
                }

                if (e.Row.FindControl("hlSpeciesResults") != null)
                {
                    hlSpeciesResults = (HyperLink)e.Row.FindControl("hlSpeciesResults");

                    string strURL = "";
                    if (strAssessmentID != "0")
                    {
                        strURL = "AssessmentResults.aspx?AssessmentID=" + strAssessmentID + "&SpeciesID=" +
                                 dr["SpeciesID"].ToString() + "&CountryID=" + dr["CountryID"].ToString();
                    }

                    hlSpeciesResults.NavigateUrl = strURL;
                }
                //JK: No idea why I was doing this - maybe to prevent dups with a previous query's dataset, but causing rows to be hidden in error - commenting out.
                //Session["PreviousRow"] = dr["SpeciesID"].ToString() + "-" + dr["CountryID"].ToString();

                //if (strPreviousRow == Session["PreviousRow"].ToString())
                //    e.Row.Visible = false;
            }
        }