示例#1
0
        // Получение данных по экспертизе поспелова для ексель
        public view_completed_expertise_pospelov GetListExpertiseReportPospelov(int id_expertise)
        {
            try
            {
                view_completed_expertise_pospelov result  = new view_completed_expertise_pospelov();
                expertises             _expertises        = db_Expertises.expertises.Where(o => o.id_expertise == id_expertise).FirstOrDefault();
                List <marks_factors>   ls_marks_factors   = db_Expertises.marks_factors.Where(o => o.id_expertise == id_expertise).ToList();
                List <marks_ribs>      ls_marks_ribs      = db_Expertises.marks_ribs.Where(o => o.id_expertise == id_expertise).ToList();
                List <results_factors> ls_results_factors = db_Expertises.results_factors.Where(o => o.id_expertise == id_expertise).ToList();
                List <results_ribs>    ls_results_ribs    = db_Expertises.results_ribs.Where(o => o.id_expertise == id_expertise).ToList();

                expertises ex_new = new expertises();
                ex_new.id_expertise = _expertises.id_expertise;
                ex_new.name         = _expertises.name;
                ex_new.id_status    = _expertises.id_status;
                ex_new.type         = _expertises.type;

                List <marks_factors> temp_marks_fact = new List <marks_factors>();
                foreach (var pr in ls_marks_factors)
                {
                    marks_factors t = new marks_factors();
                    t.id_mark             = pr.id_mark;
                    t.id_factor           = pr.id_factor;
                    t.id_expertise        = pr.id_expertise;
                    t.id_expert           = pr.id_expert;
                    t.value               = pr.value;
                    t.factors             = new factors();
                    t.factors.name        = pr.factors.name;
                    t.factors.id_factor   = pr.factors.id_factor;
                    t.factors.priority    = pr.factors.priority;
                    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;
                    temp_marks_fact.Add(t);
                }
                List <marks_ribs> temp_marks_ribs = new List <marks_ribs>();
                foreach (var pr in ls_marks_ribs)
                {
                    marks_ribs t = new marks_ribs();
                    t.id_rib                  = pr.id_rib;
                    t.id_mark_rib             = pr.id_mark_rib;
                    t.id_expertise            = pr.id_expertise;
                    t.id_expert               = pr.id_expert;
                    t.value                   = pr.value;
                    t.ribs                    = new ribs();
                    t.ribs.id_rib             = pr.ribs.id_rib;
                    t.ribs.id_factor_from     = pr.ribs.id_factor_from;
                    t.ribs.factors            = new factors();
                    t.ribs.factors.id_factor  = pr.ribs.factors.id_factor;
                    t.ribs.factors.priority   = pr.ribs.factors.priority;
                    t.ribs.id_factor_in       = pr.ribs.id_factor_in;
                    t.ribs.factors1           = new factors();
                    t.ribs.factors1.id_factor = pr.ribs.factors1.id_factor;
                    t.ribs.factors1.priority  = pr.ribs.factors1.priority;
                    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;
                    temp_marks_ribs.Add(t);
                }
                List <results_ribs> temp_results_ribs = new List <results_ribs>();
                foreach (var pr in ls_results_ribs)
                {
                    results_ribs t = new results_ribs();
                    t.id_rib             = pr.id_rib;
                    t.id_result_mark_rib = pr.id_result_mark_rib;
                    t.id_expertise       = pr.id_expertise;
                    t.value                   = pr.value;
                    t.ribs                    = new ribs();
                    t.ribs.id_rib             = pr.ribs.id_rib;
                    t.ribs.id_factor_from     = pr.ribs.id_factor_from;
                    t.ribs.factors            = new factors();
                    t.ribs.factors.id_factor  = pr.ribs.factors.id_factor;
                    t.ribs.factors.priority   = pr.ribs.factors.priority;
                    t.ribs.id_factor_in       = pr.ribs.id_factor_in;
                    t.ribs.factors1           = new factors();
                    t.ribs.factors1.id_factor = pr.ribs.factors1.id_factor;
                    t.ribs.factors1.priority  = pr.ribs.factors1.priority;
                    temp_results_ribs.Add(t);
                }
                List <results_factors> temp_results_fact = new List <results_factors>();
                foreach (var pr in ls_results_factors)
                {
                    results_factors t = new results_factors();
                    t.id_factor             = pr.id_factor;
                    t.id_expertise          = pr.id_expertise;
                    t.id_mark_result_factor = pr.id_mark_result_factor;
                    t.value             = pr.value;
                    t.factors           = new factors();
                    t.factors.name      = pr.factors.name;
                    t.factors.priority  = pr.factors.priority;
                    t.factors.id_factor = pr.factors.id_factor;
                    temp_results_fact.Add(t);
                }
                result.id_expertise         = id_expertise;
                result.expertises           = ex_new;
                result.list_marks_factors   = temp_marks_fact;
                result.list_marks_ribs      = temp_marks_ribs;
                result.list_results_factors = temp_results_fact;
                result.list_results_ribs    = temp_results_ribs;

                return(result);
            }
            catch (Exception ex)
            {
                view_completed_expertise_pospelov tmpC = new view_completed_expertise_pospelov();
                tmpC.id_expertise = -1;
                return(tmpC);
            }
        }
示例#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);
            }
        }