public Solver.Criteria ShowDialog(Solver.Criteria criteria)
        {
            if (criteria == null)
            {
                Criteria_         = null;
                Text              = "Add Criteria";
                btnRevert.Enabled = false;
            }
            else
            {
                Criteria_         = criteria.DeepCopy();
                Text              = "Edit Criteria";
                btnRevert.Enabled = true;
            }

            LoadFromCriteria();

            DialogResult result = base.ShowDialog();

            if (result == DialogResult.OK)
            {
                return(Criteria_);
            }
            return(null);
        }
Beispiel #2
0
        private void listBoxCriteria_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            if (listBoxCriteria.Items.Count == 0)
            {
                return;
            }

            Graphics g = e.Graphics;

            Solver.Criteria criteria = (Solver.Criteria)listBoxCriteria.Items[e.Index];

            const int margin = 2;
            Rectangle r      = new Rectangle(e.Bounds.X + margin, e.Bounds.Y + margin, e.Bounds.Width - 2 * margin, e.Bounds.Height - 2 * margin);

            Font         font;
            Rectangle    q;
            StringFormat format = new StringFormat();

            format.Alignment     = StringAlignment.Near;
            format.LineAlignment = StringAlignment.Near;

            /*const int numTop = 2;
             * font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular);
             * q = new Rectangle(r.X, r.Y + numTop, r.Width, r.Height - numTop);
             * g.DrawString((e.Index + 1).ToString() + ".", font, Brushes.Black, q, format);*/

            // heading: name
            const int nameLeft = 5, nameTop = 5;

            font = new Font("Microsoft Sans Serif", 11f, FontStyle.Bold);
            q    = new Rectangle(r.X + nameLeft, r.Y + nameTop, r.Width - nameLeft, r.Height - nameTop);
            g.DrawString(criteria.Field.ToString(), font, Brushes.Black, q, format);

            // subheading: preference
            const int prefLeft = 20, prefTop = 25;

            font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular);
            q    = new Rectangle(r.X + prefLeft, r.Y + prefTop, r.Width - prefLeft, r.Height - prefTop);
            string text = "Preference: " + Solver.Criteria.FieldSpecificPreference(criteria);

            g.DrawString(text, font, Brushes.Black, q, format);

            // top right corner: criteria number
            const int numRight = 3, numTop = 3;

            format.Alignment = StringAlignment.Far;
            font             = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular);
            q = new Rectangle(r.X, r.Y + numTop, r.Width - numRight, r.Height - numTop);
            g.DrawString((e.Index + 1).ToString(), font, Brushes.Black, q, format);

            g.DrawRectangle(Pens.Black, r);
        }
Beispiel #3
0
        private void listBoxCriteria_DragDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(Solver.Criteria)))
            {
                return;
            }

            Point location = listBoxCriteria.PointToClient(new Point(e.X, e.Y));

            DragTarget_   = listBoxCriteria.IndexFromPoint(location);
            DragCriteria_ = (Solver.Criteria)e.Data.GetData(typeof(Solver.Criteria));
        }
Beispiel #4
0
        private void listBoxCriteria_MouseDown(object sender, MouseEventArgs e)
        {
            int index = listBoxCriteria.IndexFromPoint(e.Location);

            if (index == -1)
            {
                listBoxCriteria.SelectedIndex = -1;
                return;
            }

            if (e.Clicks == 2 && e.Button == MouseButtons.Left)
            {
                EditCriteria();
                return;
            }

            Solver.Criteria criteria = (Solver.Criteria)listBoxCriteria.Items[index];
            DragTarget_   = -1;
            DragCriteria_ = null;
            // drag drop failed
            if (listBoxCriteria.DoDragDrop(criteria, DragDropEffects.Move) != DragDropEffects.Move)
            {
                return;
            }
            // some sort of conflict
            if (DragTarget_ == -1 || DragCriteria_ != criteria)
            {
                return;
            }
            // moving back to same position
            if (DragTarget_ == index)
            {
                return;
            }
            if (DragTarget_ > index)
            {
                listBoxCriteria.Items.Insert(DragTarget_ + 1, criteria);
                listBoxCriteria.Items.RemoveAt(index);
            }
            else
            {
                listBoxCriteria.Items.RemoveAt(index);
                listBoxCriteria.Items.Insert(DragTarget_, criteria);
            }
            listBoxCriteria.SelectedIndex = DragTarget_;

            // not preset anymore
            ddPresets.SelectedIndex = -1;
        }
Beispiel #5
0
        private void AddCriteria()
        {
            FormCriteriaDetails formDetails = new FormCriteriaDetails();

            Solver.Criteria criteria = formDetails.ShowDialog(null);
            if (criteria == null)
            {
                return;
            }
            int index = listBoxCriteria.SelectedIndex;

            if (index == -1)
            {
                index = listBoxCriteria.Items.Count;
            }
            listBoxCriteria.Items.Insert(index, criteria);

            ddPresets.SelectedIndex = -1;
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ddField.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a criteria.", "Criteria Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ddField.Focus();
                return;
            }
            if (ddPreference.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a preference.", "Criteria Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ddPreference.Focus();
                return;
            }

            Criteria_ = new Solver.Criteria(
                (Solver.FieldIndex)ddField.SelectedIndex,
                (Solver.Preference)ddPreference.SelectedIndex);

            DialogResult = DialogResult.OK;
            Close();
        }
        public Solver.Criteria ShowDialog(Solver.Criteria criteria)
        {
            if (criteria == null)
            {
                Criteria_ = null;
                Text = "Add Criteria";
                btnRevert.Enabled = false;
            }
            else
            {
                Criteria_ = criteria.DeepCopy();
                Text = "Edit Criteria";
                btnRevert.Enabled = true;
            }

            LoadFromCriteria();

            DialogResult result = base.ShowDialog();
            if (result == DialogResult.OK)
                return Criteria_;
            return null;
        }
