Exemplo n.º 1
0
        /// <summary> 得意先コードでデータを取得する </summary>
        /// <param name="code">得意先コード </param>
        /// <returns>Customer</returns>
        private async Task <Customer> GetDataByCustomerCode(string code)
        {
            Customer customerList = null;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service            = factory.Create <CustomerMasterClient>();
                CustomersResult result = await service.GetByCodeAsync(SessionKey, CompanyId, new string[] { code });
                if (result.ProcessResult.Result)
                {
                    customerList = result.Customers.FirstOrDefault();
                }
            });

            return(customerList);
        }
Exemplo n.º 2
0
        private void ImportKanaHistoryCustomer()
        {
            ImportSetting importSetting = null;
            var           task          = Util.GetMasterImportSettingAsync(Login, ImportFileType.KanaHistory);

            // 取込設定取得
            ProgressDialog.Start(ParentForm, task, false, SessionKey);
            importSetting = task.Result;

            var definition = new KanaHistoryCustomerFileDefinition(new DataExpression(ApplicationControl));

            definition.CustomerIdField.GetModelsByCode = val =>
            {
                Dictionary <string, Customer> product = null;
                ServiceProxyFactory.LifeTime(factory =>
                {
                    var customerMaster     = factory.Create <CustomerMasterClient>();
                    CustomersResult result = customerMaster.GetByCode(
                        Login.SessionKey, Login.CompanyId, val);
                    if (result.ProcessResult.Result)
                    {
                        product = result.Customers
                                  .ToDictionary(c => c.Code);
                    }
                });
                return(product ?? new Dictionary <string, Customer>());
            };

            var importer = definition.CreateImporter(m => new { m.PayerName, m.SourceBankName, m.SourceBranchName, m.CustomerId });

            importer.UserId      = Login.UserId;
            importer.UserCode    = Login.UserCode;
            importer.CompanyId   = Login.CompanyId;
            importer.CompanyCode = Login.CompanyCode;
            importer.LoadAsync   = async() => await GetKanaHistoryCustomerAsync();

            importer.RegisterAsync = async unitOfWork => await RegisterForCustomerImportAsync(unitOfWork);

            importer.InitializeWorker = async worker => worker.SetLegalPersonalities(await GetLegalPersonalitiesAsync());

            var importResult = DoImport(importer, importSetting);

            if (!importResult)
            {
                return;
            }
            grdKanaHistoryCustomer.Rows.Clear();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 債権代表者ID に紐づく得意先 または どのグループにも属さない 子の得意先を取得
        /// </summary>
        /// <returns></returns>
        private async Task <List <Customer> > GetChildCustomersWithParentOrOrphans()
        {
            List <Customer> list = null;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service            = factory.Create <CustomerMasterClient>();
                CustomersResult result = await service.GetByChildDetailsAsync(
                    SessionKey, CompanyId, ParentCustomerId);
                if (result.ProcessResult.Result)
                {
                    list = result.Customers;
                }
            });

            return(list ?? new List <Customer>());
        }
Exemplo n.º 4
0
        /// <summary> 得意先名取得 </summary>
        /// <param name="code"> 得意先コード</param>
        /// <returns>得意先名</returns>
        private string GetCustomerName(string code)
        {
            var             name   = string.Empty;
            CustomersResult result = null;
            Task            task   = ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <CustomerMasterClient>();
                result      = await service.GetByCodeAsync(SessionKey, CompanyId, new string[] { code });
            });

            ProgressDialog.Start(ParentForm, task, false, SessionKey);
            var customer = result?.Customers?.FirstOrDefault(x => x != null);

            if (customer != null)
            {
                name = customer.Name;
            }
            return(name);
        }
Exemplo n.º 5
0
        private async Task <List <Customer> > GetCustomer(string[] CustomerCode)
        {
            List <Customer> list = null;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service            = factory.Create <CustomerMasterClient>();
                CustomersResult result = await service.GetByCodeAsync(
                    Login.SessionKey,
                    Login.CompanyId,
                    CustomerCode);

                if (result.ProcessResult.Result)
                {
                    list = result.Customers;
                }
            });

            return(list ?? new List <Customer>());
        }
