Exemple #1
0
        //получения данных по экпертизе Паттерн для вывода в ексель
        public view_completed_expertise GetListExpertiseReport(int id_expertise)
        {
            try
            {
                view_completed_expertise result     = new view_completed_expertise();
                List <marks>             ls_marks   = db_Expertises.marks.Where(p => p.id_expertise == id_expertise).ToList();
                List <marks>             temp_marks = new List <marks>();
                foreach (var pr in ls_marks)
                {
                    marks t = new marks();
                    t.id_project          = pr.id_project;
                    t.id_expertise        = pr.id_expertise;
                    t.id_expert           = pr.id_expert;
                    t.id_criterion        = pr.id_criterion;
                    t.projects            = new projects();
                    t.projects.name       = pr.projects.name;
                    t.experts             = new experts();
                    t.experts.first_name  = pr.experts.first_name;
                    t.experts.second_name = pr.experts.second_name;
                    t.experts.patronymic  = pr.experts.patronymic;

                    t.criterions      = new criterions();
                    t.criterions.name = pr.criterions.name;
                    t.value           = pr.value;
                    temp_marks.Add(t);
                }
                List <results_experts> list_res_ex         = db_Expertises.results_experts.Where(p => p.id_expertise == id_expertise).ToList();
                List <results_experts> temp_result_experts = new List <results_experts>();
                foreach (var pr in list_res_ex)
                {
                    results_experts t = new results_experts();
                    t.id_project         = pr.id_project;
                    t.id_expertise       = pr.id_expertise;
                    t.id_expert          = pr.id_expert;
                    t.projects           = new projects();
                    t.projects.name      = pr.projects.name;
                    t.experts            = new experts();
                    t.experts.first_name = pr.experts.first_name;
                    t.value = pr.value;
                    temp_result_experts.Add(t);
                }
                List <results_expertises_criterions> ls_res_expertise_cr   = db_Expertises.results_expertises_criterions.Where(p => p.id_expertise == id_expertise).ToList();
                List <results_expertises_criterions> temp_res_expertise_cr = new List <results_expertises_criterions>();
                foreach (var pr in ls_res_expertise_cr)
                {
                    results_expertises_criterions t = new results_expertises_criterions();
                    t.id_project      = pr.id_project;
                    t.id_expertise    = pr.id_expertise;
                    t.id_criterion    = pr.id_criterion;
                    t.projects        = new projects();
                    t.projects.name   = pr.projects.name;
                    t.criterions      = new criterions();
                    t.criterions.name = pr.criterions.name;
                    t.value           = pr.value;
                    temp_res_expertise_cr.Add(t);
                }
                List <results_expertise> list_res_expertise = db_Expertises.results_expertise.Where(p => p.id_expertise == id_expertise).ToList();
                List <results_expertise> temp_res_expertise = new List <results_expertise>();
                foreach (var pr in list_res_expertise)
                {
                    results_expertise t = new results_expertise();
                    t.id_project    = pr.id_project;
                    t.id_expertise  = pr.id_expertise;
                    t.projects      = new projects();
                    t.projects.name = pr.projects.name;
                    t.value         = pr.value;
                    temp_res_expertise.Add(t);
                }
                result.id_expertise        = id_expertise;
                result.list_marks          = temp_marks;
                result.list_res_ex         = temp_result_experts;
                result.list_res_exppertise = temp_res_expertise;
                result.list_res_ex_cr      = temp_res_expertise_cr;

                return(result);
            }
            catch (Exception Ex)
            {
                // тут логируется ошибка
                view_completed_expertise tmpC = new view_completed_expertise();
                tmpC.id_expertise = -1;
                return(tmpC);
            }
        }
