Example #1
0
        private void Page_Init(object sender, EventArgs e)
        {
            noSuchProb.Visible = false;
            if (!Page.IsPostBack)
            {
                BaseDb db = DbFactory.ConstructDatabase();
                if (!BaseDb.IsJudge(Page.User))
                {
                    userTd.Visible = false;
                }
                else
                {
                    userDropDownList.Items.Add(new ListItem("--Ыўсющ--", "0"));
                    foreach (User u in db.GetUsers())
                    {
                        userDropDownList.Items.Add(new ListItem(u.Fullname,
                                                                db.GetUid(u.Username).ToString()));
                    }
                }

                snameDropDownList.Items.Add(new ListItem("--Ыўсрџ--", "ALL"));
                for (char c = 'A'; c <= 'Z'; c++)
                {
                    snameDropDownList.Items.Add(new ListItem(c.ToString(), c.ToString()));
                }

                int[]   old_tids = db.GetOldTids();
                int[]   now_tids = db.GetNowTids();
                Contest t        = null;
                for (int i = 0; i < old_tids.Length; i++)
                {
                    t = db.GetContest(old_tids[i]);
                    contestDropDownList.Items.Add(new ListItem(t.Name, old_tids[i].ToString()));
                }
                for (int i = 0; i < now_tids.Length; i++)
                {
                    t = db.GetContest(now_tids[i]);
                    contestDropDownList.Items.Add(new ListItem(t.Name, now_tids[i].ToString()));
                }

                resultDropDownList.Items.Add(new ListItem("--Ыўсющ--", "ALL"));
                foreach (Result r in Enum.GetValues(typeof(Result)))
                {
                    SubmissionResult res = new SubmissionResult(r);
                    resultDropDownList.Items.Add(new ListItem(res.ToString(), r.ToString()));
                }
                userDropDownList.SelectedIndex        = resultDropDownList.SelectedIndex =
                    contestDropDownList.SelectedIndex = snameDropDownList.SelectedIndex = 0;
            }
        }
Example #2
0
        private void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RequirementsProcessor rp = new RequirementsProcessor(GetType(), Context);
                rp.ProcessRequirements();

                Page.Response.AddHeader("Refresh", "90");
                if (rp.TidDefined)
                {
                    tid = selcon.TID = rp.ContestID;

                    questionsGrid.Columns[5].Visible = BaseDb.IsAdmin(Page.User);

                    using (BaseDb db = DbFactory.ConstructDatabase())
                    {
                        if (db.GetContest(tid).Future)
                        {
                            throw new NeJudgeInvalidParametersException("tid");                            //Hide("Ќельз¤ просмотреть вопросы будущего соревновани¤");
                        }
                        else
                        {
                            Off();
                            Bind();
                        }
                    }
                }
            }
        }
Example #3
0
        private void Bind(ArrayList sids)
        {
            DataTable  dt = new DataTable();
            DataRow    dr;
            Submission s;
            BaseDb     db  = DbFactory.ConstructDatabase();
            Contest    con = db.GetContest(_rp.ContestID);

            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Время");
            dt.Columns.Add("Команда");
            dt.Columns.Add("Задача");
            dt.Columns.Add("Язык");
            dt.Columns.Add("Статус");
            dt.Columns.Add("Тест №", typeof(uint));
            dt.Columns.Add("Время работы");
            dt.Columns.Add("Выделено памяти");
            foreach (int sid in sids)
            {
                dr    = dt.NewRow();
                s     = db.GetSubmission(sid);
                dr[0] = sid;
                dr[1] = HtmlFunctions.BeautifyTimeSpan(s.Time - con.Beginning, true);
                dr[2] = db.GetUser(s.UID).Fullname;
                dr[3] = String.Format("<a href='problem.aspx?pid={0}'>{1}</a>", s.PID,
                                      db.GetProblemShortName(s.PID));
                dr[4] = s.SubmissionLanguage;
                string pattern = "<a href='viewdata.aspx?mode={0}&sid={1}'>{2}</a>";
                if (s.Result.Code == Result.CE)
                {
                    dr[5] = String.Format(pattern, "comp-report", sid, s.Result.ToHtmlString());
                }
                else if (s.Result.Code == Result.FA)
                {
                    dr[5] = String.Format(pattern, "error-report", sid, s.Result.ToHtmlString());
                }
                else
                {
                    dr[5] = s.Result.ToHtmlString();
                }
                if (s.Result.TestNumber > 0)
                {
                    dr[6] = s.Result.TestNumber;
                }
                if (s.Result.Code != Result.CE && s.Result.Code != Result.FA && s.Result.Code != Result.WAIT && s.Result.Code != Result.RU && s.Result.Code != Result.TLE)
                {
                    dr[7] = Math.Round(s.Result.TimeWorked, 4) + " сек";
                }
                if (s.Result.Code != Result.CE && s.Result.Code != Result.FA && s.Result.Code != Result.WAIT && s.Result.Code != Result.RU && s.Result.Code != Result.MLE)
                {
                    dr[8] = s.Result.MemoryUsed + " КБ";
                }
                dt.Rows.Add(dr);
            }
            db.Close();
            statusGrid.DataSource = dt;
            statusGrid.DataBind();
        }
