示例#1
0
        /// <summary>
        /// 대시보드 테이블 업무 영역을 업데이트한다. (파일 템플릿 ID가 변경되면 이전에 사용 중이던 파일 템플릿은 삭제 처리 된다.)
        /// </summary>
        public bool UpdateFormTableSection(FormTableSection formSection, string updaterId)
        {
            formSection.ThrowIfNull(nameof(formSection));

            string procCommandName = "up_FormTableSection_Update";

            try
            {
                var command = Connection.GetStoredProcCommand(procCommandName);
                Connection.AddInParameter(command, "FormID", DbType.Guid, formSection.FormId);
                Connection.AddInParameter(command, "FormSectionID", DbType.Guid, formSection.FormSectionId);
                Connection.AddInParameter(command, "FileTemplateID", DbType.Guid, formSection.FileTemplateId);
                Connection.AddInParameter(command, "Name", DbType.String, formSection.FormSectionName);
                Connection.AddInParameter(command, "ScriptVariable", DbType.String, formSection.ScriptVariable);
                Connection.AddInParameter(command, "IsEnabled", DbType.Boolean, formSection.IsEnabled);
                Connection.AddInParameter(command, "UpdaterID", DbType.String, updaterId);
                Connection.AddInParameter(command, "UpdatedDate", DbType.DateTimeOffset, formSection.UpdatedDate);

                return((int)Connection.ExecuteNonQuery(command) > 0);
            }
            catch (Exception ex)
            {
                throw new DataException($"프로시져 실행 중 예기치 못한 에러가 발생했습니다.\r\n 프로시저: \"{procCommandName}\"", ex);
            }
        }
示例#2
0
        /// <summary>
        /// 대시보드 테이블 업무 영역을 추가한다.
        /// </summary>
        public bool AddFormTableSection(FormTableSection formSection, IEnumerable <string> fileSourceUploaders)
        {
            using (var repo = new FormTableRepository())
            {
                repo.BeginTransaction();

                try
                {
                    if (repo.InsertFormTableSection(formSection))
                    {
                        repo.InsertFormTableSectionGroupMembers(formSection.FormId, formSection.FormSectionId, fileSourceUploaders, formSection.CreatedDate);

                        if (formSection.FileTemplate != null)
                        {
                            repo.InsertDateFileTemplate(formSection.FileTemplate);
                        }
                        else
                        {
                            logger.Warn($"업무영역 정보로부터 파일 템플릿 정보를 찾을 수 없습니다. 업무영역: \"{formSection.FormSectionName}\""
                                        + $"\r\n\r\n"
                                        + $"{formSection}");
                        }

                        repo.CommitTransaction();

                        logger.Info($"새 업무영역을 추가하였습니다. 업무영역: \"{formSection.FormSectionName}\""
                                    + $"\r\n\r\n"
                                    + $"{formSection}");

                        return(true);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"업무영역 추가 중 알 수 없는 오류가 발생하였습니다. 업무영역: \"{formSection.FormName}/{formSection.FormSectionName}\""
                                 + $"\r\n\r\n"
                                 + $"{formSection}");

                    try
                    {
                        repo.RollBackTransaction();
                    }
                    catch (Exception rex)
                    {
                        logger.Fatal(ex, $"업무영역 추가 함수에서 롤백 실행중 치명적인 에러가 발생했습니다. 업무영역: \"{formSection.FormName}/{formSection.FormSectionName}\""
                                     + $"\r\n\r\n"
                                     + $"{formSection}");

                        ExceptionDispatchInfo.Capture(rex).Throw();
                        // not reached
                    }

                    ExceptionDispatchInfo.Capture(ex).Throw();
                    return(false); // not reached
                }

                return(false);
            }
        }
示例#3
0
        /// <summary>
        /// 대시보드 테이블 업무 영역을 반환한다.
        /// </summary>
        public FormTableSection SelectFormTableSection(Guid formId, Guid formSectionId)
        {
            string procCommandName = "up_FormTableSection_Select";

            try
            {
                var command = Connection.GetStoredProcCommand(procCommandName);
                Connection.AddInParameter(command, "FormID", DbType.Guid, formId);
                Connection.AddInParameter(command, "FormSectionID", DbType.Guid, formSectionId);

                using (DataSet ds = Connection.ExecuteDataSet(command))
                {
                    ValidateTableCount(ds, 4);

                    // 1. 업무 영역
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        var formSection = FormTableSection.ParseFrom(ds.Tables[0].Rows[0]);

                        // 2. 파일 템플릿 정보
                        if (ds.Tables[1].Rows.Count > 0)
                        {
                            formSection.FileTemplate = DataFileTemplate.ParseFrom(ds.Tables[1].Rows[0]);
                        }

                        // 3. 파일 소스 정보
                        if (ds.Tables[2].Rows.Count > 0)
                        {
                            formSection.FileSource = DataFileSource.ParseFrom(ds.Tables[2].Rows[0]);
                        }

                        // 4. 데이터 업로더 정보
                        foreach (DataRow dr in ds.Tables[3].Rows)
                        {
                            var uploader = DataFileSourceUploader.ParseFrom(dr);
                            formSection.FileSourceUploaders[uploader.UserId] = uploader;
                        }

                        return(formSection);
                    }

                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw new DataException($"프로시져 실행 중 예기치 못한 에러가 발생했습니다.\r\n 프로시저: \"{procCommandName}\"", ex);
            }
        }
