protected void btnProfitReport_Click(object sender, EventArgs e) { string sDate = Request.Form[txtStartDate.ID].Trim(); string eDate = Request.Form[txtEndDate.ID].Trim(); DateTime startDate = new DateTime(); if (string.IsNullOrEmpty(sDate)) { startDate = minTime; } else { startDate = DateTime.Parse(sDate); } DateTime endDate = new DateTime(); if (string.IsNullOrEmpty(eDate)) { endDate = minTime; } else { endDate = DateTime.Parse(eDate); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); } string carrierEncode = ddlCarrier.SelectedItem.Value; string strCompanyId = ddlCompany.SelectedItem.Value; string strCompanyName = ddlCompany.SelectedItem.Text; string strCarrierEncode = ddlCarrier.SelectedItem.Value; string strUserId = "0"; if (ddlCompany.SelectedItem.Value != "0") { strUserId = ddlCompanyUsers.SelectedItem.Value; } int clientId = 0; string clientName = Request.Form[txtClientName.ID].Trim(); if (!string.IsNullOrEmpty(clientName)) { Client client = ClientOperation.GetClientByRealName(clientName); if (client != null) { clientId = client.Id; } else { clientId = 0; } } else { clientId = -1; } int companyId = 0; if (!int.TryParse(strCompanyId, out companyId)) { companyId = 0; } int userId = 0; if (!int.TryParse(strUserId, out userId)) { userId = 0; } List<SearchOrderDetail> result = OrderOperation.GetReceiveOrderDetailStatistic(startDate, endDate, companyId, clientId, carrierEncode, userId); string fileName = StringHelper.GetEncodeNumber("LR"); string titleContent = ""; if (ddlCompany.SelectedItem.Value != "0") { titleContent = "所属公司:" + strCompanyName + " "; } if (startDate > minTime) { titleContent += "开始日期:" + startDate.ToShortDateString() + " "; } if (endDate > minTime) { titleContent += "结束日期:" + endDate.ToShortDateString() + " "; } if (ddlReportType.SelectedItem.Value == "1") { string filePath = Server.MapPath("../../Config/"); string[] fileArray = Directory.GetFiles(filePath, "*.pdf"); foreach (string file in fileArray) { File.Delete(file); } Document document = new Document(PageSize.A4, 15, 15, 10, 10); try { PdfWriter.getInstance(document, new FileStream(filePath + fileName + ".pdf", FileMode.Create)); document.Header = PdfHelper.GetHeardFooter("亿度物流", SettingOperation.LoadSetting().Phone); document.Open(); Paragraph phTitle = new Paragraph(new Chunk("利润分析表", PdfHelper.fontTitle)); phTitle.Alignment = Element.ALIGN_CENTER; Paragraph phTitle2 = new Paragraph(new Chunk(titleContent, PdfHelper.fontHeader)); phTitle2.Alignment = Element.ALIGN_LEFT; document.Add(phTitle); document.Add(phTitle2); iTextSharp.text.Table tblContent = new iTextSharp.text.Table(12); tblContent.setWidths(new int[] { 15, 10, 8, 8, 8 , 8, 9, 7, 7, 7, 7, 11 }); tblContent.WidthPercentage = 99; tblContent.Border = 0; tblContent.Cellpadding = 1; tblContent.Cellspacing = 1; tblContent.addCell(PdfHelper.GetTitleCellLeft("收件单号")); tblContent.addCell(PdfHelper.GetTitleCellLeft("收件日期")); tblContent.addCell(PdfHelper.GetTitleCellLeft("客户姓名")); tblContent.addCell(PdfHelper.GetTitleCellLeft("业务员")); tblContent.addCell(PdfHelper.GetTitleCellLeft("承运商")); tblContent.addCell(PdfHelper.GetTitleCellLeft("单号")); tblContent.addCell(PdfHelper.GetTitleCellLeft("国家")); tblContent.addCell(PdfHelper.GetTitleCellRight("重量")); tblContent.addCell(PdfHelper.GetTitleCellRight("数量")); tblContent.addCell(PdfHelper.GetTitleCellRight("收入")); tblContent.addCell(PdfHelper.GetTitleCellRight("成本")); tblContent.addCell(PdfHelper.GetTitleCellRight("利润金额")); int totalCount = 0; decimal totalIncome = 0; decimal totalCost = 0; decimal totalProfit = 0; foreach (SearchOrderDetail sod in result) { tblContent.addCell(PdfHelper.GetCellLeft(sod.OrderEncode)); tblContent.addCell(PdfHelper.GetCellLeft(OrderOperation.GetOrderByEncode(sod.OrderEncode).ReceiveDate.ToShortDateString())); tblContent.addCell(PdfHelper.GetCellLeft(sod.Client.RealName)); tblContent.addCell(PdfHelper.GetCellLeft(UserOperation.GetUserById(OrderOperation.GetOrderByEncode(sod.OrderEncode).UserId).RealName)); tblContent.addCell(PdfHelper.GetCellLeft(sod.CarrierEncode)); tblContent.addCell(PdfHelper.GetCellLeft(sod.BarCode)); tblContent.addCell(PdfHelper.GetCellLeft(sod.ToCountry)); tblContent.addCell(PdfHelper.GetCellRight(sod.Weight.ToString())); tblContent.addCell(PdfHelper.GetCellRight(sod.Count.ToString())); tblContent.addCell(PdfHelper.GetCellRight(sod.TotalCosts.ToString())); tblContent.addCell(PdfHelper.GetCellRight(sod.SelfTotalCosts.ToString())); tblContent.addCell(PdfHelper.GetCellRight((sod.TotalCosts - sod.SelfTotalCosts).ToString())); totalCount += sod.Count; totalIncome += sod.TotalCosts; totalCost += sod.SelfTotalCosts; totalProfit += (sod.TotalCosts - sod.SelfTotalCosts); } tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("总计:")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellRight(totalCount.ToString())); tblContent.addCell(PdfHelper.GetFooterCellRight(totalIncome.ToString())); tblContent.addCell(PdfHelper.GetFooterCellRight(totalCost.ToString())); tblContent.addCell(PdfHelper.GetFooterCellRight(totalProfit.ToString())); document.Add(tblContent); document.resetHeader(); } catch (Exception ex) { lblMsg.Text = "生成PDF文件出错," + ex.ToString(); } finally { document.Close(); } Response.Redirect("/Config/" + fileName + ".pdf"); } else { Response.Clear(); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Write("<table border='1'>"); Response.Write("<tr style='font-size:16px;font-weight:bold;height:35px;'><td align='center' valign='middle' colspan='12'>利润分析表</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left' colspan='12'> "+titleContent+"</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left'> 收件单号</td><td align='left'> 收件日期</td><td align='left'> 客户姓名</td><td align='left'> 业务员</td><td align='left'> 承运商</td><td align='left'> 单号</td><td align='left'> 国家</td><td align='right'> 重量</td><td align='right'> 数量</td><td align='right'> 收入</td><td align='right'> 成本</td><td align='right'> 利润金额</td></tr>"); int totalCount = 0; decimal totalIncome = 0; decimal totalCost = 0; decimal totalProfit = 0; foreach (SearchOrderDetail sod in result) { Response.Write("<tr>"); Response.Write("<td align='left'> " + sod.OrderEncode + "</td>"); Response.Write("<td align='left'> " + OrderOperation.GetOrderByEncode(sod.OrderEncode).ReceiveDate.ToShortDateString() + "</td>"); Response.Write("<td align='left'> " + sod.Client.RealName + "</td>"); Response.Write("<td align='left'> " + UserOperation.GetUserById(OrderOperation.GetOrderByEncode(sod.OrderEncode).UserId).RealName + "</td>"); Response.Write("<td align='left'> " + sod.CarrierEncode + "</td>"); Response.Write("<td align='left'>" + sod.BarCode + "</td>"); Response.Write("<td align='left'>" + sod.ToCountry + "</td>"); Response.Write("<td align='right'>" + sod.Weight.ToString() + "</td>"); Response.Write("<td align='right'>" + sod.Count.ToString() + "</td>"); Response.Write("<td align='right'>" + sod.TotalCosts.ToString() + "</td>"); Response.Write("<td align='right'>" + sod.SelfTotalCosts.ToString() + "</td>"); Response.Write("<td align='right'>" + (sod.TotalCosts - sod.SelfTotalCosts).ToString() + "</td>"); Response.Write("</tr>"); totalCount += sod.Count; totalIncome += sod.TotalCosts; totalCost += sod.SelfTotalCosts; totalProfit += (sod.TotalCosts - sod.SelfTotalCosts); } Response.Write("<tr style='font-weight:bold;'><td align='left'> 合计:</td><td colspan='7'> </td><td align='right'>" + totalCount.ToString() + "</td><td align='right'>" + totalIncome.ToString() + "</td><td align='right'>" + totalCost.ToString() + "</td><td align='right'>" + totalProfit.ToString() + "</td></tr>"); Response.Write("</table>"); Response.Flush(); Response.End(); } }
protected void btnUserReport_Click(object sender, EventArgs e) { string sDate = Request.Form[txtStartDate.ID].Trim(); string eDate = Request.Form[txtEndDate.ID].Trim(); DateTime startDate = new DateTime(); if (string.IsNullOrEmpty(sDate)) { startDate = minTime; } else { startDate = DateTime.Parse(sDate); } DateTime endDate = new DateTime(); if (string.IsNullOrEmpty(eDate)) { endDate = minTime; } else { endDate = DateTime.Parse(eDate); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); } string carrierEncode = ddlCarrier.SelectedItem.Value; string strCompanyId = ddlCompany.SelectedItem.Value; string strCompanyName = ddlCompany.SelectedItem.Text; string strCarrierEncode = ddlCarrier.SelectedItem.Value; string strUserId = "0"; if (ddlCompany.SelectedItem.Value != "0") { strUserId = ddlCompanyUsers.SelectedItem.Value; } int clientId = 0; string clientName = Request.Form[txtClientName.ID].Trim(); if (!string.IsNullOrEmpty(clientName)) { Client client = ClientOperation.GetClientByRealName(clientName); if (client != null) { clientId = client.Id; } else { clientId = 0; } } else { clientId = -1; } int companyId = 0; if (!int.TryParse(strCompanyId, out companyId)) { companyId = 0; } int userId = 0; if (!int.TryParse(strUserId, out userId)) { userId = 0; } List<UserSales> result = StatisticOperation.GetUserAssessStatistic(startDate, endDate, companyId, clientId, carrierEncode, userId); string fileName = StringHelper.GetEncodeNumber("KH"); string titleContent = ""; if (ddlCompany.SelectedItem.Value != "0") { titleContent = "所属公司:" + strCompanyName + " "; } if (startDate > minTime) { titleContent += "开始日期:" + startDate.ToShortDateString() + " "; } if (endDate > minTime) { titleContent += "结束日期:" + endDate.ToShortDateString() + " "; } if (ddlReportType.SelectedItem.Value == "1") { string filePath = Server.MapPath("../../Config/"); string[] fileArray = Directory.GetFiles(filePath, "*.pdf"); foreach (string file in fileArray) { File.Delete(file); } Document document = new Document(PageSize.A4, 15, 15, 10, 10); try { PdfWriter.getInstance(document, new FileStream(filePath + fileName + ".pdf", FileMode.Create)); document.Header = PdfHelper.GetHeardFooter("亿度物流", SettingOperation.LoadSetting().Phone); document.Open(); Paragraph phTitle = new Paragraph(new Chunk("业务员考核表", PdfHelper.fontTitle)); phTitle.Alignment = Element.ALIGN_CENTER; Paragraph phTitle2 = new Paragraph(new Chunk(titleContent, PdfHelper.fontHeader)); phTitle2.Alignment = Element.ALIGN_LEFT; document.Add(phTitle); document.Add(phTitle2); iTextSharp.text.Table tblContent = new iTextSharp.text.Table(4); tblContent.setWidths(new int[] { 30, 30, 20, 20 }); tblContent.WidthPercentage = 99; tblContent.Border = 0; tblContent.Cellpadding = 1; tblContent.Cellspacing = 1; tblContent.addCell(PdfHelper.GetTitleCellLeft("所属公司")); tblContent.addCell(PdfHelper.GetTitleCellLeft("所属部门")); tblContent.addCell(PdfHelper.GetTitleCellLeft("业务员")); tblContent.addCell(PdfHelper.GetTitleCellRight("金额")); decimal totalMoney = 0; foreach (UserSales us in result) { tblContent.addCell(PdfHelper.GetCellLeft(CompanyOperation.GetCompanyById(us.User.CompanyId).Name)); tblContent.addCell(PdfHelper.GetCellLeft(DepartmentOperation.GetDepartmentById(us.User.DepartmentId).Name)); tblContent.addCell(PdfHelper.GetCellLeft(us.User.RealName)); tblContent.addCell(PdfHelper.GetCellRight(us.Money.ToString())); totalMoney += us.Money; } tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetCellLeft("")); tblContent.addCell(PdfHelper.GetFooterCellLeft("合计:")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight(totalMoney.ToString())); document.Add(tblContent); document.resetHeader(); } catch (Exception ex) { lblMsg.Text = "生成PDF文件出错," + ex.ToString(); } finally { document.Close(); } Response.Redirect("/Config/" + fileName + ".pdf"); } else { Response.Clear(); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Write("<table border='1'>"); Response.Write("<tr style='font-size:16px;font-weight:bold;height:35px;'><td align='center' valign='middle' colspan='4'>业务员考核表</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left' colspan='4'> " + titleContent + "</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left'> 所属公司</td><td align='left'> 所属部门</td><td align='left'> 业务员</td><td align='right'> 金额</td></tr>"); decimal totalMoney = 0; foreach (UserSales us in result) { Response.Write("<tr>"); Response.Write("<td align='left'> " + CompanyOperation.GetCompanyById(us.User.CompanyId).Name + "</td>"); Response.Write("<td align='left'> " + DepartmentOperation.GetDepartmentById(us.User.DepartmentId).Name + "</td>"); Response.Write("<td align='left'> " + us.User.RealName + "</td>"); Response.Write("<td align='right'>" + us.Money.ToString() + "</td>"); Response.Write("</tr>"); totalMoney += us.Money; } Response.Write("<tr style='font-weight:bold;'><td align='left'> 合计:</td><td colspan='2'> </td><td align='right'> " + totalMoney.ToString() + "</td></tr>"); Response.Write("</table>"); Response.Flush(); Response.End(); } }
protected void btnArDetailStatistic_Click(object sender, EventArgs e) { string sDate = Request.Form[txtStartDate.ID].Trim(); string eDate = Request.Form[txtEndDate.ID].Trim(); DateTime startDate = new DateTime(); if (string.IsNullOrEmpty(sDate)) { startDate = minTime; } else { startDate = DateTime.Parse(sDate); } DateTime endDate = new DateTime(); if (string.IsNullOrEmpty(eDate)) { endDate = minTime; } else { endDate = DateTime.Parse(eDate); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); } string strCompanyId = ddlCompany.SelectedItem.Value; string strCompanyName = ddlCompany.SelectedItem.Text; string pmIds = Request.Form["chkPaymentMethod"]; string strUserId = "0"; if (ddlCompany.SelectedItem.Value != "0") { strUserId = ddlCompanyUsers.SelectedItem.Value; } int clientId = 0; string clientName = Request.Form[txtClientName.ID].Trim(); if (!string.IsNullOrEmpty(clientName)) { Client client = ClientOperation.GetClientByRealName(clientName); if (client != null) { clientId = client.Id; } else { clientId = 0; } } else { clientId = -1; } int companyId = 0; if (!int.TryParse(strCompanyId, out companyId)) { companyId = 0; } int userId = 0; if (!int.TryParse(strUserId, out userId)) { userId = 0; } List<ClientRecharge> result = StatisticOperation.GetRechargeDetailStatistic(startDate, endDate, companyId, clientId, userId, userId, pmIds); string fileName = StringHelper.GetEncodeNumber("SK"); string titleContent = ""; if (ddlCompany.SelectedItem.Value != "0") { titleContent = "所属公司:" + strCompanyName + " "; } if (startDate > minTime) { titleContent += "开始日期:" + startDate.ToShortDateString() + " "; } if (endDate > minTime) { titleContent += "结束日期:" + endDate.ToShortDateString() + " "; } if (ddlReportType.SelectedItem.Value == "1") { string filePath = Server.MapPath("../../Config/"); string[] fileArray = Directory.GetFiles(filePath, "*.pdf"); foreach (string file in fileArray) { File.Delete(file); } Document document = new Document(PageSize.A4, 15, 15, 10, 10); try { PdfWriter.getInstance(document, new FileStream(filePath + fileName + ".pdf", FileMode.Create)); document.Header = PdfHelper.GetHeardFooter("亿度物流", SettingOperation.LoadSetting().Phone); document.Open(); Paragraph phTitle = new Paragraph(new Chunk("已收款明细", PdfHelper.fontTitle)); phTitle.Alignment = Element.ALIGN_CENTER; Paragraph phTitle2 = new Paragraph(new Chunk(titleContent, PdfHelper.fontHeader)); phTitle2.Alignment = Element.ALIGN_LEFT; document.Add(phTitle); document.Add(phTitle2); iTextSharp.text.Table tblContent = new iTextSharp.text.Table(7); tblContent.setWidths(new int[] { 18, 15, 10, 15, 14, 14, 14 }); tblContent.WidthPercentage = 99; tblContent.Border = 0; tblContent.Cellpadding = 1; tblContent.Cellspacing = 1; tblContent.addCell(PdfHelper.GetTitleCellLeft("所属公司")); tblContent.addCell(PdfHelper.GetTitleCellLeft("收款单号")); tblContent.addCell(PdfHelper.GetTitleCellLeft("收款日期")); tblContent.addCell(PdfHelper.GetTitleCellLeft("发票号码")); tblContent.addCell(PdfHelper.GetTitleCellLeft("付款方式")); tblContent.addCell(PdfHelper.GetTitleCellLeft("经手人")); tblContent.addCell(PdfHelper.GetTitleCellRight("收款金额")); foreach (ClientRecharge cr in result) { Cell cellClientName = new Cell(new Paragraph("客户姓名: " + cr.Client.RealName, PdfHelper.fontContent)); cellClientName.Colspan = 7; cellClientName.HorizontalAlignment = Element.ALIGN_LEFT; cellClientName.VerticalAlignment = Element.ALIGN_MIDDLE; tblContent.addCell(cellClientName); decimal totalMoney = 0; foreach (Recharge recharge in cr.RechargeList) { tblContent.addCell(PdfHelper.GetCellLeft(CompanyOperation.GetCompanyById(recharge.CompanyId).Name)); tblContent.addCell(PdfHelper.GetCellLeft(recharge.Encode)); tblContent.addCell(PdfHelper.GetCellLeft(recharge.ReceiveTime.ToShortDateString())); tblContent.addCell(PdfHelper.GetCellLeft(recharge.Invoice)); tblContent.addCell(PdfHelper.GetCellLeft(recharge.PaymentMethodName)); tblContent.addCell(PdfHelper.GetCellLeft(recharge.UserName)); tblContent.addCell(PdfHelper.GetCellRight(recharge.Money.ToString())); totalMoney += recharge.Money; } tblContent.addCell(PdfHelper.GetFooterCellLeft("合计:")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight("")); tblContent.addCell(PdfHelper.GetFooterCellRight(totalMoney.ToString())); } document.Add(tblContent); document.resetHeader(); } catch (Exception ex) { lblMsg.Text = "生成PDF文件出错," + ex.ToString(); } finally { document.Close(); } Response.Redirect("/Config/" + fileName + ".pdf"); } else { Response.Clear(); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Write("<table border='1'>"); Response.Write("<tr style='font-size:16px;font-weight:bold;height:35px;'><td align='center' valign='middle' colspan='7'>已收款明细</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left' colspan='7'> " + titleContent + "</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left'> 所属公司</td><td align='left'> 收款单号</td><td align='left'> 收款日期</td><td align='left'> 发票号码</td><td align='left'> 付款方式</td><td align='left'> 经手人</td><td align='right'> 收款金额</td></tr>"); foreach (ClientRecharge cr in result) { Response.Write("<tr style='font-weight:bold;'><td align='left' colspan='7'> 客户姓名:" + cr.Client.RealName + "</td></tr>"); decimal totalMoney = 0; foreach (Recharge recharge in cr.RechargeList) { Response.Write("<tr>"); Response.Write("<td align='left'> " + CompanyOperation.GetCompanyById(recharge.CompanyId).Name + "</td>"); Response.Write("<td align='left'> " + recharge.Encode + "</td>"); Response.Write("<td align='left'> " + recharge.ReceiveTime.ToShortDateString() + "</td>"); Response.Write("<td align='left'> " + recharge.Invoice + "</td>"); Response.Write("<td align='left'> " + recharge.PaymentMethodName + "</td>"); Response.Write("<td align='left'> " + recharge.UserName + "</td>"); Response.Write("<td align='right'>" + recharge.Money.ToString() + "</td>"); Response.Write("</tr>"); totalMoney += recharge.Money; } Response.Write("<tr style='font-weight:bold;'><td align='left'> 合计:</td><td colspan='5'> </td><td align='right'>" + totalMoney.ToString() + "</td></tr>"); } Response.Write("</table>"); Response.Flush(); Response.End(); } }
protected void btnClientStatistic_Click(object sender, EventArgs e) { string sDate = Request.Form[txtStartDate.ID].Trim(); string eDate = Request.Form[txtEndDate.ID].Trim(); DateTime startDate = new DateTime(); if (string.IsNullOrEmpty(sDate)) { startDate = minTime; } else { startDate = DateTime.Parse(sDate); } DateTime endDate = new DateTime(); if (string.IsNullOrEmpty(eDate)) { endDate = minTime; } else { endDate = DateTime.Parse(eDate); endDate = new DateTime(endDate.Year, endDate.Month, endDate.Day, 23, 59, 59); } string strCompanyId = ddlCompany.SelectedItem.Value; string strCompanyName = ddlCompany.SelectedItem.Text; int companyId = 0; if (!int.TryParse(strCompanyId, out companyId)) { companyId = 0; } string strUserId = "0"; if (ddlCompany.SelectedItem.Value != "0") { strUserId = ddlCompanyUsers.SelectedItem.Value; } int userId = 0; if (!int.TryParse(strUserId, out userId)) { userId = 0; } List<Client> result = ClientOperation.GetClientStatistic(startDate, endDate, companyId, userId); string fileName = StringHelper.GetEncodeNumber("KH"); string titleContent = ""; if (ddlCompany.SelectedItem.Value != "0") { titleContent = "所属公司:" + strCompanyName + " "; } if (startDate > minTime) { titleContent += "开始日期:" + startDate.ToShortDateString() + " "; } if (endDate > minTime) { titleContent += "结束日期:" + endDate.ToShortDateString() + " "; } if (ddlReportType.SelectedItem.Value == "1") { string filePath = Server.MapPath("../../Config/"); string[] fileArray = Directory.GetFiles(filePath, "*.pdf"); foreach (string file in fileArray) { File.Delete(file); } Document document = new Document(PageSize.A4, 15, 15, 10, 10); try { PdfWriter.getInstance(document, new FileStream(filePath + fileName + ".pdf", FileMode.Create)); document.Header = PdfHelper.GetHeardFooter("亿度物流", SettingOperation.LoadSetting().Phone); document.Open(); Paragraph phTitle = new Paragraph(new Chunk("客户统计表", PdfHelper.fontTitle)); phTitle.Alignment = Element.ALIGN_CENTER; Paragraph phTitle2 = new Paragraph(new Chunk(titleContent, PdfHelper.fontHeader)); phTitle2.Alignment = Element.ALIGN_LEFT; document.Add(phTitle); document.Add(phTitle2); iTextSharp.text.Table tblContent = new iTextSharp.text.Table(8); tblContent.setWidths(new int[] { 13, 8, 13, 15, 15, 16, 10, 10 }); tblContent.WidthPercentage = 99; tblContent.Border = 0; tblContent.Cellpadding = 1; tblContent.Cellspacing = 1; tblContent.addCell(PdfHelper.GetTitleCellLeft("客户姓名")); tblContent.addCell(PdfHelper.GetTitleCellRight("编号")); tblContent.addCell(PdfHelper.GetTitleCellRight("用户名")); tblContent.addCell(PdfHelper.GetTitleCellRight("地区")); tblContent.addCell(PdfHelper.GetTitleCellRight("手机")); tblContent.addCell(PdfHelper.GetTitleCellRight("邮箱")); tblContent.addCell(PdfHelper.GetTitleCellRight("余额")); tblContent.addCell(PdfHelper.GetTitleCellRight("信用额度")); foreach (Client client in result) { tblContent.addCell(PdfHelper.GetCellLeft(client.RealName)); tblContent.addCell(PdfHelper.GetCellRight(client.Id.ToString())); tblContent.addCell(PdfHelper.GetCellRight(client.Username)); tblContent.addCell(PdfHelper.GetCellRight(client.Province + " " + client.City)); tblContent.addCell(PdfHelper.GetCellRight(client.Mobile)); tblContent.addCell(PdfHelper.GetCellRight(client.Email)); tblContent.addCell(PdfHelper.GetCellRight(client.Balance.ToString())); tblContent.addCell(PdfHelper.GetCellRight(client.Credit.ToString())); } document.Add(tblContent); document.resetHeader(); } catch (Exception ex) { lblMsg.Text = "生成PDF文件出错," + ex.ToString(); } finally { document.Close(); } Response.Redirect("/Config/" + fileName + ".pdf"); } else { Response.Clear(); Response.Buffer = true; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileName + ".xls"); Response.ContentEncoding = System.Text.Encoding.UTF8; Response.ContentType = "application/vnd.ms-excel"; Response.Write("<table border='1'>"); Response.Write("<tr style='font-size:16px;font-weight:bold;height:35px;'><td align='center' valign='middle' colspan='8'>客户统计表</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left' colspan='8'> " + titleContent + "</td></tr>"); Response.Write("<tr style='font-weight:bold;'><td align='left'> 客户姓名</td><td align='left'> 编号</td><td align='left'> 用户名</td><td align='left'> 地区</td><td align='left'> 手机</td><td align='left'> 邮箱</td><td align='right'> 余额</td><td align='right'> 信用额度</td></tr>"); foreach (Client client in result) { Response.Write("<tr>"); Response.Write("<td align='left'> " + client.RealName + "</td>"); Response.Write("<td align='left'> " + client.Id.ToString() + "</td>"); Response.Write("<td align='left'> " + client.Username + "</td>"); Response.Write("<td align='left'> " + client.Province + " " + client.City + "</td>"); Response.Write("<td align='left'> " + client.Mobile + "</td>"); Response.Write("<td align='left'> " + client.Email + "</td>"); Response.Write("<td align='right'>" + client.Balance.ToString() + "</td>"); Response.Write("<td align='right'>" + client.Credit.ToString() + "</td>"); Response.Write("</tr>"); } Response.Write("</table>"); Response.Flush(); Response.End(); } }
protected void btnPrintPost_Click(object sender, EventArgs e) { DateTime receiveDate = new DateTime(1999, 1, 1); if (string.IsNullOrEmpty(Request.Form[txtReceivedDate.ID].Trim()) || !DateTime.TryParse(Request.Form[txtReceivedDate.ID].Trim(), out receiveDate)) { lblMsg.Text = "如果货物已经收到请先填写收件日期!"; return; } if (order.CreateUser == null) { order.ReceiveDate = receiveDate; order.UserId = user.Id; order.CreateUser = user; OrderOperation.UpdateOrder(order); } string fileName = StringHelper.GetEncodeNumber("HYD"); string filePath = Server.MapPath("../../Config/"); string[] fileArray = Directory.GetFiles(filePath, "*.pdf"); foreach (string file in fileArray) { File.Delete(file); } Document document = new Document(PageSize.A4, 15, 15, 10, 10); try { Company company = CompanyOperation.GetCompanyById(user.CompanyId); PdfWriter.getInstance(document, new FileStream(filePath + fileName + ".pdf", FileMode.Create)); document.Header = PdfHelper.GetHeardFooter("亿度物流", company.Phone); document.Open(); Paragraph phTitle = new Paragraph(new Chunk("货运单", PdfHelper.fontTitle)); phTitle.Alignment = Element.ALIGN_CENTER; document.Add(phTitle); iTextSharp.text.Table tblTitle = new iTextSharp.text.Table(4); tblTitle.setWidths(new int[] { 15, 35, 15, 35 }); tblTitle.WidthPercentage = 99; tblTitle.Border = 0; tblTitle.Cellpadding = 1; tblTitle.Cellspacing = 1; tblTitle.addCell(PdfHelper.GetCellRight("收件单号:")); tblTitle.addCell(PdfHelper.GetCellLeft(" " + order.Encode)); tblTitle.addCell(PdfHelper.GetCellRight("收件日期:")); tblTitle.addCell(PdfHelper.GetCellLeft(" " + order.ReceiveDate.ToShortDateString())); tblTitle.addCell(PdfHelper.GetCellRight("收件方式:")); tblTitle.addCell(PdfHelper.GetCellLeft(" " + order.ReceiveType)); tblTitle.addCell(PdfHelper.GetCellRight("收件网点:")); tblTitle.addCell(PdfHelper.GetCellLeft(" " + order.CompanyName)); tblTitle.addCell(PdfHelper.GetCellRight("客户姓名:")); tblTitle.addCell(PdfHelper.GetCellLeft(" " + order.Client.RealName)); tblTitle.addCell(PdfHelper.GetCellRight("业 务 员:")); tblTitle.addCell(PdfHelper.GetCellLeft(" " + UserOperation.GetUserById(order.UserId).RealName)); tblTitle.addCell(PdfHelper.GetCellRight("备 注:")); Cell bzCellValue = new Cell(new Paragraph(" " + order.Remark, PdfHelper.fontContent)); bzCellValue.Colspan = 3; bzCellValue.HorizontalAlignment = Element.ALIGN_LEFT; bzCellValue.VerticalAlignment = Element.ALIGN_MIDDLE; tblTitle.addCell(bzCellValue); document.Add(tblTitle); iTextSharp.text.Table tblDetail = new iTextSharp.text.Table(10); tblDetail.setWidths(new int[] { 9, 8, 11, 9, 9, 9, 9, 9, 15, 12 }); tblDetail.WidthPercentage = 99; tblDetail.Border = 0; tblDetail.Cellpadding = 1; tblDetail.Cellspacing = 1; tblDetail.addCell(PdfHelper.GetCellLeft("承运商")); tblDetail.addCell(PdfHelper.GetCellLeft("数量")); tblDetail.addCell(PdfHelper.GetCellLeft("包裹重量")); tblDetail.addCell(PdfHelper.GetCellLeft("挂号费")); tblDetail.addCell(PdfHelper.GetCellLeft("取件费")); tblDetail.addCell(PdfHelper.GetCellLeft("材料费")); tblDetail.addCell(PdfHelper.GetCellLeft("保价费")); tblDetail.addCell(PdfHelper.GetCellLeft("其它费")); tblDetail.addCell(PdfHelper.GetCellLeft("条形码")); tblDetail.addCell(PdfHelper.GetCellRight("应收合计")); foreach (OrderDetail od in result) { tblDetail.addCell(PdfHelper.GetCellLeft(" " + od.CarrierEncode)); tblDetail.addCell(PdfHelper.GetCellLeft(" " + od.Count.ToString())); tblDetail.addCell(PdfHelper.GetCellLeft(" " + StringHelper.CurtNumber(od.Weight.ToString()))); tblDetail.addCell(PdfHelper.GetCellLeft(" " + StringHelper.CurtNumber(od.RegisterCosts.ToString()))); tblDetail.addCell(PdfHelper.GetCellLeft(" " + StringHelper.CurtNumber(od.FetchCosts.ToString()))); tblDetail.addCell(PdfHelper.GetCellLeft(" " + StringHelper.CurtNumber(od.MaterialCosts.ToString()))); tblDetail.addCell(PdfHelper.GetCellLeft(" " + StringHelper.CurtNumber(od.InsureCosts.ToString()))); tblDetail.addCell(PdfHelper.GetCellLeft(" " + StringHelper.CurtNumber(od.OtherCosts.ToString()))); tblDetail.addCell(PdfHelper.GetCellLeft(" " + od.BarCode)); tblDetail.addCell(PdfHelper.GetCellRight(" " + StringHelper.CurtNumber(od.TotalCosts.ToString()))); } document.Add(tblDetail); Paragraph phTotal = new Paragraph(new Chunk("总计:", PdfHelper.fontHeader)); phTotal.Add(new Chunk(" " + order.Costs.ToString() + "元", PdfHelper.fontHeader)); phTotal.Alignment = Element.ALIGN_RIGHT; document.Add(phTotal); document.Add(PdfHelper.phMaxSpace); Paragraph phTip1 = new Paragraph(new Chunk(" 请仔细核对货运单的内容,如有疑问及时与我们联系。", PdfHelper.fontContent)); phTip1.Alignment = Element.ALIGN_LEFT; document.Add(phTip1); Paragraph phTip2 = new Paragraph(new Chunk(" 您的签名意味着您认可了货运单的内容并理解接收了我们的货运条款。", PdfHelper.fontContent)); phTip2.Alignment = Element.ALIGN_LEFT; document.Add(phTip2); int spaceCount = 25; for (int i = 0; i < (spaceCount - result.Count); i++) { document.Add(PdfHelper.phMaxSpace); } Paragraph phFooter1 = new Paragraph(new Chunk(" 开 单:", PdfHelper.fontContent)); phFooter1.Add(new Chunk(" " + order.CreateUser.RealName + " ", PdfHelper.fontFooter)); phFooter1.Add(new Chunk(" 取件人:", PdfHelper.fontContent)); phFooter1.Add(new Chunk(" ", PdfHelper.fontFooter)); phFooter1.Add(new Chunk(" 客 户:", PdfHelper.fontContent)); phFooter1.Add(new Chunk(" ", PdfHelper.fontFooter)); phFooter1.Alignment = Element.ALIGN_LEFT; document.Add(phFooter1); Paragraph phFooter2 = new Paragraph(new Chunk(" 审 核:", PdfHelper.fontContent)); if (order.AuditUserId != 0) { phFooter2.Add(new Chunk(" " + UserOperation.GetUserById(order.AuditUserId).RealName + " ", PdfHelper.fontFooter)); } else { phFooter2.Add(new Chunk(" ", PdfHelper.fontFooter)); } phFooter2.Add(new Chunk(" 检 验: ", PdfHelper.fontContent)); if (order.CheckUserId != 0) { phFooter2.Add(new Chunk(" " + UserOperation.GetUserById(order.CheckUserId).RealName + " ", PdfHelper.fontFooter)); } else { phFooter2.Add(new Chunk(" ", PdfHelper.fontFooter)); } phFooter2.Add(new Chunk(" 财 务:", PdfHelper.fontContent)); phFooter2.Add(new Chunk(" ", PdfHelper.fontFooter)); phFooter2.Add(new Chunk(" 归 档:", PdfHelper.fontContent)); phFooter2.Add(new Chunk(" ", PdfHelper.fontFooter)); phFooter2.Alignment = Element.ALIGN_LEFT; document.Add(phFooter2); document.resetHeader(); } catch (Exception ex) { lblMsg.Text = "生成PDF文件出错," + ex.ToString(); } finally { document.Close(); } Response.Redirect("/Config/" + fileName + ".pdf"); }