Example #4
0
 public Monitor(int tid)
 {
     _tid     = tid;
     _db      = DbFactory.ConstructDatabase();
     _con     = _db.GetContest(_tid);
     _users   = new ArrayList();
     _last_ac = new LastAcceptedData();
     _has_ac  = false;
     gen_monitor();
 }
Example #5
0
        private void Page_Load(object sender, EventArgs e)
        {
            ArrayList tids = new ArrayList();
            BaseDb    db   = DbFactory.ConstructDatabase();

            if (now)
            {
                int[] nowtids = db.GetNowTids();
                foreach (int tid in nowtids)
                {
                    tids.Add(tid);
                }
            }
            if (old)
            {
                int[] oldtids = db.GetOldTids();
                foreach (int tid in oldtids)
                {
                    tids.Add(tid);
                }
            }
            if (future)
            {
                int[] futuretids = db.GetFutureTids();
                foreach (int tid in futuretids)
                {
                    tids.Add(tid);
                }
            }

            Contest t;
            string  str = "";

            foreach (int tid in tids)
            {
                if (!IsPostBack)
                {
                    t = db.GetContest(tid);
                    selContests.Items.Add(new ListItem(t.Name, tid.ToString()));
                }
                foreach (Problem p in db.GetProblems(tid))
                {
                    str += "new Problem(\"Задача " + p.ShortName + ". " + p.Name + "\"," + p.PID + "," + tid + "),";
                }
            }
            db.Close();

            Page.RegisterArrayDeclaration("arr", (str.Length != 0) ? str.Substring(0, str.Length - 1) : str);
            Page.RegisterArrayDeclaration("hi", ctrlsl2hide);

            if (!Page.IsStartupScriptRegistered("Startup"))
            {
                Page.RegisterStartupScript("Startup", "<script>Init()</script>");
            }
        }
Example #6
0
 private void Page_Load(object sender, EventArgs e)
 {
     if (!BaseDb.IsAdmin(Page.User))
     {
         throw new NeJudgeSecurityException("Administrator");
     }
     if (!IsPostBack)
     {
         try
         {
             pid = int.Parse(Request.QueryString["pid"]);
         }
         catch
         {
             pid = -1;
         }
         try
         {
             tid = int.Parse(Request.QueryString["tid"]);
         }
         catch
         {
             tid = -1;
         }
         BaseDb db = DbFactory.ConstructDatabase();
         if (db.CheckPid(pid))
         {
             tid = db.GetTid(pid);
             Problem p = db.GetProblem(pid);
             problemNameTextBox.Text  = Server.HtmlDecode(p.Name);
             problemTextTextBox.Text  = Server.HtmlDecode(p.Text);
             inputFormatTextBox.Text  = Server.HtmlDecode(p.InputFormat);
             outputFormatTextBox.Text = Server.HtmlDecode(p.OutputFormat);
             inputSampleTextbox.Text  = Server.HtmlDecode(p.InputSample);
             outputSampleTextbox.Text = Server.HtmlDecode(p.OutputSample);
             authorTextBox.Text       = Server.HtmlDecode(p.Author);
         }
         else if (db.CheckTid(tid))
         {
             pid = -1;
             finishButton.Text = "Добавить задачу";
             if (db.GetContest(tid).Old)
             {
                 throw new NeJudgeInvalidParametersException("tid");
             }
         }
         else
         {
             throw new NeJudgeInvalidParametersException("tid");
         }
         db.Close();
     }
 }
/*
 *              private void Hide(string mess)
 *              {
 *                      outerror.InnerHtml = "<FONT COLOR='Red'><b>" + mess + "</b></FONT>";
 *                      Table3.Visible = false;
 *                      Table4.Visible = false;
 *              }
 */

        private void Page_Load(object sender, EventArgs e)
        {
            if (!BaseDb.IsAdmin(Page.User))
            {
                throw new NeJudgeSecurityException("Administrator");
            }
            if (!IsPostBack)
            {
                try
                {
                    if (tid == -1)
                    {
                        tid = int.Parse(Request.QueryString["tid"]);
                    }
                }
                catch
                {
                    tid = -1;
                }
                if (db.CheckTid(tid))
                {
                    Contest t = db.GetContest(tid);
                    beginningTextBox.Text = t.Beginning.ToString("dd.MM.yyyy H:mm");
                    endingTextBox.Text    = t.Ending.ToString("dd.MM.yyyy H:mm");
                    nameTextbox.Text      = t.Name;
                    if (t.Now)
                    {
                        beginningTextBox.Enabled = false;
                        //deleteButton.Visible = false;
                        //HideRemoveCheckBox();
                    }
                    if (t.Old)
                    {
                        beginningTextBox.Enabled = false;
                        endingTextBox.Enabled    = false;
                        addButton.Visible        = false;
                        //deleteButton.Visible = false;
                        //HideRemoveCheckBox();
                    }
                    RedrawRepeater();
                }
                else
                {
                    tid = -1;
                    addButton.Visible    = false;
                    deleteButton.Visible = false;
                    finishButton.Text    = "—оздать соревнование";
                }
            }
        }
