/// <summary> /// 新增发票 /// </summary> /// <param name="invoice"></param> public void AddVatInvoice(VatInvoice invoice) { DataSet ds = GetVatInvoice(invoice.InvoiceCode, invoice.InvoiceNumber, "", "", "", "", "", false); if (ds.Tables[0].Rows.Count == 0) { string commandStr = @"INSERT INTO Vat_Invoice(InvoiceType,InvoiceTypeOrg, InvoiceCode, InvoiceNumber, InvoiceDate, PurchaserName, PurchaserRegisterNum, PurchaserAddress, PurchaserBank, SellerName, SellerRegisterNum, SellerAddress, SellerBank, TotalAmount, TotalTaxAmount, TotalTax, Remarks,InvoicePatch, Payee,Checker,NoteDrawer,CreateTime,UpdateTime,PushStatus) VALUES(@InvoiceType,@InvoiceTypeOrg, @InvoiceCode, @InvoiceNumber, @InvoiceDate, @PurchaserName, @PurchaserRegisterNum, @PurchaserAddress, @PurchaserBank, @SellerName, @SellerRegisterNum, @SellerAddress, @SellerBank, @TotalAmount, @TotalTaxAmount, @TotalTax, @Remarks,@InvoicePatch, @Payee,@Checker,@NoteDrawer,@CreateTime,@UpdateTime,@PushStatus)"; var parameters = new object[] { invoice.InvoiceType, invoice.InvoiceTypeOrg, invoice.InvoiceCode, invoice.InvoiceNumber, invoice.InvoiceDate, invoice.PurchaserName, invoice.PurchaserRegisterNum, invoice.PurchaserAddress, invoice.PurchaserBank, invoice.SellerName, invoice.SellerRegisterNum, invoice.SellerAddress, invoice.SellerBank, invoice.TotalAmount, invoice.TotalTaxAmount, invoice.TotalTax, invoice.Remarks, invoice.InvoicePatch, invoice.Payee, invoice.Checker, invoice.NoteDrawer, invoice.CreateTime, invoice.UpdateTime, invoice.PushStatus }; SQLiteHelper.ExecuteNonQuery(connectionString, commandStr, parameters); } else { string commandStr = @"UPDATE Vat_Invoice SET UpdateTime = @UpdateTime WHERE InvoiceCode = @InvoiceCode AND InvoiceNumber = @InvoiceNumber"; var parameters = new object[] { invoice.UpdateTime, invoice.InvoiceCode, invoice.InvoiceNumber }; SQLiteHelper.ExecuteNonQuery(connectionString, commandStr, parameters); } }
/// <summary> /// 更改发票 /// </summary> /// <param name="invoice"></param> public void UpdateVatInvoice(VatInvoice invoice) { string commandStr = @"UPDATE Vat_Invoice SET InvoiceTypeOrg = @InvoiceTypeOrg, InvoiceCode = @InvoiceCode, InvoiceNumber = @InvoiceNumber, InvoiceDate = @InvoiceDate, PurchaserName = @PurchaserName, PurchaserRegisterNum = @PurchaserRegisterNum, PurchaserAddress = @PurchaserAddress, PurchaserBank = @PurchaserBank, SellerName = @SellerName, SellerRegisterNum = @SellerRegisterNum, SellerAddress = @SellerAddress, SellerBank = @SellerBank, TotalAmount = @TotalAmount, TotalTaxAmount = @TotalTaxAmount, TotalTax = @TotalTax WHERE Id = @id"; var parameters = new object[] { invoice.InvoiceTypeOrg, invoice.InvoiceCode, invoice.InvoiceNumber, invoice.InvoiceDate, invoice.PurchaserName, invoice.PurchaserRegisterNum, invoice.PurchaserAddress, invoice.PurchaserBank, invoice.SellerName, invoice.SellerRegisterNum, invoice.SellerAddress, invoice.SellerBank, invoice.TotalAmount, invoice.TotalTaxAmount, invoice.TotalTax, invoice.Id }; SQLiteHelper.ExecuteNonQuery(connectionString, commandStr, parameters); }
public override IInvoice CreateInvoice() { var invoice = new VatInvoice(); invoice.VATValues = new List <int> { 8, 11, 23 }; //Tu np. odwołanie do zewnętrznego API, które zwraca listę stawek VAT. return(invoice); }
/// <summary> /// 保存数据更改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tstripButton_save_Click(object sender, EventArgs e) { try { if (DataGridView_Invoice.IsCurrentCellInEditMode) { DataGridView_Invoice.CurrentCell = null; } int rows = DataGridView_Invoice.Rows.Count; for (int i = 0; i < rows; i++) { VatInvoice invoice = new VatInvoice { Id = int.Parse(DataGridView_Invoice.Rows[i].Cells["Id"].Value.ToString()), InvoiceTypeOrg = DataGridView_Invoice.Rows[i].Cells["InvoiceTypeOrg"].Value.ToString(), InvoiceCode = DataGridView_Invoice.Rows[i].Cells["InvoiceCode"].Value.ToString(), InvoiceNumber = DataGridView_Invoice.Rows[i].Cells["InvoiceNumber"].Value.ToString(), InvoiceDate = DataGridView_Invoice.Rows[i].Cells["InvoiceDate"].Value.ToString(), PurchaserName = DataGridView_Invoice.Rows[i].Cells["PurchaserName"].Value.ToString(), PurchaserRegisterNum = DataGridView_Invoice.Rows[i].Cells["PurchaserRegisterNum"].Value.ToString(), PurchaserAddress = DataGridView_Invoice.Rows[i].Cells["PurchaserAddress"].Value.ToString(), PurchaserBank = DataGridView_Invoice.Rows[i].Cells["PurchaserBank"].Value.ToString(), SellerName = DataGridView_Invoice.Rows[i].Cells["SellerName"].Value.ToString(), SellerRegisterNum = DataGridView_Invoice.Rows[i].Cells["SellerRegisterNum"].Value.ToString(), SellerAddress = DataGridView_Invoice.Rows[i].Cells["SellerAddress"].Value.ToString(), SellerBank = DataGridView_Invoice.Rows[i].Cells["SellerBank"].Value.ToString(), TotalAmount = decimal.Parse(DataGridView_Invoice.Rows[i].Cells["TotalAmount"].Value.ToString()), TotalTaxAmount = decimal.Parse(DataGridView_Invoice.Rows[i].Cells["TotalTaxAmount"].Value.ToString()), TotalTax = decimal.Parse(DataGridView_Invoice.Rows[i].Cells["TotalTax"].Value.ToString()) }; vatInvoiceBll.UpdateVatInvoice(invoice); } MessageBox.Show("保存成功", "提示"); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常提示"); } }
public List <VatInvoice> ModelTransform(List <Root> roots) { List <VatInvoice> invoices = new List <VatInvoice>(); foreach (var root in roots) { var invoice = new VatInvoice(); invoice.InvoiceType = root.words_result.InvoiceType; invoice.InvoiceTypeOrg = root.words_result.InvoiceTypeOrg; invoice.Comodities = new List <Comodity>(); for (var i = 0; i < root.words_result.CommodityName.Count; i++) { var commodity = new Comodity(); if (root.words_result.CommodityName != null && root.words_result.CommodityName.Count > 0) { //commodity.Name = root.words_result.CommodityName.Select(t => t.word).ToArray()[i]; commodity.Name = root.words_result.CommodityName.Find(t => t.row == (i + 1).ToString()).word; } //type if (root.words_result.CommodityType != null && root.words_result.CommodityType.Count > 0) { commodity.Type = root.words_result.CommodityType.Find(t => t.row == (i + 1).ToString()).word; } //unit if (root.words_result.CommodityUnit != null && root.words_result.CommodityUnit.Count > 0) { commodity.Unit = root.words_result.CommodityUnit.Find(t => t.row == (i + 1).ToString()).word; } //num if (root.words_result.CommodityNum != null && root.words_result.CommodityNum.Count > 0) { commodity.Quantity = root.words_result.CommodityNum.Find(t => t.row == (i + 1).ToString()).word; } //UnitPrice if (root.words_result.CommodityPrice != null && root.words_result.CommodityPrice.Count > 0) { commodity.UnitPrice = root.words_result.CommodityPrice.Find(t => t.row == (i + 1).ToString()).word; } //Amount if (root.words_result.CommodityAmount != null && root.words_result.CommodityAmount.Count > 0) { commodity.Price = root.words_result.CommodityAmount.Find(t => t.row == (i + 1).ToString()).word; } //TaxRate if (root.words_result.CommodityTaxRate != null && root.words_result.CommodityTaxRate.Count > 0) { commodity.TaxRate = root.words_result.CommodityTaxRate.Find(t => t.row == (i + 1).ToString()).word; } //TaxAmount if (root.words_result.CommodityTax != null && root.words_result.CommodityTax.Count > 0) { commodity.TaxAmount = root.words_result.CommodityTax.Find(t => t.row == (i + 1).ToString()).word; } invoice.Comodities.Add(commodity); } invoices.Add(invoice); } return(invoices); }
/// <summary> /// 奥普斯凯发票扫描(OCR) /// </summary> public string InvoiceScan() { try { string tpImgName = ""; int index = 0; string strIndex = ""; string imageName = ""; string imagePath = ""; string tmp_ImagePath = AppDomain.CurrentDomain.BaseDirectory + @"\vatinvoiceimages\tempimages\"; if (!Directory.Exists(tmp_ImagePath)) { Directory.CreateDirectory(tmp_ImagePath); } else { DeleteFolder(tmp_ImagePath); } bool isHavePaper = true; int recode = -1; int ncells = 0; int nType = -2; Dictionary <string, string> invResult = new Dictionary <string, string>(); while (isHavePaper) { index++; strIndex = ""; strIndex = string.Format("{0:D4}", index); tpImgName = tmp_ImagePath + strIndex + ".jpg"; recode = billOcr.AcquireNewImage(tpImgName); //扫描图像 //识别图像 if (recode == 0) { char[] cArrFieldName = new char[256]; cArrFieldName.Initialize(); int nFiledName = billOcr.GetFieldNameEx(cArrFieldName); if (nFiledName == 0) { string strFieldName = new string(cArrFieldName); } recode = billOcr.RecognizeForm(out ncells, out nType); //识别图像 if (recode == 0) //识别后读取数据 { invResult = GetRecogResult(ncells); _logger.Info("发票识别结果:" + JsonConvert.SerializeObject(invResult)); if (invResult != null) { VatInvoice invoice = new VatInvoice(); VatInvoiceBll invoiceBll = new VatInvoiceBll(); invoice.InvoiceType = invResult["票据类型"].ToString(); invoice.InvoiceTypeOrg = invoice.InvoiceType == "专票" ? "增值税专用发票" : "增值税普通发票"; invoice.InvoiceCode = invResult["发票代码"].ToString(); invoice.InvoiceNumber = invResult["发票号码"].ToString(); invoice.InvoiceDate = invResult["开票日期"].ToString(); invoice.PurchaserName = invResult["购方企业名称"].ToString(); invoice.PurchaserRegisterNum = invResult["购方纳税号"].ToString(); invoice.PurchaserAddress = invResult["购买方地址及电话"].ToString(); invoice.PurchaserBank = invResult["购买方开户行及账号"].ToString(); invoice.SellerName = invResult["销方企业名称"].ToString(); invoice.SellerRegisterNum = invResult["销方纳税号"].ToString(); invoice.SellerAddress = invResult["销售方地址及电话"].ToString(); invoice.SellerBank = invResult["销售方开户行及账号"].ToString(); invoice.TotalAmount = decimal.Parse(invResult["金额"].ToString()); invoice.TotalTaxAmount = decimal.Parse(invResult["价税合计"].ToString()); invoice.TotalTax = decimal.Parse(invResult["税额"].ToString()); invoice.Payee = invResult["收款人"].ToString(); invoice.Checker = invResult["复核"].ToString(); invoice.NoteDrawer = invResult["开票人"].ToString(); invoice.Remarks = invResult["备注"].ToString(); invoice.CreateTime = DateTime.Now; invoice.UpdateTime = DateTime.Now; invoice.PushStatus = 0; //按发票代码、发票号码重命名文件,并按开票日期年月建立归档文件夹 string imageDoc = invoice.InvoiceDate.Substring(0, 7); imagePath = AppDomain.CurrentDomain.BaseDirectory + @"vatinvoiceimages\" + imageDoc + @"\"; if (!Directory.Exists(imagePath)) { Directory.CreateDirectory(imagePath); } imageName = invoice.InvoiceCode + "_" + invoice.InvoiceNumber; string newImagePath = imagePath + imageName + ".jpg"; FileInfo fileInfo = new FileInfo(tpImgName); if (!File.Exists(newImagePath)) { fileInfo.MoveTo(Path.Combine(newImagePath)); } invoice.InvoicePatch = imageDoc + @"\" + imageName + ".jpg"; invoiceBll.AddVatInvoice(invoice); } } } isHavePaper = billOcr.IsHavePaper(); } return("1"); } catch (Exception ex) { _logger.Info(string.Format("系统异常,{0}!", ex.ToString())); return(string.Format("系统异常,请重新扫描,{0}!", ex.ToString())); } }