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; public partial class Admin_Text_Style : 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) { Load_Fonts(); GetData(); } } void Load_Fonts() { DataSet DS = ClSqlCmd.DataSetSel(@"SELECT [Font_ID] ,[Font_Name] ,[Module_ID] FROM [dbo].[__StandardEngine_T_Fonts] where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"] + @" Order by [Font_Name] asc" ); ///////////////////////////////// DS.Tables[0].Rows.InsertAt(DS.Tables[0].NewRow(), 0); DS.Tables[0].Rows[0]["Font_Name"] = "غير محدد"; ///////////////////////////////// ddl_FontFamily_Outer.DataSource = DS; ddl_FontFamily_Outer.DataTextField = "Font_Name"; ddl_FontFamily_Outer.DataValueField = "Font_ID"; ddl_FontFamily_Outer.DataBind(); } void GetData() { DataSet DS = ClSqlCmd.DataSetSel(@" SELECT [ModuleStyle_ID] ,[" + Request.Params["T"].Trim().Replace("'", "''") + @"_TextStyle_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) { DataSet DS_Sub = new DataSet(); if (DS.Tables[0].Rows[0][Request.Params["T"].Trim().Replace("'", "''") + "_TextStyle_ID"] != Convert.DBNull) { #region Get Data DS_Sub = ClSqlCmd.DataSetSel(@" SELECT [ForeColor] ,[BackColor] ,[FontFamily] ,[FontSize] ,[Align] ,[Bold] ,[Underline] ,[Italic] ,[Direction] ,[FontFamily_Outer] FROM [dbo].[__StandardEngine_T_TextStyle] where [TextStyle_ID]=" + DS.Tables[0].Rows[0][Request.Params["T"].Trim().Replace("'", "''") + "_TextStyle_ID"].ToString()); #endregion #region Set Data if (DS_Sub.Tables.Count > 0 && DS_Sub.Tables[0].Rows.Count > 0) { if (DS_Sub.Tables[0].Rows[0]["ForeColor"] != Convert.DBNull) txt_ForeColor.Value = DS_Sub.Tables[0].Rows[0]["ForeColor"].ToString(); if (DS_Sub.Tables[0].Rows[0]["BackColor"] != Convert.DBNull) { txt_BackColor.Value = DS_Sub.Tables[0].Rows[0]["BackColor"].ToString(); cb_BackColor_Trans.Checked = false; } else { txt_BackColor.Value = ""; cb_BackColor_Trans.Checked = true; } if (DS_Sub.Tables[0].Rows[0]["FontFamily"] != Convert.DBNull) ddl_FontFamily.Value = DS_Sub.Tables[0].Rows[0]["FontFamily"].ToString(); if (DS_Sub.Tables[0].Rows[0]["FontSize"] != Convert.DBNull) ddl_FontSize.Value = DS_Sub.Tables[0].Rows[0]["FontSize"].ToString(); if (DS_Sub.Tables[0].Rows[0]["Align"] != Convert.DBNull) ddl_Align.Value = DS_Sub.Tables[0].Rows[0]["Align"].ToString(); if (DS_Sub.Tables[0].Rows[0]["Bold"] != Convert.DBNull) cb_Bold.Checked = DS_Sub.Tables[0].Rows[0]["Bold"].ToString().ToLower() == "bold" ? true : false; if (DS_Sub.Tables[0].Rows[0]["Underline"] != Convert.DBNull) cb_Underline.Checked = DS_Sub.Tables[0].Rows[0]["Underline"].ToString().ToLower() == "underline" ? true : false; if (DS_Sub.Tables[0].Rows[0]["Italic"] != Convert.DBNull) cb_Italic.Checked = DS_Sub.Tables[0].Rows[0]["Italic"].ToString().ToLower() == "italic" ? true : false; if (DS_Sub.Tables[0].Rows[0]["Direction"] != Convert.DBNull) ddl_Direction.Value = DS_Sub.Tables[0].Rows[0]["Direction"].ToString(); if (DS_Sub.Tables[0].Rows[0]["FontFamily_Outer"] != Convert.DBNull) ddl_FontFamily_Outer.SelectedValue = DS_Sub.Tables[0].Rows[0]["FontFamily_Outer"].ToString(); } #endregion } } } protected void Button1_Click(object sender, EventArgs e) { DataSet DS = ClSqlCmd.DataSetSel(@" SELECT [ModuleStyle_ID] ,[" + Request.Params["T"].Trim().Replace("'", "''") + @"_TextStyle_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 Update in current ModuleStyles to NULL ClSqlCmd.CommandExc(@" update [dbo].[__StandardEngine_T_ModuleStyles] set [" + Request.Params["T"].Trim().Replace("'", "''") + @"_TextStyle_ID]=NULL where [Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]); #endregion //////////////////////////////////////////////////////////////////// if (DS.Tables[0].Rows[0][Request.Params["T"].Trim().Replace("'", "''") + "_TextStyle_ID"] != Convert.DBNull) { #region Delete Current ClSqlCmd.CommandExc(@" Delete FROM [dbo].[__StandardEngine_T_TextStyle] where [TextStyle_ID]=" + DS.Tables[0].Rows[0][Request.Params["T"].Trim().Replace("'", "''") + "_TextStyle_ID"].ToString()); #endregion } } #region Variables string str_TextStyle_ID; string str_ForeColor; string str_BackColor; string str_FontFamily; string str_FontSize; string str_Align; string str_Bold; string str_Underline; string str_Italic; string str_Direction; string str_FontFamily_Outer; #endregion //Get template style text string str_Style_Txt = System.IO.File.ReadAllText(Request.MapPath("") + "/../Templates/TextStyle.css"); str_Style_Txt = str_Style_Txt.Replace("", Request.Params["T"].Trim().Replace("'", "''")); #region Insert _TextStyle_ID str_TextStyle_ID = ClSqlCmd.DataSetSel("select dbo.__StandardEngine_F_MaxID_TextStyle()+1").Tables[0].Rows[0][0].ToString(); str_ForeColor = "N'" + txt_ForeColor.Value + "'"; str_BackColor = !cb_BackColor_Trans.Checked ? ("N'" + txt_BackColor.Value + "'") : "NULL"; str_FontFamily = "N'" + ddl_FontFamily.Value + "'"; str_FontSize = "N'" + ddl_FontSize.Value + "'"; str_Align = "N'" + ddl_Align.Value + "'"; str_Bold = cb_Bold.Checked ? "N'bold'" : "N'normal'"; str_Underline = cb_Underline.Checked ? "N'underline'" : "N'none'"; str_Italic = cb_Italic.Checked ? "N'italic'" : "N'normal'"; str_Direction = "N'" + ddl_Direction.Value + "'"; str_FontFamily_Outer = ddl_FontFamily_Outer.SelectedValue != "" ? ddl_FontFamily_Outer.SelectedValue : "NULL"; ClSqlCmd.CommandExc(@" INSERT INTO [dbo].[__StandardEngine_T_TextStyle] ([TextStyle_ID] ,[ForeColor] ,[BackColor] ,[FontFamily] ,[FontSize] ,[Align] ,[Bold] ,[Underline] ,[Italic] ,[Direction] ,[FontFamily_Outer]) VALUES ( " + str_TextStyle_ID + @", " + str_ForeColor + @", " + str_BackColor + @", " + str_FontFamily + @", " + str_FontSize + @", " + str_Align + @", " + str_Bold + @", " + str_Underline + @", " + str_Italic + @", " + str_Direction + @", " + str_FontFamily_Outer + @" )"); #region Update style text str_Style_Txt = str_Style_Txt.Replace("", txt_ForeColor.Value); str_Style_Txt = str_Style_Txt.Replace("", (!cb_BackColor_Trans.Checked ? txt_BackColor.Value : "transparent")); str_Style_Txt = str_Style_Txt.Replace("", (ddl_FontFamily_Outer.SelectedValue != "" ? ("'" + ddl_FontFamily_Outer.SelectedItem.Text + "',") : "") + ddl_FontFamily.Value); str_Style_Txt = str_Style_Txt.Replace("", ddl_FontSize.Value); str_Style_Txt = str_Style_Txt.Replace("", cb_Bold.Checked ? "bold" : "normal"); str_Style_Txt = str_Style_Txt.Replace("", cb_Underline.Checked ? "underline" : "none"); str_Style_Txt = str_Style_Txt.Replace("", cb_Italic.Checked ? "italic" : "normal"); str_Style_Txt = str_Style_Txt.Replace("", ddl_Align.Value); str_Style_Txt = str_Style_Txt.Replace("", "solid 1px " + txt_ForeColor.Value); str_Style_Txt = str_Style_Txt.Replace("", ddl_Direction.Value); #endregion #endregion #region update current ModuleStyles ClSqlCmd.CommandExc(@" update [dbo].[__StandardEngine_T_ModuleStyles] set [" + Request.Params["T"].Trim().Replace("'", "''") + @"_TextStyle_ID]=" + str_TextStyle_ID + @" 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"])); } } }