コード例 #1
0
        public FormulaDTO ToFormulaDTO(DataAccess.Formula item, bool withDetails)
        {
            FormulaDTO result = new FormulaDTO();

            ToFormulaDTO(item, result, withDetails);
            return(result);
        }
コード例 #2
0
 public void ToFormulaDTO(DataAccess.Formula item, FormulaDTO result, bool withDetails)
 {
     result.Name     = item.Name;
     result.ID       = item.ID;
     result.EntityID = item.TableDrivedEntityID ?? 0;
     if (item.LinearFormulaID != null)
     {
         result.FormulaType     = FormulaType.Linear;
         result.LinearFormulaID = item.LinearFormulaID.Value;
     }
     else if (item.CodeFunction_TableDrivedEntityID != null)
     {
         result.FormulaType          = FormulaType.CodeFunctionEntity;
         result.CodeFunctionEntityID = item.CodeFunction_TableDrivedEntityID.Value;
     }
     else if (item.DatabaseFunction_TableDrivedEntityID != null)
     {
         result.FormulaType = FormulaType.DatabaseFunctionEntity;
         result.DatabaseFunctionEntityID = item.DatabaseFunction_TableDrivedEntityID.Value;
     }
     else if (item.CodeFunctionID != null)
     {
         result.FormulaType    = FormulaType.CodeFunction;
         result.CodeFunctionID = item.CodeFunctionID.Value;
     }
     if (item.LinearFormula != null)
     {
         result.Tooltip = item.LinearFormula.FormulaText;
     }
     result.Title = item.Title;
     //result.ValueCustomType = (ValueCustomType)item.ValueCustomType;
     result.ResultDotNetType = GetFormulaDotNetType(item.ResultType);
     result.ResultType       = item.ResultType;
     //////BizFormulaUsage
     //////result.FormulaUsed = item.FormulaUsage.Any();
     if (withDetails)
     {
         foreach (var dbFormulaItem in item.FormulaItems1)
         {
             result.FormulaItems.Add(ToFormualaItemDTO(item.TableDrivedEntityID ?? 0, dbFormulaItem));
         }
     }
 }
コード例 #3
0
        //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);
            }
        }