Exemplo n.º 6
0
        public async Task <IEnumerable <Customer> > SearchInfo()
        {
            List <Customer> list   = null;
            CustomersResult result = null;
            await ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <CustomerMasterClient>();
                switch (Key)
                {
                case SearchCustomer.Group:
                    result = await service.GetCustomerGroupAsync(Application.Login.SessionKey, Application.Login.CompanyId, CustomerId[0]);
                    break;

                case SearchCustomer.IsParent:
                    result = await service.GetParentItemsAsync(Application.Login.SessionKey, Application.Login.CompanyId);
                    break;

                case SearchCustomer.OtherChildrenWithoutGroup:
                    result = await service.GetByChildDetailsAsync(Application.Login.SessionKey, Application.Login.CompanyId, CustomerId[0]);
                    break;

                case SearchCustomer.WithList:
                    result = await service.GetCustomerWithListAsync(Application.Login.SessionKey, Application.Login.CompanyId, CustomerId?.Distinct().ToArray());
                    break;

                default:
                    result = await service.GetItemsAsync(Application.Login.SessionKey, Application.Login.CompanyId, null);
                    break;
                }

                if (result.ProcessResult.Result)
                {
                    list = result.Customers;
                }
            });

            return(list);
        }
        /// <summary> 得意先名取得 </summary>
        /// <param name="code"> 得意先コード</param>
        /// <returns>得意先名</returns>
        private string GetCustomerName(string code)
        {
            string          customerName = string.Empty;
            CustomersResult result       = null;
            var             task         = ServiceProxyFactory.LifeTime(async factory =>
            {
                var service = factory.Create <CustomerMasterClient>();
                result      = await service.GetCustomerWithListAsync(
                    SessionKey, CompanyId, CustomerIdList.Distinct().ToArray());
            });

            ProgressDialog.Start(ParentForm, task, false, SessionKey);
            if (result.ProcessResult.Result)
            {
                var customer = result.Customers.SingleOrDefault(x => x.Code == code);
                if (customer != null)
                {
                    customerName       = customer.Name;
                    AdvancedCustomerId = customer.Id;
                }
            }
            return(customerName);
        }
Exemplo n.º 8
0
        private void txtCustomerCode_Validated(object sender, EventArgs e)
        {
            ClearStatusMessage();
            var customerResult = new Customer();

            if (string.IsNullOrEmpty(txtCustomerCode.Text))
            {
                return;
            }

            try
            {
                var task = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var service            = factory.Create <CustomerMasterClient>();
                    CustomersResult result = await service.GetByCodeAsync(SessionKey, CompanyId, new string[] { txtCustomerCode.Text });

                    customerResult = result.Customers.FirstOrDefault();

                    if (customerResult != null)
                    {
                        txtCustomerCode.Text = customerResult.Code;
                        txtCustomerName.Text = customerResult.Name;
                    }
                    else
                    {
                        txtCustomerName.Clear();
                    }
                });
                ProgressDialog.Start(ParentForm, task, false, SessionKey);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }
