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 System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; public partial class Admin_Logos : System.Web.UI.Page { DBAccess.DBAccess ClSqlCmd; public void Page_Load(object sender, EventArgs e) { ClSqlCmd = new DBAccess.DBAccess(System.Configuration.ConfigurationSettings.AppSettings["SE_ConnectionString"]); /////////////////////////////////////////////////////////////////////////// if (!Page.IsPostBack) { GetData(); } } private Size NewthumbSize(int currentwidth, int currentheight, int MaxWH) { //Calculate the Size of the New image Double tempMultiplier; Size NewSize = new Size(); if (currentheight > currentwidth) // portrait { if (currentheight > MaxWH) { NewSize = new Size(Convert.ToInt32(currentwidth * MaxWH / currentheight), Convert.ToInt32(currentheight * MaxWH / currentheight)); } else { NewSize = new Size(Convert.ToInt32(currentwidth), Convert.ToInt32(currentheight)); } } else { if (currentwidth > MaxWH) { NewSize = new Size(Convert.ToInt32(currentwidth * MaxWH / currentwidth), Convert.ToInt32(currentheight * MaxWH / currentwidth)); } else { NewSize = new Size(Convert.ToInt32(currentwidth), Convert.ToInt32(currentheight)); } } return NewSize; } private string ImgRes_Save(string filepath, string id, int MaxWH) { System.Drawing.Image g = System.Drawing.Image.FromFile(filepath); ImageFormat thisFormat = g.RawFormat; Size thumbSize = new Size(); thumbSize = NewthumbSize(g.Width, g.Height, MaxWH); //create a new Bitmap the size of the new image Bitmap imgOutput = new Bitmap(thumbSize.Width, thumbSize.Height); //create a new graphic from the Bitmap Graphics graphic = Graphics.FromImage((System.Drawing.Image)imgOutput); graphic.SmoothingMode = SmoothingMode.HighQuality; graphic.InterpolationMode = InterpolationMode.HighQualityBicubic; graphic.PixelOffsetMode = PixelOffsetMode.HighQuality; //draw the newly resized image graphic.DrawImage(g, 0, 0, thumbSize.Width, thumbSize.Height); //if (MaxWH > 300) //{ // using (System.Drawing.Image j = System.Drawing.Image.FromFile(Request.MapPath("") + "/Pics/Logo.png", true)) // { // graphic.DrawImage(j, new Rectangle(10, thumbSize.Height - (((g.Width / 4) * 90 / 200) + 10), (g.Width / 4), ((g.Width / 4) * 90 / 200))); // } //} System.IO.FileStream fs = new FileStream(Request.MapPath("") + "\\..\\Photos_Swfs\\" + id.ToString() + "_" + MaxWH.ToString() + ".jpg", FileMode.OpenOrCreate); //imgOutput.Save(Response.OutputStream, thisFormat); //output to the user imgOutput.Save(fs, thisFormat); //output to the user //tidy up //dispose and free up the resources graphic.Dispose(); g.Dispose(); imgOutput.Dispose(); fs.Dispose(); g = null; return id.ToString() + "_" + MaxWH.ToString() + ".jpg"; } void GetData() { DataSet DS = ClSqlCmd.DataSetSel(@" SELECT [ModuleStyle_ID] ,[Logo_FileName] ,[Logo_WidthPerc] ,[Logo_Footer_FileName] ,[Logo_Footer_WidthPerc] FROM [dbo].[__StandardEngine_T_ModuleStyles] where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0) { if (DS.Tables[0].Rows[0]["Logo_FileName"] != Convert.DBNull) { img_Logo_FileName.Src = "../Photos_Swfs/" + DS.Tables[0].Rows[0]["Logo_FileName"].ToString(); ////////////// img_Logo_FileName.Visible = true; btn_Logo_FileName_Delete.Visible = true; } else { img_Logo_FileName.Visible = false; btn_Logo_FileName_Delete.Visible = false; } ddl_Logo_WidthPerc.Value = DS.Tables[0].Rows[0]["Logo_WidthPerc"].ToString(); /////////////////////////////////////////////////////////////////////// if (DS.Tables[0].Rows[0]["Logo_Footer_FileName"] != Convert.DBNull) { img_Logo_Footer_FileName.Src = "../Photos_Swfs/" + DS.Tables[0].Rows[0]["Logo_Footer_FileName"].ToString(); ////////////// img_Logo_Footer_FileName.Visible = true; lnk_Logo_Footer_FileName_Delete.Visible = true; } else { img_Logo_Footer_FileName.Visible = false; lnk_Logo_Footer_FileName_Delete.Visible = false; } ddl_Logo_Footer_WidthPerc.Value = DS.Tables[0].Rows[0]["Logo_Footer_WidthPerc"].ToString(); } } protected void Button1_Click(object sender, EventArgs e) { DataSet DS = ClSqlCmd.DataSetSel(@" SELECT [ModuleStyle_ID] FROM [dbo].[__StandardEngine_T_ModuleStyles] where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); if (DS.Tables.Count < 0 || DS.Tables[0].Rows.Count <= 0) { #region Insert New ModuleStyles ClSqlCmd.CommandExc(@" Insert into [dbo].[__StandardEngine_T_ModuleStyles] ( [ModuleStyle_ID] ,[Module_ID] ) values ( dbo.__StandardEngine_F_MaxID_ModuleStyles()+1 ," + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + @" )"); #endregion } else { } #region Variables string str_Logo_FileName="NULL"; string str_Logo_WidthPerc="NULL"; string str_Logo_Footer_FileName="NULL"; string str_Logo_Footer_WidthPerc="NULL"; #endregion //Get template style text string str_Style_Txt = System.IO.File.ReadAllText(Request.MapPath("") + "/../Templates/LogoMenuStyle.css"); str_Style_Txt = str_Style_Txt.Replace("", Request.Params["T"].Trim().Replace("'", "''")); #region Insert Logo_FileName if (file_Logo_FileName.Value != "") { //Delete Prev Photo if exists f_Delete_Logo(); ////////////////////////////// file_Logo_FileName.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Photos_Swfs\\" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + "_Logo.png"); str_Logo_FileName = "N'" + ImgRes_Save(Request.MapPath("") + "\\..\\Photos_Swfs\\" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + "_Logo.png", "000", 1000) + "'"; //str_Logo_FileName = "N'" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + "_Logo.png" + "'"; } else { str_Logo_FileName = "[Logo_FileName]"; } #endregion #region Insert Logo_Footer_FileName if (file_Logo_Footer_FileName.Value != "") { //Delete Prev Photo if exists f_Delete_Logo_Footer(); ////////////////////////////// file_Logo_Footer_FileName.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Photos_Swfs\\" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + "_Logo_Footer.png"); str_Logo_Footer_FileName = "N'" + ImgRes_Save(Request.MapPath("") + "\\..\\Photos_Swfs\\" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + "_Logo_Footer.png", "0000", 1000) + "'"; //str_Logo_Footer_FileName="N'"+System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]+"_Logo_Footer.png"+"'"; } else { str_Logo_Footer_FileName = "[Logo_Footer_FileName]"; } #endregion str_Logo_WidthPerc="N'"+ddl_Logo_WidthPerc.Value+"'"; str_Logo_Footer_WidthPerc="N'"+ddl_Logo_Footer_WidthPerc.Value+"'"; str_Style_Txt = str_Style_Txt.Replace("", ddl_Logo_WidthPerc.Value); str_Style_Txt = str_Style_Txt.Replace("", Convert.ToString( ( 100 - Convert.ToInt32( ddl_Logo_WidthPerc.Value.Replace("%","") )) )+"%" ); str_Style_Txt = str_Style_Txt.Replace("", ddl_Logo_Footer_WidthPerc.Value); str_Style_Txt = str_Style_Txt.Replace("", Convert.ToString((100 - Convert.ToInt32(ddl_Logo_Footer_WidthPerc.Value.Replace("%", "")))) + "%"); #region update current ModuleStyles ClSqlCmd.CommandExc(@" update [dbo].[__StandardEngine_T_ModuleStyles] set [Logo_FileName]="+str_Logo_FileName+@" ,[Logo_WidthPerc]="+str_Logo_WidthPerc+@" ,[Logo_Footer_FileName]="+str_Logo_Footer_FileName+@" ,[Logo_Footer_WidthPerc]="+str_Logo_Footer_WidthPerc+@" where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); #endregion #region write css files System.IO.File.WriteAllText(Request.MapPath("") + "/../CSS/" + Request.Params["T"].Trim().Replace("'", "") + ".css", str_Style_Txt); #endregion /////////////////////////////////////////////////////////////////////// if (Request.Params["retP"] != null && Request.Params["retP"] != "") { Response.Redirect(Server.UrlDecode(Request.Params["retP"])); } } protected void btn_Logo_FileName_Delete_Click(object sender, EventArgs e) { f_Delete_Logo(); ////////////////////////////////////////////////////////////////////// Response.Redirect(Request.Url.ToString()); } protected void lnk_Logo_Footer_FileName_Delete_Click(object sender, EventArgs e) { f_Delete_Logo_Footer(); ////////////////////////////////////////////////////////////////////// Response.Redirect(Request.Url.ToString()); } protected void f_Delete_Logo() { DataSet DS = ClSqlCmd.DataSetSel(@" SELECT [Logo_FileName] FROM [dbo].[__StandardEngine_T_ModuleStyles] where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0) { if (DS.Tables[0].Rows[0]["Logo_FileName"] != Convert.DBNull) { try { System.IO.File.Delete(Request.MapPath("") + "/../Photos_Swfs/" + DS.Tables[0].Rows[0]["Logo_FileName"].ToString()); } catch { } } ClSqlCmd.DataSetSel(@" update [dbo].[__StandardEngine_T_ModuleStyles] set [Logo_FileName]=NULL where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); } } protected void f_Delete_Logo_Footer() { DataSet DS = ClSqlCmd.DataSetSel(@" SELECT [Logo_Footer_FileName] FROM [dbo].[__StandardEngine_T_ModuleStyles] where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0) { if (DS.Tables[0].Rows[0]["Logo_Footer_FileName"] != Convert.DBNull) { try { System.IO.File.Delete(Request.MapPath("") + "/../Photos_Swfs/" + DS.Tables[0].Rows[0]["Logo_Footer_FileName"].ToString()); } catch { } } ClSqlCmd.DataSetSel(@" update [dbo].[__StandardEngine_T_ModuleStyles] set [Logo_Footer_FileName]=NULL where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); } } }