string printLabForHtmlByTable(string modelheadfile, string modelcontentfile) { string fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".html"; #region //获取模板文件内容 string strurlfile = HttpContext.Current.Server.MapPath("~/Model/" + modelheadfile + ".html"); StringBuilder htmltext = new StringBuilder(FileOper.getFileContent(strurlfile)); //string sql = "select * from ProduceOrderDetail a,ProduceOrderHeader b, bomdetail c,bomheader d where c.itemno=a.itemno and c.fsn=d.sn and d.orderno=b.saleorderno and a.fsn=b.sn and a.proorderno='" + Grid1.Rows[Grid1.SelectedRowIndex].Values[2].ToString() + "' and b.proorderno='" + Grid1.Rows[Grid1.SelectedRowIndex].Values[2].ToString() + "'"; string sql = " select a.SaleOrderNo,a.ProNo,a.ProName, a.SendOutOrderNo,a.remark,a.itemno,a.itemname,a.spec,a.quantity,a.unit,c.material,c.surfacedeal,c.storehouse,BarCode from SendOutProcessDetail a join SendOutProcessHeader b on b.SN=a.FSN LEFT JOIN BomDetail c on a.bomsn = c.SN where a.fsn = " + Grid1.DataKeys[Grid1.SelectedRowIndex][0].ToString() + ""; //Alert.Show(sql); //return ""; SQLHelper.DbHelperSQL.SetConnectionString(""); DataTable dt = SQLHelper.DbHelperSQL.ReturnDataTable(sql, 30); int pagecount = dt.Rows.Count; int labcount = int.Parse(numLabCount.Text); htmltext.Replace("$pagecount", "张数:" + (pagecount * labcount).ToString()); FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/pdf/" + fname), FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(htmltext.ToString()); //获取模板内容 StringBuilder htmlcontent = new StringBuilder(FileOper.getFileContent(HttpContext.Current.Server.MapPath("~/Model/" + modelcontentfile + ".html"))); #endregion try { #region 将模板内容循环添加PDF中 int pageindex = 1; for (int k = 0; k < labcount; k++) { // 添加文档内容 for (int i = 0; i < pagecount; i++) { htmltext.Clear(); if (pageindex != 1) { htmltext.Append("<div class='page'><br></div>"); } htmltext.Append(htmlcontent.ToString()); #region //替换模板内容 htmltext.Replace("$orderno", dt.Rows[i]["saleorderno"].ToString()); htmltext.Replace("$SendOutOrderNo", dt.Rows[i]["SendOutOrderNo"].ToString()); htmltext.Replace("$proname", dt.Rows[i]["proname"].ToString()); htmltext.Replace("$prono", dt.Rows[i]["prono"].ToString()); htmltext.Replace("$itemno", dt.Rows[i]["itemno"].ToString()); htmltext.Replace("$itemname", dt.Rows[i]["itemname"].ToString()); htmltext.Replace("$spec", dt.Rows[i]["spec"].ToString()); htmltext.Replace("$material", dt.Rows[i]["material"].ToString()); htmltext.Replace("$codevalue", dt.Rows[i]["BarCode"].ToString()); //IDAutomation.NetAssembly.FontEncoder fe = new IDAutomation.NetAssembly.FontEncoder(); //htmltext.Replace("$code", fe.Code128(dt.Rows[i]["BarCode"].ToString(), 0, false)); //fe = null; System.Threading.Thread.Sleep(5); System.Drawing.Bitmap bitmap = BarcodeHelper.Generate1(dt.Rows[i]["BarCode"].ToString(), 150, 150);// CreateQRCode(str, 200, 5); string s = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string codejpg = HttpContext.Current.Server.MapPath("~/pdf/" + s + ".bmp"); //image.Save(codejpg); bitmap.Save(codejpg); htmltext.Replace("$code", s); #endregion sw.WriteLine(htmltext); pageindex++; } } #endregion sw.WriteLine("</body></html>"); } catch (Exception ee) { Alert.Show(ee.ToString()); } finally { sw.Close(); fs.Close(); } return(fname); }
string printForHtmlByGrid(string modelheadfile, string modelcontentfile) { string fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".html"; #region //获取模板文件内容 string strurlfile = HttpContext.Current.Server.MapPath("~/Model/" + modelheadfile + ".html"); StringBuilder htmltext = new StringBuilder(FileOper.getFileContent(strurlfile)); int pagecount = Grid2.SelectedRowIndexArray.Length; int labcount = int.Parse(numLabCount2.Text); htmltext.Replace("$pagecount", "张数:" + (pagecount * labcount).ToString()); FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/pdf/" + fname), FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(htmltext.ToString()); //获取模板内容 StringBuilder htmlcontent = new StringBuilder(FileOper.getFileContent(HttpContext.Current.Server.MapPath("~/Model/" + modelcontentfile + ".html"))); #endregion try { #region 将模板内容循环添加PDF中 SQLHelper.DbHelperSQL.SetConnectionString(""); string sql = ""; int pageindex = 1; for (int k = 0; k < labcount; k++) { // 添加文档内容 foreach (int i in Grid2.SelectedRowIndexArray) { htmltext.Clear(); if (pageindex != 1) { htmltext.Append("<div class='page'><br></div>"); } htmltext.Append(htmlcontent.ToString()); #region //替换模板内容 htmltext.Replace("$orderno", Grid2.Rows[i].Values[3].ToString()); htmltext.Replace("$SendOutOrderNo", Grid2.Rows[i].Values[2].ToString()); htmltext.Replace("$proname", Grid2.Rows[i].Values[5].ToString()); htmltext.Replace("$prono", Grid2.Rows[i].Values[4].ToString()); htmltext.Replace("$itemno", Grid2.Rows[i].Values[6].ToString()); htmltext.Replace("$itemname", Grid2.Rows[i].Values[7].ToString()); htmltext.Replace("$spec", Grid2.Rows[i].Values[8].ToString()); sql = "select material from bomdetail c,bomheader d where c.fsn=d.sn and c.itemno='" + Grid2.Rows[i].Values[6].ToString() + "' and d.prono='" + Grid2.Rows[i].Values[4].ToString() + "' and d.orderno='" + Grid2.Rows[i].Values[3].ToString() + "'"; htmltext.Replace("$material", SQLHelper.DbHelperSQL.GetSingle(sql, 30)); sql = "select surfacedeal from bomdetail c,bomheader d where c.fsn=d.sn and c.itemno='" + Grid2.Rows[i].Values[6].ToString() + "' and d.prono='" + Grid2.Rows[i].Values[4].ToString() + "' and d.orderno='" + Grid2.Rows[i].Values[3].ToString() + "'"; htmltext.Replace("$codevalue", Grid2.Rows[i].Values[11].ToString()); //IDAutomation.NetAssembly.FontEncoder fe = new IDAutomation.NetAssembly.FontEncoder(); //htmltext.Replace("$code", fe.Code128(Grid2.Rows[i].Values[2].ToString(), 0, false)); //fe = null; System.Threading.Thread.Sleep(5); System.Drawing.Bitmap bitmap = BarcodeHelper.Generate1(Grid2.Rows[i].Values[11].ToString(), 150, 150);// CreateQRCode(str, 200, 5); string s = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string codejpg = HttpContext.Current.Server.MapPath("~/pdf/" + s + ".bmp"); //image.Save(codejpg); bitmap.Save(codejpg); htmltext.Replace("$code", s); #endregion sw.WriteLine(htmltext); pageindex++; } } #endregion sw.WriteLine("</body></html>"); } catch (Exception ee) { Alert.Show(ee.ToString()); } finally { sw.Close(); fs.Close(); } return(fname); }
string printOrderForHtmlBySQL(string printsetfile, string htmlheadfile, string htmlcontentfile, string htmlfootfile) { string fname = DateTime.Now.ToString("yyyyMMddHHmmssffff") + ".html"; #region //获取模板文件内容 StringBuilder printsettext = new StringBuilder(FileOper.getFileContent(HttpContext.Current.Server.MapPath("~/Model/" + printsetfile + ".html"))); //int pagecount = Grid2.SelectedRowIndexArray.Length; //int labcount = int.Parse(numLabCount2.Text); printsettext.Replace("$pagecount", ""); FileStream fs = new FileStream(HttpContext.Current.Server.MapPath("~/pdf/" + fname), FileMode.Append); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(printsettext.ToString()); //获取模板内容 StringBuilder htmlheadtext = new StringBuilder(FileOper.getFileContent(HttpContext.Current.Server.MapPath("~/Model/" + htmlheadfile + ".html"))); StringBuilder htmlcontenttext = new StringBuilder(FileOper.getFileContent(HttpContext.Current.Server.MapPath("~/Model/" + htmlcontentfile + ".html"))); StringBuilder htmlfoottext = new StringBuilder(FileOper.getFileContent(HttpContext.Current.Server.MapPath("~/Model/" + htmlfootfile + ".html"))); #endregion try { #region 将模板内容循环添加PDF中 SQLHelper.DbHelperSQL.SetConnectionString(""); int pageindex = 1; //替换头部 string sql = "select * from CPOrderHeader where sn=" + Grid1.DataKeys[Grid1.SelectedRowIndex][0].ToString(); SQLHelper.DbHelperSQL.SetConnectionString(""); DataTable dt = SQLHelper.DbHelperSQL.ReturnDataTable(sql, 30); if (dt != null && dt.Rows.Count > 0) { //IDAutomation.NetAssembly.FontEncoder fe = new IDAutomation.NetAssembly.FontEncoder(); //htmlheadtext.Replace("$code$", fe.Code128(dt.Rows[0]["CPOrderNo"].ToString(), 0, false)); //fe = null; System.Threading.Thread.Sleep(5); System.Drawing.Bitmap bitmap = BarcodeHelper.Generate1(dt.Rows[0]["CPOrderNo"].ToString(), 150, 150);// CreateQRCode(str, 200, 5); string s = DateTime.Now.ToString("yyyyMMddHHmmssffff"); string codejpg = HttpContext.Current.Server.MapPath("~/pdf/" + s + ".bmp"); bitmap.Save(codejpg); htmlheadtext.Replace("$code$", s); htmlheadtext.Replace("$CPOrderNo$", dt.Rows[0]["CPOrderNo"].ToString()); htmlheadtext.Replace("$codevalue$", dt.Rows[0]["CPOrderNo"].ToString()); htmlheadtext.Replace("$CPDate$", DateTime.Parse(dt.Rows[0]["CPDate"].ToString()).ToString("yyyy-MM-dd")); htmlheadtext.Replace("$Provider$", dt.Rows[0]["Provider"].ToString()); htmlheadtext.Replace("$JBRName$", dt.Rows[0]["JBRName"].ToString()); htmlheadtext.Replace("$ContactMan$", dt.Rows[0]["ContactMan"].ToString()); htmlheadtext.Replace("$Tel$", dt.Rows[0]["Tel"].ToString()); htmlheadtext.Replace("$Fax$", dt.Rows[0]["Fax"].ToString()); htmlfoottext.Replace("$JHDate$", DateTime.Parse(dt.Rows[0]["JHDate"].ToString()).ToString("yyyy-MM-dd")); htmlfoottext.Replace("$JHPlace$", dt.Rows[0]["JHPlace"].ToString()); } sw.WriteLine(htmlheadtext); StringBuilder str = new StringBuilder(); string itemrows = ""; float sum = 0; //for (int k = 0; k < labcount; k++) //{ str.Clear(); if (pageindex != 1) { str.Append("<div class='page'><br></div>"); } str.Append(htmlcontenttext.ToString()); sql = "select * from dbo.CPOrderDetail where fsn=" + dt.Rows[0]["SN"].ToString(); dt = SQLHelper.DbHelperSQL.ReturnDataTable(sql, 30); // 添加文档内容 for (int i = 0; i < dt.Rows.Count; i++) { itemrows += "<tr><td class='b_b_r' style='padding:10px;'>" + (i + 1).ToString().PadLeft(3 - (i + 1).ToString().Length, '0') + "</td><td class='b_b_r'>" + dt.Rows[i]["itemno"].ToString() + "</td><td class='b_b_r'>" + dt.Rows[i]["itemname"].ToString() + "</td><td class='b_b_r'>" + dt.Rows[i]["spec"].ToString() + "</td><td class='b_b_r'>" + dt.Rows[i]["unit"].ToString() + "</td><td class='b_b_r'>" + dt.Rows[i]["quantity"].ToString() + "</td><td class='b_b'>" + dt.Rows[i]["remark"].ToString() + "</td></tr>"; sum += float.Parse(dt.Rows[i]["quantity"].ToString()); } itemrows += "<tr><td class='b_r' style='padding:10px;' colspan='5'>合计:</td><td class='b_r'>" + sum.ToString() + "</td><td class=''></td></tr>"; str.Replace("$items", itemrows); sw.WriteLine(str); pageindex++; //} #endregion sw.WriteLine(htmlfoottext.ToString()); sw.WriteLine(" </div></body></html>"); } catch (Exception ee) { Alert.Show(ee.ToString()); } finally { sw.Close(); fs.Close(); } return(fname); }