Esempio n. 1
0
 //手动增加发票
 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)
                         {
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 2
0
 //发票修改
 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);
                 }
             }
         }
     }
 }
Esempio n. 3
0
        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)
                    {
                    }
                }
            }
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
        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;
            }
        }