using System;
using System.Data;
using System.IO;
using System.Text;
using System.Web;
public partial class UserControls_TA_uc_Header : System.Web.UI.UserControl
{
    cls_Common getnew = new cls_Common();
    BrandingEventdata obj_Branding = new BrandingEventdata();
    string strDelarLogo;
    //string strCustomerLogo;
    DataSet ds_Logo = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds = getnew.getNewsBanner("LeftNewsEvent");
        if (ds.Tables[0].Rows.Count > 0)
        {
            this.litLeftNews.Text = "<marquee direction='up' onmouseover='this.stop();' onmouseout='this.start();' scrollamount='1' height='72'><b>" + ds.Tables[0].Rows[0]["NewsEventTitle"] + "</b><br><br>" + ds.Tables[0].Rows[0]["NewsEventDescription"] + "</marquee>";
        }
        ds = getnew.getNewsBanner("RightNewsEvent");
        if (ds.Tables[0].Rows.Count > 0)
        {
            this.litRightNews.Text = "<marquee direction='up' onmouseover='this.stop();' onmouseout='this.start();' scrollamount='1' height='72'><b>" + ds.Tables[0].Rows[0]["NewsEventTitle"] + "</b><br><br>" + ds.Tables[0].Rows[0]["NewsEventDescription"] + "</marquee>";
        }
        ds.Clear();
        ds.Dispose();
        // DataSet ds = new DataSet();
        ds = getnew.getNewsBanner("LeftNewsEvent");
        this.litLeftNews.Text = "";
        string marqText = "<marquee direction='up' onmouseover='this.stop();' onmouseout='this.start();' scrollamount='1' height='72'>";
        for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
        {
            if (ds.Tables[0].Rows[i]["NewsEventTitle"] != DBNull.Value && ds.Tables[0].Rows[i]["NewsEventDescription"] != DBNull.Value)
                marqText = marqText + "<b>" + ds.Tables[0].Rows[i]["NewsEventTitle"] + "</b><br><br>" + ds.Tables[0].Rows[i]["NewsEventDescription"] + "<br><br>";
        }
        this.litLeftNews.Text = marqText;
        ds = getnew.getNewsBanner("RightNewsEvent");
        this.litRightNews.Text = "";
        marqText = "<marquee direction='up' onmouseover='this.stop();' onmouseout='this.start();' scrollamount='1' height='72'>";
        for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
        {
            if (ds.Tables[0].Rows[i]["NewsEventTitle"] != DBNull.Value && ds.Tables[0].Rows[i]["NewsEventDescription"] != DBNull.Value)
                marqText = marqText + "<b>" + ds.Tables[0].Rows[i]["NewsEventTitle"] + "</b><br><br>" + ds.Tables[0].Rows[i]["NewsEventDescription"] + "<br><br>";
        }
        this.litRightNews.Text = marqText;
        //if (ds.Tables[0].Rows.Count > 0)
        //{
        //    this.litRightNews.Text = "<marquee direction='up' onmouseover='this.stop();' onmouseout='this.start();' scrollamount='1' height='75'><b>" + ds.Tables[0].Rows[0]["NewsEventTitle"] + "</b><br><br>" + ds.Tables[0].Rows[0]["NewsEventDescription"] + "</marquee>";
        //}
        ds.Clear();
        ds.Dispose();
        GetImagePath();
        //Rendercontents();
    }
    private void Rendercontents()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<object classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
        sb.Append("codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,2,0 ");
        sb.Append("<param name=movie value=c:\\intro[1].swf> ");
        sb.Append("<param name=quality value=high> ");
        sb.Append("<param name=BGCOLOR value=#000000>");
        sb.Append("<param name=SCALE value=showall>");
        sb.Append("<embed src=c:\\intro[1].swf");
        sb.Append("pluginspage=http://www.macromedia.com/go/getflashplayer type=application/x-shockwave-flash ");
        sb.Append("bgcolor=#000000 ");
        sb.Append("scale= showall></embed></object>");
    }
    protected void GetImagePath()
    {
        try
        {
            if (System.Configuration.ConfigurationManager.AppSettings["DelarLogo"].ToString() != "")
            {
                strDelarLogo = System.Configuration.ConfigurationManager.AppSettings["DelarLogo"].ToString();
                IMG2.Visible = true;
                IMG2.Src = "../" + strDelarLogo;
            }
            else
            {
                IMG2.Visible = false;
            }
            ds_Logo = obj_Branding.SelectCusLogo();
            if (ds_Logo != null && ds_Logo.Tables.Count > 0)
            {
                if (ds_Logo.Tables[0].Rows.Count > 0)
                {
                    if (ds_Logo.Tables[0].Rows[0]["Cus_Image"] != System.DBNull.Value)
                    {
                        byte[] img = (byte[])ds_Logo.Tables[0].Rows[0]["Cus_Image"];
                        GetImage(img);
                        //Clear temporary internet files
                        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        //this.IMG1.Src = AppDomain.CurrentDomain.BaseDirectory + "Customer_Logo.jpg";
                        Random rnd = new Random();
                        this.IMG1.Src = "~/Customer_Logo.jpg?Rnd=" + rnd.NextDouble();
                    }
                    else
                    {
                        IMG1.Visible = false;
                    }
                }
                else
                {
                    IMG1.Visible = false;
                }
            }
            ds_Logo.Dispose();
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
    public void GetImage(byte[] Logo)
    {
        string strPath = AppDomain.CurrentDomain.BaseDirectory + "Customer_Logo.jpg";
        if (File.Exists(strPath))
        {
            File.Delete(strPath);
        }
        MemoryStream stream = new MemoryStream(Logo);
        System.Drawing.Image img = System.Drawing.Image.FromStream(stream);
        img.Save(strPath);
    }
}