コード例 #1
0
    private void Bind()
    {
        ///注意:拼SQL语句时,注意空格
        ViewState["orderColumnName"] = " a.ProductID ";
        ViewState["columnNames"]     = " b.ProductName as TypeName, a.productid,a.ProductName,a.ProductCode,f.country,a.ProductArea,c.ProductSpecName,a.ProductTypeName,e.ProductUnitName, a.PreferentialPrice, a.PreferentialPv,a.CommonPrice,a.CommonPV,a.AlertnessCount,a.isCombineProduct,a.isSell ";

        ViewState["tableNames"] = " product as a,product as b,ProductSpec as c,ProductType as d,ProductUnit as e ,(select distinct Country from City) as f,Country as g ";
        ViewState["conditions"] = " a.isFold=0 and a.pid=b.productid and a.ProductSpecID=c.productSpecID and  a.productTypeID=d.productTypeID and a.SmallProductUnitID=e.productUnitID and a.countryCode=g.CountryCode and f.Country=g.[name]  ";

        ///通过联合查询获取产品详细信息
        DataTable dt = ProductDetailsBLL.GetMoreProductDetailsInfo();

        if (dt.Rows.Count < 1)
        {
            this.lblMessage.Text    = GetTran("001928", "对不起,没有相关信息");
            this.lblMessage.Visible = true;
        }

        else
        {
            ViewState["sortTable"]    = dt;
            this.gvProduct.DataSource = dt;
            this.gvProduct.DataBind();


            ///分页
            Pager pager = Page.FindControl("Pager1") as Pager;
            pager.PageBind(0, 10, ViewState["tableNames"].ToString(), ViewState["columnNames"].ToString(), ViewState["conditions"].ToString(), ViewState["orderColumnName"].ToString(), "gvProduct");
        }
    }
コード例 #2
0
    /// <summary>
    /// 导出Excel
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnExcel_Click(object sender, EventArgs e)
    {
        //Out to excle the data of ProductDetailsInfo
        DataTable dt = ProductDetailsBLL.OutToExcel_ProductDetailsInfo();

        if (dt.Rows.Count < 1)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "", Transforms.ReturnAlert(GetTran("001712", "对不起,没有可以导出的数据!")));
            return;
        }

        else
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToString(dt.Rows[i]["isCombineProduct"]) == "0")
                {
                    dt.Rows[i]["isCombineProduct"] = GetTran("000235", "否");
                }

                else
                {
                    dt.Rows[i]["isCombineProduct"] = GetTran("000233", "是");
                }

                if (Convert.ToString(dt.Rows[i]["isSell"]) == "0")
                {
                    dt.Rows[i]["isSell"] = GetTran("000233", "是");
                }

                else
                {
                    dt.Rows[i]["isSell"] = GetTran("000235", "否");
                }
            }

            Excel.OutToExcel
                (dt, GetTran("001929", "产品明细"), new string[]
            {
                "TypeName=" + GetTran("001852", "产品类名"),
                "ProductCode=" + GetTran("000263", "产品编码"),
                "ProductName=" + GetTran("000501", "产品名称"),

                "ProductSpecName=" + GetTran("000880", "产品规格"),
                "ProductTypeName=" + GetTran("000882", "产品型号"),
                "ProductUnitName=" + GetTran("001868", "产品单位"),

                "country=" + GetTran("001872", "产品所属国家"),
                "ProductArea=" + GetTran("001877", "产品产地"),
                "PreferentialPrice=" + GetTran("001882", "优惠单价"),
                "PreferentialPv=" + GetTran("001883", "优惠积分"),
                "CommonPrice=" + GetTran("001886", "普通单价"),
                "CommonPV=" + GetTran("001888", "普通积分"),
                "AlertnessCount=" + GetTran("000365", "预警数量"),
                "isCombineProduct=" + GetTran("001890", "是否组合产品"),
                "isSell=" + GetTran("001891", "是否销售")
            }
                );
        }
    }