Exemplo n.º 9
0
        private void ExportCustomer(CustomerSearch customerData)
        {
            List <Customer> list       = null;
            string          serverPath = null;

            var task = ServiceProxyFactory.LifeTime(async factory =>
            {
                var service            = factory.Create <CustomerMasterClient>();
                CustomersResult result = await service.GetItemsAsync(SessionKey, CompanyId, customerData);

                if (result.ProcessResult.Result)
                {
                    list = result.Customers;
                }
            });
            Task <string> pathTask = GetServerPath();

            ProgressDialog.Start(ParentForm, Task.WhenAll(task, pathTask), false, SessionKey);
            serverPath = pathTask.Result;

            if (!list.Any())
            {
                ShowWarningDialog(MsgWngNoExportData);
                return;
            }

            if (!Directory.Exists(serverPath))
            {
                serverPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            }

            var filePath = string.Empty;
            var fileName = $"得意先マスター{DateTime.Today:yyyyMMdd}.csv";

            if (!ShowSaveExportFileDialog(serverPath, fileName, out filePath))
            {
                return;
            }

            var definition = new CustomerFileDefinition(new DataExpression(ApplicationControl));

            definition.ExcludeInvoicePublishField.Ignored  = !UsePublishInvoice;
            definition.ExcludeReminderPublishField.Ignored = !UseReminder;
            var exporter = definition.CreateExporter();

            exporter.UserId      = Login.UserId;
            exporter.UserCode    = Login.UserCode;
            exporter.CompanyId   = CompanyId;
            exporter.CompanyCode = Login.CompanyCode;

            Func <int[], Dictionary <int, Category> > getter = ids =>
            {
                Dictionary <int, Category> product = null;
                ServiceProxyFactory.LifeTime(factory =>
                {
                    var categoryservice     = factory.Create <CategoryMasterClient>();
                    CategoriesResult result = categoryservice.Get(SessionKey, ids);
                    if (result.ProcessResult.Result)
                    {
                        product = result.Categories.ToDictionary(c => c.Id);
                    }
                });
                return(product ?? new Dictionary <int, Category>());
            };

            definition.CollectCategoryIdField.GetModelsById             = getter;
            definition.LessThanCollectCategoryIdField.GetModelsById     = getter;
            definition.GreaterThanCollectCategoryId3Field.GetModelsById = getter;
            definition.GreaterThanCollectCategoryId2Field.GetModelsById = getter;
            definition.GreaterThanCollectCategoryId1Field.GetModelsById = getter;

            NLogHandler.WriteDebug(this, "得意先マスター 出力開始");
            ProgressDialog.Start(ParentForm, (cancel, progress) =>
            {
                return(exporter.ExportAsync(filePath, list, cancel, progress));
            }, true, SessionKey);

            if (exporter.Exception != null)
            {
                NLogHandler.WriteErrorLog(this, exporter.Exception, SessionKey);
                ShowWarningDialog(MsgErrExportError);
                return;
            }

            NLogHandler.WriteDebug(this, "得意先マスター 出力終了");

            DispStatusMessage(MsgInfFinishExport);
            Settings.SavePath <Customer>(Login, filePath);
        }
Exemplo n.º 10
0
        private void PrintCustomerMaster()
        {
            ZeroLeftPaddingWithoutValidated();

            if (!RequiredCheck())
            {
                return;
            }

            CustomerSearch customerSearch = CreateSearchCondition();

            ClearStatusMessage();

            Task task = null;

            GrapeCity.ActiveReports.SectionReport report = null;
            string serverPath = null;

            if (rdoCustomerMasterList.Checked)
            {
                task = ServiceProxyFactory.LifeTime(async factory =>
                {
                    serverPath             = await GetServerPath();
                    var service            = factory.Create <CustomerMasterClient>();
                    CustomersResult result = await service.GetItemsAsync(SessionKey, CompanyId, customerSearch);

                    if (result.ProcessResult.Result)
                    {
                        var customerList = new List <Customer>(result.Customers);
                        if (customerList.Any())
                        {
                            var cusReport = new CustomerSectionReport();
                            cusReport.SetBasicPageSetting(Login.CompanyCode, Login.CompanyName);
                            cusReport.Name = "得意先マスター一覧" + DateTime.Today.ToString("yyyyMMdd");
                            cusReport.SetData(customerList);
                            cusReport.Run(false);
                            report = cusReport;
                        }
                    }
                });
            }
            else if (rdoCustomerLedger.Checked)
            {
                ClearStatusMessage();

                task = ServiceProxyFactory.LifeTime(async factory =>
                {
                    serverPath             = await GetServerPath();
                    var service            = factory.Create <CustomerMasterClient>();
                    CustomersResult result = await service.GetItemsAsync(SessionKey, CompanyId, customerSearch);

                    if (result.ProcessResult.Result)
                    {
                        var ledgerList = new List <Customer>(result.Customers);
                        if (ledgerList.Any())
                        {
                            var cusAccReport = new CustomerAccountSectionReport();
                            cusAccReport.SetBasicPageSetting(Login.CompanyCode, Login.CompanyName);
                            cusAccReport.Name = "得意先台帳" + DateTime.Now.ToString("yyyyMMdd");

                            cusAccReport.SetData(ledgerList, UsePublishInvoice, UseReminder);
                            cusAccReport.Run(false);
                            report = cusAccReport;
                        }
                    }
                });
            }
            else
            {
                ClearStatusMessage();
                task = ServiceProxyFactory.LifeTime(async factory =>
                {
                    serverPath  = await GetServerPath();
                    var service = factory.Create <CustomerFeeMasterClient>();
                    CustomerFeesResult result = await service.GetForPrintAsync(SessionKey, CompanyId);

                    if (result.ProcessResult.Result)
                    {
                        var cusFeeList = new List <CustomerFee>(result.CustomerFeePrint);

                        int precision = 0;
                        if (UseForeignCurrency)
                        {
                            precision = cusFeeList.Select(x => x.CurrencyPrecision).Max();
                        }

                        if (cusFeeList.Any())
                        {
                            CustomerFeeSectionReport cusFeeReport = new CustomerFeeSectionReport();
                            cusFeeReport.SetBasicPageSetting(Login.CompanyCode, Login.CompanyName);
                            cusFeeReport.Name      = "登録手数料一覧" + DateTime.Now.ToString("yyyyMMdd");
                            cusFeeReport.Precision = precision;
                            cusFeeReport.SetData(cusFeeList, ApplicationControl.UseForeignCurrency);
                            cusFeeReport.Run(false);
                            report = cusFeeReport;
                        }
                    }
                });
            }

            if (task != null)
            {
                ProgressDialog.Start(ParentForm, Task.Run(() => task), false, SessionKey);
                if (report == null)
                {
                    ShowWarningDialog(MsgWngPrintDataNotExist);
                    return;
                }
                ShowDialogPreview(ParentForm, report, serverPath);
            }
        }
