protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                rptr.DataSource = RegistrationSettings.GetAll();
                rptr.DataBind();

                ((BaseSRPPage)Page).TranslateStrings(rptr);
            }
        }
Esempio n. 2
0
        public static List <IRegistrationSetting> GetDoubleSettings(IRegistrationSetting setting)
        {
            var conflictedSettings = new List <IRegistrationSetting>();

            #region Конфликт по условиям

            var allSettings = RegistrationSettings.GetAll(s => !Equals(s, setting) && setting.SettingType == s.SettingType &&
                                                          s.Status.Value == CoreEntities.DatabookEntry.Status.Active).ToList();

            foreach (var documentKind in setting.DocumentKinds)
            {
                conflictedSettings.AddRange(allSettings.Where(s => s.DocumentKinds.Any(o => o.DocumentKind == documentKind.DocumentKind)).ToList());
            }

            allSettings = conflictedSettings.ToList();
            conflictedSettings.Clear();

            if (setting.BusinessUnits.Any())
            {
                foreach (var unit in setting.BusinessUnits)
                {
                    conflictedSettings.AddRange(allSettings.Where(s => s.BusinessUnits.Any(o => o.BusinessUnit == unit.BusinessUnit)).ToList());
                }
            }
            else
            {
                conflictedSettings.AddRange(allSettings.Where(s => !s.BusinessUnits.Any()).ToList());
            }

            allSettings = conflictedSettings.ToList();
            conflictedSettings.Clear();

            if (setting.Departments.Any())
            {
                foreach (var department in setting.Departments)
                {
                    conflictedSettings.AddRange(allSettings.Where(s => s.Departments.Any(o => o.Department == department.Department)).ToList());
                }
            }
            else
            {
                conflictedSettings.AddRange(allSettings.Where(s => !s.Departments.Any()).ToList());
            }

            #endregion

            return(conflictedSettings.Distinct().ToList());
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var sessionProgramId = Session["ProgramID"];
                int programId;
                if (sessionProgramId != null)
                {
                    try
                    {
                        programId = sessionProgramId.ToString().SafeToInt();
                    }
                    catch (Exception)
                    {
                        programId = Programs.GetDefaultProgramID();
                    }
                }
                else
                {
                    programId = Programs.GetDefaultProgramID();
                }
                var currentProgram = Programs.FetchObject(programId);

                DateTime startDate = currentProgram.StartDate < currentProgram.LoggingStart
                    ? currentProgram.StartDate
                    : currentProgram.LoggingStart;

                DateTime endDate = currentProgram.EndDate > currentProgram.LoggingEnd
                    ? currentProgram.EndDate
                    : currentProgram.LoggingEnd;

                if (DateTime.Now < startDate)
                {
                    Response.Redirect("~");
                }
                else if (DateTime.Now > endDate)
                {
                    Response.Redirect("~");
                }
                var dataSource = RegistrationSettings.GetAll();
                rptr.DataSource = dataSource;
                rptr.DataBind();

                ((BaseSRPPage)Page).TranslateStrings(rptr);
            }
        }
Esempio n. 4
0
 public static IQueryable <IRegistrationSetting> GetRegistrationSettingsByDocumentKind(IDocumentKind documentKind)
 {
     return(RegistrationSettings.GetAll(s => s.Status == Docflow.RegistrationSetting.Status.Active)
            .Where(s => s.DocumentKinds.Any(k => k.DocumentKind.Id == documentKind.Id)));
 }
