using System; using System.Globalization; using System.Collections; using System.ComponentModel; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace AeroNet.ops { /// /// Ââîä íîâîñòåé /// public class ops_NewsEdit : Common { protected string action; protected System.Web.UI.WebControls.Label lblID; protected System.Web.UI.WebControls.TextBox tbData; protected System.Web.UI.WebControls.RadioButtonList rblType; protected System.Web.UI.WebControls.TextBox tbAuthor; protected System.Web.UI.WebControls.TextBox tbTitle; protected System.Web.UI.WebControls.TextBox tbText; protected System.Web.UI.WebControls.Button UpdateBtn; protected System.Web.UI.WebControls.Button DelBtn; protected System.Web.UI.WebControls.Button CancelBtn; protected int id; protected int type; protected SqlDataReader dr; protected void GetNewsLoad (int id) { ops_NewsDB news = new ops_NewsDB(); dr = news.GetNews(id); while(dr.Read()) { lblID.Text = dr["ID"].ToString(); tbData.Text = String.Format("{0:d}",dr["Date"]); tbAuthor.Text = dr["Author"].ToString(); rblType.SelectedValue = dr["Type"].ToString(); tbTitle.Text = dr["Title"].ToString(); tbText.Text = dr["Text"].ToString(); } } private void UpdateBtn_Click(object sender, System.EventArgs e) { System.Collections.Specialized.NameValueCollection colForm = Request.Form; SqlConnection myConnection = new SqlConnection(connString); SqlCommand myCommand = new SqlCommand("ops_UpdateNews", myConnection); myCommand.CommandType = CommandType.StoredProcedure; SqlParameter parameterID = new SqlParameter("@ID", SqlDbType.Int, 4); parameterID.Value = Convert.ToInt32(lblID.Text); myCommand.Parameters.Add(parameterID); SqlParameter parameterNewsData = new SqlParameter("@Date", SqlDbType.VarChar, 50); parameterNewsData.Value = tbData.Text; myCommand.Parameters.Add(parameterNewsData); SqlParameter parameterType = new SqlParameter("@Type", SqlDbType.Int, 4); parameterType.Value = Convert.ToInt32(rblType.SelectedItem.Value); myCommand.Parameters.Add(parameterType); SqlParameter parameterAuthor = new SqlParameter("@Author", SqlDbType.NVarChar, 50); parameterAuthor.Value = tbAuthor.Text; myCommand.Parameters.Add(parameterAuthor); SqlParameter parameterTitle = new SqlParameter("@Title", SqlDbType.NVarChar, 255); parameterTitle.Value = tbTitle.Text; myCommand.Parameters.Add(parameterTitle); SqlParameter parameterText = new SqlParameter("@Text", SqlDbType.NText); parameterText.Value = tbText.Text; myCommand.Parameters.Add(parameterText); myConnection.Open(); myCommand.ExecuteNonQuery(); myConnection.Close(); Response.Write(""); } private void DelBtn_Click(object sender, System.EventArgs e) { ops_NewsDB news = new ops_NewsDB(); news.RemoveNews(id); Response.Write(""); } private void CancelBtn_Click(object sender, System.EventArgs e) { Response.Write(""); } private void Page_Load(object sender, System.EventArgs e) { OpsMenu(); //Ñ÷èòûâàíèå ïàðàìåòðà action èç ñòðîêè çàïðîñà if (Request.QueryString["action"] == null) { action = "edit"; } else { action = Request.QueryString["action"].ToString(); } //Ñ÷èòûâàíèå id íîâîñòè èç ñòðîêè çàïðîñà if (Request.QueryString["id"] == null) { id = 2; } else { id = Convert.ToInt32(Request.QueryString["id"]); } if (!Page.IsPostBack) { System.Collections.Specialized.NameValueCollection colForm = Request.Form; if (action != "del") GetNewsLoad (id); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.UpdateBtn.Click += new System.EventHandler(this.UpdateBtn_Click); this.DelBtn.Click += new System.EventHandler(this.DelBtn_Click); this.CancelBtn.Click += new System.EventHandler(this.CancelBtn_Click); this.Load += new System.EventHandler(this.Page_Load); } #endregion } }