Esempio n. 1
0
 public CustomFormulaControl(MetroBillCommands commands, int userId, bool isSnapShot,
                             IEnumerable<SimpleFormulaModel> formulas,IEnumerable<string> checkedColumns)
 {
     InitializeComponent();
     Commands = commands;
     _userId = userId;
     _isSnapShot = isSnapShot;
     _formulas = new List<SimpleFormulaModel>();
     foreach (var simpleFormulaModel in formulas)
     {
         var nModel = new SimpleFormulaModel
                          {
                              Name = simpleFormulaModel.Name,
                              Elements = simpleFormulaModel.Elements.ToList(),
                              Formula = simpleFormulaModel.Formula,
                              FormulaId = simpleFormulaModel.FormulaId,
                              FormulaType = simpleFormulaModel.FormulaType,
                              IsSnapShot = simpleFormulaModel.IsSnapShot,
                              UsedColumns = simpleFormulaModel.UsedColumns.ToList(),
                              UserId = simpleFormulaModel.UserId
                          };
         AddFormula(nModel);
     }
     ui_comboBoxEx_useColumn.Items.Clear();
     foreach (var checkedColumn in checkedColumns)
     {
         ui_comboBoxEx_useColumn.Items.Add(checkedColumn);
     }
 }
        public static List<SimpleFormulaModel> GetFormulaForUser(int userId)
        {
            var formulas = new List<SimpleFormulaModel>();

            var sql = "SELECT * FROM " + TblFormulas;

            if (CurrentDbIsShared)
            {
                sql += " WHERE UserId= " + userId;
            }

            var reader = GetReader(sql);
            if (reader != null)
            {
                try
                {
                    while (reader.Read())
                    {
                        var formula = new SimpleFormulaModel
                        {
                            FormulaId = reader.GetInt32(0),
                            UserId = reader.GetInt32(1),
                            IsSnapShot = reader.GetBoolean(2),
                            Name = reader.GetString(3),
                            Formula = reader.GetString(4),
                            UsedColumns = reader.GetString(5).Split(',').ToList(),
                        };
                        if (formula.UsedColumns.Count == 1 && formula.UsedColumns[0] == "")
                        {
                            formula.UsedColumns.Clear();
                        }

                        var elements = reader.GetString(6).Split('@');
                        formula.Elements = new List<ElementStructure>();
                        foreach (var element in elements)
                        {
                            ElementType type;
                            if (Enum.TryParse(element.Split('^')[0], out type))
                            {
                                var value = element.Split('^')[1];
                                var elementStruc = new ElementStructure
                                {
                                    Type = type,
                                    Value = value
                                };
                                formula.Elements.Add(elementStruc);
                            }
                        }

                        formulas.Add(formula);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return formulas;
        }
        public static List<SimpleFormulaModel> GetFormulaForTimeSlice(int tsId)
        {
            var formulas = new List<SimpleFormulaModel>();

            var sql = "SELECT * FROM " + TblFormulaTsRelations
                        + " LEFT JOIN " + TblFormulas
                        + " ON " + TblFormulaTsRelations + ".FormulaID = "
                        + TblFormulas + ".ID" + " WHERE " + TblFormulaTsRelations + ".TsID = '" + tsId + "' AND " + TblFormulas + ".SSorTS = false ;";

            var reader = GetReader(sql);
            if (reader != null)
            {
                try
                {
                    while (reader.Read())
                    {
                        var formula = new SimpleFormulaModel
                        {
                            FormulaId = reader.GetInt32(3),
                            UserId = reader.GetInt32(4),
                            IsSnapShot = reader.GetBoolean(5),
                            Name = reader.GetString(6),
                            Formula = reader.GetString(7),
                            UsedColumns = reader.GetString(8).Split(',').ToList(),
                        };
                        if (formula.UsedColumns.Count == 1 && formula.UsedColumns[0]=="")
                        {
                            formula.UsedColumns.Clear();
                        }

                        var elements = reader.GetString(9).Split('@');
                        formula.Elements = new List<ElementStructure>();
                        foreach (var element in elements)
                        {
                            ElementType type;
                            if (Enum.TryParse(element.Split('^')[0], out type))
                            {
                                var value = element.Split('^')[1];
                                var elementStruc = new ElementStructure
                                    {
                                        Type = type,
                                        Value = value
                                    };
                                formula.Elements.Add(elementStruc);
                            }
                        }

                        formulas.Add(formula);
                    }
                }
                finally
                {
                    reader.Close();
                }
            }
            return formulas;
        }
Esempio n. 4
0
 private void AddFormula(SimpleFormulaModel fmodel)
 {
     _formulas.Add(fmodel);
     elementContainerControl1.AddElement(fmodel.Name);
 }