在c#中xmlworkerhelper的索引超出范围

时间:2017-06-05 05:42:15

标签: asp.net

PaymentService.PaymentServiceClient client = new 
PaymentService.PaymentServiceClient();
PaymentTransactionDto model = new PaymentTransactionDto();
OrderInvoiceDto invoiceData;
List<ProductRepoDto> products;
List<OrderTaxDto> taxes;
// Check payment status                    
int chkProduct = 0;
int chkCourse = 0;
int chkProductCourse = 0;

#region Get order details for invoice
var order_details = client.GetOrderDetailsForInvoice(Convert.ToInt32(Oid.Rows[0]["OrderId"]));
invoiceData = new OrderInvoiceDto();
if (order_details != null)
{
    invoiceData = AutoMapConverter<PaymentService.OrderInvoiceDto, OrderInvoiceDto>.GetMappedData(order_details);
}
#endregion

#region Get Products list in order
var productList = client.GetOrderItemsByOrderId(Convert.ToInt32(Oid.Rows[0]["OrderId"]));
products = new List<ProductRepoDto>();
if (productList != null && productList.Count() > 0)
{
    products = AutoMapConverter<PaymentService.ProductRepoDto, ProductRepoDto>.GetMappedList(productList.ToList());
}
#endregion

#region ADD Taxes
#region check product type
decimal Amount = 0;
foreach (var item in products)
{
    if (item.TypeId == 1)
        chkCourse = 1;
    if (item.TypeId == 2)
        chkProduct = 1;
    if (chkCourse == 1 && chkProduct == 1)
        chkProductCourse = 1;
    Amount = Amount + (item.Amount * item.Quantity);
    Amount = Amount - item.Discount;
}
#endregion

// Apply taxes
client.AddOrderTaxMappingDetails(Convert.ToInt64(orderid), Amount);
#endregion

#region Get Applied Tax details
var taxesApplied = client.GetOrderAppliedTaxes(Convert.ToInt64(orderid));
taxes = new List<OrderTaxDto>();
if (taxesApplied != null && taxesApplied.Count() > 0)
{
    taxes = AutoMapConverter<PaymentService.OrderTaxDto, OrderTaxDto>.GetMappedList(taxesApplied.ToList());
}
#endregion

string pdfbody = System.IO.File.ReadAllText(Server.MapPath("~/Views/Payment/InvoiceView.cshtml"));

Document document = new Document();
string fileName = string.Format("{0}.pdf", invoiceData.OrderNumber);
var fpath = HttpContext.Current.Server.MapPath("~/Document/Payment/Invoice/");

if (!Directory.Exists(fpath))
{
    Directory.CreateDirectory(fpath);
}

pdfbody = pdfbody.Replace("$name$", string.Format("{0} {1}", invoiceData.Billing_FirstName, invoiceData.Billing_LastName));
pdfbody = pdfbody.Replace("$address$", invoiceData.Billing_Address);
pdfbody = pdfbody.Replace("$billingCity$", invoiceData.Billing_City);
pdfbody = pdfbody.Replace("$billingPinCode$", invoiceData.Billing_PinCode.ToString());
pdfbody = pdfbody.Replace("$billingState$", invoiceData.Billing_State);
pdfbody = pdfbody.Replace("$billingCountry$", invoiceData.Billing_Country);

//pdfbody = pdfbody.Replace("$netAmt$", invoiceData.NetAmt.ToString());
//pdfbody = pdfbody.Replace("$grossAmt$", invoiceData.GrossAmt.ToString());
//pdfbody = pdfbody.Replace("$discountAmt$", invoiceData.DiscountAmt.ToString());

pdfbody = pdfbody.Replace("$orderNumber$", invoiceData.OrderNumber.Remove(0, 2));
pdfbody = pdfbody.Replace("$orderDate$", CommonFunctions.EpochToIstDate(Convert.ToDouble(invoiceData.OrderDate)));

StringBuilder b = new StringBuilder();

decimal totalAmount = 0;
foreach (var item in products)
{
    if (!string.IsNullOrEmpty(item.ActivationKey))
    item.ActivationKey = string.Format("Activation Key:{0}", item.ActivationKey);
    b.AppendFormat("<tr><td width='60%'>{0}<br/>{1}</td>", item.ProductName, item.ActivationKey);
    b.AppendFormat("<td width='10%' align='left'>{0}</td>", item.Quantity);
    b.AppendFormat("<td width='30%' align='right'>{0}</td></tr>", (item.Amount * item.Quantity) - item.Discount);

    totalAmount = totalAmount + (item.Amount * item.Quantity);
    totalAmount = totalAmount - item.Discount;
}
pdfbody = pdfbody.Replace("$OrderDetailsList$", Convert.ToString(b));
if (taxes != null && taxes.Count > 0)
{
    b = new StringBuilder();
    foreach (var item in taxes)
    {
        b.AppendFormat("<tr><td width='80%' colspan='2'>{0} ({1}%)</td>", item.TaxName, item.Percentage);
        b.AppendFormat("<td width='20%' align='right'>{0}</td></tr>", item.Amount);
    }
    pdfbody = pdfbody.Replace("$OrderTaxDetailsList$", Convert.ToString(b));
}
else
{
    pdfbody = pdfbody.Replace("$OrderTaxDetailsList$", "");
}
pdfbody = pdfbody.Replace("$netAmt$", totalAmount.ToString());
pdfbody = pdfbody.Replace("$rupees$", CommonFunctions.ConvertNumbertoWords(Convert.ToInt32((int)Math.Ceiling(totalAmount))));

PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(fpath + fileName, FileMode.Create));

document.Open();
StringReader sr = new StringReader(pdfbody);
XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, sr);
document.Close();                                    

我想生成pdf invoice.so我使用的是itextsharp 但我在XMLWorkerHelper上获得了索引超出绑定的数组。 我使用的是itextsharp.xmlworker.dll,v5.4.5.0 当我尝试更新itextsharp.xmlworker.dll,v5.4.5.9 这段代码工作得很好..但是我项目中使用iTextsharp的所有其他模块都会出现错误。 如果这是版本问题,那么我如何在bin文件夹中添加两个不同的dll并使用它 或者是代码相关的错误?

0 个答案:

没有答案