Beispiel #8
0
        private void EditCriteria()
        {
            int index = listBoxCriteria.SelectedIndex;

            if (index == -1)
            {
                return;
            }

            Solver.Criteria     criteria    = (Solver.Criteria)listBoxCriteria.SelectedItem;
            FormCriteriaDetails formDetails = new FormCriteriaDetails();

            criteria = formDetails.ShowDialog(criteria);
            if (criteria == null)
            {
                return;
            }
            listBoxCriteria.Items.RemoveAt(index);
            listBoxCriteria.Items.Insert(index, criteria);
            listBoxCriteria.SelectedIndex = index;

            ddPresets.SelectedIndex = -1;
        }
Beispiel #9
0
        private void listBoxCriteria_DragDrop(object sender, DragEventArgs e)
        {
            if (!e.Data.GetDataPresent(typeof(Solver.Criteria)))
                return;

            Point location = listBoxCriteria.PointToClient(new Point(e.X, e.Y));
            DragTarget_ = listBoxCriteria.IndexFromPoint(location);
            DragCriteria_ = (Solver.Criteria)e.Data.GetData(typeof(Solver.Criteria));
        }
Beispiel #10
0
        private void listBoxCriteria_MouseDown(object sender, MouseEventArgs e)
        {
            int index = listBoxCriteria.IndexFromPoint(e.Location);
            if (index == -1)
            {
                listBoxCriteria.SelectedIndex = -1;
                return;
            }

            if (e.Clicks == 2 && e.Button == MouseButtons.Left)
            {
                EditCriteria();
                return;
            }

            Solver.Criteria criteria = (Solver.Criteria)listBoxCriteria.Items[index];
            DragTarget_ = -1;
            DragCriteria_ = null;
            // drag drop failed
            if (listBoxCriteria.DoDragDrop(criteria, DragDropEffects.Move) != DragDropEffects.Move)
                return;
            // some sort of conflict
            if (DragTarget_ == -1 || DragCriteria_ != criteria)
                return;
            // moving back to same position
            if (DragTarget_ == index)
                return;
            if (DragTarget_ > index)
            {
                listBoxCriteria.Items.Insert(DragTarget_ + 1, criteria);
                listBoxCriteria.Items.RemoveAt(index);
            }
            else
            {
                listBoxCriteria.Items.RemoveAt(index);
                listBoxCriteria.Items.Insert(DragTarget_, criteria);
            }
            listBoxCriteria.SelectedIndex = DragTarget_;

            // not preset anymore
            ddPresets.SelectedIndex = -1;
        }
Beispiel #11
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // check if there were any changes
            bool changed = false;

            if (Solver_.Comparer.Criteria.Count == listBoxCriteria.Items.Count)
            {
                for (int i = 0; i < Solver_.Comparer.Criteria.Count; i++)
                {
                    Solver.Criteria criteria = Solver_.Comparer.Criteria[i];
                    Solver.Criteria other    = (Solver.Criteria)listBoxCriteria.Items[i];
                    if (criteria.FieldIndex != other.FieldIndex || criteria.Preference != other.Preference)
                    {
                        changed = false;
                        break;
                    }
                }
            }
            else
            {
                changed = true;
            }
            if (!changed && Solver_.Filters.Count == listBoxFilters.Items.Count)
            {
                for (int i = 0; i < Solver_.Filters.Count; i++)
                {
                    Solver.Filter filter = Solver_.Filters[i];
                    Solver.Filter other  = (Solver.Filter)listBoxFilters.Items[i];
                    if (filter.FieldIndex == other.FieldIndex &&
                        filter.Exclude == other.Exclude &&
                        filter.Test == other.Test &&
                        filter.ValueAsInt == other.ValueAsInt)
                    {
                        changed = false;
                        break;
                    }
                }
            }
            else
            {
                changed = true;
            }

            if (!changed)
            {
                DialogResult = DialogResult.Cancel;
                Close();
                return;
            }

            // copy changes across
            Solver_.Comparer.Criteria.Clear();
            foreach (Solver.Criteria criteria in listBoxCriteria.Items)
            {
                Solver_.Comparer.Criteria.Add(criteria);
            }

            Solver_.Filters.Clear();
            foreach (Solver.Filter filter in listBoxFilters.Items)
            {
                Solver_.Filters.Add(filter);
            }

            DialogResult = DialogResult.OK;
            Close();
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ddField.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a criteria.", "Criteria Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ddField.Focus();
                return;
            }
            if (ddPreference.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a preference.", "Criteria Details", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                ddPreference.Focus();
                return;
            }

            Criteria_ = new Solver.Criteria(
                (Solver.FieldIndex)ddField.SelectedIndex,
                (Solver.Preference)ddPreference.SelectedIndex);

            DialogResult = DialogResult.OK;
            Close();
        }