 using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 WebCode;

public partial class user_function_email : Base
{
    protected int i_sel = 0;
    protected string s_ret = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        i_sel = function.GetNumber(Para("sel"));
        switch (i_sel)
        {
            case 11:// 订阅 Email 
                {
                    string s_guid = "";
                    int i_id = function.GetNumber(ds.GetDataString("select E_ID from Sys_Email where E_Name='" + Para("email") + "'  ", "@E_ID@"));

                    if (i_id == 0)
                    {
                        s_ret = "1";
                        WebCode.Table table = new WebCode.Table("Sys_Email");
                        table["E_Guid"] = Guid.NewGuid().ToString();
                        table["E_Name"] = Para("email");
                        table["E_Date"] = Now();
                        table["E_Status"] = "0";
                        table.Add();
                        s_guid = table["E_Guid"];
                    }
                    else
                    {
                        WebCode.Table table = new WebCode.Table("Sys_Email", i_id.ToString());

                        if (table["E_Status"] == "1")
                        {
                            s_ret = "2";
                        }
                        else
                        {
                            s_guid = table["E_Guid"];
                            s_ret = "1";
                        }


                    }

                    if (s_ret == "1")
                    {
                        //发送邮件
                        string s_name = function.GetSysData("WebName");
                        string s_content = ts.TranslateAll("@@Const.SubscribeEmail()@@");
                        s_content = s_content.Replace("@webname@", s_name);
                        s_content = s_content.Replace("@host@", Request.Url.Host);
                        s_content = s_content.Replace("@guid@", s_guid);
                        Email.GetInstance().SendMail(Para("email"), s_name + "邮件订阅确认", s_content);
                    }

                    break;


                }
            case 12:// 确认订阅   Email 
                {
                    int i_id = function.GetNumber(ds.GetDataString("select E_ID from Sys_Email where E_Status=0 and E_GUID='" + Para("guid") + "'  ", "@E_ID@"));

                    if (i_id > 0)
                    {
                        //i_id有效
                        
                        WebCode.Table table = new WebCode.Table("Sys_Email", i_id.ToString());
                        s_ret = table["E_Name"];
                        table["E_Status"] = "1";
                        table.Update();
                    }
                    break;
                }
            case 13: //取消订阅 Email
                {
                    int i_id = function.GetNumber(ds.GetDataString("select E_ID from Sys_Email where E_Name='" + Para("email") + "'  ", "@E_ID@"));

                    if (i_id > 0)
                    {
                        s_ret = Para("email");
                        ds.ExecuteSQL(" delete from Sys_Email where E_ID=" + i_id);
                    }
                    break;
                }
        }
    }
}
