//发票修改 private void ModifyInvoice() { if (TempViewInvoice != null && ViewInvoices != null) { if (Person == null || Accountant == null) { MessageBox.Show("请检查报销人姓名和财务人员", "信息提示", MessageBoxButton.OK, MessageBoxImage.Information); } else { MessageBoxResult result = MessageBox.Show($"确认要修改当前发票号码为{ViewInvoice.InvoiceNumber}的发票信息吗?", "提示", 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; QueryInvoice.ID = TempViewInvoice.ID; QueryInvoice.Amount = TempViewInvoice.Amount; QueryInvoice.Date = TempViewInvoice.Date; QueryInvoice.RecDate = TempViewInvoice.RecDate; QueryInvoice.InvoiceNumber = TempViewInvoice.InvoiceNumber; QueryInvoice.InvoiceCode = TempViewInvoice.InvoiceCode; QueryInvoice.AccountantId = Accountant.AccountantId; QueryInvoice.PersonId = Person.PersonId; QueryInvoice.Verification = TempViewInvoice.Verification; using (var db = new DataModel()) { db.Entry(QueryInvoice).State = EntityState.Modified; db.SaveChanges(); } ViewInvoice = (InputInvoice)(CloneObject(TempViewInvoice)); var temp = ViewInvoices.Where(i => i.ID == ViewInvoice.ID).First(); if (temp != null) { var index = ViewInvoices.IndexOf(temp); ViewInvoices[index] = ViewInvoice; } ViewInvoice = ViewInvoices.Where(i => i.ID == TempViewInvoice.ID).FirstOrDefault(); calSummary(); ButtonEna = true; ButtonEnaN = false; State = "发票查询状态"; } catch (Exception e) { Console.WriteLine(e.Message); } } } } }
private void ExcuteDeleteCommand() { if (TempViewInvoice != null) { MessageBoxResult result = MessageBox.Show($"确认要删除发票号码为{TempViewInvoice.InvoiceNumber},金额为{TempViewInvoice.Amount}的发票吗", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { try { using (var db = new DataModel()) { QueryInvoice = db.Invoices.Where(i => i.ID == TempViewInvoice.ID).FirstOrDefault(); db.Invoices.Remove(QueryInvoice); db.SaveChanges(); } ViewInvoice = ViewInvoices.Where(i => i.ID == TempViewInvoice.ID).First(); if (ViewInvoice != null) { int index = ViewInvoices.IndexOf(ViewInvoice); ViewInvoices.Remove(ViewInvoice); QueryCount = ViewInvoices.Count; if (QueryCount > 0) { calSummary(); if (index > 0) { ViewInvoice = ViewInvoices[index - 1]; } else { ViewInvoice = ViewInvoices[0]; } } } //ClearTempInvioice(); //Department =null; //Person = null; //Accountant = null; } catch (Exception) { } } } }
private async Task Verify() { // Call asynchronous network methods in a try/catch block to handle exceptions. try { string date = TempViewInvoice.Date.ToString("yyyyMMdd"); string verifyCode = TempViewInvoice.Verification.ToString(); verifyCode = verifyCode.Substring(verifyCode.Length - 6); string getString = string.Format("http://apis.juhe.cn/fp/query?fpdm={0}&fphm={1}&kprq={2}&jym={3}&je={4}&key=e4cdb0800eb9d34b148b54ca90951b3b", TempViewInvoice.InvoiceCode.ToString(), TempViewInvoice.InvoiceNumber.ToString(), date, verifyCode, TempViewInvoice.Amount.ToString()); //HttpResponseMessage response = await client.GetAsync(getString); //response.EnsureSuccessStatusCode(); //string responseBody = await response.Content.ReadAsStringAsync(); // Above three lines can be replaced with new helper method below string responseBody = await client.GetStringAsync(getString); //string responseBody = "{\"reason\":\"成功\",\"result\":{\"orderid\":\"JH336202003031456261476\",\"xfmc\":\"上海圆迈贸易有限公司\",\"xfsh\":\"91310114666025597Y\",\"xfdz\":\"上海市嘉定工业区叶城路1118号19层1901室 021-39915587\",\"xfzh\":\"招商银行股份有限公司北京青年路支行 121907731210104\",\"gfmc\":\"个人\",\"gfsh\":\"\",\"gfdz\":\"\",\"gfzh\":\"\",\"jym\":\"63936313063773165070\",\"jqbm\":\"661619911295\",\"je\":\"76.00\",\"zfbz\":\"N\",\"bz\":\"订单号:111636717032\",\"spxx\":[{\"spmc\":\"*肉及肉制品*元盛 新西兰原切牛腱子肉 1kg 进口草饲牛肉\",\"ggxh\":\"牛腱子1kg\",\"spdw\":\"袋\",\"spsl\":\"1.00000000\",\"spdj\":\"84.00000000\",\"spje\":\"84.00\",\"spslv\":\"免税\",\"spse\":\"***\",\"flbm\":\"\",\"cph\":\"\",\"type\":\"\",\"txrqq\":\"\",\"txrqz\":\"\"},{\"spmc\":\"*肉及肉制品*元盛 新西兰原切牛腱子肉 1kg 进口草饲牛肉\",\"ggxh\":\"\",\"spdw\":\"\",\"spsl\":\"\",\"spdj\":\"\",\"spje\":\"-8.00\",\"spslv\":\"免税\",\"spse\":\"***\",\"flbm\":\"\",\"cph\":\"\",\"type\":\"\",\"txrqq\":\"\",\"txrqz\":\"\"}],\"se\":\"0.00\",\"jshj\":\"76.00\",\"fplx\":\"10\"},\"error_code\":0}"; Object obj = JsonConvert.DeserializeObject(responseBody) as JObject; dynamic d = obj; string veriState; //string success = d.reason; string amount = d.result.je; string code = d.error_code; string tempx; switch (code) { case "0": veriState = "校验正确"; break; case "233600": veriState = "信息不一致"; break; case "233602": veriState = "查无此票"; break; case "233601": veriState = "发票错误"; break; default: veriState = d.reason;; break; } if (code == "0" || code == "233600" || code == "233602" || code == "233601") { using (var db = new DataModel()) { QueryInvoice = db.Invoices.Where(i => i.ID == TempViewInvoice.ID).FirstOrDefault(); QueryInvoice.VerifyState = veriState; tempx = QueryInvoice.Amount.ToString(); if (tempx != amount && code == "0") { QueryInvoice.VerifyState = "金额不正确"; } db.Entry(QueryInvoice).State = EntityState.Modified; db.SaveChanges(); } ViewInvoice.VerifyState = QueryInvoice.VerifyState; var temp = ViewInvoices.Where(i => i.ID == ViewInvoice.ID).First(); if (temp != null) { var index = ViewInvoices.IndexOf(temp); ViewInvoices[index] = ViewInvoice; } ViewInvoice = ViewInvoices.Where(i => i.ID == TempViewInvoice.ID).FirstOrDefault(); } else { MessageBox.Show(veriState + ",查询失败!", "提示", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (HttpRequestException e) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", e.Message); } }