Example #8
0
 private void Page_Init(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         BaseDb  db = DbFactory.ConstructDatabase();
         Contest t;
         if (now)
         {
             int[] nowtids = db.GetNowTids();
             for (int i = 0; i < nowtids.Length; i++)
             {
                 t = db.GetContest(nowtids[i]);
                 tidDropDownList.Items.Add(new ListItem(t.Name, nowtids[i].ToString()));
             }
         }
         if (old)
         {
             int[] oldtids = db.GetOldTids();
             for (int i = 0; i < oldtids.Length; i++)
             {
                 t = db.GetContest(oldtids[i]);
                 tidDropDownList.Items.Add(new ListItem(t.Name, oldtids[i].ToString()));
             }
         }
         if (future)
         {
             int[] futuretids = db.GetFutureTids();
             for (int i = 0; i < futuretids.Length; i++)
             {
                 t = db.GetContest(futuretids[i]);
                 tidDropDownList.Items.Add(new ListItem(t.Name, futuretids[i].ToString()));
             }
         }
         db.Close();
     }
 }
Example #9
0
        private void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RequirementsProcessor rp = new RequirementsProcessor(GetType(), Context);
                rp.ProcessRequirements();

                selprob.AddHidableControl(goButton);

                if (rp.PidDefined)
                {
                    selprob.PID = rp.ProblemID;

                    BaseDb  db = DbFactory.ConstructDatabase();
                    Problem p  = db.GetProblem(rp.ProblemID);
                    Contest t  = db.GetContest(p.TID);
                    db.Close();

                    if (!BaseDb.IsAdmin(Page.User) && t.Future)
                    {
                        throw new NeJudgeInvalidParametersException("pid");                        //"Соревнование, задачу с которого вы хотите просмотреть, ещё не началось. Попробуйте позже."
                    }
                    #region Возня со ссылками
                    InitLinks(rp.ProblemID);
                    if (BaseDb.IsAdmin(Page.User))
                    {
                        Hyperlink2.Text        = "Редактировать";
                        Hyperlink2.NavigateUrl = "../editproblem.aspx?pid=" + rp.ProblemID + "&ret=p";

                        Hyperlink3.Visible = Hyperlink4.Visible = false;
                    }
                    else
                    {
                        if (BaseDb.IsAnonymous(Page.User) || t.Old)
                        {
                            Hyperlink2.Visible = Hyperlink3.Visible = Hyperlink4.Visible = false;
                        }
                    }
                    #endregion

                    FillLiterals(p);
                }
                else
                {
                    Hide();
                }
            }
        }
Example #10
0
        private void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RequirementsProcessor rp = new RequirementsProcessor(GetType(), Context);
                rp.ProcessRequirements();
                using (BaseDb db = DbFactory.ConstructDatabase())
                {
                    if (rp.TidDefined)
                    {
                        selcon.TID = rp.ContestID;

                        #region Ссылочки (Visible в зависимости от роли)
                        InitLinks(rp.ContestID);
                        if (BaseDb.IsAnonymous(Page.User))
                        {
                            subHyperLink.Visible  = false;
                            quesHyperLink.Visible = false;
                        }
                        if (BaseDb.IsAdmin(Page.User))
                        {
                            editHyperLink.Visible = true;
                        }
                        #endregion

                        if (db.GetContest(rp.ContestID).Future&& !BaseDb.IsAdmin(Page.User))
                        {
                            throw new NeJudgeInvalidParametersException("tid");                            //Hide("Это соревнование начнется через " + HtmlFunctions.BeautifyTimeSpan(db.GetContest(tid).Beginning - DateTime.Now, false) + ". Сейчас задачи посмотреть нельзя.");
                        }
                        else
                        {
                            RedrawRepeater(rp.ContestID);
                        }
                    }
                    else
                    {
                        Hide("");
                    }
                }
            }
        }
