public string GetPrintHeaders()
    {
        TerminalStatus terminal = GobalTools.GetTerminal();
        string         result   = string.Empty;

        result += GobalTools.GetTerminalOrderId(terminal.StorePrefix);
        result += ";" + terminal.StoreNo + ";" + terminal.StoreName + ";" + terminal.StorePhone;
        return(result);
    }
    protected void btnSure_Click(object sender, EventArgs e)
    {
        if (this.txtValidCode.Text.Trim().Length == 4)
        {
            bool result = GobalTools.IsRight(this.txtValidCode.Text.Trim());
            if (result)
            {
                string             ordersqlFormat = @"
INSERT INTO yuantuo_terminal_orders
           (orderid
           ,productid
           ,product
           ,num
           ,singleprice
           ,terminalid
           ,totalprice
           ,isadd
           ,mobile,orderdate)
     VALUES ('{0}',{1},'{2}',{3},{4},{5},{6},{7},'{8}','{9}')
";
                FT.DAL.IDataAccess access         = FT.DAL.DataAccessFactory.GetDataAccess();

                int fontsize   = 9;
                int lineheight = 15;
                // int left = 15;
                int    left   = 1;
                string script = string.Empty;
                string domain = Request.Url.ToString();
                // nowUrl.in
                // domain = domain.Substring(domain.IndexOf(":") + 3);//http://之后的
                domain = domain.Substring(0, domain.IndexOf("/YuanTuo"));
                //string urlPrefix = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.IndexOf('/', 0, 3));
                // string logo = Page.ResolveUrl("~/YuanTuo/images/yijielogo.bmp");
                string logo = domain + "/YuanTuo/images/yijielogo.bmp";
                // string logo="http://127.0.0.1:12345/BuyWebSiteDemo/YuanTuo/images/yijielogo.bmp";
                string         orderid  = Session["orderid"].ToString();
                TerminalStatus terminal = GobalTools.GetTerminal();

                string        mobile         = this.txtMobile.Value;
                StringBuilder productcontent = new StringBuilder();
                string        productid      = Session["seeproductid"].ToString();
                ProductInfo   entity         = SimpleOrmOperator.Query <ProductInfo>(Convert.ToInt32(productid));
                int           num            = Convert.ToInt32(Request.Params["ordernum"].ToString());



                double price = Convert.ToDouble(Request.Params["price"].ToString());

                string    sendSql          = "select top 1 productid,b.name as productname,b.no,sendproductid,num from yuantuo_product_send  a left join yuantuo_product_info b on b.id=a.sendproductid where getdate() between startdate and enddate and productid=" + entity.Id.ToString() + " order by enddate desc";
                DataTable dt               = access.SelectDataTable(sendSql, "tmp");
                string    sendPrintContent = string.Empty;
                string    orderdate        = DateTimeHelper.DtToLongString(System.DateTime.Now);
                if (dt != null && dt.Rows.Count == 1)
                {
                    int    sendproductid = Convert.ToInt32(dt.Rows[0]["sendproductid"].ToString());
                    int    sendnumpre    = Convert.ToInt32(dt.Rows[0]["num"].ToString());
                    string sendno        = dt.Rows[0]["no"].ToString();
                    string sendname      = dt.Rows[0]["productname"].ToString();
                    if (num > sendnumpre)
                    {
                        int sendnum = num / sendnumpre;
                        access.ExecuteSql(string.Format(ordersqlFormat
                                                        , orderid, sendproductid, sendname, sendnum, 0, terminal.Id, 0, 1, mobile, orderdate
                                                        ).Replace("\r\n", ""));
                        // " obj.AddContent('04012          78        77','宋体',font,left,height);";
                        sendPrintContent = "height+=lineHeight;obj.AddContent('" + sendname + "(赠品)','宋体'," + fontsize.ToString() + ",left,height);height+=lineHeight;obj.AddContent('" + sendno + "          " + sendnum + "        " + "0" + "','宋体'," + fontsize.ToString() + ",left,height);";
                    }
                }
                access.ExecuteSql(string.Format(ordersqlFormat
                                                , orderid, entity.Id, entity.Name, num, price, terminal.Id, price * num, 0, mobile, orderdate
                                                ).Replace("\r\n", ""));


                /*
                 *    height+=lineHeight;
                 *  obj.AddContent('汽车台座专用香氛50(ml)','宋体',10,left,height);
                 *   height+=lineHeight;
                 *  obj.AddContent('04011              856          78','宋体',10,left,height);
                 *   height+=lineHeight;
                 *  obj.AddContent('金额合计:66,768.00','宋体',10,left,height);
                 */

                productcontent.Append("height+=lineHeight;");
                productcontent.Append("obj.AddContent('" + entity.Name + "','宋体'," + fontsize.ToString() + ",left,height);");
                productcontent.Append("height+=lineHeight;");
                productcontent.Append("obj.AddContent('" + entity.No + "          " + num + "        " + price + "','宋体'," + fontsize.ToString() + ",left,height);");
                productcontent.Append(sendPrintContent);
                productcontent.Append("height+=lineHeight;");
                productcontent.Append("obj.AddContent('金额合计:" + string.Format("{0:N2}", price * num) + "','黑体'," + 10.ToString() + ",left,height);");
                //80mm

                /* script = string.Format(printScriptFormatter
                 *   ,logo,orderid,terminal.StoreNo,terminal.StoreName,terminal.StorePhone
                 *   , mobile, productcontent.ToString(), System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                 *  ,Page.ResolveUrl("~/YuanTuo/Index.aspx")
                 *  ,entity.GetProductDays.ToString()
                 *  , fontsize, left,lineheight,fontsize+2,entity.GetProductDays+4
                 *   );
                 * */
                script = string.Format(printScriptFormatter58
                                       , logo, orderid, terminal.StoreNo, terminal.StoreName, terminal.StorePhone
                                       , mobile, productcontent.ToString(), System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                                       , Page.ResolveUrl("~/YuanTuo/Index.aspx")
                                       , entity.GetProductDays.ToString()
                                       , fontsize, left, lineheight, fontsize + 2, entity.GetProductDays + 4
                                       );
                ClientScript.RegisterStartupScript(this.GetType(), "tmp", script);
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "tmp", "<script type='text/javascript'>setValidError();</script>");
            }
        }
    }