示例#4
0
        /// <summary>
        /// 대시보드 테이블 업무 영역을 업데이트한다.
        /// </summary>
        public FormTableSection UpdateFormTableSection(FormTableSection formSection, IEnumerable <string> fileSourceUploaders)
        {
            formSection.ThrowIfNull(nameof(formSection));

            using (var repo = new FormTableRepository())
            {
                var old = repo.SelectFormTableSection(formSection.FormId, formSection.FormSectionId);
                if (old == null)
                {
                    throw new ObjectNotFoundException($"업데이트될 업무영역을 찾을 수 없습니다. 업무영역: \"{formSection.FormSectionName}\""
                                                      + $"\r\n"
                                                      + $"업무영역 ID: {formSection.FileSourceId}");
                }

                repo.BeginTransaction();

                try
                {
                    var diff = old.Diff(formSection);

                    if (repo.UpdateFormTableSection(formSection, CurrentUser.UserId))
                    {
                        repo.InsertFormTableSectionGroupMembers(formSection.FormId, formSection.FormSectionId, fileSourceUploaders, DateTimeOffset.Now);

                        if (old.FileTemplateId != formSection.FileTemplateId)
                        {
                            repo.InsertDateFileTemplate(formSection.FileTemplate);
                        }
                        else
                        {
                            repo.UpdateDateFileTemplate(formSection.FileTemplate);
                        }

                        repo.CommitTransaction();

                        logger.Info($"업무영역이 업데이트 되었습니다. 업무영역: \"{formSection.FormSectionName}\""
                                    + $"\r\n\r\n"
                                    + $"updated: {UpdatedField.Print(diff)}"
                                    + $"\r\n\r\n"
                                    + $"{formSection}");

                        return(formSection);
                    }
                }
                catch (Exception ex)
                {
                    logger.Error(ex, $"업무영역 업데이트 중 확인 중 알 수 없는 오류가 발생하였습니다. 업무영역: \"{formSection.FormName}/{formSection.FormSectionName}\""
                                 + $"\r\n\r\n"
                                 + $"{formSection}");

                    try
                    {
                        repo.RollBackTransaction();
                    }
                    catch (Exception rex)
                    {
                        logger.Fatal(ex, $"업무영역 업데이트 함수에서 롤백 실행중 치명적인 에러가 발생했습니다. 업무영역: \"{formSection.FormName}/{formSection.FormSectionName}\""
                                     + $"\r\n\r\n"
                                     + $"{formSection}");

                        ExceptionDispatchInfo.Capture(rex).Throw();
                        // not reached
                    }

                    ExceptionDispatchInfo.Capture(ex).Throw();
                    return(null); // not reached
                }

                return(null);
            }
        }
示例#5
0
        /// <summary>
        /// 페이징 처리된 대시보드 테이블 업무 영역을 반환한다.
        /// </summary>
        public PagedModel <FormTableSection> SelectFormTableSectionPagedList(PagingOption option)
        {
            string procCommandName = "up_FormTableSection_SelectPagedList";

            try
            {
                var command = Connection.GetStoredProcCommand(procCommandName);
                Connection.AddInParameter(command, "PageNumber", DbType.Int32, option.PageNumber);
                Connection.AddInParameter(command, "PageCount", DbType.Int32, option.PageCount);
                Connection.AddInParameter(command, "SortBy", DbType.String, option.SortBy);
                Connection.AddInParameter(command, "OrderBy", DbType.String, option.OrderBy.ToEnumMemberString());

                using (DataSet ds = Connection.ExecuteDataSet(command))
                {
                    ValidateTableCount(ds, 4);

                    var result = new PagedModel <FormTableSection>(option)
                    {
                        PagingOption = option
                    };
                    int totalCount = 0;

                    // 1. 업무 영역
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        var formSection = FormTableSection.ParseFrom(dr, out totalCount);
                        result.Items.Add(formSection);
                    }

                    // 2. 파일 템플릿 정보
                    foreach (DataRow dr in ds.Tables[1].Rows)
                    {
                        var fileTemplate = DataFileTemplate.ParseFrom(dr);
                        var formSections = result.Items.FindAll(o => o.FileTemplateId == fileTemplate.FileTemplateId);
                        if (formSections.Any())
                        {
                            formSections.ForEach(o =>
                            {
                                o.FileTemplate = fileTemplate;
                            });
                        }
                    }

                    // 3. 파일 소스 정보
                    foreach (DataRow dr in ds.Tables[2].Rows)
                    {
                        var fileSource   = DataFileSource.ParseFrom(dr);
                        var formSections = result.Items.FindAll(o => o.FormId == fileSource.FormId && o.FormSectionId == fileSource.FormSectionId);
                        if (formSections.Any())
                        {
                            formSections.ForEach(o =>
                            {
                                o.FileSource = fileSource;
                            });
                        }
                    }

                    // 4. 데이터 업로더 정보
                    foreach (DataRow dr in ds.Tables[3].Rows)
                    {
                        var uploader     = DataFileSourceUploader.ParseFrom(dr);
                        var formSections = result.Items.FindAll(o => o.FormId == uploader.FormId && o.FormSectionId == uploader.FormSectionId);
                        if (formSections.Any())
                        {
                            formSections.ForEach(o =>
                            {
                                o.FileSourceUploaders[uploader.UserId] = uploader;
                            });
                        }
                    }

                    result.TotalCount = totalCount;

                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw new DataException($"프로시져 실행 중 예기치 못한 에러가 발생했습니다.\r\n 프로시저: \"{procCommandName}\"", ex);
            }
        }