Example #11
0
        private void Button1_Click(object sender, EventArgs e)
        {
            int pid = selprob.PID;

            using (BaseDb db = DbFactory.ConstructDatabase())
            {
                int tid = db.GetTid(pid);
                if (db.GetContest(tid).Now)
                {
                    if (Page.IsValid)
                    {
                        db.AddQuestion(pid, db.GetUid(Page.User.Identity.Name), tid, qTextBox.Text);
                        Response.Redirect("~/questions.aspx?tid=" + tid, false);
                    }
                }
                else
                {
                    throw new NeJudgeInvalidParametersException("pid");                     //"—оревнование либо закончилось, либо ещЄ не начиналась."
                }
            }
        }
        private void Page_Load(object sender, EventArgs e)
        {
            BaseDb db = DbFactory.ConstructDatabase();

            if (db.CheckPid(pid))
            {
                Problem p = db.GetProblem(pid);
                if (db.GetContest(p.TID).Future)
                {
                    Hide("Соревнование,	задачу с которого вы хотите	просмотреть, ещё не	началось. Попробуйте позже.");
                }
                else
                {
                    nameLiteral.Text = "<h1> Задача	" + p.ShortName +
                                       " (	#"+ pid + " ).	"+ p.Name + "</h1>";
                    Limits l = DfTest.GetLimits(pid.ToString());
                    tlLiteral.Text += l.Time + "	секунды";
                    mlLiteral.Text += l.Memory + " КБ";
                    olLiteral.Text += l.Output + " байт";
                    if (p.Text == "")
                    {
                        textLiteral.Visible = false;
                    }
                    else
                    {
                        textLiteral.Text += p.Text;
                    }
                    if (p.InputFormat == "")
                    {
                        infoLiteral.Visible = false;
                    }
                    else
                    {
                        infoLiteral.Text += p.InputFormat;
                    }
                    if (p.OutputFormat == "")
                    {
                        outfoLiteral.Visible = false;
                    }
                    else
                    {
                        outfoLiteral.Text += p.OutputFormat;
                    }
                    string str = "";
                    if (p.InputSample == "")
                    {
                        inexLiteral.Visible = false;
                    }
                    else
                    {
                        StringReader str_rdr = new StringReader(p.InputSample);

                        while ((str = str_rdr.ReadLine()) != null)
                        {
                            inexLiteral.Text += str + "<br>";
                        }
                        inexLiteral.Text += "</code>";
                    }
                    if (p.OutputSample == "")
                    {
                        outexLiteral.Visible = false;
                    }
                    else
                    {
                        StringReader str_rdr2 = new StringReader(p.OutputSample);
                        while ((str = str_rdr2.ReadLine()) != null)
                        {
                            outexLiteral.Text += str + "<br>";
                        }
                        outexLiteral.Text += "</code>";
                    }
                    if (p.Author == "")
                    {
                        authorLiteral.Visible = false;
                    }
                    else
                    {
                        authorLiteral.Text += p.Author;
                        authorLiteral.Text += "<hr>";
                    }
                }
            }
            else
            {
                throw new NeJudgeInvalidParametersException("pid");
            }
            db.Close();
        }
Example #13
0
        private void Page_Load(object sender, EventArgs e)
        {
            if (BaseDb.IsAnonymous(Page.User))
            {
                throw new NeJudgeSecurityException("User, Administrator, Judge");
            }
            if (!IsPostBack)
            {
                Page.Response.AddHeader("Refresh", "90");
                ArrayList sids = new ArrayList();
                int       page = 0;
                #region параметры
                _rp = new RequirementsProcessor(this.GetType(), Context);
                _rp.ProcessRequirements();
                if (Page.Request.QueryString["sname"] != null)
                {
                    problem = Page.Request.QueryString["sname"];
                }
                if (Page.Request.QueryString["result"] != null)
                {
                    result = Page.Request.QueryString["result"];
                }
                try
                {
                    page = int.Parse(Page.Request.QueryString["page"]);
                }
                catch
                {
                    page = 0;
                }
                using (BaseDb db = DbFactory.ConstructDatabase())
                {
                    if (_rp.UidDefined)
                    {
                        if (BaseDb.IsJudge(Page.User))
                        {
                            filter.UserID = _rp.UserID;
                        }
                        else
                        {
                            throw new NeJudgeSecurityException("Judge");
                        }
                    }

                    if (_rp.TidDefined)
                    {
                        //filter.ContestID = _rp.ContestID;
                        if (db.GetContest(_rp.ContestID).Future)
                        {
                            Hide("Невозможно просмотреть submissions будущего соревнования");
                        }
                        else
                        {
                            int pid = -1;
                            if (problem != "")
                            {
                                pid = db.GetPidByShortName(_rp.ContestID, problem);
                                if (pid == -1)
                                {
                                    throw new NeJudgeInvalidParametersException("sname");
                                }
                                else
                                {
                                    if (!Page.IsPostBack)
                                    {
                                        filter.ProblemID = problem[0];
                                    }
                                }
                            }
                            if (result != "")
                            {
                                try
                                {
                                    Result r = (Result)Enum.Parse
                                                   (typeof(Result), result);
                                    if (!Page.IsPostBack)
                                    {
                                        filter.Result = r;
                                    }
                                }
                                catch (ArgumentException)
                                {
                                    throw new NeJudgeInvalidParametersException("result");
                                }
                            }
                            #endregion
                            foreach (Submission s in db.GetSubmissions(_rp.ContestID,
                                                                       _rp.UidDefined ? _rp.UserID : 0,
                                                                       (problem == "") ? 0 : pid, result))
                            {
                                sids.Add(s.SID);
                            }
                            if (sids.Count == 0)
                            {
                                //Hide("В этом соревновании нет ни одного submission");
                            }
                            sids.Reverse();
                            statusGrid.VirtualItemCount = sids.Count;
                            if (sids.Count - page * statusGrid.PageSize < 0)
                            {
                                page = sids.Count / statusGrid.PageSize;
                            }
                            statusGrid.CurrentPageIndex = page;
                            ArrayList arr = new ArrayList();
                            int       l;
                            if (sids.Count - page * statusGrid.PageSize < statusGrid.PageSize)
                            {
                                l = sids.Count;
                            }
                            else
                            {
                                l = page * statusGrid.PageSize + statusGrid.PageSize;
                            }
                            for (int i = page * statusGrid.PageSize; i < l; i++)
                            {
                                arr.Add(sids[i]);
                            }
                            Bind(arr);
                            HtmlFunctions.BeautifyDataGrid(statusGrid);
                        }
                    }
                    else
                    {
                        Hide(null);
                    }
                }
            }
        }
