//手动增加发票 private void AppendInvoice() { if (TempViewInvoice != null) { if (Person == null || Accountant == null) { MessageBox.Show("请检查报销人姓名和财务人员", "信息提示", MessageBoxButton.OK, MessageBoxImage.Information); } else { using (var db = new DataModel()) { if (db.Invoices.Any(a => a.InvoiceNumber == TempViewInvoice.InvoiceNumber)) { MessageBox.Show("该发票已经报销过", "警告", MessageBoxButton.OK, MessageBoxImage.Warning); } else { MessageBoxResult result = MessageBox.Show($"确认手动添加发票号码为{TempViewInvoice.InvoiceNumber},金额为{TempViewInvoice.Amount}的发票吗", "提示", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) { try { TempViewInvoice.AcctId = Accountant.AccountantId; TempViewInvoice.PersonId = Person.PersonId; TempViewInvoice.AcctName = Accountant.Person.PersonName; TempViewInvoice.PersonName = Person.PersonName; var tempinvoice = new Invoice() { Amount = TempViewInvoice.Amount, Date = TempViewInvoice.Date, RecDate = TempViewInvoice.RecDate, InvoiceNumber = TempViewInvoice.InvoiceNumber, InvoiceCode = TempViewInvoice.InvoiceCode, AccountantId = Accountant.AccountantId, PersonId = Person.PersonId, Verification = TempViewInvoice.Verification }; db.Invoices.Add(tempinvoice); db.SaveChanges(); //var tempViewInvoice = (InputInvoice)(CloneObject(TempViewInvoice)); //这地方用全部重新查询一遍最好 ViewInvoices.Add(TempViewInvoice); ViewInvoice = ViewInvoices.Last(); calSummary(); ButtonEna = true; ButtonEnaN = false; State = "发票查询状态"; } catch (Exception) { } } } } } } }
private void ExcuteQueryCommand() { RadioButton = RadioButtons.Where(p => p.IsCheck).First(); RadioTimeButton = RadioTimeButtons.Where(p => p.IsCheck).First(); using (var db = new DataModel()) { if (QueryDateEna) { switch (RadioButton.Content) { case "录入部门": if (QueryDepartment != null) { QueryInvoices = db.Invoices.Where(i => i.Person.DepId == QueryDepartment.DepartmentId).ToList(); } break; case "所有": QueryInvoices = db.Invoices.ToList(); break; case "发票号码": QueryInvoices = db.Invoices.Where(i => i.InvoiceNumber.ToString().Contains(InvoiceSN)).ToList(); break; case "录入人员": if (QueryAccountant != null) { QueryInvoices = db.Invoices.Where(i => i.AccountantId == QueryAccountant.AccountantId).ToList(); } break; case "报销人": if (QueryPerson != null) { QueryInvoices = db.Invoices.Where(i => i.PersonId == QueryPerson.PersonId).ToList(); } break; default: break; } if (RadioTimeButton.Content == "录入日期") { QueryInvoices = QueryInvoices.Where(i => i.RecDate >= FromDate && i.RecDate <= ToDate).ToList(); } else if (RadioTimeButton.Content == "发票日期") { QueryInvoices = QueryInvoices.Where(i => i.Date >= FromDate && i.Date <= ToDate).ToList(); } } else { switch (RadioButton.Content) { case "录入部门": if (QueryDepartment != null) { QueryInvoices = db.Invoices.Where(i => i.Person.DepId == QueryDepartment.DepartmentId).ToList(); } break; case "所有": QueryInvoices = db.Invoices.ToList(); break; case "发票号码": QueryInvoices = db.Invoices.Where(i => i.InvoiceNumber.ToString().Contains(InvoiceSN)).ToList(); break; case "录入人员": if (QueryAccountant != null) { QueryInvoices = db.Invoices.Where(i => i.AccountantId == QueryAccountant.AccountantId).ToList(); } break; case "报销人": if (QueryPerson != null) { QueryInvoices = db.Invoices.Where(i => i.PersonId == QueryPerson.PersonId).ToList(); } break; default: break; } } ViewInvoices.Clear(); QueryInvoices.ForEach(i => { InputInvoice viewInvoice = new InputInvoice(); i.Person = db.Persons.Where(p => p.PersonId == i.PersonId).FirstOrDefault(); i.Accountant = db.Accountants.Where(o => o.AccountantId == i.AccountantId).FirstOrDefault(); i.Accountant.Person = db.Persons.Where(p => p.PersonId == i.AccountantId).FirstOrDefault(); viewInvoice.ID = i.ID; viewInvoice.InvoiceNumber = i.InvoiceNumber; viewInvoice.InvoiceCode = i.InvoiceCode; viewInvoice.Date = i.Date; viewInvoice.RecDate = i.RecDate; viewInvoice.AcctId = i.AccountantId; viewInvoice.PersonId = i.Person.PersonId; viewInvoice.PersonName = i.Person.PersonName; viewInvoice.AcctName = i.Accountant.Person.PersonName; viewInvoice.Amount = i.Amount; viewInvoice.Verification = i.Verification; viewInvoice.VerificationCode = i.VerificationCode; viewInvoice.VerifyState = i.VerifyState; ViewInvoices.Add(viewInvoice); }); QueryCount = ViewInvoices.Count; calSummary(); //TempViewInvoice = null; //Department = null; //Person = null; //Accountant = null; } }