//public CodeFunctionEntityFormulaDTO GetCodeFunctionEntityFormula(DR_Requester requester, int FormulaID, bool withDetails)
        //{
        //    using (var projectContext = new DataAccess.MyProjectEntities())
        //    {
        //        var dbFormula = projectContext.Formula.First(x => x.ID == FormulaID);
        //        CodeFunctionEntityFormulaDTO result = new CodeFunctionEntityFormulaDTO();
        //        ToFormulaDTO(dbFormula, result, withDetails);
        //        if (withDetails)
        //        {
        //            BizCodeFunction bizCodeFunction = new MyModelManager.BizCodeFunction();
        //            result.CodeFunctionEntity = bizCodeFunction.GetCodeFunctionEntity(requester, result.CodeFunctionEntityID);
        //        }
        //        return result;
        //    }
        //}
        public LinearFormulaDTO GetLinearFormula(DR_Requester requester, int FormulaID, bool withDetails)
        {
            using (var projectContext = new DataAccess.MyProjectEntities())
            {
                var dbFormula           = projectContext.Formula.First(x => x.ID == FormulaID);
                LinearFormulaDTO result = new LinearFormulaDTO();
                ToFormulaDTO(dbFormula, result, withDetails);

                result.FormulaText = dbFormula.LinearFormula.FormulaText;
                result.Version     = dbFormula.LinearFormula.Version;

                return(result);
            }
        }
