private void DefaultParametrs(CompanyEF company = null, bool refresh = false) { IikColor = System.Windows.Media.Brushes.Black; if (!refresh) { archiveManager = new ArchiveManager(dataManager); CountriesList = DataBaseClient.ReadCountries(); } if (company == null) { Company = new CompanyEF(); Company.createdate = DateTime.Now; IsSupplier = true; } else { try { if (DataBaseClient.ReadSupplier(Company.id) != null) { IsSupplier = true; } if (DataBaseClient.ReadCustomer(Company.id) != null) { IsCustomer = true; } SelectedCountry = CountriesList.Where(x => x.id == company.countryid).FirstOrDefault(); ContractsList = DataBaseClient.ReadContracts(Company.id); C01List = DataBaseClient.ReadSuppliersJournals(DataBaseClient.GetSupplierId(Company.id)); SearchSupplier = Company.name; if (Company.iik == null) { return; } if (Company.iik.Length < 20) { IikColor = System.Windows.Media.Brushes.Red; } else { IikColor = System.Windows.Media.Brushes.Black; } } catch (Exception ex) { MessagesService.Show("ОШИБКА", "Ошибка загрузки данных для страницы"); AppJournal.Write("Company", "Get company info from db error :" + ex.ToString(), true); } } }
public CompanyViewModel(CompanyEF companyInfo = null) { if (companyInfo != null) { Company = companyInfo; FormTitle = "Просмотр/редактирование компании"; } else { FormTitle = "Создание компании"; } DefaultParametrs(companyInfo); }
private void PutContractTo1C() { AppJournal.Write("Contract", "Put contract to 1c", true); if (AllFieldsSet()) { string result = ""; int baseType = 2; CompanyEF company = DataBaseClient.ReadCompany(companyId); Contracts contract = new Contracts(); string companyBin = Contract.company.bin; if (_1CTransport.SearchCompany(companyBin, baseType) == null) { companyBin = companyBin.PadLeft(12, '0'); } contract = _1CTransport.SearchContract(companyBin, Contract.number, baseType = (int)Contract.brokerid == 4 ? 3 : (int)Contract.brokerid); if (contract == null) { contract = new Contracts(); contract.CtlgName = "Договор №" + Contract.number + " от " + Contract.agreementdate; contract.CtlgCode = ""; contract.ClientIIN = companyBin; contract.ContractNumber = Contract.number.Replace("с", "c"); contract.ContracDate = Contract.agreementdate; contract.ContractType = "СПокупателем"; contract.Settlements = ""; contract.StartDate = null; contract.TerminationDate = null; contract.Comments = ".NET Автоматизация"; contract.СontractСurrency = Contract.currency.code; result = _1CTransport.CreateContract(baseType, contract); } else { result = "exist"; } BankAccounts bankAccount = new BankAccounts(); bankAccount = _1CTransport.SearchBankAccount(company.iik, companyBin, baseType = Contract.brokerid == 4 ? 3 : (int)Contract.brokerid); if (bankAccount == null) { _1CTransport.CreateBankAccount(company.iik, companyBin, Contract.currency.code, baseType = Contract.brokerid == 4 ? 3 : (int)Contract.brokerid, Contract.bank.company.bik); } if (result.Contains("ok")) { MessagesService.Show("РЕЗУЛЬТАТ ЗАНЕСЕНИЯ В 1С", "Договор создан успешно"); } else if (result.Contains("exist")) { MessagesService.Show("РЕЗУЛЬТАТ ЗАНЕСЕНИЯ В 1С", "Договор с таким номером уже существует в 1С"); } else { MessagesService.Show("РЕЗУЛЬТАТ ЗАНЕСЕНИЯ В 1С", "При создании договора возникла ошибка"); AppJournal.Write("Contract", "Put contract to 1c error :" + result, true); } } else { MessagesService.Show("РЕЗУЛЬТАТ ЗАНЕСЕНИЯ В 1С", "Не все поля заполненны"); } }
private async void GetContractFrom1C() { AppJournal.Write("Contract", "Get contract from 1c", true); CompanyEF Company = DataBaseClient.ReadCompany(companyId); string contractNum = await MessagesService.GetInput("ПОИСК В 1С", "Введите номер договора"); if (!string.IsNullOrEmpty(contractNum)) { try { Contracts = _1CTransport.SearchContract(Company.bin, contractNum, 1); if (Contracts != null) { SelectedBroker = BrokersList.Where(x => x.id == 1).First(); BankAccounts = _1CTransport.SearchBankAccount(Company.iik, Company.bin, 1); } else { Contracts = _1CTransport.SearchContract(Company.bin, contractNum, 2); if (Contracts != null) { SelectedBroker = BrokersList.Where(x => x.id == 2).First(); BankAccounts = _1CTransport.SearchBankAccount(Company.iik, Company.bin, 2); } else { Contracts = _1CTransport.SearchContract(Company.bin, contractNum, 3); if (Contracts != null) { SelectedBroker = BrokersList.Where(x => x.id == 4).First(); BankAccounts = _1CTransport.SearchBankAccount(Company.iik, Company.bin, 3); } } } if (Contracts != null) { Contract.agreementdate = Contracts.ContracDate; Contract.number = Contracts.ContractNumber; if (BankAccounts != null) { SelectedBank = BanksList.Where(x => x.company.bik == BankAccounts.BankBIК).First(); } if (Contracts.ContractType.ToUpper().Contains("ПРОЧЕЕ") || Contracts.ContractType.ToUpper().Contains("ПОКУПАТЕЛЕМ")) { SelectedContractType = ContractTypesList.Where(x => x.id == 1).First(); } else { SelectedContractType = ContractTypesList.Where(x => x.id == 2).First(); } SelectedCurrency = CurrenciesList.Where(x => x.code == Contracts.СontractСurrency).First(); Contract = Contract; } } catch (Exception ex) { Contracts = null; AppJournal.Write("Contract", "Get contract from 1c error :" + ex.ToString(), true); } } if (Contracts == null) { MessagesService.Show("РЕЗУЛЬТАТ ПОИСКА В БАЗАХ", "Результатов нет"); } }