using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.UI;
public partial class TA_uc_HeaderMain : System.Web.UI.UserControl
{
    #region "Variable Declaration"
    BrandingEventdata obj_Branding = new BrandingEventdata();
    string strDelarLogo;
    DataSet ds_Logo = new DataSet();
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        cls_Common getnew = new cls_Common();
        if (!Page.IsPostBack)
        {
            GetImagePath();
        }
        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;
        ds.Clear();
        ds.Dispose();
    }
    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);
                        HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                        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);
    }
}
