public InvoicesViewModel()
 {
     Refresh();
     if (Invoices.Any())
     {
         Invoice = Invoices[0];
     }
     SwitchToAddNewCommand = new RelayCommand(() => Navigator.SwitchView(ViewModelLocator.AddInvoiceViewModel));
     GoHomeCommand         = new RelayCommand(() => Navigator.SwitchView(ViewModelLocator.HomeViewModel));
 }
        private Dictionary <string, IEnumerable <Invoice> > GetInvoicesByCurrency(Organisation organisation, Invoices invoices)
        {
            var result = new Dictionary <string, IEnumerable <Invoice> >();

            foreach (var currency in _currencies)
            {
                if (invoices.Any(i => i.CurrencyCode == currency.Code))
                {
                    result.Add(currency.Description, invoices.Where(i => i.CurrencyCode == currency.Code).ToList());
                }
            }

            return(result);
        }
        private void Listener_ScanerEvent(ScanerHook.ScanerCodes codes)
        {
            string[] content = codes.Result.ToString().Split(',');
            try
            {
                DateTime dateTime;
                if (!DateTime.TryParseExact(content[5], "yyyy/M/ddHH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
                {
                    DateTime.TryParseExact(content[5], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime);
                }

                InputInvoice invoice = new InputInvoice()
                {
                    InvoiceCode      = content[2],
                    InvoiceNumber    = content[3],
                    Date             = dateTime,
                    RecDate          = DateTime.Now,
                    Verification     = content[6],
                    AcctId           = Information.AccountantId,
                    PersonId         = Properties.Settings.Default.PersonId,
                    VerificationCode = (content.Length == 8)?content[7] : null
                };
                decimal amount = 0;
                //invoice.AcctId = Information.AccountantId;
                //invoice.PersonId = Properties.Settings.Default.PersonId;
                using (var db = new DataModel())
                {
                    invoice.PersonName = db.Persons.Where(p => p.PersonId == invoice.PersonId).FirstOrDefault().PersonName;
                }
                if (decimal.TryParse(content[4], out amount))
                {
                    invoice.Amount = amount;
                }
                if (Invoices.Any(i => i.InvoiceNumber == invoice.InvoiceNumber && i.InvoiceCode == invoice.InvoiceCode))
                {
                    string time = DateTime.Now.ToString("HH:mm:ss");
                    ScanMessage = time + "  该发票已扫描,等待入库!";

                    //MessageBox.Show("该发票已经扫描等待入库", "信息", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    using (var db = new DataModel())
                    {
                        if (db.Invoices.Any(a => a.InvoiceNumber == invoice.InvoiceNumber && a.InvoiceCode == invoice.InvoiceCode))
                        {
                            string time = DateTime.Now.ToString("HH:mm:ss");
                            ScanMessage = time + "  该发票已经报销过!";
                            //MessageBox.Show("该发票已经报销过", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                        }
                        else
                        {
                            string time = DateTime.Now.ToString("HH:mm:ss");
                            ScanMessage = time + "  发票扫描成功!";
                            Message     = $"发票代码: {invoice.InvoiceCode} 发票号码: {invoice.InvoiceNumber} 税前金额: {invoice.Amount} " +
                                          $"发票日期: {invoice.Date.ToString("yyyy年MM月dd日")}";
                            invoice.AcctName    = db.Accountants.Where(o => o.AccountantId == Information.AccountantId).FirstOrDefault().Person.PersonName;
                            invoice.VerifyState = "未校验";
                            Invoices.Add(invoice);
                            InputCount = Invoices.Count;
                            BtnEnableJudgement();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ScanMessage = "非正常发票数据";
            }
        }