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.Data.OleDb; using System.Xml; using System.IO; public partial class controlportal_Default : System.Web.UI.Page { DataSet ds; string connString = ConfigurationSettings.AppSettings["ConString"]; UdeFulLinks usfulLinks = new UdeFulLinks(); protected void Page_Load(object sender, EventArgs e) { if (Session["isPermuted"] == null) Response.Redirect("~/controlportal/Login.aspx"); FillGrid(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { if (ds != null) { if (ds.Tables[0].Rows[GridView1.SelectedIndex] != null) { if (ds.Tables[0].Rows[GridView1.SelectedIndex]["Type"].ToString() != "0") ddlType.SelectedValue = ds.Tables[0].Rows[GridView1.SelectedIndex]["Type"].ToString(); txtarName.Text = ds.Tables[0].Rows[GridView1.SelectedIndex]["ar_name"].ToString(); txtName.Text = ds.Tables[0].Rows[GridView1.SelectedIndex]["en_name"].ToString(); txtLink.Text = ds.Tables[0].Rows[GridView1.SelectedIndex]["Link"].ToString(); } } } protected string chngchars(string strText) { string UpdatedText; UpdatedText = strText.Replace("'", "''"); return UpdatedText; } protected void btnSave_Click(object sender, ImageClickEventArgs e) { Label2.Text = ""; usfulLinks.link = chngchars(txtLink.Text); usfulLinks.en_name = chngchars(txtName.Text); usfulLinks.ar_name = chngchars(txtarName.Text); usfulLinks.type = ddlType.SelectedIndex + 1; try { OleDbCommand command; string query; if (Session["isNew"] != null) { query = "INSERT INTO usefullinks (en_name,type,ar_name,Link) VALUES('" + usfulLinks.en_name + "'," + usfulLinks.type + ",'" + usfulLinks.ar_name + "','" + usfulLinks.link + "')"; Session.Remove("isNew"); clrBoxs(); } else { usfulLinks.ID = (int)ds.Tables[0].Rows[GridView1.SelectedIndex]["ID"]; query = "UPDATE usefullinks SET en_name='" + usfulLinks.en_name + "', ar_name='" + usfulLinks.ar_name + "',Link='" + usfulLinks.link + "', Type=" + usfulLinks.type + " WHERE id=" + usfulLinks.ID.ToString(); } OleDbConnection connection = new OleDbConnection(connString); command = new OleDbCommand(query, connection); connection.Open(); command.ExecuteNonQuery(); connection.Close(); FillGrid(); } catch (OleDbException ex) { //loging code Label2.Text = ex.Message; } } protected void btnNew_Click(object sender, ImageClickEventArgs e) { Label2.Text = ""; clrBoxs(); Session.Add("isNew", "true"); ds.Tables.Clear(); FillGrid(); } private void FillGrid() { ds = new DataSet(); string Query = "SELECT * FROM usefullinks "; OleDbConnection con = new OleDbConnection(connString); con.Open(); OleDbDataAdapter adap = new OleDbDataAdapter(Query, con); adap.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); } protected void btnDel_Click(object sender, ImageClickEventArgs e) { Label2.Text = ""; OleDbCommand command; string query; string strID = ds.Tables[0].Rows[GridView1.SelectedIndex]["ID"].ToString(); ds.Tables.Clear(); query = "DELETE FROM usefullinks WHERE id=" + strID; OleDbConnection connection = new OleDbConnection(connString); command = new OleDbCommand(query, connection); connection.Open(); command.ExecuteNonQuery(); connection.Close(); FillGrid(); clrBoxs(); } private void clrBoxs() { //Remove Selection Label2.Text = ""; txtarName.Text = string.Empty; txtLink.Text = string.Empty; txtName.Text = string.Empty; ddlType.SelectedIndex = -1; //txtPath.Text = string.Empty; } protected void btnCancel_Click(object sender, ImageClickEventArgs e) { ViewState.Remove("isNew"); GridView1.SelectedIndex = -1; clrBoxs(); } }