Esempio n. 5
0
        public override void BeforeExecute(Sungero.Reporting.Server.BeforeExecuteEventArgs e)
        {
            RegistrationSettingReport.ReportDate = Calendar.UserToday;

            // Заполнить значения по умолчанию, если отчет вызван в невизуальном режиме.
            if (RegistrationSettingReport.FilterDepartmentsForBusinessUnits == null)
            {
                RegistrationSettingReport.FilterDepartmentsForBusinessUnits = true;
            }

            var filterDepartment = RegistrationSettingReport.FilterDepartmentsForBusinessUnits == true;

            #region Описание параметров

            if (RegistrationSettingReport.BusinessUnit != null)
            {
                RegistrationSettingReport.ParamsDescriprion += string.Format("{0}: {1} \n", Reports.Resources.RegistrationSettingReport.BusinessUnit, RegistrationSettingReport.BusinessUnit.Name);
            }

            if (!string.IsNullOrWhiteSpace(RegistrationSettingReport.Direction))
            {
                RegistrationSettingReport.ParamsDescriprion += string.Format("{0}: {1} \n", Reports.Resources.RegistrationSettingReport.DocumentFlow, RegistrationSettingReport.DirectionLabel);
            }

            RegistrationSettingReport.ParamsDescriprion += string.Format("{0}: {1} \n", Reports.Resources.RegistrationSettingReport.FilterDepartmentsForBusinessUnits,
                                                                         RegistrationSettingReport.FilterDepartmentsForBusinessUnits == true ? Reports.Resources.RegistrationSettingReport.Yes : Reports.Resources.RegistrationSettingReport.No);

            #endregion

            var sourceDataTableName = Constants.RegistrationSettingReport.SourceTableName;
            RegistrationSettingReport.SourceDataTableName = sourceDataTableName;
            var reportSessionId = System.Guid.NewGuid().ToString();
            RegistrationSettingReport.ReportSessionId = reportSessionId;

            var units = RegistrationSettingReport.BusinessUnit != null ?
                        new List <Company.IBusinessUnit>()
            {
                RegistrationSettingReport.BusinessUnit
            } :
            Company.BusinessUnits.GetAll().Where(u => u.Status == CoreEntities.DatabookEntry.Status.Active).ToList();

            var flows = new List <Enumeration>()
            {
                DocumentFlow.Incoming, DocumentFlow.Outgoing, DocumentFlow.Inner, DocumentFlow.Contracts
            };
            if (!string.IsNullOrWhiteSpace(RegistrationSettingReport.Direction))
            {
                flows = flows.Where(i => i.Value == RegistrationSettingReport.Direction).ToList();
            }

            var kinds = DocumentKinds.GetAll().Where(k => k.Status == CoreEntities.DatabookEntry.Status.Active &&
                                                     !Equals(k.NumberingType, DocumentKind.NumberingType.NotNumerable)).ToList();
            var settings    = RegistrationSettings.GetAll().Where(s => s.Status == CoreEntities.DatabookEntry.Status.Active && s.DocumentRegister.Status == CoreEntities.DatabookEntry.Status.Active).ToList();
            var departments = Company.Departments.GetAll().Where(d => d.Status == CoreEntities.DatabookEntry.Status.Active).OrderBy(d => d.Name).ToList();

            var separator             = ";" + System.Environment.NewLine;
            var allDepartmentString   = Reports.Resources.RegistrationSettingReport.AllDepartmentString;
            var otherDepartmentString = Reports.Resources.RegistrationSettingReport.OtherDepartmentString;
            // Строчки также используются в условной разметке для подсветки красным\курсивом.
            var settingNotFound  = Reports.Resources.RegistrationSettingReport.SettingNotFound;
            var defaultSetting   = Reports.Resources.RegistrationSettingReport.DefaultSetting;
            var registerNotFound = Reports.Resources.RegistrationSettingReport.RegisterNotFound;

            var tableData = new List <Structures.RegistrationSettingReport.TableLine>();

            foreach (var unit in units)
            {
                foreach (var flow in flows)
                {
                    foreach (var kind in kinds.Where(k => Equals(k.DocumentFlow, flow)))
                    {
                        var error       = Equals(kind.NumberingType, DocumentKind.NumberingType.Numerable) ? settingNotFound : defaultSetting;
                        var subSettings = settings.Where(s => Equals(s.DocumentFlow, flow) &&
                                                         (!s.BusinessUnits.Any() || s.BusinessUnits.Any(u => Equals(u.BusinessUnit, unit))) &&
                                                         s.DocumentKinds.Any(k => Equals(k.DocumentKind, kind)))
                                          .ToList();

                        foreach (var setting in subSettings)
                        {
                            var subDepartments = setting.Departments.Where(d => !filterDepartment || Equals(d.Department.BusinessUnit, unit)).ToList();
                            if (setting.Departments.Any() && !subDepartments.Any())
                            {
                                continue;
                            }

                            var department = !setting.Departments.Any() ? allDepartmentString : string.Join(separator, subDepartments.Select(d => d.Department.Name));
                            var example    = Functions.DocumentRegister.GetValueExample(setting.DocumentRegister);

                            var line = Structures.RegistrationSettingReport.TableLine.Create();
                            line.BusinessUnit           = unit.Name;
                            line.DocumentFlow           = GetDocumentFlowName(flow);
                            line.DocumentFlowIndex      = flows.IndexOf(flow);
                            line.DocumentKind           = kind.Name;
                            line.RegistrationSetting    = setting.Name;
                            line.RegistrationSettingUri = Hyperlinks.Get(setting);
                            line.Priority            = setting.Priority ?? 0;
                            line.Departments         = department;
                            line.SettingType         = GetSettingType(kind, setting);
                            line.DocumentRegister    = setting.DocumentRegister.Name;
                            line.DocumentRegisterUri = Hyperlinks.Get(setting.DocumentRegister);
                            line.NumberExample       = example;
                            line.ReportSessionId     = reportSessionId;

                            tableData.Add(line);
                        }

                        // Если настроек для вида не найдено.
                        if (!subSettings.Any() && kind.NumberingType == DocumentKind.NumberingType.Numerable)
                        {
                            var line = Structures.RegistrationSettingReport.TableLine.Create();
                            line.BusinessUnit        = unit.Name;
                            line.DocumentFlow        = GetDocumentFlowName(flow);
                            line.DocumentFlowIndex   = flows.IndexOf(flow);
                            line.DocumentKind        = kind.Name;
                            line.RegistrationSetting = error;
                            line.Priority            = -1;
                            line.Departments         = allDepartmentString;
                            line.SettingType         = GetSettingType(kind, null);
                            line.ReportSessionId     = reportSessionId;

                            tableData.Add(line);
                            continue;
                        }

                        // Если есть хоть одна настройка для всех подразделений - идём дальше.
                        if (subSettings.Any(s => !s.Departments.Any()))
                        {
                            continue;
                        }
                        // Если нет подразделений без настроек - идем дальше
                        var allDeparmentInUnit = departments.Where(d => Equals(d.BusinessUnit, unit)).ToList();
                        var settingDepartments = subSettings.SelectMany(s => s.Departments).Select(s => s.Department).ToList();
                        if (!allDeparmentInUnit.Except(settingDepartments).Any())
                        {
                            continue;
                        }

                        var allDepartments = filterDepartment ?
                                             departments.Where(d => Equals(d.BusinessUnit, unit)).ToList() :
                                             departments;
                        var registers       = new List <IDocumentRegister>();
                        var firstDepartment = allDepartments.Except(settingDepartments).FirstOrDefault();
                        if (firstDepartment != null)
                        {
                            registers.AddRange(Functions.DocumentRegister.GetDocumentRegistersByParams(kind, unit, firstDepartment, SettingType.Registration, false));
                        }
                        registers = registers.Distinct().ToList();
                        var regDepartment = allDepartments.Any(d => settingDepartments.Contains(d)) ? otherDepartmentString : allDepartmentString;

                        if (!registers.Any())
                        {
                            var line = Structures.RegistrationSettingReport.TableLine.Create();
                            line.BusinessUnit        = unit.Name;
                            line.DocumentFlow        = GetDocumentFlowName(flow);
                            line.DocumentFlowIndex   = flows.IndexOf(flow);
                            line.DocumentKind        = kind.Name;
                            line.RegistrationSetting = registerNotFound;
                            line.Priority            = -1;
                            line.Departments         = regDepartment;
                            line.SettingType         = GetSettingType(kind, null);
                            line.ReportSessionId     = reportSessionId;

                            tableData.Add(line);
                        }

                        foreach (var register in registers)
                        {
                            var example = Functions.DocumentRegister.GetValueExample(register);

                            var line = Structures.RegistrationSettingReport.TableLine.Create();
                            line.BusinessUnit        = unit.Name;
                            line.DocumentFlow        = GetDocumentFlowName(flow);
                            line.DocumentFlowIndex   = flows.IndexOf(flow);
                            line.DocumentKind        = kind.Name;
                            line.RegistrationSetting = error;
                            line.Priority            = 0;
                            line.Departments         = regDepartment;
                            line.DocumentRegister    = register.Name;
                            line.DocumentRegisterUri = Hyperlinks.Get(register);
                            line.SettingType         = GetSettingType(kind, null);
                            line.NumberExample       = example;
                            line.ReportSessionId     = reportSessionId;

                            tableData.Add(line);
                        }
                    }
                }
            }

            // Полная сортировка данных.
            tableData = tableData
                        .OrderBy(t => t.BusinessUnit)
                        .ThenBy(t => t.DocumentFlowIndex)
                        .ThenBy(t => t.DocumentKind)
                        .ThenByDescending(t => t.Priority)
                        .ThenBy(t => t.Departments)
                        .ToList();

            for (var i = 0; i < tableData.Count; i++)
            {
                tableData[i].Id = i;
            }

            Functions.Module.WriteStructuresToTable(RegistrationSettingReport.SourceDataTableName, tableData);
        }