Ejemplo n.º 1
0
        private List <ConditionFormat> GetConditionsFromXml(string filename)
        {
            List <ConditionFormat> listConditionFormats = new List <ConditionFormat>();
            IFormatProvider        formatter            = new NumberFormatInfo {
                NumberDecimalSeparator = ","
            };
            XDocument xdoc = XDocument.Load(filename);
            XElement  root = xdoc.Root;

            XElement xeConditions = root.Element("Conditions");

            foreach (XElement xeCondition in xeConditions.Elements())
            {
                ConditionFormat conditionFormat = new ConditionFormat
                {
                    ColumnName = xeCondition.Attribute("ColumnName").Value,
                    Operator   = xeCondition.Attribute("Operator").Value
                };
                string formula1 = xeCondition.Attribute("Formula1").Value;

                conditionFormat.Text     = xeCondition.Attribute("Text").Value;
                conditionFormat.Formula1 = double.Parse(formula1, formatter);
                string formula2 = xeCondition.Attribute("Formula2").Value;
                conditionFormat.Formula2 = double.Parse(formula2, formatter);
                XElement xeFormate = xeCondition.Element("Format");

                conditionFormat.FontBold      = bool.Parse(xeFormate.Attribute("FontBold").Value);
                conditionFormat.ForeColor     = Color.FromArgb(int.Parse(xeFormate.Attribute("ForeColor").Value));
                conditionFormat.InteriorColor = Color.FromArgb(int.Parse(xeFormate.Attribute("InteriorColor").Value));

                listConditionFormats.Add(conditionFormat);
            }
            return(listConditionFormats);
        }
Ejemplo n.º 2
0
        private void BtnAccept_Click(object sender, EventArgs e)
        {
            IFormatProvider formatter = new NumberFormatInfo {
                NumberDecimalSeparator = ","
            };
            List <ConditionFormat> listCondintions = new List <ConditionFormat>();

            foreach (DataGridViewRow row in RulesDataGrid.Rows)
            {
                int             id = (int)row.Cells[0].Value;
                ConditionFormat cf = _ListCondintions.Find(x => x.ID == id);
                if (cf is null)
                {
                    cf = new ConditionFormat
                    {
                        ID = _ListCondintions.Count
                    };
                }

                string name        = row.Cells[1].Value?.ToString() ?? "";
                string operatorCon = row.Cells[2].Value?.ToString();
                string formula1    = row.Cells[3].Value?.ToString() ?? "";
                string formula2    = row.Cells[4].Value?.ToString() ?? "";

                cf            = _ListCondintions[id];
                cf.Operator   = operatorCon;
                cf.ColumnName = name;
                if (operatorCon == "Содержит")
                {
                    cf.Text = formula1;
                }
                else
                {
                    cf.Formula1 = double.Parse(formula1, formatter);
                    cf.Formula2 = double.Parse(formula2, formatter);
                }

                listCondintions.Add(cf);
            }

            manager.ListConditionFormats = listCondintions;
            manager.Save();
            DialogResult = DialogResult.OK;
            Close();
        }
Ejemplo n.º 3
0
        private void CustomDataGrid_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0)
            {
                return;
            }
            int id = (int)RulesDataGrid.Rows[e.RowIndex].Cells[0].Value;

            if (id < _ListCondintions.Count)
            {
                _ConditionFormat       = _ListCondintions[id];
                richTextBox1.ForeColor = _ConditionFormat.ForeColor;
                richTextBox1.BackColor = _ConditionFormat.InteriorColor;
                ChkBoxBold.Checked     = _ConditionFormat.FontBold;
                FontStyle style = _ConditionFormat.FontBold ? FontStyle.Bold : FontStyle.Regular;
                richTextBox1.Font = new Font("Tahoma", 10, style);
            }
        }