Exemplo n.º 11
0
        private void Export()
        {
            ClearStatusMessage();
            try
            {
                List <CustomerGroup> listCustomerGroup = null;
                string serverPath = null;
                var    task       = ServiceProxyFactory.LifeTime(async factory =>
                {
                    var service = factory.Create <GeneralSettingMasterClient>();
                    GeneralSettingResult result = await service.GetByCodeAsync(
                        SessionKey, CompanyId, "サーバパス");
                    if (result.ProcessResult.Result)
                    {
                        serverPath = result.GeneralSetting?.Value;
                    }
                });

                Task <List <CustomerGroup> > printDataTask = GetPrintDataAsync();
                ProgressDialog.Start(ParentForm, Task.WhenAll(task, printDataTask), false, SessionKey);

                listCustomerGroup = printDataTask.Result;

                if (!listCustomerGroup.Any())
                {
                    ShowWarningDialog(MsgWngNoExportData);
                    return;
                }

                if (!Directory.Exists(serverPath))
                {
                    serverPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                }

                var filePath = string.Empty;
                var fileName = $"債権代表者マスター{DateTime.Today:yyyyMMdd}.csv";
                if (!ShowSaveExportFileDialog(serverPath, fileName, out filePath))
                {
                    return;
                }

                var definition = new CustomerGroupFileDefinition(new DataExpression(ApplicationControl));
                var exporter   = definition.CreateExporter();
                exporter.UserId      = Login.UserId;
                exporter.UserCode    = Login.UserCode;
                exporter.CompanyId   = CompanyId;
                exporter.CompanyCode = Login.CompanyCode;
                definition.ParentCustomerField.GetModelsById = ids =>
                {
                    Dictionary <int, Customer> product = null;
                    ServiceProxyFactory.LifeTime(factory =>
                    {
                        var customer           = factory.Create <CustomerMasterClient>();
                        CustomersResult result = customer.Get(SessionKey, ids);
                        if (result.ProcessResult.Result)
                        {
                            product = result.Customers.ToDictionary(c => c.Id);
                        }
                    });
                    return(product ?? new Dictionary <int, Customer>());
                };
                definition.ChildCustomerField.GetModelsById = definition.ParentCustomerField.GetModelsById;
                ProgressDialog.Start(ParentForm, (cancel, progress) =>
                {
                    return(exporter.ExportAsync(filePath, listCustomerGroup, cancel, progress));
                }, true, SessionKey);

                if (exporter.Exception != null)
                {
                    NLogHandler.WriteErrorLog(this, exporter.Exception, SessionKey);
                    ShowWarningDialog(MsgErrExportError);
                    return;
                }

                DispStatusMessage(MsgInfFinishExport);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
                DispStatusMessage(MsgErrExportError);
            }
        }