Exemplo n.º 1
0
        public static void Dispose()
        {
            if (_application is null)
            {
                return;
            }

            ComObjectHelper.ReleaseComObjectSafe(_application.WorksheetFunction);
            _application.Quit();
            ComObjectHelper.ReleaseComObjectSafe(_application);
            _application = null;
        }
Exemplo n.º 2
0
        protected override async Task <bool> OnProcessingAsync(BaseEvent ev)
        {
            var @event = (ev as CountryCreatedEvent);
            var stream = Mapper.Map <EventStream>(@event);

            this._eventRepository.Add(stream);

            SAPbobsCOM.CountriesService countriesService = null;
            SAPbobsCOM.CountryParams    countryParams    = null;
            SAPbobsCOM.Country          country          = null;

            try
            {
                countriesService = SapCompany.DICompany.GetCompanyService().GetBusinessService(SAPbobsCOM.ServiceTypes.CountriesService) as SAPbobsCOM.CountriesService;
                country          = countriesService.GetDataInterface(SAPbobsCOM.CountriesServiceDataInterfaces.csCountry) as SAPbobsCOM.Country;

                country.Code          = @event.CountryCode;
                country.Name          = @event.CountryName;
                country.AddressFormat = 1;

                countryParams = countriesService.AddCountry(country);

                if (countryParams.Code != country.Code)
                {
                    return(await Task.FromResult(false));
                }
            }
            catch (Exception ex)
            {
                if (countriesService != null)
                {
                    ComObjectHelper.ReleaseComObject(countriesService);
                }
                if (country != null)
                {
                    ComObjectHelper.ReleaseComObject(country);
                }
                if (countryParams != null)
                {
                    ComObjectHelper.ReleaseComObject(countryParams);
                }

                throw ex;
            }
            finally
            {
                if (countriesService != null)
                {
                    ComObjectHelper.ReleaseComObject(countriesService);
                }
                if (country != null)
                {
                    ComObjectHelper.ReleaseComObject(country);
                }
                if (countryParams != null)
                {
                    ComObjectHelper.ReleaseComObject(countryParams);
                }
            }

            return(await Task.FromResult(true));
        }
        protected override async Task <bool> OnProcessingAsync(BaseEvent ev)
        {
            var @event = (ev as JournalVoucherCreatedEvent);
            var stream = Mapper.Map <EventStream>(@event);

            this._eventRepository.Add(stream);

            SAPbobsCOM.JournalVouchers voucher = null;

            try
            {
                if (@event.Entries.Count() > 0)
                {
                    voucher = SapCompany.DICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalVouchers) as SAPbobsCOM.JournalVouchers;

                    foreach (var entry in @event.Entries)
                    {
                        try
                        {
                            voucher.JournalEntries.ReferenceDate = entry.ReferenceDate;

                            #region for test 2017-07-07

                            //voucher.JournalEntries.Memo = entry.Memo;
                            // NOTE: 임시 테스트를 위해 적요에 해당 steamId를 삽입 후 추후 조회에서 처리
                            // TODO: 추후 유저필드 추가 후에 해당 필드로 변경필요 (추가해야할 UDF: StreamId, ApiUserId, ClientId)
                            // ApiUser 와 ClientId를 받을 필요가 있음. request 에서 부터 전달되어야 함.
                            voucher.JournalEntries.Memo = @event.EventStream.ToString();
                            //voucher.JournalEntries.UserFields.Fields.Item("U_StreamId").Value = @event.EventStream.ToString();
                            //voucher.JournalEntries.UserFields.Fields.Item("U_ApiUserName").Value = "";
                            //voucher.JournalEntries.UserFields.Fields.Item("U_ClientId").Value = "";

                            #endregion

                            voucher.JournalEntries.DueDate = entry.DueDate;

                            foreach (var entryLine in entry.Lines)
                            {
                                voucher.JournalEntries.Lines.AccountCode = entryLine.AccountCode;
                                voucher.JournalEntries.Lines.Debit       = Convert.ToDouble(entryLine.Debit);
                                voucher.JournalEntries.Lines.Credit      = Convert.ToDouble(entryLine.Credit);
                                voucher.JournalEntries.Lines.DueDate     = entryLine.DueDate;
                                voucher.JournalEntries.Lines.ShortName   = entryLine.ShortName;
                                voucher.JournalEntries.Lines.LineMemo    = entryLine.LineMemo;
                                voucher.JournalEntries.Lines.BaseSum     = Convert.ToDouble(entryLine.BaseSum);
                                // TODO: 유저필드 셋팅

                                voucher.JournalEntries.Lines.Add();
                            }
                        }
                        catch (Exception ex)
                        {
                            sapHowmuchLogger.Error($"One or more Journal Entry is not valid");
                            throw ex;
                        }

                        var entryResult = voucher.JournalEntries.Add();

                        if (entryResult != 0)
                        {
                            sapHowmuchLogger.Error("전표 추가 에러");                             // TODO: 예외 처리 조정
                            throw new Exception($"SBO Error Code: {SapCompany.DICompany.GetLastErrorCode()}, Error Description: {SapCompany.DICompany.GetLastErrorDescription()}");
                        }
                    }
                }

                int result = voucher.Add();

                if (result != 0)
                {
                    sapHowmuchLogger.Error("분개장 추가 에러");                     // TODO: 예외 처리 조정
                    throw new Exception($"SBO Error Code: {SapCompany.DICompany.GetLastErrorCode()}, Error Description: {SapCompany.DICompany.GetLastErrorDescription()}");
                }

                // NOTE: xml 파일로 저장하더라도, 실제적으로 해당 분개장 번호는 리턴되지 않음
                // streamId 를 특정 컬럼에 저장한다음
                // 추후 그 streamId로 조회해서 키값을 얻어와야 할 것으로 보임
                // 이 작업은 controller 단에서 처리하는 방향으로 결정

                //@event.VoucherListNumber = 0;
            }
            catch (Exception ex)
            {
                if (voucher != null)
                {
                    ComObjectHelper.ReleaseComObject(voucher);
                }

                sapHowmuchLogger.Error($"Journal vourcher create failed: {ex.Message}");

                throw ex;
            }

            return(await Task.FromResult(true));
        }
        /// <summary>
        /// Called while processing the event asynchronously.
        /// </summary>
        /// <param name="ev">Event instance.</param>
        /// <returns>Returns <c>True</c>, if the given event has been processed; otherwise returns <c>False</c>.</returns>
        protected override async Task <bool> OnProcessingAsync(BaseEvent ev)
        {
            var @event = (ev as EmployeeInfoCreatedEvent);
            var stream = Mapper.Map <EventStream>(@event);

            this._eventRepository.Add(stream);

            SAPbobsCOM.EmployeesInfo employeeInfo = null;

            try
            {
                employeeInfo = SapCompany.DICompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oEmployeesInfo) as SAPbobsCOM.EmployeesInfo;

                employeeInfo.ExternalEmployeeNumber = @event.ExtEmpno;
                employeeInfo.LastName  = @event.LastName;
                employeeInfo.FirstName = @event.FirstName;

                if (@event.StartDate.HasValue)
                {
                    employeeInfo.StartDate = @event.StartDate.Value;
                }

                if (@event.Status.HasValue)
                {
                    employeeInfo.StatusCode = @event.Status.Value;
                }

                if (@event.TermDate.HasValue)
                {
                    employeeInfo.TerminationDate = @event.TermDate.Value;
                }

                if (!string.IsNullOrWhiteSpace(@event.Active))
                {
                    employeeInfo.Active = @event.Active.ToSBOYesOrNo();
                }

                if (@event.Dept.HasValue)
                {
                    employeeInfo.Department = @event.Dept.Value;
                }

                employeeInfo.Position       = @event.Position;
                employeeInfo.HomeCountry    = @event.HomeCountr;
                employeeInfo.CountryOfBirth = @event.BrthCountr;

                if (!string.IsNullOrWhiteSpace(@event.Sex))
                {
                    employeeInfo.Gender = @event.Sex.ToSBOGenderType();
                }

                if (@event.BirthDate.HasValue)
                {
                    employeeInfo.DateOfBirth = @event.BirthDate.Value;
                }

                employeeInfo.HomePhone   = @event.HomeTel;
                employeeInfo.MobilePhone = @event.Mobile;
                employeeInfo.eMail       = @event.Email;
                employeeInfo.HomeStreet  = @event.HomeStreet;
                employeeInfo.HomeZipCode = @event.HomeZip;

                if (!string.IsNullOrWhiteSpace(@event.MartStatus))
                {
                    employeeInfo.MartialStatus = @event.MartStatus.ToSBOMeritalStatus();
                }

                // TODO: add 하는 오브젝트의 user field 에 event id 를 넣고,
                // end point 에서 쿼리 리파지터리를 통해
                // 해당 event id 에 해당하는 오브젝트의 id 를 받아오는 방법으로 키를 받도록 한다.

                int result = employeeInfo.Add();

                if (result != 0)
                {
                    throw new Exception($"SBO Error code: {SapCompany.DICompany.GetLastErrorCode()}, Error description: {SapCompany.DICompany.GetLastErrorDescription()}");
                }
            }
            catch (Exception ex)
            {
                if (employeeInfo != null)
                {
                    ComObjectHelper.ReleaseComObject(employeeInfo);
                }
                throw ex;
            }
            finally
            {
                if (employeeInfo != null)
                {
                    ComObjectHelper.ReleaseComObject(employeeInfo);
                }
            }

            return(await Task.FromResult(true));
        }