示例#1
0
        protected void Initialize()
        {
            // add application name and
            Title = Utils.FormatTitle();

            LoadThemes();
            LoadUsers();

            labelName.TooltipText  = cbeName.TooltipText;
            labelTheme.TooltipText = comboTheme.TooltipText;

            statusMessage = new StatusMessage(lblStatus, imgStatus);

            statusMessage.Message(Catalog.GetString("Enter your name, theme and press \"My Variant\" button"), Stock.DialogInfo);
        }
示例#2
0
        protected virtual void OnActionGenerateActivated(object sender, System.EventArgs e)
        {
            #region

            // TODO: Do not correct entered name, just normalize it internally

            // TODO: Valid name regex (culture- or option- dependent)

            // TODO: Name normalization regex (remove spaces, ё => e)

            var sName = cbeName.ActiveText.ToLower().Trim();

            // remove duplicate whitespace
            sName = Regex.Replace(sName, @"\s+", " ");


            // filter invalid symbols
            // [^а-я-\s] - with "-"
            sName = Regex.Replace(sName, @"[^а-яё\s]", "", RegexOptions.IgnoreCase);

            if (!UserInfo.IsValidName(sName))
            {
                statusMessage.Message(
                    Catalog.GetString("Name was entered incorrectly!"),
                    Catalog.GetString("Name must consists from three parts - lastname (family name), firstname and othername, separated with spaces."),
                    Stock.DialogError
                    );

                cbeName.ErrorBell();
                return;
            }

            var sNameParts = sName.Split(' ');

            sName = CharToUpper(sNameParts [0], 0) + " " + CharToUpper(sNameParts [1], 0) + " " + CharToUpper(sNameParts [2], 0);

            RememberUser(sName);

            // THINK: RU locale-specific
            // replace 'Ё' after remember, so it is equivalent to 'Е'
            sName = sName.Replace("ё", "е").Replace("Ё", "Е");

            sNameParts = sName.ToUpper().Split(' ');
            //cbeName.Entry.Text = sName;

            //sName = sName.ToUpper();

            #endregion

            var uniqueInt = UniqueInt(
                Mix(sNameParts [0], sNameParts [1], sNameParts [2]));

            var rnd = new Random(uniqueInt);

            // roll dice three times
            rnd.Next();
            rnd.Next();
            rnd.Next();              // new version

            //int nTasksToSelect = 10;
            //int iGrouping = 2;
            //int ToSumComplexity = 10 * 5 - 3; // примерно 10 задач средней сложности (5) минус 5 (чуть меньше половинной сложности)

            if (comboTheme.Active == 0)
            {
                statusMessage.Message(
                    Catalog.GetString("You must choose a theme!"),
                    Catalog.GetString("You must choose a theme of work to generate variant for it."),
                    Stock.DialogError
                    );

                comboTheme.ErrorBell();
                return;
            }

            lsTasks         = new List <TaskInfo> (100);
            lsTasksSelected = new List <TaskInfo> (10);

            ThemeInfo theme = null;
            foreach (ThemeInfo t in lsThemes)
            {
                if (t.Title == comboTheme.ActiveText)
                {
                    theme = t;
                    break;
                }
            }

            if (theme == null)
            {
                statusMessage.Message(
                    Catalog.GetString("Unexpected error!"),
                    Catalog.GetString("Unexpected error occured! Application restart recommended."),
                    Stock.DialogError
                    );

                comboTheme.ErrorBell();
                return;
            }

            lsTasks = DataProvider.Database.Fetch <TaskInfo, ProblemBookSectionInfo, ProblemBookInfo> (
                "SELECT TA.*, PBS.*, PB.* FROM Tasks AS TA " +
                "INNER JOIN ThemeSectionPairs AS TSP " +
                "ON TA.ProblemBookSectionID = TSP.ProblemBookSectionID " +
                "INNER JOIN ProblemBookSections AS PBS " +
                "ON TA.ProblemBookSectionID = PBS.ProblemBookSectionID " +
                "INNER JOIN ProblemBooks AS PB " +
                "ON PBS.ProblemBookID = PB.ProblemBookID " +
                "WHERE TSP.ThemeID = @0 ORDER BY TA.[Order] ASC", theme.ThemeID);

            var nTasks = lsTasks.Count;

            if (nTasks == 0)
            {
                statusMessage.Message(
                    Catalog.GetString("No tasks for choosen theme!"),
                    Catalog.GetString("No tasks for choosen theme found in the database"),
                    Stock.DialogWarning
                    );

                comboTheme.ErrorBell();
                return;
            }

            // массив маски выбранных задач
            // если taskMask[i] = true, задача выбрана
            var taskMask = new bool[nTasks];
            for (var i = 0; i < taskMask.Length; i++)
            {
                taskMask [i] = false;
            }

            var easyTasks    = SelectTasks(2, 1, 3, taskMask, rnd);
            var hardTasks    = SelectTasks(2, 9, 10, taskMask, rnd);
            var complexTasks = SelectTasks(2, 7, 8, taskMask, rnd);
            var commonTasks  = SelectTasks(
                10 - complexTasks.Count - hardTasks.Count - easyTasks.Count,
                4, 6, taskMask, rnd);

            lsTasksSelected.AddRange(easyTasks);
            lsTasksSelected.AddRange(hardTasks);
            lsTasksSelected.AddRange(complexTasks);
            lsTasksSelected.AddRange(commonTasks);

            lsTasksSelected.Sort(new TaskOrderComparer());

            while (table2.Children.Length > 0)
            {
                table2.Remove(table2.Children [0]);
            }

            // CHECK: what is it for?
            if (table2.Children.Length < lsTasksSelected.Count)
            {
                for (var i = 0; i < lsTasksSelected.Count; i++)
                {
                    var button = new Button();
                    table2.Add(button);

                    var tableChild = table2 [button] as Table.TableChild;
                    tableChild.XOptions = tableChild.YOptions = AttachOptions.Expand | AttachOptions.Fill;

                    var x = (uint)(i % 5) * 2 + 1;
                    var y = (uint)(i / 5);

                    tableChild.LeftAttach   = x;
                    tableChild.RightAttach  = tableChild.LeftAttach + 1;
                    tableChild.TopAttach    = y;
                    tableChild.BottomAttach = tableChild.TopAttach + 1;

                    // add label
                    var label = new Label();
                    table2.Add(label);

                    tableChild = table2 [label] as Table.TableChild;

                    label.UseMarkup = true;
                    label.LabelProp = string.Format("<b>{0,2}:</b>", i + 1);
                    label.SetAlignment(1, 0.5f);

                    tableChild.LeftAttach   = x - 1;
                    tableChild.RightAttach  = tableChild.LeftAttach + 1;
                    tableChild.TopAttach    = y;
                    tableChild.BottomAttach = tableChild.TopAttach + 1;

                    label.Show();
                    button.Show();
                }                 // for
            }

            statusMessage.Message(
                string.Format(Catalog.GetString("{0} tasks choosen"), lsTasksSelected.Count),
                Stock.DialogInfo
                );

            sizegroupButtons = new SizeGroup(SizeGroupMode.Horizontal);

            // fill task buttons
            var ti = 0;
            foreach (var w in table2.Children)
            {
                if (w is Button)
                {
                    // FIXME: Sort order is inverse!
                    // must be: TaskInfo t = lsTasksSelected [ti++];

                    var task = lsTasksSelected [lsTasksSelected.Count - ++ti];

                    var button = w as Button;
                    button.Label        = task.ToString();
                    button.TooltipText  = task.ToDetailString();
                    button.BorderWidth  = 2;
                    button.WidthRequest = 100;
                    button.FocusOnClick = true;
                    button.Clicked     += new EventHandler(OnTaskButtonClicked);

                    sizegroupButtons.AddWidget(button);

                    #region Button coloring (disabled)

                    // Button coloring is disabled - not supported by all GTK themes

                    /* // color by complexity
                     * Gdk.Color color = new Gdk.Color (192, 255, 192);
                     * if (t.ComplexityLevel == TaskComplexity.Low)
                     *      color = new Gdk.Color (255, 255, 255);
                     * else if (t.ComplexityLevel == TaskComplexity.Higher)
                     *      color = new Gdk.Color (255, 255, 192);
                     * else if (t.ComplexityLevel == TaskComplexity.High)
                     *      color = new Gdk.Color (255, 192, 192);
                     * ModifyButtonBg (b, color);
                     */

                    /* // color by taskbook
                     * Gdk.Color color = new Gdk.Color (200, 255, 200);
                     * if (t.Designation == "Зл")
                     *      color = new Gdk.Color (200, 255, 200);
                     * else if (t.Designation == "Аб")
                     *      color = new Gdk.Color (255, 255, 255);
                     * else if (t.Designation == "Юр")
                     *      color = new Gdk.Color (200, 200, 255);
                     *
                     * ModifyWidgetBg (rb, color);
                     */

                    #endregion
                }
            }

            // display theme description on label and make label visible
            labelThemeDesc.LabelProp   = "<i>" + theme.Description + "</i>";
            labelThemeDesc.TooltipText = theme.Description;
            labelThemeDesc.Visible     = true;

            // make task table and checkbutton visible
            table2.Visible      = true;
            chkOpenBook.Visible = true;

            // dump generated varian to textview
            textview1.Buffer.Text =
                string.Format(Catalog.GetString("Variant for:\n{0}\n{1}"), sName, TasksToText(lsTasksSelected));
        }