using System; using System.Data; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Admin_Fonts : System.Web.UI.Page { public double dbl_HeightPerc; DBAccess.DBAccess DBAcc = new DBAccess.DBAccess(System.Configuration.ConfigurationSettings.AppSettings["SE_ConnectionString"]); private void Page_Load(object sender, System.EventArgs e) { if (!Page.IsPostBack) { load(); } } public void load() { lbl_msg_CantDelete.Visible = false; DataSet DS = DBAcc.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" ); DataGrid1.DataSource = DS; DataGrid1.DataBind(); #region Adding the con firm delete if (this.DataGrid1.Controls.Count > 0 && this.DataGrid1.Controls[0].Controls.Count > 2) { for (int i = 1; i < this.DataGrid1.Controls[0].Controls.Count - 1; i++) { LinkButton lnkB = (LinkButton)this.DataGrid1.Controls[0].Controls[i].FindControl("Linkbutton3"); lnkB.Attributes["onclick"] = "javascript:return confirm('Confirm data deletion');"; } } #endregion if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0) { lbl_msg_NoCats.Visible = false; DataGrid1.Visible = true; } else { lbl_msg_NoCats.Visible = true; DataGrid1.Visible = false; } } public void edit(string _str_ID) { lbl_msg_CantDelete.Visible = false; DataSet dataSet1 = new DataSet(); dataSet1 = DBAcc.DataSetSel(@" SELECT [Font_ID] ,[Font_Name] ,[Module_ID] FROM [dbo].[__StandardEngine_T_Fonts] where [Font_ID]= " + _str_ID ); //////////////////////////////////////////////////////////////////////////////////////////// hdn_ID.Value = _str_ID; if (dataSet1.Tables[0].Rows[0]["Font_Name"] != Convert.DBNull) { txt_Font_Name.Text = dataSet1.Tables[0].Rows[0]["Font_Name"].ToString(); hdn_passed_fil_1.Value = dataSet1.Tables[0].Rows[0]["Font_Name"].ToString(); } RequiredFieldValidator2.Enabled = false; } public void newrow() { lbl_msg_CantDelete.Visible = false; hdn_ID.Value = "0"; hdn_passed_fil_1.Value = ""; RequiredFieldValidator2.Enabled = true; } protected void Button1_Click1(object sender, EventArgs e) { #region validation bool valid = true; if (!valid) { return; } #endregion string Font_ID_v_s = ""; string Font_Name_v_s = txt_Font_Name.Text == "" ? "NULL" : "N'" + txt_Font_Name.Text.Replace("'", "''") + "'"; string Module_ID_v_s = System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]; string Fil_v_s=""; if (hdn_ID.Value == "0" || hdn_ID.Value == "") { Font_ID_v_s = DBAcc.DataSetSel("select dbo.[__StandardEngine_F_MaxID_Fonts]()+1 ").Tables[0].Rows[0][0].ToString(); #region Uploading the files if (fil_1.Value != "") { Fil_v_s = Font_ID_v_s + fil_1.PostedFile.FileName.Substring(fil_1.PostedFile.FileName.LastIndexOf(".")); fil_1.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Fonts\\" + Fil_v_s); } if (fil_2.Value != "") { Fil_v_s = Font_ID_v_s + fil_2.PostedFile.FileName.Substring(fil_2.PostedFile.FileName.LastIndexOf(".")); fil_2.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Fonts\\" + Fil_v_s); } if (fil_3.Value != "") { Fil_v_s = Font_ID_v_s + fil_3.PostedFile.FileName.Substring(fil_3.PostedFile.FileName.LastIndexOf(".")); fil_3.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Fonts\\" + Fil_v_s); } #endregion DBAcc.CommandExc(@" INSERT INTO [dbo].[__StandardEngine_T_Fonts] ([Font_ID] ,[Font_Name] ,[Module_ID]) VALUES (" + Font_ID_v_s + @", " + Font_Name_v_s + @", " + Module_ID_v_s + @" )" ); } else { Font_ID_v_s = hdn_ID.Value.Replace("'", ""); #region Uploading the files if (fil_1.Value != "") { Fil_v_s = Font_ID_v_s + fil_1.PostedFile.FileName.Substring(fil_1.PostedFile.FileName.LastIndexOf(".")); fil_1.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Fonts\\" + Fil_v_s); } if (fil_2.Value != "") { Fil_v_s = Font_ID_v_s + fil_2.PostedFile.FileName.Substring(fil_2.PostedFile.FileName.LastIndexOf(".")); fil_2.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Fonts\\" + Fil_v_s); } if (fil_3.Value != "") { Fil_v_s = Font_ID_v_s + fil_3.PostedFile.FileName.Substring(fil_3.PostedFile.FileName.LastIndexOf(".")); fil_3.PostedFile.SaveAs(Request.MapPath("") + "\\..\\Fonts\\" + Fil_v_s); } #endregion DBAcc.CommandExc(@" update [dbo].[__StandardEngine_T_Fonts] set [Font_Name]=" + Font_Name_v_s + @" where [Font_ID]=" + Font_ID_v_s ); } Save_FontsCSS(); newrow(); load(); btn_Cancel.Visible = false; btn_NewCat.Visible = true; td_Fields.Visible = false; td_Grid.Visible = true; } protected void Button2_Click1(object sender, EventArgs e) { btn_NewCat.Visible = false; btn_Cancel.Visible = true; td_Fields.Visible = true; td_Grid.Visible = false; newrow(); } protected void DataGrid1_ItemCommand1(object source, DataGridCommandEventArgs e) { int int_Order; DataSet DS_Bnrs = new DataSet(); switch (e.CommandName) { case "Edit": hdn_rowindex.Value = e.Item.ItemIndex.ToString().Trim(); hdn_ID.Value = e.CommandArgument.ToString(); btn_NewCat.Visible = false; btn_Cancel.Visible = true; td_Fields.Visible = true; td_Grid.Visible = false; edit(e.CommandArgument.ToString()); break; case "Delete": try { DBAcc.CommandExc(@" Delete FROM [dbo].[__StandardEngine_T_Fonts] where [Font_ID]=" + e.CommandArgument.ToString()); System.IO.File.Delete(Request.MapPath("") + "\\..\\Fonts\\" + e.CommandArgument.ToString() + ".ttf"); System.IO.File.Delete(Request.MapPath("") + "\\..\\Fonts\\" + e.CommandArgument.ToString() + ".woff"); System.IO.File.Delete(Request.MapPath("") + "\\..\\Fonts\\" + e.CommandArgument.ToString() + ".eot"); } catch { lbl_msg_CantDelete.Visible = true; return; } Save_FontsCSS(); load(); break; } } protected void Button3_Click1(object sender, EventArgs e) { } protected void Button4_Click(object sender, EventArgs e) { btn_NewCat.Visible = true; btn_Cancel.Visible = false; td_Fields.Visible = false; td_Grid.Visible = true; } protected void category_id_SelectedIndexChanged(object sender, EventArgs e) { load(); } protected void Save_FontsCSS() { string str_Fonts_CSS = ""; //Get template style text string str_Style_Txt = System.IO.File.ReadAllText(Request.MapPath("") + "/../Templates/Font_Face.css"); DataSet DS = DBAcc.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_ID] asc" ); if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0) { foreach (DataRow DR in DS.Tables[0].Rows) { str_Fonts_CSS += str_Style_Txt; str_Fonts_CSS = str_Fonts_CSS.Replace("", DR["Font_Name"].ToString()); str_Fonts_CSS = str_Fonts_CSS.Replace("", DR["Font_ID"].ToString()); } } #region write css files System.IO.File.WriteAllText(Request.MapPath("") + "/../CSS/" + "Fonts.css", str_Fonts_CSS); #endregion } }