using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class AR_WUC_AdminBar : System.Web.UI.UserControl
{
EditorPage EP_1;
UpperBanner UB_1;
bool bool_inAdmin = false;
bool bool_HideControls = false;
public string str_Position_Style;
public string str_Size_Style;
public string str_HdnFields;
public int int_EditorPage_Type_ID;
public string str_Group_Start_EditorPage_ID;
DBAccess.DBAccess ClSqlCmd;
public void Page_Load(object sender, EventArgs e)
{
ClSqlCmd = new DBAccess.DBAccess(System.Configuration.ConfigurationSettings.AppSettings["SE_ConnectionString"]);
lnk_Save.Attributes["onclick"] = "javascript:return window.onbeforeunload='';";
lnk_Publish.Attributes["onclick"] = "javascript:return window.onbeforeunload='';";
DateTime ED = Convert.ToDateTime("1/1/2050");
if (System.DateTime.Today > ED)
{
Response.Redirect("http://www.sam-ware.com/Expired?T=WS");
}
///////////////////////////////////////////////////////////////////////////
if (Session["AdminID" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]] == null || Session["AdminID" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]].ToString() == "") //Admin logged in
{
tbl_AdminBar.Visible = false;
td_AdminControls_Left.Visible = false;
td_AdminControls_Right.Visible = false;
}
else
{
tbl_AdminBar.Visible = true;
td_AdminControls_Left.Visible = true;
td_AdminControls_Right.Visible = true;
}
///////////////////////////////////////////////////////////////////////////
if (!Page.IsPostBack)
{
#region Showing Corporate
if (Session["Admin_CorporateName"] != null)
{
lbl_CorporateName.Text = "إدارة موقع " + Session["Admin_CorporateName"].ToString();
//td_CorporateName.InnerText = "إدارة موقع " + Session["Admin_CorporateName"].ToString();
}
#endregion
#region Showing Corporate
if (Session["Admin_Name"] != null)
{
lbl_Name.Text = "المدير: " + Session["Admin_Name"].ToString();
}
#endregion
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Session.Remove("AdminID" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]);
Session.Remove("Admin_Name");
Session.Remove("Admin_Password");
Session.Remove("Admin_Level");
Session.Remove("Admin_Corporate_ID");
Session.Remove("Admin_CorporateName");
Response.Redirect(Request.Url.ToString());
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("Admin/Module-Settings.aspx?retP=" + Server.UrlEncode(Request.Url.ToString()));
}
protected void Lnk_Save_Click(object sender, EventArgs e)
{
bool bool_redirect = false;
bool_redirect = Save();
if (bool_redirect)
{
Response.Redirect(Request.Url.ToString());
}
}
string f_FormSQLStyle(string _str_EditorPage_ID)
{
string str_SQL = "";
string str_Position_Style = "";
string str_Size_Style = "";
if (Request.Form["hdn_Position_" + _str_EditorPage_ID] != null
&& Request.Form["hdn_Position_" + _str_EditorPage_ID] != "")
{
str_Position_Style = "N'"+Request.Form["hdn_Position_" + _str_EditorPage_ID]+"'";
}
if(Request.Form["hdn_Size_" + _str_EditorPage_ID] != null
&& Request.Form["hdn_Size_" + _str_EditorPage_ID] != "")
{
str_Size_Style = "N'"+Request.Form["hdn_Size_" + _str_EditorPage_ID]+"'";
}
if (str_Position_Style != "" || str_Size_Style != "")
{
str_SQL = @" UPDATE [dbo].[__StandardEngine_T_EditorPages]
SET
[Position_Style] = " + (str_Position_Style != "" ? str_Position_Style : "[Position_Style]") + @"
,[Size_Style] = " + (str_Size_Style != "" ? str_Size_Style : "[Size_Style]") + @"
WHERE [EditorPage_ID] = " +_str_EditorPage_ID;
}
#region Get Children
DataSet DS = ClSqlCmd.DataSetSel(@" SELECT
[EditorPage_ID]
FROM [dbo].[__StandardEngine_T_EditorPages]
where
[Parent_EditorPage_ID]=" + _str_EditorPage_ID + @"
Order by
[Order] asc,
[EditorPage_ID] asc");
if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
{
foreach (DataRow DR in DS.Tables[0].Rows)
{
str_SQL += f_FormSQLStyle(DR["EditorPage_ID"].ToString());
}
}
#endregion
return str_SQL;
}
protected void LinkButton3_Click(object sender, EventArgs e)
{
Session.Add("HideControls", 1);
Response.Redirect(Request.Url.ToString());
}
protected void LinkButton4_Click(object sender, EventArgs e)
{
Session.Remove("HideControls");
Response.Redirect(Request.Url.ToString());
}
protected bool Save()
{
bool bool_redirect = false;
string str_SQL = "";
#region Delete Deleted Elements
if (Request.Form["hdn_Deleted_IDs"] != null && Request.Form["hdn_Deleted_IDs"] != "")
{
string[] strs_DeletedIDs = Request.Form["hdn_Deleted_IDs"].Split(null);
foreach (string _str_ID in strs_DeletedIDs)
{
if (_str_ID.Trim() != "")
{
//str_SQL += " delete from dbo.__StandardEngine_T_EditorPages where EditorPage_ID=" + _str_ID;
}
}
if (str_SQL != "")
{
//Response.Write(">>>>>>"+str_SQL);
//Response.End();
ClSqlCmd.CommandExc(str_SQL);
bool_redirect = true;
}
}
#endregion
DataSet DS = ClSqlCmd.DataSetSel(@" SELECT
[EditorPage_ID]
,[Position_Style]
,[Size_Style]
FROM [dbo].[__StandardEngine_T_EditorPages]
where
( [EditorPage_Type_ID]=1001 OR
[EditorPage_Type_ID]=2001
) and
[Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]);
if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0)
{
foreach (DataRow DR in DS.Tables[0].Rows)
{
if (DR["EditorPage_ID"] != Convert.DBNull)
{
str_SQL += f_FormSQLStyle(DR["EditorPage_ID"].ToString());
}
}
}
str_SQL += f_FormSQLStyle(Request.Params["ID"].Replace("'", ""));
if (str_SQL != "")
{
ClSqlCmd.CommandExc(str_SQL);
bool_redirect = true;
}
//////////////////////////////////////////////
return bool_redirect;
}
protected void Publish()
{
string str_HTML_Final = "";
//Main
str_HTML_Final += @"
| <--Header--> |
|
|
|
<--Content-->
|
| <--Footer--> |
|
";
/////////////////////////////////////////////////////////////////////////////////////////////
//str_HTML_Final = str_HTML_Final.Replace("<--Header-->", GetData(1001));
//str_HTML_Final = str_HTML_Final.Replace("<--Content-->", GetData(0));
//str_HTML_Final = str_HTML_Final.Replace("<--Footer-->", GetData(2001));
//UB_1 = new UpperBanner(Server, Request, bool_inAdmin, bool_HideControls);
//str_HTML_Final = str_HTML_Final.Replace("<--Banner-->", UB_1.getall());
Save(GetData(1001), 1000, "9997", null, System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]);
Save(GetData(0), 1000, "9999", Request.Params["ID"].Replace("'", ""), System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]);
Save(GetData(2001), 1000, "9998", null, System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]);
////////////////////////////////////////////////////////////////////////////////////////////
}
string GetData(int _int_EditorPage_Type_ID)
{
string str_HTML = "";
string str_Start_EditorPage_ID;
string str_Start_EditorPage_Type_ID;
EP_1 = new EditorPage(Server, Request, "", false, true,_int_EditorPage_Type_ID);
DataSet DS;
str_HdnFields = "";
int_EditorPage_Type_ID = _int_EditorPage_Type_ID;
str_Start_EditorPage_ID = "-1";
str_Start_EditorPage_Type_ID = "";
str_HTML = "<--Content-->";
//////////////////////////////////////////////////////////
#region Get
str_Group_Start_EditorPage_ID = ClSqlCmd.DataSetSel(@"select [dbo].[__StandardEngine_F_Group_FirstPage](
[dbo].[__StandardEngine_F_EditorPage_Group_ID]( " + Request.Params["ID"].Replace("'", "") + @" )
)").Tables[0].Rows[0][0].ToString();
EP_1.str_Group_Start_EditorPage_ID = str_Group_Start_EditorPage_ID;
#endregion
///////////////////////////////////////////////////////////
if (int_EditorPage_Type_ID > 0) //Header
{
str_Start_EditorPage_Type_ID = int_EditorPage_Type_ID.ToString();
///////////////////////////////////////////////
DS = ClSqlCmd.DataSetSel(@" SELECT
[EditorPage_ID]
,[Position_Style]
,[Size_Style]
FROM [dbo].[__StandardEngine_T_EditorPages]
where
[EditorPage_Type_ID]=" + int_EditorPage_Type_ID.ToString() + @" and
[Module_ID]=" + System.Configuration.ConfigurationSettings.AppSettings["SE_ModuleID"]);
if (DS.Tables.Count > 0 && DS.Tables[0].Rows.Count > 0 && DS.Tables[0].Rows[0]["EditorPage_ID"] != Convert.DBNull)
{
str_Size_Style = DS.Tables[0].Rows[0]["Size_Style"].ToString();
////////////////////////
str_Start_EditorPage_ID = DS.Tables[0].Rows[0]["EditorPage_ID"].ToString();
}
else
{
str_Start_EditorPage_ID = "-1";
}
}
else
{
str_Start_EditorPage_ID = Request.Params["ID"].Replace("'", "");
}
//////////////////////////////////////////////////////////
str_HTML = str_HTML.Replace("<--Content-->", EP_1.f_FormEditorPage(str_Start_EditorPage_ID, str_Start_EditorPage_Type_ID, "", 0, ""));
///////////////////////////////////////////////
return str_HTML;
}
void Save(string _str_HTML_Final, int _int_ValueLength, string _str_EditorPage_Type,string _str_Parent_EditorPage_ID, string _str_Module_ID)
{
string str_HTML_Final = _str_HTML_Final;
int int_ValueLength = _int_ValueLength;
string str_EditorPage_Type = _str_EditorPage_Type;
string str_InsertValue = "";
//Delete Previous
ClSqlCmd.CommandExc(@" delete from [dbo].[__StandardEngine_T_EditorPages]
where
[EditorPage_Type_ID]=" + str_EditorPage_Type
+ (_str_Parent_EditorPage_ID != null ? (@" and [Parent_EditorPage_ID]=" + _str_Parent_EditorPage_ID) : "")
+ (_str_Module_ID != null ? (@" and [Module_ID]=" + _str_Module_ID) : "")
);
//Save
while (str_HTML_Final.Length > 0)
{
if (str_HTML_Final.Length > int_ValueLength)
{
str_InsertValue = str_HTML_Final.Substring(0, int_ValueLength).Replace("'", "''");
str_HTML_Final = str_HTML_Final.Remove(0, int_ValueLength);
}
else
{
str_InsertValue = str_HTML_Final.Replace("'", "''");
str_HTML_Final = "";
}
ClSqlCmd.CommandExc(@" INSERT INTO [dbo].[__StandardEngine_T_EditorPages]
(
[EditorPage_ID]
,[HTMLContent]
,[Parent_EditorPage_ID]
,[EditorPage_Type_ID]
,[Order]
,[Module_ID]
)
VALUES
(
dbo.__StandardEngine_F_MaxID_EditorPages()+1
,N'" + str_InsertValue + @"'
," + (_str_Parent_EditorPage_ID!=null?_str_Parent_EditorPage_ID:"NULL") + @"
,"+_str_EditorPage_Type+@"
,[dbo].[__StandardEngine_F_MaxOrder_EditorPages__Type] (" + (_str_Parent_EditorPage_ID!=null?_str_Parent_EditorPage_ID:"NULL") + @"," + _str_EditorPage_Type + @")
," + (_str_Module_ID!=null?_str_Module_ID:"NULL") + @"
)");
}
}
protected void lnk_Publish_Click(object sender, EventArgs e)
{
bool bool_redirect = false;
bool_redirect = Save();
Publish();
if (bool_redirect)
{
Response.Redirect(Request.Url.ToString());
}
}
}