示例#1
0
 //fungsi: menghandle ketika row pada gridview akan di edit,
 //set fokus pada isian di gridview
 protected void GvStatus_RowEditing(object sender, GridViewEditEventArgs e)
 {
     if (Page.IsValid)
     {
         GvStatus.EditIndex = e.NewEditIndex;
         GvStatus.DataBind();
         this.ScriptManager1.SetFocus(GvStatus.Rows[e.NewEditIndex].Cells[1].FindControl("txtCol1Edit").ClientID);
     }
     else
     {
         e.Cancel = true;
     }
 }
示例#2
0
        //fungsi: pindah halaman/index page dari gridview
        protected void txtHalaman_TextChanged(object sender, System.EventArgs e)
        {
            GridViewRow rowPager   = GvStatus.BottomPagerRow;
            TextBox     txtHalaman = (TextBox)(rowPager.Cells[0].FindControl("txtHalaman"));

            try
            {
                if (int.Parse(txtHalaman.Text) <= GvStatus.PageCount + 1 && int.Parse(txtHalaman.Text) > 0)
                {
                    GvStatus.PageIndex = (int.Parse(txtHalaman.Text)) - 1;
                    GvStatus.DataBind();
                }
            }
            catch (Exception)
            {
                txtHalaman.Text = (GvStatus.PageIndex + 1).ToString();
            }
        }