Exemple #2
0
        //Метод добавления статуса экспертизы pattern
        public int AddStatusExpertise(int id_expertise)
        {
            try
            {
                List <experts_expertises> experts_Expertises = db_Expertises.experts_expertises.Where(o => o.id_expertise == id_expertise).ToList();
                if (experts_Expertises != null)
                {
                    bool triger = true;
                    foreach (experts_expertises ex_status in experts_Expertises)
                    {
                        if (ex_status.id_status == 1)
                        {
                            triger = false;
                        }
                    }
                    if (triger == true)
                    {
                        expertises _expertises = db_Expertises.expertises.Where(o => o.id_expertise == id_expertise).FirstOrDefault();
                        _expertises.id_status = 2;
                        db_Expertises.SaveChanges();
                        if (_expertises.type == 1)
                        {
                            List <expertises_criterions> ls_ex_cr = db_Expertises.expertises_criterions.Where(o => o.id_expertise == id_expertise).ToList();
                            List <results_experts>       ls_rs_ex = db_Expertises.results_experts.Where(o => o.id_expertise == id_expertise).ToList();
                            List <marks> ls_marks = db_Expertises.marks.Where(o => o.id_expertise == id_expertise).ToList();

                            var criterions    = db_Expertises.marks.Where(o => o.id_expertise == id_expertise).GroupBy(o => o.id_criterion).ToList();
                            var projects      = db_Expertises.marks.Where(o => o.id_expertise == id_expertise).GroupBy(o => o.id_project).ToList();
                            int count_experts = db_Expertises.experts_expertises.Where(o => o.id_expertise == id_expertise).ToList().Count();
                            for (int i = 0; i < criterions.Count(); i++)
                            {
                                int    id_criterion = criterions[i].Key;
                                double value        = 0;
                                for (int j = 0; j < projects.Count(); j++)
                                {
                                    value = 0;
                                    int id_project = projects[j].Key;
                                    foreach (marks mark in ls_marks)
                                    {
                                        if (mark.id_project == id_project && mark.id_criterion == id_criterion)
                                        {
                                            value += mark.value;
                                        }
                                    }
                                    value = value / count_experts;
                                    results_expertises_criterions res = new results_expertises_criterions();
                                    res.id_criterion = id_criterion;
                                    res.id_expertise = id_expertise;
                                    res.id_project   = id_project;
                                    res.value        = value;
                                    db_Expertises.results_expertises_criterions.Add(res);
                                    db_Expertises.SaveChanges();
                                }
                            }
                            List <results_expertises_criterions> ls_res_ex_cr = db_Expertises.results_expertises_criterions.Where(o => o.id_expertise == id_expertise).ToList();
                            for (int i = 0; i < projects.Count(); i++)
                            {
                                int    id_project = projects[i].Key;
                                double value      = 0;
                                for (int j = 0; j < criterions.Count(); j++)
                                {
                                    int    id_criterion     = criterions[j].Key;
                                    var    value_criterion  = ls_res_ex_cr.Where(o => o.id_criterion == id_criterion && o.id_project == id_project).FirstOrDefault().value;
                                    double weight_criterion = ls_ex_cr.Where(o => o.id_criterion == id_criterion).FirstOrDefault().weight;
                                    value += value_criterion * weight_criterion;
                                }
                                results_expertise res = new results_expertise();
                                res.id_expertise = id_expertise;
                                res.id_project   = id_project;
                                res.value        = value;
                                db_Expertises.results_expertise.Add(res);
                                db_Expertises.SaveChanges();
                            }
                            return(_expertises.id_expertise);
                        }
                        else
                        {
                            List <marks_factors> ls_fact = db_Expertises.marks_factors.Where(o => o.id_expertise == id_expertise).ToList();
                            if (ls_fact != null)
                            {
                                var ls_fact_group = ls_fact.GroupBy(o => o.id_factor).ToList();

                                for (int i = 0; i < ls_fact_group.Count(); i++)
                                {
                                    int    number_fact = 0;
                                    double value       = 0;
                                    foreach (var fact in ls_fact)
                                    {
                                        if (fact.id_factor == ls_fact_group[i].Key)
                                        {
                                            value += fact.value;
                                            number_fact++;
                                        }
                                    }
                                    value = value / number_fact;
                                    results_factors res = new results_factors();
                                    res.id_expertise = id_expertise;
                                    res.id_factor    = ls_fact_group[i].Key;
                                    res.value        = value;
                                    db_Expertises.results_factors.Add(res);
                                    db_Expertises.SaveChanges();
                                }
                            }
                            List <marks_ribs> ls_ribs = db_Expertises.marks_ribs.Where(o => o.id_expertise == id_expertise).ToList();
                            if (ls_ribs != null)
                            {
                                var ls_fact_ribs = ls_ribs.GroupBy(o => o.id_rib).ToList();

                                for (int i = 0; i < ls_fact_ribs.Count(); i++)
                                {
                                    int    number_fact = 0;
                                    double value       = 0;
                                    foreach (var fact in ls_ribs)
                                    {
                                        if (fact.id_rib == ls_fact_ribs[i].Key)
                                        {
                                            value += fact.value;
                                            number_fact++;
                                        }
                                    }
                                    value = value / number_fact;
                                    results_ribs res = new results_ribs();
                                    res.id_expertise = id_expertise;
                                    res.id_rib       = ls_fact_ribs[i].Key;
                                    res.value        = value;
                                    db_Expertises.results_ribs.Add(res);
                                    db_Expertises.SaveChanges();
                                }
                            }
                            return(id_expertise);
                        }
                    }
                }
                return(-1);
            }
            catch (Exception ex)
            {
                return(-1);
            }
        }