private IList <modPrintItem> GenerateLabelData() { IList <modPrintItem> list = new List <modPrintItem>(); int t_margin = 5; int l_margin = 5; int RowHeight = 20; string fontname = "宋体"; float fontsize = 8; float fontsize_title = 10; int linewidth = 230; int printlogo = 0; int[] colLeft = { 10, 120, 160, 190 }; FontStyle title_fontstyle = FontStyle.Bold; FontStyle label_fontstyle = FontStyle.Regular; int iTop = t_margin; modPrintItem mod = new modPrintItem(); int iLogoWidth = 0; if (printlogo == 1) { mod = new modPrintItem(); mod.printType = "IMAGE"; mod.PrintImage = Properties.Resources.ICON_16; mod.iLeft = l_margin; mod.iTop = iTop; iLogoWidth = 28; mod.iWidth = iLogoWidth; mod.iHeight = 30; list.Add(mod); iLogoWidth += 2; } mod = new modPrintItem(); mod.printType = "TXT"; mod.PrintText = clsLxms.GetParameterValue("COMPANY_NAME"); mod.iLeft = 40; mod.iTop = iTop; mod.FontName = fontname; mod.FontSize = fontsize_title; mod.LabelFontStyle = title_fontstyle; list.Add(mod); mod = new modPrintItem(); mod.printType = "LINE"; mod.PrintText = ""; mod.iLeft = l_margin + iLogoWidth; iTop += RowHeight + 3; mod.iTop = iTop; mod.iWidth = linewidth - iLogoWidth; mod.FontName = fontname; mod.FontSize = fontsize; list.Add(mod); ///////////////////////////////////////////////////////////////////// string labeltitle = string.Empty; string content = string.Empty; SizeF size = Util.GetSizeF(this.Controls[0], labeltitle, fontname, fontsize); iTop += RowHeight + 3; list.Add(new modPrintItem { printType = "TXT", PrintText = "商品名称", iLeft = colLeft[0], iTop = iTop, FontName = fontname, FontSize = fontsize + 1, LabelFontStyle = FontStyle.Bold }); list.Add(new modPrintItem { printType = "TXT", PrintText = "单价", iLeft = colLeft[1], iTop = iTop, FontName = fontname, FontSize = fontsize + 1, LabelFontStyle = FontStyle.Bold }); list.Add(new modPrintItem { printType = "TXT", PrintText = "数量", iLeft = colLeft[2], iTop = iTop, FontName = fontname, FontSize = fontsize + 1, LabelFontStyle = FontStyle.Bold }); list.Add(new modPrintItem { printType = "TXT", PrintText = "金额", iLeft = colLeft[3] + 5, iTop = iTop, FontName = fontname, FontSize = fontsize + 1, LabelFontStyle = FontStyle.Bold }); ///////////////////////////////////////////////////////////////////// decimal totalAmount = 0; BindingCollection <modSalesShipmentDetail> listDetail = _dal.GetDetail(DBGridHistory.CurrentRow.Cells["ShipId"].Value.ToString(), out Util.emsg); if (listDetail != null && listDetail.Count > 0) { foreach (modSalesShipmentDetail modd in listDetail) { iTop += RowHeight + 3; list.Add(new modPrintItem { printType = "TXT", PrintText = modd.ProductName.Length <= 17 ? modd.ProductName : modd.ProductName.Substring(1, 14) + "...", iLeft = colLeft[0], iTop = iTop, FontName = fontname, FontSize = fontsize, LabelFontStyle = label_fontstyle }); list.Add(new modPrintItem { printType = "TXT", PrintText = modd.Price.ToString(), iLeft = colLeft[1], iTop = iTop, FontName = fontname, FontSize = fontsize, LabelFontStyle = label_fontstyle }); list.Add(new modPrintItem { printType = "TXT", PrintText = modd.Qty.ToString(), iLeft = colLeft[2], iTop = iTop, FontName = fontname, FontSize = fontsize, LabelFontStyle = label_fontstyle }); list.Add(new modPrintItem { printType = "TXT", PrintText = (modd.Price * modd.Qty).ToString(), iLeft = colLeft[3], iTop = iTop, FontName = fontname, FontSize = fontsize, LabelFontStyle = label_fontstyle }); totalAmount += modd.Price * modd.Qty; } } iTop += RowHeight + 3; mod = new modPrintItem(); mod.printType = "LINE"; mod.PrintText = ""; mod.iLeft = l_margin; mod.iTop = iTop; mod.iWidth = linewidth - iLogoWidth; mod.FontName = fontname; mod.FontSize = fontsize; list.Add(mod); iTop += RowHeight + 3; list.Add(new modPrintItem { printType = "TXT", PrintText = "合 计:", iLeft = colLeft[0], iTop = iTop, FontName = fontname, FontSize = fontsize + 1, LabelFontStyle = FontStyle.Bold }); list.Add(new modPrintItem { printType = "TXT", PrintText = totalAmount.ToString(), iLeft = colLeft[1], iTop = iTop, FontName = fontname, FontSize = fontsize + 1, LabelFontStyle = FontStyle.Bold }); _iPaperHeight = 30 + iTop; return(list); }
private void toolExport_Click(object sender, EventArgs e) { if (DBGrid.CurrentRow == null) { return; } frmSingleSelect frm = new frmSingleSelect(); frm.InitData("请选择导出单据类别:", "送货单,购销合同", "送货单", ComboBoxStyle.DropDownList); if (frm.ShowDialog() == DialogResult.OK) { IList <modExcelRangeData> list = new List <modExcelRangeData>(); modSalesShipment mod = (modSalesShipment)DBGrid.CurrentRow.DataBoundItem; BindingCollection <modSalesShipmentDetail> listdetail = _dal.GetDetail(mod.ShipId, out Util.emsg); dalCustomerList dalcust = new dalCustomerList(); modCustomerList modcust = dalcust.GetItem(mod.CustId, out Util.emsg); switch (Util.retValue1) { case "送货单": case "收营单": string company = clsLxms.GetParameterValue("COMPANY_NAME"); switch (company) { case "深圳市蓝图净化用品有限公司": list.Add(new modExcelRangeData("№ " + mod.ShipNo, "H6", "I6")); list.Add(new modExcelRangeData(modcust.FullName, "C7", "E7")); list.Add(new modExcelRangeData(modcust.Tel, "G7", "I7")); list.Add(new modExcelRangeData(modcust.Linkman, "C8", "E8")); list.Add(new modExcelRangeData(modcust.Fax, "G8", "I8")); list.Add(new modExcelRangeData(mod.ShipAddr, "C9", "I9")); list.Add(new modExcelRangeData(mod.CustOrderNo, "A13", "C13")); list.Add(new modExcelRangeData(modcust.PayMethod, "D13", "E13")); dalAdminEmployeeList dalemp = new dalAdminEmployeeList(); modAdminEmployeeList modemp = dalemp.GetItem(mod.SalesMan, out Util.emsg); if (modemp != null) { list.Add(new modExcelRangeData(modemp.EmployeeName, "F13", "F13")); } else { list.Add(new modExcelRangeData(mod.SalesMan, "F13", "F13")); } list.Add(new modExcelRangeData(mod.ShipDate.ToString("yyyy年MM月dd日"), "G13", "G13")); for (int i = 0; i < listdetail.Count; i++) { modSalesShipmentDetail modd = listdetail[i]; string col = (17 + i).ToString().Trim(); list.Add(new modExcelRangeData((i + 1).ToString(), "A" + col, "A" + col)); list.Add(new modExcelRangeData(modd.ProductName, "B" + col, "C" + col)); list.Add(new modExcelRangeData(modd.Specify, "D" + col, "D" + col)); list.Add(new modExcelRangeData(modd.Qty.ToString(), "E" + col, "E" + col)); list.Add(new modExcelRangeData(modd.UnitNo, "F" + col, "F" + col)); list.Add(new modExcelRangeData(modd.Price.ToString("#,##0.00"), "G" + col, "G" + col)); list.Add(new modExcelRangeData((modd.Qty * modd.Price).ToString("#,##0.00"), "H" + col, "H" + col)); list.Add(new modExcelRangeData(modd.Remark, "I" + col, "I" + col)); } clsExport.ExportByTemplate(list, "蓝图送货单", 1, 24, 10, 1); break; default: list.Add(new modExcelRangeData(clsLxms.GetParameterValue("COMPANY_NAME"), "A1", "L1")); list.Add(new modExcelRangeData("TEL:" + clsLxms.GetParameterValue("COMPANY_TEL") + " Fax:" + clsLxms.GetParameterValue("COMPANY_FAX"), "A2", "L2")); list.Add(new modExcelRangeData("公司地址:" + clsLxms.GetParameterValue("COMPANY_ADDR"), "A3", "L3")); if (mod.InvoiceStatus >= 1) { list.Add(new modExcelRangeData("S", "L4", "L4")); } list.Add(new modExcelRangeData(mod.ShipType, "E4", "I5")); list.Add(new modExcelRangeData(mod.CustOrderNo, "C4", "D4")); list.Add(new modExcelRangeData(modcust.FullName, "C5", "D5")); list.Add(new modExcelRangeData(mod.ShipAddr, "C6", "D6")); list.Add(new modExcelRangeData(modcust.Linkman + " " + modcust.Tel, "K4", "K4")); list.Add(new modExcelRangeData(mod.ShipNo, "K5", "K5")); list.Add(new modExcelRangeData(mod.ShipDate.ToString("yyyy年MM月dd日"), "K6", "K6")); list.Add(new modExcelRangeData("合计金额:" + clsMoney.ConvertToMoney(Convert.ToDouble(mod.DetailSum + mod.OtherMny - mod.KillMny)), "A16", "I17")); list.Add(new modExcelRangeData(string.Format("{0:C2}", mod.DetailSum + mod.OtherMny - mod.KillMny), "J16", "K16")); list.Add(new modExcelRangeData("付款方式:" + mod.PayMethod, "J17", "K17")); list.Add(new modExcelRangeData(Util.UserName, "K20", "K20")); for (int i = 0; i < listdetail.Count; i++) { modSalesShipmentDetail modd = listdetail[i]; string col = (8 + i).ToString().Trim(); list.Add(new modExcelRangeData((i + 1).ToString(), "A" + col, "A" + col)); list.Add(new modExcelRangeData(modd.ProductName, "B" + col, "D" + col)); list.Add(new modExcelRangeData(modd.UnitNo, "E" + col, "E" + col)); list.Add(new modExcelRangeData(modd.Qty.ToString(), "F" + col, "G" + col)); list.Add(new modExcelRangeData(string.Format("{0:C2}", modd.Price), "H" + col, "I" + col)); list.Add(new modExcelRangeData(string.Format("{0:C2}", modd.Qty * modd.Price), "J" + col, "J" + col)); list.Add(new modExcelRangeData(modd.Remark, "K" + col, "K" + col)); } clsExport.ExportByTemplate(list, "送货单", 1, 20, 11, 1); break; } break; case "购销合同": list.Add(new modExcelRangeData(modcust.FullName, "B6", "E6")); list.Add(new modExcelRangeData(mod.ShipNo, "I6", "I6")); list.Add(new modExcelRangeData(mod.ShipDate.ToString("yyyy年MM月dd日"), "I7", "I7")); list.Add(new modExcelRangeData("金额大写:" + clsMoney.ConvertToMoney(Convert.ToDouble(mod.DetailSum + mod.OtherMny - mod.KillMny)), "A23", "I23")); list.Add(new modExcelRangeData(string.Format("{0:C2}", mod.DetailSum + mod.OtherMny - mod.KillMny), "H22", "H22")); dalProductList dalpdt = new dalProductList(); for (int i = 0; i < listdetail.Count; i++) { modSalesShipmentDetail modd = listdetail[i]; string col = (10 + i).ToString().Trim(); //list.Add(new modExcelRangeData((i+1).ToString(), "A" + col, "A" + col)); list.Add(new modExcelRangeData(modd.ProductName, "B" + col, "B" + col)); modProductList modpdt = dalpdt.GetItem(modd.ProductId, out Util.emsg); if (modpdt != null) { list.Add(new modExcelRangeData(modpdt.Brand, "C" + col, "C" + col)); } list.Add(new modExcelRangeData(modd.Qty.ToString(), "D" + col, "D" + col)); list.Add(new modExcelRangeData(modd.UnitNo, "E" + col, "E" + col)); list.Add(new modExcelRangeData(string.Format("{0:C2}", modd.Price), "G" + col, "G" + col)); list.Add(new modExcelRangeData(string.Format("{0:C2}", modd.Qty * modd.Price), "H" + col, "H" + col)); list.Add(new modExcelRangeData(modd.Remark, "I" + col, "I" + col)); } clsExport.ExportByTemplate(list, "购销合同", 1, 38, 9, 1); break; } } }