   
//÷tableϲԪǩļע룬ͼƬע
 // ȡWord
    public static byte[] SingleReport(int bID, string code)
    {
        scc.BLL.lulu_ReportBill reportBll = new scc.BLL.lulu_ReportBill();
        scc.BLL.lulu_BusinessBill businessBll = new scc.BLL.lulu_BusinessBill();
        scc.BLL.lulu_BusinessBill_Item itemBll = new scc.BLL.lulu_BusinessBill_Item();
        scc.BLL.scc_user userBll = new scc.BLL.scc_user();

        DataTable dtb = businessBll.GetView_BillList("Bu_Id=" + bID).Tables[0];

        string fileName = "";
        string str2 = "";
        if (dtb.Rows.Count > 0)
        {
           
            fileName = HttpContext.Current.Server.MapPath("~/Template/JSST.doc");
            str2 = HttpContext.Current.Server.MapPath("~/Doc/" + code + ".doc");
            Document doc = new Document(fileName);

            //Wordģϵǩ
            //CustomerAdrress,CustomerName,InSampleDate,OutSampleDate,ReportNo,ReviewUser,SampleName,SampleNumber,
            //SamplePhoto,SampleRemark,table,TestUser,ND

            #region ǩֵ

            Bookmark sampleNumber = doc.Range.Bookmarks["SampleNumber"];
            sampleNumber.Text = dtb.Rows[0]["Bu_Number"].ToString() + dtb.Rows[0]["Bu_NumberUnit"].ToString();

            Bookmark sampleRemark = doc.Range.Bookmarks["SampleRemark"];
            sampleRemark.Text = dtb.Rows[0]["Bu_Remark"].ToString();

            Bookmark adrr = doc.Range.Bookmarks["CustomerAdrress"];
            adrr.Text = dtb.Rows[0]["Bu_TheArea"].ToString();

            Bookmark customerName = doc.Range.Bookmarks["CustomerName"];
            customerName.Text = dtb.Rows[0]["Bu_CustomerName"].ToString();

            Bookmark inSampleDate = doc.Range.Bookmarks["InSampleDate"];
            inSampleDate.Text = dtb.Rows[0]["Bu_InSampleDate"].ToString() != "" ? DateTime.Parse(dtb.Rows[0]["Bu_InSampleDate"].ToString()).ToString("yyyy-MM-dd") : "";

            Bookmark outSampleDate = doc.Range.Bookmarks["OutSampleDate"];
            outSampleDate.Text = DateTime.Now.ToString("yyyy-MM-dd");

            Bookmark reportNo = doc.Range.Bookmarks["ReportNo"];
            reportNo.Text = code;
            
            Bookmark sampleName = doc.Range.Bookmarks["SampleName"];
            sampleName.Text = dtb.Rows[0]["Bu_SampleName"].ToString();

            #endregion

            DocumentBuilder builder = new DocumentBuilder(doc);

            DataTable dtItem = itemBll.GetItemReportList(dtb.Rows[0]["Bu_Id"].ToString()).Tables[0];
            int ItemLen = dtItem.Rows.Count;

            builder.MoveToBookmark("table");
            builder.StartTable();

            #region ͷʼ

            builder.RowFormat.Alignment = Aspose.Words.Tables.RowAlignment.Center;
            builder.CellFormat.Borders.LineStyle = LineStyle.Single;
            builder.CellFormat.Borders.Color = Color.Red;
            builder.Bold = true;

            //Insert some table
            builder.InsertCell();
            builder.Write("(Detection Item)");
            builder.CellFormat.Width = 270;
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//ֱ            
            builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;//ˮƽж     
            
            builder.InsertCell();
            builder.Write("(TestingResults)");
            builder.CellFormat.Width = 105;
            builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  

            builder.InsertCell();
            builder.Write("(LOQ)");
            builder.CellFormat.Width = 100;
            builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  

            builder.InsertCell();
            builder.Write("(Detection Method)");
            builder.CellFormat.Width = 270;
            builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
            builder.EndRow();
            builder.Bold = false;

            #endregion

            string strND = "";
            string strP = "";          
            string userID = "0";
            int tem = 0;
            string tampID = "";

            // ѭtable
            for (int i = 0; i < ItemLen; i++)
            {
                if (tem == 0) { userID = dtItem.Rows[i]["BuI_TestUser"].ToString(); }

                #region ȡ

                string itemName = dtItem.Rows[i]["tName"].ToString() + (dtItem.Rows[i]["tCode"].ToString()!=""?("(" +dtItem.Rows[i]["tCode"].ToString()+ ")").ToString():"").ToString();
                
          
                // if ((dtItem.Rows[i]["BuI_TestResultType"].ToString() == "D") || (dtItem.Rows[i]["BuI_TestResultType"].ToString() == "ND"))
                string result = "";
                string resultType = dtItem.Rows[i]["BuI_TestResultType"].ToString();
                if ((resultType == "") || (resultType == "δ"))
                {
                    if (resultType == "δ") { strND = "ND"; }
                    if (dtItem.Rows[i]["BuI_TestResult"].ToString().IndexOf('<') > -1)
                    {
                        result = "<" + dtItem.Rows[i]["BuI_TestResult"].ToString().Trim(new char[] { '<' });
                    }
                    else
                    {
                        result = dtItem.Rows[i]["BuI_TestResult"].ToString();
                    }
                }
                else
                {
                    if (resultType == "N") { result = resultType + "(N)"; }
                    else if (resultType == P") { result = resultType + "(P)"; }
                    {
                        result = dtItem.Rows[i]["BuI_TestResultType"].ToString();
                    }
                }
                string limited = dtItem.Rows[i]["teLimited"].ToString() + dtItem.Rows[i]["teUnit"].ToString();
                if (limited == "") { limited = "/"; }
                string method = dtItem.Rows[i]["teName"].ToString();
                string ftCode = dtItem.Rows[i]["ftCode"].ToString() != "" ? ("("+dtItem.Rows[i]["ftCode"].ToString()+")").ToString() : "";
                string ftName = dtItem.Rows[i]["ftName"].ToString() + ftCode;
                string fitemId = dtItem.Rows[i]["tItem"].ToString();

                #endregion

                #region ͼ

                //жϵһִвѯ
                if (tampID == "")
                {
                    //ȡ
                    tampID = fitemId;
                    builder.Bold = true;
                    builder.InsertCell();
                    builder.Write(ftName);
                    builder.CellFormat.Width = 475;
                    builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//ֱ   

                    builder.InsertCell();
                    builder.Write(method);
                    builder.CellFormat.Width = 270;
                    builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                    builder.CellFormat.HorizontalMerge = CellMerge.None;
                    builder.CellFormat.VerticalMerge = CellMerge.First;//б붨һʼĵԪ
                    builder.Bold = false;
                    builder.EndRow();

                    //С
                    builder.InsertCell();
                    builder.Write(itemName);
                    builder.CellFormat.Width = 270;
                    builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//ֱ  
                    builder.CellFormat.HorizontalMerge = CellMerge.None;
                    builder.CellFormat.VerticalMerge = CellMerge.None;

                    builder.InsertCell();
                    builder.Write(result);
                    builder.CellFormat.Width = 105;
                    builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                    builder.CellFormat.HorizontalMerge = CellMerge.None;
                    builder.CellFormat.VerticalMerge = CellMerge.None;

                    builder.InsertCell();
                    builder.Write(limited);
                    builder.CellFormat.Width = 100;
                    builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                    builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                    builder.CellFormat.HorizontalMerge = CellMerge.None;
                    builder.CellFormat.VerticalMerge = CellMerge.None;

                    //˵ԪһеԪϲ
                    builder.InsertCell();
                    builder.CellFormat.Width = 270;
                    builder.CellFormat.HorizontalMerge = CellMerge.None;
                    builder.CellFormat.VerticalMerge = CellMerge.Previous;
                    
                    builder.EndRow();
                }
                else
                {
                    //жϲ֮ͬת
                    if (tampID != fitemId)
                    {
                        tampID = fitemId;

                        //ȡ
                        builder.Bold = true;
                        builder.InsertCell();
                        builder.Write(ftName);
                        builder.CellFormat.Width = 475;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;
        
                        builder.InsertCell();               
                        builder.CellFormat.Width = 270;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.First;//б붨һʼĵԪ
                        builder.Write(method);
                        builder.Bold = false;
                        builder.EndRow();
                        
                        //С
                        builder.InsertCell();
                        builder.Write(itemName);
                        builder.CellFormat.Width = 270;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;

                        builder.InsertCell();
                        builder.Write(result);
                        builder.CellFormat.Width = 105;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;

                        builder.InsertCell();
                        builder.Write(limited);
                        builder.CellFormat.Width = 100;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;

                        //˵ԪһеԪϲ
                        builder.InsertCell();
                        builder.CellFormat.Width = 270;
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.Previous;
                        // builder.Write(method);

                        builder.EndRow();

                    }
                    else
                    {
                        //ѭȡС
                        builder.InsertCell();
                        builder.Write(itemName);
                        builder.CellFormat.Width = 270;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Left;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;

                        builder.InsertCell();
                        builder.Write(result);
                        builder.CellFormat.Width = 105;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;

                        builder.InsertCell();
                        builder.Write(limited);
                        builder.CellFormat.Width = 100;
                        builder.CellFormat.VerticalAlignment = Aspose.Words.Tables.CellVerticalAlignment.Center;
                        builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;//ֱ  
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.None;

                        //˵ԪһеԪϲ
                        builder.InsertCell();
                        // builder.Write(method);
                        builder.CellFormat.Width = 270;                
                        builder.CellFormat.HorizontalMerge = CellMerge.None;
                        builder.CellFormat.VerticalMerge = CellMerge.Previous;
                        builder.EndRow();

                    }

                }

                #endregion

            }

            builder.EndTable();

            //NDע͸ֵ
            if (strND != "")
            {
                Bookmark nd = doc.Range.Bookmarks["ND"];
                nd.Text = "aa";
            }

            //Pע͸ֵ
            if (strP != "")
            {
                Bookmark p = doc.Range.Bookmarks["P"];
                p.Text = "bb"";
            }

            //Աǩ
            ///scc.Model.scc_user model = userBll.GetModel(int.Parse(userID));
            string photoUser = "xz.jpg";//dtb.Rows[0]["Bu_AnnexImage"].ToString();
            string urlUser = HttpContext.Current.Server.MapPath("~/Upload/ZP/" + photoUser);
            if (File.Exists(urlUser))
            {
                builder.MoveToBookmark("TestUser");
                builder.InsertImage(urlUser, 145, 45);
            }

            //ͼƬ
            string photoSanple = "pg.jpg";//dtb.Rows[0]["Bu_AnnexImage"].ToString();
            string urlSample = HttpContext.Current.Server.MapPath("~/Upload/SampleImag/" + photoSanple);

            if (File.Exists(urlSample))
            {
                builder.MoveToBookmark("SamplePhoto");
                builder.InsertImage(urlSample, 400, 200);
            }

            doc.Save(str2);

        }

        FileStream stream = new FileInfo(str2).OpenRead();
        byte[] buffer = new byte[stream.Length];
        stream.Read(buffer, 0, Convert.ToInt32(stream.Length));
        stream.Close();
        return buffer;
    }


    //wordPDF
    public static int CreatePDF(string ids) 
    {
        int result = 0;

        scc.BLL.lulu_ReportBill reportBll = new scc.BLL.lulu_ReportBill();

        DataTable dt = reportBll.GetReportCodeList(ids).Tables[0];

        int rows = dt.Rows.Count;

        if (rows > 0)
        {
            try
            {
                for (int i = 0; i < rows; i++)
                {
                    string code = dt.Rows[i]["R_RportCode"].ToString();

                    string docUlr = HttpContext.Current.Server.MapPath("~/Doc/" + code + ".doc");
                    if (File.Exists(docUlr))
                    {
                        string pdfUrl = HttpContext.Current.Server.MapPath("~/DocPDF/" + code + ".pdf");
                        Document doc = new Document(docUlr);

                        //PDFļ
                        doc.Save(pdfUrl);
                        result++;
                    }
                }
            }
            catch { result = 0; }

        }
        else { result = 0; }


        return result;
    }