示例#6
0
        /// <summary>
        /// 대시보드 테이블 업무 영역 리스트를 반환한다.
        /// </summary>
        /// <param name="queryUserId">값이 있는 경우, 해당 유저가 접근 가능한 데이터만 반환</param>
        /// <param name="fileSourceDateRanges">값이 있는 경우, 해당 날짜의 데이터 파일 소스 정보를 반환</param>
        public IEnumerable <FormTableSection> SelectFormTableSectionList(Guid?formId, string queryUserId = null, List <DataDateRange> fileSourceDateRanges = null)
        {
            string procCommandName = "up_FormTableSection_SelectList";

            try
            {
                var command = Connection.GetStoredProcCommand(procCommandName);

                if (formId.HasValue)
                {
                    Connection.AddInParameter(command, "FormID", DbType.Guid, formId.Value);
                }

                Connection.AddInParameter(command, "QueryUserID", DbType.String, queryUserId);

                if (fileSourceDateRanges != null)
                {
                    // 특정한 날짜 범위 내의 데이터 소스 값만 반환하기 위해 날짜 범위를 DB에 전달한다.
                    using (var spParamDateRanges = new DataTable()) // type_DataSourceDateRanges
                    {
                        spParamDateRanges.Columns.Add("UploadInterval", typeof(string));
                        spParamDateRanges.Columns.Add("BeginDate", typeof(DateTimeOffset));
                        spParamDateRanges.Columns.Add("EndDate", typeof(DateTimeOffset));
                        spParamDateRanges.Columns.Add("IsCurrentData", typeof(bool));

                        foreach (var dateRange in fileSourceDateRanges)
                        {
                            spParamDateRanges.Rows.Add(new object[]
                            {
                                dateRange.UploadInterval,
                                dateRange.BeginDate,
                                dateRange.EndDate,
                                dateRange.IsCurrentData
                            });
                        }

                        var param = command.Parameters.AddWithValue("SourceDateRanges", spParamDateRanges);
                        param.SqlDbType = SqlDbType.Structured;
                    }
                }

                using (DataSet ds = Connection.ExecuteDataSet(command))
                {
                    ValidateTableCount(ds, 4);

                    var result = new List <FormTableSection>();

                    // 1. 업무 영역
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        var formSection = FormTableSection.ParseFrom(dr);
                        result.Add(formSection);
                    }

                    // 2. 파일 템플릿 정보
                    foreach (DataRow dr in ds.Tables[1].Rows)
                    {
                        var fileTemplate = DataFileTemplate.ParseFrom(dr);
                        var formSections = result.FindAll(o => o.FileTemplateId == fileTemplate.FileTemplateId);
                        if (formSections.Any())
                        {
                            formSections.ForEach(o =>
                            {
                                o.FileTemplate = fileTemplate;
                            });
                        }
                    }

                    // 3. 파일 소스 정보
                    foreach (DataRow dr in ds.Tables[2].Rows)
                    {
                        var  fileSource    = DataFileSource.ParseFrom(dr);
                        bool isCurrentData = dr.Get <bool>("IsCurrentData");

                        var formSections = result.FindAll(o => o.FormId == fileSource.FormId && o.FormSectionId == fileSource.FormSectionId);
                        if (formSections.Any())
                        {
                            formSections.ForEach(o =>
                            {
                                if (isCurrentData)
                                {
                                    o.FileSource = fileSource;
                                }
                                else
                                {
                                    o.PrevFileSource = fileSource;
                                }
                            });
                        }
                    }

                    // 4. 데이터 업로더 정보
                    foreach (DataRow dr in ds.Tables[3].Rows)
                    {
                        var uploader     = DataFileSourceUploader.ParseFrom(ds.Tables[3].Rows[0]);
                        var formSections = result.FindAll(o => o.FormId == uploader.FormId && o.FormSectionId == uploader.FormSectionId);
                        if (formSections.Any())
                        {
                            formSections.ForEach(o =>
                            {
                                o.FileSourceUploaders[uploader.UserId] = uploader;
                            });
                        }
                    }

                    return(result);
                }
            }
            catch (Exception ex)
            {
                throw new DataException($"프로시져 실행 중 예기치 못한 에러가 발생했습니다.\r\n 프로시저: \"{procCommandName}\"", ex);
            }
        }