Example #14
0
        private void Page_Load(object sender, EventArgs e)
        {
            int tid;

            try
            {
                tid = int.Parse(Page.Request.QueryString["TID"]);
            }
            catch
            {
                tid = -1;
            }
            BaseDb db = DbFactory.ConstructDatabase();

            if (db.CheckTid(tid))
            {
                PlaceHolder1.Controls.Add(new LiteralControl("<div align='center'><h1 style='color:#418ade;'>" + db.GetContest(tid).Name + "</h1></div><hr>"));
                ArrayList a = db.GetProblems(tid);
                foreach (Problem p in a)
                {
                    Control c = LoadControl("PageModules/printproblem.ascx");
                    ((printproblem)c).PID = p.PID;
                    PlaceHolder1.Controls.Add(c);
                    PlaceHolder1.Controls.Add(new LiteralControl("<br>"));
                }
            }
            else
            {
                throw new NeJudgeInvalidParametersException("tid");
            }
        }
Example #15
0
        private void Button1_Click(object sender, EventArgs e)
        {
            int pid = selprob.PID;

            using (BaseDb db = DbFactory.ConstructDatabase())
            {
                int tid = db.GetTid(pid);
                if (db.GetContest(tid).Now)
                {
                    if (Page.IsValid)
                    {
                        string extension = "";
                        switch (languageDropDownList.SelectedValue)
                        {
                        case "Pascal":
                            extension = "pas";
                            break;

                        case "C++":
                            extension = "cpp";
                            break;

                        case "C":
                            extension = "c";
                            break;

                        default:
                            extension = "cpp";
                            break;
                        }

                        string temp = Path.GetTempFileName();

                        if (sourceTextBox.Text.Trim() != "")
                        {
                            StreamWriter sw = null;
                            try
                            {
                                sw = new StreamWriter(temp);
                                sw.WriteLine(sourceTextBox.Text.Trim());
                            }
                            finally
                            {
                                if (sw != null)
                                {
                                    sw.Close();
                                }
                            }
                        }
                        else
                        {
                            if (fileBrowser.PostedFile != null)
                            {
                                fileBrowser.PostedFile.SaveAs(temp);
                            }
                        }

                        int        uid = db.GetUid(Page.User.Identity.Name);                  //TODO
                        Language   l   = (Language)Enum.Parse(typeof(Language), extension, true);
                        Submission s   = new Submission(pid, uid, tid, DateTime.Now, l);
                        int        sid = db.AddSubmission(s);
                        if (Directory.Exists(Path.Combine(Config.SubmissionsDirectory, sid.ToString())))
                        {
                            Directory.Delete(Path.Combine(Config.SubmissionsDirectory, sid.ToString()));
                        }
                        Directory.CreateDirectory(Path.Combine(Config.SubmissionsDirectory, sid.ToString()));
                        File.Move(temp, Path.Combine(Path.Combine(
                                                         Config.SubmissionsDirectory, sid.ToString()), "sln." + extension)); //TODO:переделать

                        DfTest dt = new DfTest(pid.ToString(), sid.ToString(), l.ToString());
                        Thread t  = new Thread(new ThreadStart(dt.CheckSolution));
                        Response.Redirect("~/status.aspx?tid=" + tid, false);
                        t.Start();
                    }
                }
                else
                {
                    throw new NeJudgeInvalidParametersException("pid");                    //"Соревнование либо закончилась, либо ещё не начиналось.";
                }
            }
        }