Пример #2
0
 private LinearFormulaDTO GetLinearFormulaDTO()
 {
     if (optLinear.IsChecked == true)
     {
         var result = new LinearFormulaDTO();
         result.FormulaText = txtFormula.Text;
         return(result);
         // result.Version = (short)txtVersion.Text;
     }
     else
     {
         return(null);
     }
 }
        //public FormulaParameterDTO GetFormulaParameter(int formulaParameterID)
        //{
        //    List<FormulaParameterDTO> result = new List<FormulaParameterDTO>();
        //    using (var projectContext = new DataAccess.MyProjectEntities())
        //    {
        //        return ToFormulaParameterDTO(projectContext.FormulaParameter.First(x => x.ID == formulaParameterID));
        //    }
        //}
        //public List<FormulaParameterDTO> GetFormulaParameters(int entityID)
        //{
        //    List<FormulaParameterDTO> result = new List<FormulaParameterDTO>();
        //    using (var projectContext = new DataAccess.MyProjectEntities())
        //    {
        //        var list = projectContext.FormulaParameter.Where(x => x.TableDrivedEntityID == entityID);
        //        foreach (var item in list)
        //            result.Add(ToFormulaParameterDTO(item));
        //        return result;
        //    }
        //}

        //private FormulaParameterDTO ToFormulaParameterDTO(FormulaParameter cItem)
        //{
        //    var result = new FormulaParameterDTO();
        //    result.ID = cItem.ID;
        //    result.FormulaID = cItem.FormulaID;
        //    result.EntityID = cItem.TableDrivedEntityID;
        //    result.Name = cItem.Name;
        //    result.Title = cItem.Title;
        //    result.ResultType = GetFormulaDotNetType(cItem.Formula.ResultType);
        //    return result;
        //}



        //public int UpdateDatabaseFunction(DatabaseFunctionDTO DatabaseFunction)
        //{
        //    using (var projectContext = new DataAccess.MyProjectEntities())
        //    {
        //        var dbDatabaseFunction = projectContext.DatabaseFunction.FirstOrDefault(x => x.ID == DatabaseFunction.ID);
        //        if (dbDatabaseFunction == null)
        //            dbDatabaseFunction = new DataAccess.DatabaseFunction();
        //        dbDatabaseFunction.FunctionName = DatabaseFunction.FunctionName;
        //        dbDatabaseFunction.ID = DatabaseFunction.ID;
        //        if (DatabaseFunction.EntityID != 0)
        //            dbDatabaseFunction.TableDrivedEntityID = DatabaseFunction.EntityID;
        //        dbDatabaseFunction.Title = DatabaseFunction.Title;
        //        dbDatabaseFunction.ReturnType = DatabaseFunction.ReturnType;
        //        dbDatabaseFunction.RelatedSchema = DatabaseFunction.Schema;
        //        while (dbDatabaseFunction.DatabaseFunctionParameter.Any())
        //        {
        //            dbDatabaseFunction.DatabaseFunctionParameter.Remove(dbDatabaseFunction.DatabaseFunctionParameter.First());
        //        }
        //        foreach (var column in DatabaseFunction.DatabaseFunctionParameter)
        //        {
        //            DatabaseFunctionParameter dbColumn = new DataAccess.DatabaseFunctionParameter();
        //            dbColumn.ColumnID = column.ColumnID;
        //            dbColumn.DataType = column.DataType;
        //            dbColumn.ParamName = column.ParameterName;
        //            dbDatabaseFunction.DatabaseFunctionParameter.Add(dbColumn);
        //        }
        //        if (dbDatabaseFunction.ID == 0)
        //            projectContext.DatabaseFunction.Add(dbDatabaseFunction);
        //        projectContext.SaveChanges();
        //        return dbDatabaseFunction.ID;
        //    }
        //}


        //private Enum_ColumnType ConvertParameterResultType(string resultType)
        //{
        //    if (string.IsNullOrEmpty(resultType))
        //        return Enum_ColumnType.None;
        //    else if (resultType == "String")
        //        return Enum_ColumnType.String;
        //    else if (resultType == "Numeric")
        //        return Enum_ColumnType.Numeric;
        //    else if (resultType == "Boolean")
        //        return Enum_ColumnType.Boolean;
        //    else if (resultType == "Date")
        //        return Enum_ColumnType.Date;
        //    return Enum_ColumnType.None;
        //}
        //private string ConvertParameterResultType(Enum_ColumnType resultType)
        //{
        //    return resultType.ToString();
        //}

        public int UpdateFormula(FormulaDTO formula, LinearFormulaDTO linearFormula)
        {
            using (var projectContext = new DataAccess.MyProjectEntities())
            {
                DataAccess.Formula dbFormula = null;
                if (formula.ID == 0)
                {
                    dbFormula = new Formula();
                }
                else
                {
                    dbFormula = projectContext.Formula.FirstOrDefault(x => x.ID == formula.ID);
                }

                dbFormula.Name = formula.Name;
                dbFormula.ID   = formula.ID;
                if (formula.EntityID != 0)
                {
                    dbFormula.TableDrivedEntityID = formula.EntityID;
                }
                else
                {
                    dbFormula.TableDrivedEntityID = null;
                }
                dbFormula.ResultType = formula.ResultType;

                //dbFormula.ValueCustomType = (Int16)Formula.ValueCustomType;
                dbFormula.Title = formula.Title;
                while (dbFormula.FormulaItems1.Any())
                {
                    projectContext.FormulaItems.Remove(dbFormula.FormulaItems1.First());
                }
                foreach (var formulaItem in formula.FormulaItems)
                {
                    var dbFormulaItem = ToFormualaItem(formulaItem, dbFormula);
                    dbFormula.FormulaItems1.Add(dbFormulaItem);
                }

                if (formula.FormulaType == FormulaType.Linear)
                {
                    if (dbFormula.LinearFormula == null)
                    {
                        dbFormula.LinearFormula = new LinearFormula();
                    }
                    dbFormula.LinearFormula.FormulaText = linearFormula.FormulaText;
                    dbFormula.LinearFormula.Version     = linearFormula.Version;
                }
                else
                {
                    if (dbFormula.LinearFormula != null)
                    {
                        projectContext.LinearFormula.Remove(dbFormula.LinearFormula);
                    }
                }
                if (formula.FormulaType == FormulaType.CodeFunctionEntity)
                {
                    dbFormula.CodeFunction_TableDrivedEntityID = formula.CodeFunctionEntityID;
                }
                else
                {
                    dbFormula.CodeFunction_TableDrivedEntityID = null;
                }
                if (formula.FormulaType == FormulaType.CodeFunction)
                {
                    dbFormula.CodeFunctionID = formula.CodeFunctionID;
                }
                else
                {
                    dbFormula.CodeFunctionID = null;
                }
                if (formula.FormulaType == FormulaType.DatabaseFunctionEntity)
                {
                    dbFormula.DatabaseFunction_TableDrivedEntityID = formula.DatabaseFunctionEntityID;
                }
                else
                {
                    dbFormula.DatabaseFunction_TableDrivedEntityID = null;
                }
                if (dbFormula.ID == 0)
                {
                    projectContext.Formula.Add(dbFormula);
                }
                projectContext.SaveChanges();
                return(dbFormula.ID);
            }
        }