using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Email.Subscription;
using System.Text;

/// <summary>
/// EM_ProcessLable 的摘要说明
/// </summary>
namespace nspEmail.Lables
{
    public class EM_ProcessLable
    {
        public EM_ProcessLable()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }
        /// <summary>
        /// 获取订阅商业资讯
        /// </summary>
        /// <param name="typeID">行业资讯ID</param>
        /// <returns></returns>
        public static string EM_Newslist(string typeID)
        {
            //获取路径
            // Base.BasePage.Config.WebURL + "News/Detail-'"++"'" + Base.BasePage.Config.Rewrite;
            string strUrl = Base.BasePage.Config.WebURL + "News/Detail-";
            string strExtension = Base.BasePage.Config.Rewrite;
            DataTable dt = EmailSQLDAL.GetDataTable("select top 9 * from W_Consultative where TypeID=" + typeID + " order by AddDate desc");
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append(@"<table width='100%'>");
            strBuilder.Append(@"<tr><td>今日要闻</td></tr></table><table width='100%'");
            strBuilder.Append(@"<tr><td height='37'><div align='center'><div align='center'><font style='font-family:黑体;font-size:16px'>");
            strBuilder.Append(@"<a href='" + strUrl + "" + dt.Rows[0]["ID"] + "" + strExtension + "'>" + dt.Rows[0]["Title"] + "</a></font></div></div></td></tr>");
            strBuilder.Append(@"<tr><td align='center'><div align='center'><a href='" + strUrl + "" + dt.Rows[1]["ID"] + "" + strExtension + "'>" + dt.Rows[1]["Title"] + "</a>|</div>");
            strBuilder.Append(@"<a href='" + strUrl + "" + dt.Rows[2]["ID"] + "" + strExtension + "'>" + dt.Rows[2]["Title"] + "</a></td></tr></table>");
            strBuilder.Append(@"<table width='100%'>");
            for (int i = 3; i < dt.Rows.Count; i++)
            {
                strBuilder.Append(@"<tr><td>·<a href='" + strUrl + "" + dt.Rows[i]["ID"] + "" + strExtension + "'>" + dt.Rows[i]["Title"] + "</a></td></tr>");
            }
            strBuilder.Append(@"</table>");
            string strLable = strBuilder.ToString();
            return strLable;
        }
        ///<summary>
        ///处理网站供求统计信息
        ///</summary>
        ///<returns></returns>
        public static string EM_ProductInfo()
        {
            StringBuilder strBuilder = new StringBuilder();
            DataTable dt = Solely.Other.GetCount();
            if (dt.Rows.Count > 0)
            {
                strBuilder.Append("<table width='100%'><tr><th>");
                strBuilder.Append("统计</th><th>总数</th><th>已审</th><th>未审</th><th>推荐</th><th>查看</th></tr>");
                for (int i = 0; i < 3; i++)
                {
                    if (i == 0)
                    {
                        strBuilder.Append(@"<tr><td>供应信息</td><td><a href='");
                        strBuilder.Append(Base.BasePage.Config.WebURL);
                        strBuilder.Append(@"Member/Trade/SupplyManage.aspx' target='_blank'>");
                        strBuilder.Append(dt.Rows[i]["t1"].ToString());
                        strBuilder.Append(@"</a></td><td><a href='");
                        strBuilder.Append(Base.BasePage.Config.WebURL);
                        strBuilder.Append(@"Member/Trade/SupplyManage.aspx?Verify=1' target='_blank'>");
                        strBuilder.Append(dt.Rows[i]["t2"].ToString());
                        strBuilder.Append(@"</a></td><td><a href='");
                        strBuilder.Append(Base.BasePage.Config.WebURL);
                        strBuilder.Append(@"Member/Trade/SupplyManage.aspx?Verify=3' target='_blank'>");
                        strBuilder.Append(dt.Rows[i]["t3"].ToString());
                        strBuilder.Append(@"</a></td><td>");
                        strBuilder.Append(dt.Rows[i]["t4"].ToString());
                        strBuilder.Append(@"</td><td>");
                        strBuilder.Append(@"<a href='" + Base.BasePage.Config.WebURL + "Member/Trade/SupplyManage.aspx");
                        strBuilder.Append(@"' Target='_bank'>");
                        strBuilder.Append(@"查看</a><td>");
                    }
                    if (i == 1)
                    {
                        strBuilder.Append(@"<tr><td>求购信息</td><td><a href='");
                        strBuilder.Append(Base.BasePage.Config.WebURL);
                        strBuilder.Append(@"Member/Trade/PurchaseManage.aspx' target='_blank'>");
                        strBuilder.Append(dt.Rows[i]["t1"].ToString());
                        strBuilder.Append(@"</a></td><td><a href='");
                        strBuilder.Append(Base.BasePage.Config.WebURL);
                        strBuilder.Append(@"Member/Trade/PurchaseManage.aspx?verify=1' target='_blank'>");
                        strBuilder.Append(dt.Rows[i]["t2"].ToString());
                        strBuilder.Append(@"</a></td><td><a href='");
                        strBuilder.Append(Base.BasePage.Config.WebURL);
                        strBuilder.Append(@"Member/Trade/PurchaseManage.aspx?Verify=3' target='_blank'>");
                        strBuilder.Append(dt.Rows[i]["t3"].ToString());
                        strBuilder.Append(@"</a></td><td>");
                        strBuilder.Append(dt.Rows[i]["t4"].ToString());
                        strBuilder.Append(@"</td><td>");
                        strBuilder.Append(@"<a href='{PB_WebURL}Member/Trade/PurchaseManage.aspx");
                        strBuilder.Append(@"' Target='_bank'>");
                        strBuilder.Append(@"查看</a><td>");
                    }
                    strBuilder.Append(@"</tr>");

                }
                strBuilder.Append(@"</table> ");
            }
            return strBuilder.ToString();
        }
        /// <summary>
        /// 获取订阅供求信息
        /// </summary>
        /// <returns></returns>
        public static string EM_Productlist()
        {
            DataTable dt = new SubscriptionProduct().GetDataTable("where 1=1");
            StringBuilder strBuilder = new StringBuilder();
            strBuilder.Append(@"<table width='100%'>");
            strBuilder.Append(@"<tr><td>供应关键词:");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Type"].ToString() == "供应")
                    strBuilder.Append(dt.Rows[i]["Keyword"].ToString() + "&nbsp;&nbsp;");

            }
            strBuilder.Append(@"</td></tr><tr><td>求购关键词:");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i]["Type"].ToString() == "求购")
                    strBuilder.Append(dt.Rows[i]["Keyword"].ToString() + "&nbsp;&nbsp;");
            }
            strBuilder.Append(@"</td></tr>");

            for (int i = 0; i < dt.Rows.Count; i++)
            {

                if (dt.Rows[i]["Type"].ToString() == "供应")
                {

                    string[] strArea = dt.Rows[i]["Area"].ToString().Split(new char[] { ',' });
                    string strSelect = "a.ID,a.Name,a.AddDate,b.Province,b.City";
                    string strWhere = "where a.[Key] like '%" + dt.Rows[i]["Keyword"].ToString() + "%' and a.IndType='" + dt.Rows[i]["IndType"] + "' and b.Province='" + strArea[0] + "' and b.City='" + strArea[1] + "' and (datediff(day,a.AddDate,getdate())<'" + dt.Rows[i]["Validity"] + "')";
                    string strTable = "C_Supply as a inner join U_UserInfo b on a.UserID=b.UserID ";
                    DataTable dt1 = EmailSQLDAL.GetDataTable(strSelect, strWhere, strTable);
                    if (dt1.Rows.Count != 0)
                    {
                        strBuilder.Append(@"<tr><td>");
                        strBuilder.Append(dt.Rows[i]["Keyword"].ToString());
                        strBuilder.Append(@"最新供应信息&nbsp;(共有供应信息" + dt1.Rows.Count + "条，以下是最新的" + dt1.Rows.Count + "条)");
                        strBuilder.Append(@"</td></tr>");
                        strBuilder.Append(@"<tr>");
                        for (int j = 0; j < dt1.Rows.Count; j++)
                        {
                            strBuilder.Append(@"<td><a href='");
                            strBuilder.Append(Base.BasePage.Config.WebURL);
                            strBuilder.Append(@"Supply/Detail.aspx?id=");
                            strBuilder.Append(dt1.Rows[j]["ID"]);
                            strBuilder.Append(@"' target='_bank'>");
                            strBuilder.Append(dt1.Rows[j]["Name"]);
                            strBuilder.Append(@"</a></br>");
                            strBuilder.Append(dt1.Rows[j]["AddDate"]);
                            strBuilder.Append(@"&nbsp;&nbsp;");
                            strBuilder.Append(dt.Rows[j]["Area"]);
                            strBuilder.Append(@"</td>");

                        }
                        strBuilder.Append(@"</tr>");
                    }
                }
                if (dt.Rows[i]["Type"].ToString() == "求购")
                {

                    string[] strArea = dt.Rows[i]["Area"].ToString().Split(new char[] { ',' });
                    string strSelect = "a.ID,a.Name,a.AddDate,b.Province,b.City";
                    string strWhere = "where a.[Key] like '%" + dt.Rows[i]["Keyword"].ToString() + "%' and a.IndType='" + dt.Rows[i]["IndType"] + "' and b.Province='" + strArea[0] + "' and b.City='" + strArea[1] + "' and (datediff(day,a.AddDate,getdate())<'" + dt.Rows[i]["Validity"] + "')";
                    string strTable = "C_Purchase as a inner join U_UserInfo b on a.UserID=b.UserID ";
                    DataTable dt1 = EmailSQLDAL.GetDataTable(strSelect, strWhere, strTable);
                    if (dt1.Rows.Count != 0)
                    {
                        strBuilder.Append(@"<tr><td>");
                        strBuilder.Append(dt.Rows[i]["Keyword"].ToString());
                        strBuilder.Append(@"最新供应信息&nbsp;(共有求购信息" + dt1.Rows.Count + "条，以下是最新的" + dt1.Rows.Count + "条)");
                        strBuilder.Append(@"</td></tr>");
                        strBuilder.Append(@"<tr>");
                        for (int j = 0; j < dt1.Rows.Count; j++)
                        {
                            strBuilder.Append(@"<td><a href='");
                            strBuilder.Append(Base.BasePage.Config.WebURL);
                            strBuilder.Append(@"Purchase/Detail.aspx?id=");
                            strBuilder.Append(dt1.Rows[j]["ID"]);
                            strBuilder.Append(@"' target='_bank'>");
                            strBuilder.Append(dt1.Rows[j]["Name"]);
                            strBuilder.Append(@"</a></br>");
                            strBuilder.Append(dt1.Rows[j]["AddDate"]);
                            strBuilder.Append(@"&nbsp;&nbsp;");
                            strBuilder.Append(dt.Rows[j]["Area"]);
                            strBuilder.Append(@"</td>");
                        }
                        strBuilder.Append(@"</tr>");
                    }
                }

            }
            strBuilder.Append(@"</table>");
            return strBuilder.ToString();
        }


    }
}
