Exemple #1
0
    protected void Bindgrid()
    {
        #region Declaration of localvariable and table Variable
        int       filterId;
        DataTable dtTable = new DataTable();
        dtTable = CreateDataTable();
        string userName         = "";
        int    varTechnicianId  = 0;
        string varSortParameter = "createdatetime";

        #endregion

        #region Get Current User and his Role
        MembershipUser User              = Membership.GetUser();
        string         varUserRole       = "";
        string         varRoleTechnician = "";
        if (User != null)
        {
            userName = User.UserName.ToString();
            string[] arrUserRole = Roles.GetRolesForUser();
            varUserRole       = arrUserRole[0].ToString();
            varRoleTechnician = Resources.MessageResource.strTechnicianRole.ToString();
        }
        #endregion

        #region Get User object  by Calling Function Get_UserLogin_By_UserName() via passing parameter username and organizationid
        objOrganization = objOrganization.Get_Organization();
        objUser         = objUser.Get_UserLogin_By_UserName(userName, objOrganization.Orgid);
        #endregion


        #region If User Exist
        if (objUser.Userid != 0)
        {
            string fromdate = null;
            string todate   = null;

            #region Find how many sites have been mapped to current user by calling function Get_All_By_userid() via passing parameter userid
            int userid = objUser.Userid;
            colUserToSite = ObjUserToSite.Get_All_By_userid(userid);
            #endregion
            #region Fetch each object from Collection of UserToSiteMapping
            foreach (UserToSiteMapping obj in colUserToSite)
            {
                #region Declare Local Variables and Collection of Incident_mst Type
                string Status;
                BLLCollection <Incident_mst> col = new BLLCollection <Incident_mst>();
                int siteid;
                #endregion
                #region Get the Siteid and Filter Parameter
                siteid   = obj.Siteid;
                filterId = 0;
                #endregion

                #region If Role of User is Technician



                #region If Filter Variable is All
                if (filterId == 0)
                {
                    col = objIncident.Get_All_By_Siteid_Requesterid(siteid, objUser.Userid, fromdate, todate, varSortParameter);
                }
                #endregion



                #endregion



                #region Fetch Each object of type Incident_mst from Collection Incident_mst
                foreach (Incident_mst objInc in col)
                {
                    #region Create Table row and assign value to it
                    DataRow row;
                    row = dtTable.NewRow();
                    row["incidentid"]     = Convert.ToString(objInc.Incidentid);
                    row["title"]          = objInc.Title;
                    row["requesterid"]    = Convert.ToString(objInc.Requesterid);
                    row["createdbyid"]    = Convert.ToString(objInc.Createdbyid);
                    row["siteid"]         = Convert.ToString(objInc.Siteid);
                    row["createdatetime"] = Convert.ToString(objInc.Createdatetime);
                    objIncidentStates     = objIncidentStates.Get_By_id(objInc.Incidentid);
                    row["statusid"]       = objIncidentStates.Statusid;
                    row["technicianid"]   = objIncidentStates.Technicianid;
                    row["priorityid"]     = objIncidentStates.Priorityid;
                    dtTable.Rows.Add(row);
                    #endregion
                }
                #endregion
            }
            #endregion
            #region Bind Grid from datasource dtTable
            DataView dvData        = new DataView(dtTable);
            string   sortFormat    = "{0} {1}";
            String   sortDirection = "DESC";
            if (varSortParameter == "createdatetime")
            {
                varSortParameter = "incidentid";
            }
            dvData.Sort = String.Format(sortFormat, varSortParameter, sortDirection);



            grdvwRequest.DataSource = dvData;
            grdvwRequest.DataBind();
            #endregion
        }
        #endregion
    }