Example #16
0
        private void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                RequirementsProcessor rp = new RequirementsProcessor(GetType(), Context);
                rp.ProcessRequirements();
                //Page.Response.AddHeader("Refresh","300");
                if (rp.TidDefined)
                {
                    Contest con;
                    BaseDb  db = DbFactory.ConstructDatabase();
                    using ( db )
                    {
                        con = db.GetContest(rp.ContestID);
                        if (con.Future)
                        {
                            Hide("Нельзя просмотреть монитор будущего соревнования");
                            db.Close();
                        }
                        else
                        {
                            DateTime cur_time = TimeUtils.ZeroDateTime(DateTime.Now);
                            DateTime t_begin  = TimeUtils.ZeroDateTime(con.Beginning);
                            DateTime t_end    = TimeUtils.ZeroDateTime(con.Ending);

                            // Последнее обновление
                            TimeSpan dur       = TimeUtils.ZeroTimeSpan(t_end - t_begin);
                            TimeSpan elapsed   = TimeUtils.ZeroTimeSpan((cur_time - t_begin < dur) ? cur_time - t_begin : dur);
                            TimeSpan estimated = TimeUtils.ZeroTimeSpan(dur - elapsed);
                            if (elapsed >= dur)
                            {
                                st_label.InnerHtml +=
                                    "<span style='color:red;font-size:small;display:block;'>(Соревнование окончено)</span>";
                            }
                            refresh.Text = HtmlFunctions.BeautifyTimeSpan(elapsed, false);
                            // Продолжительность соревнования
                            period.Text = HtmlFunctions.BeautifyTimeSpan(dur, false);
                            left.Text   = HtmlFunctions.BeautifyTimeSpan(estimated, false);
                        }
                    }

                    /*DataTable mon_dt = new DataTable("Результаты"), stat_dt = new DataTable("Статистика");
                     * mon_dt.Columns.Add("ID");
                     * mon_dt.Columns.Add("Имя участника");
                     * //mon_dt.PrimaryKey = new DataColumn[]{mon_dt.Columns[0]};
                     *
                     * stat_dt.Columns.Add("Показатель");
                     * DataRow dr = stat_dt.NewRow();
                     * dr[0] = "Команд решили";
                     * stat_dt.Rows.Add(dr);
                     * dr = stat_dt.NewRow();
                     * dr[0] = "Команд решили/команд всего";
                     * stat_dt.Rows.Add(dr);
                     *
                     * int tid = rp.ContestID;
                     * selcon.TID = tid;
                     * BaseDb db = DbFactory.ConstructDatabase();
                     * //HyperLink1.NavigateUrl += tid;
                     * //Прочитали результаты
                     * Contest t;
                     *
                     * if ((t = db.GetContest(tid)).Future)
                     * {
                     *      Hide("Нельзя просмотреть монитор будущего сорвевнования");
                     *      db.Close();
                     * }
                     * else
                     * {
                     *      DateTime cur_time = ZeroDateTime(DateTime.Now);
                     *      DateTime t_begin = ZeroDateTime(t.Beginning);
                     *      DateTime t_end = ZeroDateTime(t.Ending);
                     *
                     *      // Последнее обновление
                     *      TimeSpan dur = ZeroTimeSpan(t_end - t_begin);
                     *      TimeSpan elapsed = ZeroTimeSpan( (cur_time - t_begin < dur) ? cur_time - t_begin : dur);
                     *      TimeSpan estimated = ZeroTimeSpan(dur - elapsed);
                     *      if ( elapsed >= dur )
                     *      {
                     *              st_label.InnerHtml +=
                     *                      "<span style='color:red;font-size:small;display:block;'>(Соревнование окончено)</span>";
                     *      }
                     *      refresh.Text = HtmlFunctions.BeautifyTimeSpan(elapsed, false);
                     *      // Продолжительность соревнования
                     *      period.Text = HtmlFunctions.BeautifyTimeSpan(dur, false);
                     *      left.Text = HtmlFunctions.BeautifyTimeSpan(estimated, false);
                     *
                     *      ArrayList ps = db.GetProblems(tid);
                     *      if (ps.Count == 0)
                     *      {
                     *              Hide("В этом соревновании нет задач");
                     *              return;
                     *      }
                     *      int i = 0;
                     *      for (i = 0; i < ps.Count; i++)
                     *      {
                     *              mon_dt.Columns.Add(((Problem) ps[i]).ShortName);
                     *              //mon_dt.Columns.Add(string.Format("<a style='grid_first' href='problem.aspx?pid={0}'>{1}</a>",((Problem)ps[i]).PID, ((Problem)ps[i]).ShortName));
                     *              stat_dt.Columns.Add(((Problem) ps[i]).ShortName);
                     *              //stat_dt.Columns.Add(string.Format("<a href='problem.aspx?pid={0}'>{1}</a>",((Problem)ps[i]).PID, ((Problem)ps[i]).ShortName));
                     *      }
                     *      mon_dt.Columns.Add("Всего решено");
                     *      mon_dt.Columns.Add("Время");
                     *      mon_dt.Columns.Add("Место");
                     *      //Колонки созданы
                     *      TimeSpan the_latest = new TimeSpan(0, 0, 0, 0, 0);
                     *      bool has_ac = false;
                     *      ArrayList user_data = new ArrayList();
                     *
                     #region обработка очереди
                     *
                     *      foreach (Submission s in db.GetSubmissions(tid, 0))
                     *      {
                     *              // Юзер, пославший текущий сабмишн
                     *              UserData u = null;
                     *              foreach (UserData ud in user_data)
                     *              {
                     *                      if (ud.UID == s.UID)
                     *                      {
                     *                              u = ud;
                     *                              break;
                     *                      }
                     *              }
                     *              // Новая строка с юзером
                     *              if (u == null)
                     *              {
                     *                      u = new UserData();
                     *                      u.UID = (uint) s.UID;
                     *                      u.Solved = 0;
                     *                      u.Time = new TimeSpan(0, 0, 0, 0, 0);
                     *                      u.Problems = new ArrayList();
                     *                      foreach (Problem p in ps)
                     *                      {
                     *                              Attempts at = new Attempts();
                     *                              at.AcTime = new TimeSpan(0, 0, 0, 0, 0);
                     *                              at.Count = 0;
                     *                              at.PID = (uint) p.PID;
                     *                              u.Problems.Add(at);
                     *                      }
                     *                      user_data.Add(u);
                     *              }
                     *              Attempts subm_att = null;
                     *              foreach (Attempts sat in u.Problems)
                     *              {
                     *                      if (sat.PID == s.PID)
                     *                      {
                     *                              subm_att = sat;
                     *                              break;
                     *                      }
                     *              }
                     *              if (subm_att == null)
                     *              {
                     *                      throw new ApplicationException("Невозможно найти задачу в описании участника");
                     *              }
                     *              if (s.Result.Code == Result.AC)
                     *              {
                     *                      if (subm_att.Count <= 0)
                     *                      {
                     *                              // вычисление попыток
                     *                              subm_att.Count = -subm_att.Count + 1;
                     *                              subm_att.AcTime = s.Time - t_begin;
                     *                              subm_att.AcTime = ZeroTimeSpan(subm_att.AcTime);
                     *                              has_ac = true;
                     *                              if (the_latest < subm_att.AcTime)
                     *                              {
                     *                                      the_latest = subm_att.AcTime;
                     *                              }
                     *                              // начисление времени с учетом штрафа
                     *                              u.Time += subm_att.AcTime +
                     *                                      new TimeSpan(0, 0, (subm_att.Count - 1)*20, 0, 0);
                     *                      }
                     *              }
                     *              else if (s.Result.Code != Result.WAIT && s.Result.Code != Result.RU)
                     *              {
                     *                      if (subm_att.Count <= 0)
                     *                      {
                     *                              subm_att.Count--;
                     *                      }
                     *              }
                     *      }
                     *
                     #endregion
                     *
                     *      foreach (UserData ud in user_data)
                     *      {
                     *              foreach (Attempts atte in ud.Problems)
                     *              {
                     *                      if (atte.Count > 0)
                     *                      {
                     *                              ud.Solved++;
                     *                      }
                     *              }
                     *      }
                     *
                     *      if (has_ac)
                     *      {
                     *              lastac.Text = HtmlFunctions.BeautifyTimeSpan(the_latest, false);
                     *      }
                     *      else
                     *      {
                     *              lastac.Text = "Еще не было";
                     *      }
                     *      user_data.Sort(new UserCompare());
                     *      if (user_data.Count == 0)
                     *      {
                     *              st_label.InnerHtml += "<span style='color:#CFC411;font-size:small;display:block;'>(Не было послано ни одного решения)</span>";
                     *      }
                     *      int[] ac_counts = new int[ps.Count];
                     *      int[] total_counts = new int[ps.Count];
                     *      foreach (UserData ud in user_data)
                     *      {
                     *              DataRow mon_dtr = mon_dt.NewRow();
                     *              mon_dtr[0] = ud.UID;
                     *              User us = db.GetUser((int) ud.UID);
                     *              mon_dtr[1] = us.Fullname;
                     *              mon_dt.Rows.Add(mon_dtr);
                     *              for (int j = 0; j < ud.Problems.Count; j++)
                     *              {
                     *                      int count = ((Attempts) ud.Problems[j]).Count;
                     *                      if (count > 0)
                     *                      {
                     *                              // Write a result to the problem's column
                     *                              mon_dtr[2 + j] = "<span style='color:blue;'>+";
                     *                              if (count != 1)
                     *                              {
                     *                                      mon_dtr[2 + j] += (count - 1).ToString();
                     *                              }
                     *                              mon_dtr[2 + j] += "</span><span style='font-size:smaller;display:block;'>(";
                     *                              mon_dtr[2 + j] += HtmlFunctions.BeautifyTimeSpan(((Attempts) ud.Problems[j]).AcTime, true);
                     *                              mon_dtr[2 + j] += ")</span>";
                     *                              // Update AC received users count
                     *                              ac_counts[j]++;
                     *                              total_counts[j]++;
                     *                      }
                     *                      else if (count < 0)
                     *                      {
                     *                              mon_dtr[2 + j] = "<span style='color:red;'>";
                     *                              mon_dtr[2 + j] += count.ToString();
                     *                              mon_dtr[2 + j] += "</span>";
                     *                              total_counts[j]++;
                     *                      }
                     *                      else
                     *                      {
                     *                              mon_dtr[2 + j] = "";
                     *                      }
                     *              }
                     *              mon_dtr[mon_dt.Columns.Count - 2] = (int) ud.Time.TotalMinutes;
                     *              mon_dtr[mon_dt.Columns.Count - 3] = ud.Solved;
                     *      }
                     *      db.Close();
                     *      for (int l = 0; l < mon_dt.Rows.Count; l++)
                     *      {
                     *              mon_dt.Rows[l][mon_dt.Columns.Count - 1] = l + 1;
                     *      }
                     *
                     *
                     *      monitorDG.DataSource = mon_dt;
                     *      monitorDG.DataBind();
                     *
                     #region статистика
                     *
                     *      for (int k = 0; k < ps.Count; k++)
                     *      {
                     *              stat_dt.Rows[0][k + 1] = ac_counts[k];
                     *              double ac_percent = (total_counts[k] == 0)
                     *                      ? 0 : (double)ac_counts[k] / (double)total_counts[k] * 100.0;
                     *              stat_dt.Rows[1][k + 1] = String.Format("{0:F2}%", ac_percent);
                     *      }
                     *      statDG.DataSource = stat_dt;
                     *      statDG.DataBind();
                     *
                     #endregion
                     *
                     *      Draw(mon_dt.Columns.Count - 3);
                     * }*/
                    Monitor m = MonitorManager.GetMonitor(rp.ContestID, Context);
                    m.Reload();
                    if (m.HasAccepted)
                    {
                        lastac.Text = String.Format("{0}<br><strong>Задача {1}</strong>",
                                                    HtmlFunctions.BeautifyTimeSpan(
                                                        TimeUtils.ZeroTimeSpan(m.LastAccepted.Time - con.Beginning), false),
                                                    m.LastAccepted.ProblemShortName);
                    }
                    else
                    {
                        lastac.Text = "Еще не было";
                    }
                    DataTable mon = m.FormatMonitor();
                    monitorDG.DataSource = mon;
                    monitorDG.DataBind();
                    Draw(mon.Columns.Count - 3);
                    statDG.DataSource = m.FormatStats();
                    statDG.DataBind();
                }
                else
                {
                    Hide("");
                }
            }
        }
