using System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using TABS.MailCarrier.WebSDK.Board;

public partial class Mail_PermitSend_ConfirmedList : System.Web.UI.Page
{
    protected override void InitializeCulture()
    {
        string defLang = WebUser.CurrentUser.UiLanguage;
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(defLang);
        Thread.CurrentThread.CurrentUICulture = new CultureInfo(defLang);
        base.InitializeCulture();
    }

    protected void Page_Init(object sender, EventArgs e)
    {
        WebUtil.SetMcCommonCss2(Page.Header);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = AppSetting.GetTitleInfo(Request).Title;
        if (!IsPostBack)
        {
            MsgGridView.Columns[0].HeaderText = Resources.Mail.MailWaitForApproval;
        }
    }

    protected void MsgGridView_PreRender(object sender, EventArgs e)
    {
        GridView gv = (GridView)sender;
        if ((gv.ShowHeader == true && gv.Rows.Count > 0) || (gv.ShowHeaderWhenEmpty == true))
        {
            gv.HeaderRow.TableSection = TableRowSection.TableHeader;
        }
        if (gv.ShowFooter == true && gv.Rows.Count > 0)
        {
            gv.FooterRow.TableSection = TableRowSection.TableFooter;
        }
    }

    protected string GetTo(string toList, int toCount)
    {
        if (toCount == 1)
            return Server.HtmlEncode(toList);
        else
            return Server.HtmlEncode(string.Format("{0} ...({1})", toList, toCount));
    }

    protected string GetDate(DateTime date)
    {
        return WebUser.CurrentUser.ToLocalTime(date).ToString("g");
    }

    protected string GetStatus(int flag, object confirmDate, int toCount, Guid clid)
    {
        string status = "";
        bool comment = false;
        switch (flag)
        {
            case 0:
                status = string.Format("{0}({1}) [<a href=\"javascript:CancelSending('{2}')\">{3}</a>]",
                    GetLocalResourceObject("Status01").ToString(), toCount, clid, GetLocalResourceObject("CancelSending").ToString());  // 대기
                break;
            case 1:
                status = string.Format(GetLocalResourceObject("Status02").ToString(), WebUser.CurrentUser.ToLocalTime((DateTime)confirmDate)); // 승인
                comment = true;
                break;
            case 2:
                status = string.Format(GetLocalResourceObject("Status03").ToString(), WebUser.CurrentUser.ToLocalTime((DateTime)confirmDate)); // 거부
                comment = true;
                break;
            case 3:
                status = string.Format(GetLocalResourceObject("Status04").ToString(), WebUser.CurrentUser.ToLocalTime((DateTime)confirmDate)); // 자동승인
                break;
            case 4:
                status = string.Format(GetLocalResourceObject("Status05").ToString(), WebUser.CurrentUser.ToLocalTime((DateTime)confirmDate)); // 발신자에 의한 취소됨
                comment = true;
                break;
            case 5:
                status = string.Format(GetLocalResourceObject("Status06").ToString(), WebUser.CurrentUser.ToLocalTime((DateTime)confirmDate)); // 자동거부
                comment = true;
                break;
        }
        if (comment)
        {
            status = string.Format("<a href='#' onclick=\"OpenComment('{0}');return false;\">{1}</a>", clid, Server.HtmlEncode(status));
        }
        return status;
    }
}