コード例 #1
0
        public string GetDataFactorAndCriteriaJson(int branchId, int factorId)
        {
            var criterias = from criteria in db.Criterias
                            where (criteria.FactorId.Equals(factorId) && criteria.BranchId.Equals(branchId))
                            select criteria;
            var allcriteria = db.Criterias.Where(m => m.BranchId == branchId).ToList();

            // tính toán đưa vào dữ liệu

            CompetitivenessJsons jsonObject = new CompetitivenessJsons();
            var MeanWeightCriteria          = 0.00;

            foreach (var cr in criterias)
            {
                var JsonImportantWeight = new CompetitivenessJson
                {
                    Axis  = cr.CriteriaName,
                    Value = (Double)cr.Weight
                };

                jsonObject.ImportantWeight.Add(JsonImportantWeight);
            }
            foreach (var criteria in allcriteria)
            {
                MeanWeightCriteria += (Double)criteria.Weight;
            }

            var countFactor = allcriteria.Count();

            MeanWeightCriteria = MeanWeightCriteria / countFactor;
            MeanWeightCriteria = Math.Round(MeanWeightCriteria, 4, MidpointRounding.AwayFromZero);
            foreach (var cr in criterias)
            {
                var JsonImportantWeight = new CompetitivenessJson
                {
                    Axis  = cr.CriteriaName,
                    Value = MeanWeightCriteria
                };
                jsonObject.MeanWeight.Add(JsonImportantWeight);
            }
            string json = new JavaScriptSerializer().Serialize(jsonObject);

            JObject jo = new JObject();

            // Parse json *OBJECT*
            jo = JObject.Parse(json);
            JToken     tokenImportantWeight  = jo["ImportantWeight"];
            JToken     tokenMeanWeight       = jo["MeanWeight"];
            var        ImportantWeightString = tokenImportantWeight.ToString();
            var        MeanWeightString      = tokenMeanWeight.ToString();
            var        result     = ("[" + ImportantWeightString + "," + MeanWeightString + "]").Replace("Axis", "axis").Replace("Value", "value").Replace("\n", "").Replace("\r", "").Replace('\"', '"');
            ChartModel modelChart = new ChartModel();

            modelChart.modelChart = result;
            return(result);
        }
コード例 #2
0
        public string GetDataOfCriteriaCompareJson(int companyId, int factorId)
        {
            CompetitivenessJsons jsonObject = new CompetitivenessJsons();
            var company         = db.Companies.Where(x => x.CompanyId == companyId).SingleOrDefault();
            var criteriaNormals = db.Criterias.Where(x => x.FactorId == factorId && x.BranchId == company.BranchId);

            foreach (var criteriaNomal in criteriaNormals)
            {
                var JsonScoreNormal = new CompetitivenessJson
                {
                    Axis  = criteriaNomal.CriteriaName,
                    Value = (Double)criteriaNomal.Score
                };
                jsonObject.MeanWeight.Add(JsonScoreNormal);
            }

            var criteriaCompanys = db.CriteriasOfCompany.Where(x => x.CompanyId == companyId && x.FactorId == factorId);

            foreach (var criteriaCompany in criteriaCompanys)
            {
                var JsonScoreCompany = new CompetitivenessJson
                {
                    Axis  = criteriaCompany.CriteriaName,
                    Value = (Double)criteriaCompany.Score
                };
                jsonObject.ImportantWeight.Add(JsonScoreCompany);
            }

            string json = new JavaScriptSerializer().Serialize(jsonObject);

            JObject jo = new JObject();

            // Parse json *OBJECT*
            jo = JObject.Parse(json);
            JToken     tokenImportantWeight  = jo["ImportantWeight"];
            JToken     tokenMeanWeight       = jo["MeanWeight"];
            var        ImportantWeightString = tokenImportantWeight.ToString();
            var        MeanWeightString      = tokenMeanWeight.ToString();
            var        result     = ("[" + ImportantWeightString + "," + MeanWeightString + "]").Replace("Axis", "axis").Replace("Value", "value").Replace("\n", "").Replace("\r", "").Replace('\"', '"');
            ChartModel modelChart = new ChartModel();

            modelChart.modelChart = result;
            return(result);
        }
コード例 #3
0
        public string GetDataFactorJson(int id)
        {
            var model   = new AllModel();
            var branchs = (from branch in db.Branchs
                           where 1 == 1
                           select branch);

            foreach (var branch in branchs)
            {
                model.branch.Add(branch);
            }

            var factors = from factor in db.Factors
                          where factor.BranchId.Equals(id)
                          select factor;

            foreach (var fa in factors)
            {
                model.factor.Add(fa);
            }

            var criterias = from criteria in db.Criterias
                            where criteria.BranchId.Equals(id)
                            select criteria;

            foreach (var criteria in criterias)
            {
                model.criteria.Add(criteria);
            }
            var attributes = from attribute in db.Attributes
                             where attribute.BranchId.Equals(id)
                             select attribute;

            foreach (var attribute in attributes)
            {
                model.attribute.Add(attribute);
            }

            CompetitivenessJsons jsonObject = new CompetitivenessJsons();

            foreach (var fa in factors)
            {
                var JsonImportantWeight = new CompetitivenessJson
                {
                    Axis  = fa.FactorName,
                    Value = (Double)fa.Weight
                };
                jsonObject.ImportantWeight.Add(JsonImportantWeight);
            }

            var MeanWeightFactor = 0.00;
            var countFactor      = factors.Count();

            foreach (var fa in factors)
            {
                MeanWeightFactor += (Double)fa.Weight;
            }
            MeanWeightFactor = MeanWeightFactor / countFactor;
            MeanWeightFactor = Math.Round(MeanWeightFactor, 4, MidpointRounding.AwayFromZero);
            foreach (var fa in factors)
            {
                var JsonImportantWeight = new CompetitivenessJson
                {
                    Axis  = fa.FactorName,
                    Value = MeanWeightFactor
                };
                jsonObject.MeanWeight.Add(JsonImportantWeight);
            }
            string json = new JavaScriptSerializer().Serialize(jsonObject);

            JObject jo = new JObject();

            // Parse json *OBJECT*
            jo = JObject.Parse(json);
            JToken     tokenImportantWeight  = jo["ImportantWeight"];
            JToken     tokenMeanWeight       = jo["MeanWeight"];
            var        ImportantWeightString = tokenImportantWeight.ToString();
            var        MeanWeightString      = tokenMeanWeight.ToString();
            var        result     = ("[" + ImportantWeightString + "," + MeanWeightString + "]").Replace("Axis", "axis").Replace("Value", "value").Replace("\n", "").Replace("\r", "").Replace('\"', '"');
            ChartModel modelChart = new ChartModel();

            modelChart.modelChart = result;
            return(result);
        }