public void CreateInvoice() { float totalAmt = 0; int numbPages = 0; int numbItems = dictShipmentGroup.Count; if (numbItems <= maxItem) numbPages = 1; else numbPages = ((numbItems - maxItem - 1) / (maxItem - 1) + 2); for (int i = 1; i <= numbPages ; i++ ) { Excel.Worksheet xlShtSource = (Excel.Worksheet)xlWb.Worksheets["InvoiceTemplate"]; //Excel.Worksheet xlShtSource = xlWb.Worksheets["InvoiceTemplate"]; xlShtSource.Copy(System.Type.Missing, xlShtSource); Excel.Worksheet xlSht = (Excel.Worksheet)xlWb.Worksheets["InvoiceTemplate (2)"]; xlSht.Name = InvoiceNo; xlSht.Visible = Microsoft.Office.Interop.Excel.XlSheetVisibility.xlSheetVisible; xlSht.Cells[15, 15] = SalseOrder.OrderNo; xlSht.Cells[12, 6] = SalseOrder.Customer.Name; xlSht.Cells[13, 6] = SalseOrder.Customer.Add1; xlSht.Cells[14, 6] = SalseOrder.Customer.Add2; xlSht.Cells[15, 6] = SalseOrder.Customer.Add3; int lineNo, itemStart, itemEnd; lineNo = 18; itemStart = ((i - 1) * (maxItem - 1)) + 1; if (i == numbPages) itemEnd = numbItems; else itemEnd = i * 21; for (int j = itemStart; j <= itemEnd; j++) { ShipmentGroup sGroup = dictShipmentGroup.ElementAt(j - 1).Value; xlSht.Cells[lineNo, 4] = j; xlSht.Cells[lineNo, 5] = sGroup.Qty; xlSht.Cells[lineNo, 8] = sGroup.CustomerItemNo + " (" + sGroup.Item.ItemName + ")"; xlSht.Cells[lineNo, 21] = sGroup.Item.ItemType.ItemTypeName; xlSht.Cells[lineNo, 22] = sGroup.Item.Material.Name; xlSht.Cells[lineNo, 23] = sGroup.Item.ItemNo; xlSht.Cells[lineNo, 15] = sGroup.Price.ToString("#.###"); totalAmt = totalAmt + sGroup.Amt; lineNo++; } xlSht.Cells[13, 15] = DateTime.Today; if (numbPages == 1) { xlSht.Cells[12, 15] = InvoiceNo; xlSht.Cells[41, 17] = totalAmt; UDFunction udFunction = new UDFunction(); //string a = string.Format("HONG KONG DOLLARS {0} ONLY. *******", udFunction.NumberToEnglish(totalAmt)); //string b = udFunction.NumberToEnglish(totalAmt); xlSht.Cells[41, 5] = string.Format("HONG KONG DOLLARS {0} ONLY. *******", udFunction.NumberToEnglish(totalAmt)); } else { xlSht.Cells[12, 15] = string.Format("{0} (Page {1} of {2})", InvoiceNo, i, numbPages); if (numbPages == 1) { xlSht.Cells[41, 17] = totalAmt; } else { xlSht.Cells[39, 8] = string.Format("( Continue on Page {0})", i + 1); xlSht.Cells[41, 17] = "'---------"; } } } }
private void btnPrintLabel_Click(object sender, EventArgs e) { if (float.Parse(txtTotalWHQty.Text) > 0) { lblSSLabel lblSSLabel = new lblSSLabel(); SSLabel ssLabel = new SSLabel(); ArrayList ssLabelList = new ArrayList(); ssLabel.Inspector = "Inspector111"; ssLabel.IrNo = "IR000001"; ssLabel.ProdOrder = ProdRoute.ProdOrder; ssLabelList.Add(ssLabel); lblSSLabel.DataSource = ssLabelList; lblSSLabel.ShowPreview(); } if (float.Parse(txtTotalPOQty.Text) > 0) { lblCebuLabel lblCebuLabel = new lblCebuLabel(); Dictionary<string, float> dictSoQty = new Dictionary<string, float>(); foreach (SoGrid sogrid in soList) { if (dictSoQty.ContainsKey(sogrid.SalesOrderNo)) dictSoQty[sogrid.SalesOrderNo] = dictSoQty[sogrid.SalesOrderNo] + sogrid.IssueQty; else dictSoQty.Add(sogrid.SalesOrderNo, sogrid.IssueQty); } ArrayList cbLabelList = new ArrayList(); float boxQty = float.Parse(txtBoxQty.Text); UDFunction udfunction = new UDFunction(); foreach (KeyValuePair<string, float> kvp in dictSoQty) { int totalPrint = udfunction.Fix(kvp.Value / boxQty); float balQty = kvp.Value - (boxQty * totalPrint); for (int i = 0; i < totalPrint; i++) { CebuLabel cbLabel = new CebuLabel(); cbLabel.Item = ProdRoute.Item; cbLabel.IrNo = "IRno"; cbLabel.Inspector = "Inspector"; cbLabel.Qty = boxQty; cbLabelList.Add(cbLabel); } if (balQty > 0) { CebuLabel cbLabel = new CebuLabel(); cbLabel.Item = ProdRoute.Item; cbLabel.IrNo = "IRno"; cbLabel.Inspector = "Inspector"; cbLabel.Qty = balQty; cbLabelList.Add(cbLabel); } } lblCebuLabel.DataSource = cbLabelList; lblCebuLabel.ShowPreview(); } }