Example #17
0
        private void Bind()
        {
            DataTable dt = new DataTable("Соревнования");

            dt.Columns.Add("TID");
            dt.Columns.Add("Name");
            dt.Columns.Add("Monitor");
            dt.Columns.Add("Beginning", typeof(DateTime));
            dt.Columns.Add("Ending", typeof(DateTime));
            dt.Columns.Add("Status");
            DataRow dr;
            Contest t;

            using (BaseDb db = DbFactory.ConstructDatabase())
            {
                int[] oldtids = db.GetOldTids();
                int[] nowtids = db.GetNowTids();
                int[] futtids = db.GetFutureTids();

                foreach (int tid in nowtids)
                {
                    t     = db.GetContest(tid);
                    dr    = dt.NewRow();
                    dr[0] = tid;
                    if (t.Future && !BaseDb.IsAdmin(Page.User))
                    {
                        dr[1] = t.Name;
                    }
                    else
                    {
                        dr[1] = "<a href='contest.aspx?tid=" + tid + "'>" + t.Name + "</a>";
                    }
                    if (!t.Future || BaseDb.IsAdmin(Page.User))
                    {
                        dr[2] = "<a href='monitor.aspx?tid=" + tid + "'>Ссылка</a>";
                    }
                    dr[3] = t.Beginning;
                    dr[4] = t.Ending;
                    dr[5] = "Идет";
                    dt.Rows.Add(dr);
                }
                foreach (int tid in futtids)
                {
                    t     = db.GetContest(tid);
                    dr    = dt.NewRow();
                    dr[0] = tid;
                    if (t.Future && !BaseDb.IsAdmin(Page.User))
                    {
                        dr[1] = t.Name;
                    }
                    else
                    {
                        dr[1] = "<a href='contest.aspx?tid=" + tid + "'>" + t.Name + "</a>";
                    }
                    if (!t.Future || BaseDb.IsAdmin(Page.User))
                    {
                        dr[2] = "<a href='monitor.aspx?tid=" + tid + "'>Ссылка</a>";
                    }
                    dr[3] = t.Beginning;
                    dr[4] = t.Ending;
                    dr[5] = "Ещё не начиналось ( начнется через " + HtmlFunctions.BeautifyTimeSpan(db.GetContest(tid).Beginning - DateTime.Now, false) + " )";
                    dt.Rows.Add(dr);
                }
                foreach (int tid in oldtids)
                {
                    t     = db.GetContest(tid);
                    dr    = dt.NewRow();
                    dr[0] = tid;
                    if (t.Future && !BaseDb.IsAdmin(Page.User))
                    {
                        dr[1] = t.Name;
                    }
                    else
                    {
                        dr[1] = "<a href='contest.aspx?tid=" + tid + "'>" + t.Name + "</a>";
                    }
                    if (!t.Future || BaseDb.IsAdmin(Page.User))
                    {
                        dr[2] = "<a href='monitor.aspx?tid=" + tid + "'>Ссылка</a>";
                    }
                    dr[3] = t.Beginning;
                    dr[4] = t.Ending;
                    dr[5] = "Закончилось";
                    dt.Rows.Add(dr);
                }
            }
            DataGrid1.DataSource = dt;
            DataGrid1.DataBind();
        }