コード例 #1
0
 partial void DeleteReport(Report instance);
コード例 #2
0
 partial void InsertReport(Report instance);
コード例 #3
0
 partial void UpdateReport(Report instance);
コード例 #4
0
        protected void reports_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var row = (GridViewRow)((Control)e.CommandSource).Parent.Parent;
            string sitename = Request.Params["site"];

            if (e.CommandName == "DeleteReport")
            {
                ReportType type = (ReportType)Enum.Parse(typeof(ReportType), (row.Cells[0].Controls[1] as Label).Text);
                DateTime date = DateTime.ParseExact((row.Cells[1].Controls[1] as Label).Text, "g", System.Threading.Thread.CurrentThread.CurrentCulture);
                string message = HttpUtility.HtmlDecode((row.Cells[2].Controls[1] as Label).Text);

                using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
                {
                    var rep = dc.Report.FirstOrDefault(r => r.Message == message && (r.Date - date).Minutes <= 1 && r.Type == type && r.Site_FK == sitename);
                    if (rep != null)
                    {
                        dc.Report.DeleteOnSubmit(rep);
                        dc.SubmitChanges();

                        // now get last report for this site and check with last update to set the new site state
                        Site site = dc.Site.First(s => s.Name == sitename);
                        var latestReport = dc.Report.Where(r => r.Site_FK == sitename).OrderByDescending(r => r.Date).FirstOrDefault();
                        if (latestReport == null)
                        {
                            site.State = SiteState.Working;
                        }
                        else
                        {
                            if (site.LastUpdated > latestReport.Date)
                            {
                                site.State = SiteState.Working;
                            }
                            else
                            {
                                if (latestReport.Type == ReportType.Broken && site.State == SiteState.Working) site.State = SiteState.Reported;
                                else if (latestReport.Type == ReportType.ConfirmedBroken) site.State = SiteState.Broken;
                                else if (latestReport.Type == ReportType.RejectedBroken || latestReport.Type == ReportType.Fixed || latestReport.Type == ReportType.Suggestion) site.State = SiteState.Working;
                            }
                        }
                        dc.SubmitChanges();

                        BindGrid();
                    }
                }
            }
            else if (e.CommandName == "AddReport")
            {
                ReportType type = (ReportType)Enum.Parse(typeof(ReportType), (row.FindControl("ddType") as DropDownList).SelectedValue);
                string message = (row.FindControl("tbxNewMessage") as TextBox).Text;
                if (!string.IsNullOrEmpty(message))
                {
                    using (OnlineVideosDataContext dc = new OnlineVideosDataContext())
                    {
                        Report report = new Report()
                        {
                            Date = DateTime.Now,
                            Message = message,
                            Type = type,
                            Site_FK = sitename
                        };
                        dc.Report.InsertOnSubmit(report);

                        // set new site state
                        Site site = dc.Site.First(s => s.Name == sitename);
                        switch (type)
                        {
                            case ReportType.Broken:
                                if (site.State == SiteState.Working) site.State = SiteState.Reported;
                                break;
                            case ReportType.ConfirmedBroken:
                                site.State = SiteState.Broken;
                                break;
                            case ReportType.RejectedBroken:
                            case ReportType.Fixed:
                                site.State = SiteState.Working;
                                break;
                        }

                        dc.SubmitChanges();

                        BindGrid();
                    }
                }
            }
        }