示例#3
0
        private void BindGridView(bool clearAllFilters = false)
        {
            using (var aryaDc = new AryaDbDataContext())
            {
                var currUser = (from u in aryaDc.Users where u.EmailAddress == Email select u).FirstOrDefault();
                if (currUser == null)
                {
                    FormsAuthentication.RedirectToLoginPage();
                    return;
                }

                using (var taskDc = new AryaServicesDbDataContext())
                {
                    var tasks = Enumerable.Empty <AryaTask>().AsQueryable();
                    if (currUser.IsAdmin)
                    {
                        tasks = taskDc.AryaTasks;
                    }
                    else
                    {
                        //Import Admin Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.ImportAdminGroup,
                                                 new[] { typeof(ImportWorker).Name }, false));
                        //Import User Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.ImportUserGroup,
                                                 new[] { typeof(ImportWorker).Name }, true));

                        var exportJobTypes = ExportWorkerBase.GetExports().Select(e => e.GetType().Name).ToList();
                        //Export Admin Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.ExportAdminGroup,
                                                 exportJobTypes.Union(typeof(CustomExportWorker).Name), false));
                        //Standard Export User Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.StandardExportUserGroup,
                                                 exportJobTypes, true));
                        //Custom Export User Tasks
                        tasks =
                            tasks.Union(GetTasks(aryaDc, taskDc, currUser, Group.CustomExportUserGroup,
                                                 new[] { typeof(CustomExportWorker).Name }, true));
                    }

                    if (!clearAllFilters)
                    {
                        Guid selectedProject, selectedUser;
                        if (Guid.TryParse(DdlProjects.SelectedValue, out selectedProject))
                        {
                            tasks = tasks.Where(task => task.ProjectID == selectedProject);
                        }

                        if (Guid.TryParse(DdlSubmittedBy.SelectedValue, out selectedUser))
                        {
                            tasks = tasks.Where(task => task.SubmittedBy == selectedUser);
                        }

                        var selectedJobType = DdlJobType.SelectedValue;
                        if (!string.IsNullOrWhiteSpace(selectedJobType) && selectedJobType != "ALL")
                        {
                            tasks = tasks.Where(task => task.JobType == DdlJobType.SelectedValue);
                        }

                        var selectedStatus = DdlStatus.SelectedValue;
                        if (!string.IsNullOrWhiteSpace(selectedStatus) && selectedStatus != "ALL")
                        {
                            tasks = tasks.Where(task => task.Status == DdlStatus.SelectedValue);
                        }
                    }
                    var allTasks = tasks.OrderByDescending(task => task.SubmittedOn).Take(100).ToList();

                    var distinctUserProjects =
                        allTasks.Select(t => t.SubmittedBy + "|" + t.ProjectID).Distinct().ToList();
                    var userProjects = (from up in aryaDc.UserProjects
                                        //from task in tasks.ToList()
                                        //where task.SubmittedBy == up.UserID && task.ProjectID == up.ProjectID
                                        where distinctUserProjects.Contains(up.UserID + "|" + up.ProjectID)
                                        select new { up.User, up.Project }).ToList();

                    var visibleTasks = from task in allTasks
                                       from up in userProjects
                                       where up.Project.ID == task.ProjectID && up.User.ID == task.SubmittedBy
                                       let project                                                           = up.Project
                                                                            let user                         = up.User
                                                                                                   let state =
                        WorkerBase.GetFriendlyWorkerState(
                            (WorkerState)Enum.Parse(typeof(WorkerState), task.Status))
                        orderby task.SubmittedOn descending
                        select
                        new
                    {
                        task.ID,
                        task.ProjectID,
                        ProjectName = project.DisplayName,
                        Type        = task.DisplayJobType,
                        task.JobType,
                        task.Description,
                        task.Status,
                        FriendlyStatus = state,
                        user.FullName,
                        task.SubmittedBy,
                        task.SubmittedOn
                    };

                    if (sortExpression != string.Empty)
                    {
                        visibleTasks = LinqExtensions.ApplyOrder(visibleTasks, sortExpression,
                                                                 sortOrder == "asc" ? "OrderBy" : "OrderByDescending");
                    }

                    var visibleTaskList = visibleTasks.Distinct().ToList();
                    GvStatus.DataSource = visibleTaskList;
                    GvStatus.DataBind();

                    if (visibleTaskList.Count == 0)
                    {
                        return;
                    }

                    if (!Page.IsPostBack)
                    {
                        var projects =
                            userProjects.Select(
                                up =>
                                new DropDownListItem
                        {
                            Text  = up.Project.DisplayName,
                            Value = up.Project.ID.ToString()
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["projects"] = projects;

                        var users =
                            userProjects.Select(
                                up => new DropDownListItem {
                            Text = up.User.FullName, Value = up.User.ID.ToString()
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["users"] = users;

                        var jobTypes =
                            allTasks.Select(
                                task => new DropDownListItem {
                            Text = task.DisplayJobType, Value = task.JobType
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["jobTypes"] = jobTypes;

                        var statuses =
                            allTasks.Select(task => new DropDownListItem {
                            Text = task.Status, Value = task.Status
                        })
                            .Distinct(new KeyEqualityComparer <DropDownListItem>(item => item.Value))
                            .OrderBy(item => item.Text)
                            .ToList();
                        Session["statuses"] = statuses;
                    }

                    var prjs            = Session["projects"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visibleProjects =
                        prjs.Where(prj => visibleTaskList.Any(task => task.ProjectID.ToString() == prj.Value)).ToList();
                    visibleProjects.Insert(visibleProjects.Count > 1 ? 0 : 1,
                                           new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visibleProjects.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visibleProjects.AddRange(prjs.Where(prj => !visibleProjects.Contains(prj)));
                    DdlProjects.DataSource = visibleProjects;
                    DdlProjects.DataBind();

                    var usrs         = Session["users"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visibleusers =
                        usrs.Where(usr => visibleTaskList.Any(task => task.SubmittedBy.ToString() == usr.Value))
                        .ToList();
                    visibleusers.Insert(visibleusers.Count > 1 ? 0 : 1,
                                        new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visibleusers.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visibleusers.AddRange(usrs.Where(usr => !visibleusers.Contains(usr)));
                    DdlSubmittedBy.DataSource = visibleusers;
                    DdlSubmittedBy.DataBind();

                    var jbts            = Session["jobTypes"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visiblejobTypes =
                        jbts.Where(jbt => visibleTaskList.Any(task => task.JobType == jbt.Value)).ToList();
                    visiblejobTypes.Insert(visiblejobTypes.Count > 1 ? 0 : 1,
                                           new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visiblejobTypes.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visiblejobTypes.AddRange(jbts.Where(jbt => !visiblejobTypes.Contains(jbt)));
                    DdlJobType.DataSource = visiblejobTypes;
                    DdlJobType.DataBind();

                    var stus            = Session["statuses"] as List <DropDownListItem> ?? new List <DropDownListItem>();
                    var visiblestatuses =
                        stus.Where(stu => visibleTaskList.Any(task => task.Status == stu.Value)).ToList();
                    visiblestatuses.Insert(visiblestatuses.Count > 1 ? 0 : 1,
                                           new DropDownListItem {
                        Text = "ALL", Value = "ALL"
                    });
                    visiblestatuses.Add(new DropDownListItem {
                        Text = "-----", Value = "ALL"
                    });
                    visiblestatuses.AddRange(stus.Where(stu => !visiblestatuses.Contains(stu)));
                    DdlStatus.DataSource = visiblestatuses;
                    DdlStatus.DataBind();
                }
            }
        }