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.SqlClient;

namespace SaveToDB
{
  public partial class _Default : System.Web.UI.Page
  {

    private string Notes
    {
      get
      {
        return Grid1.SelectedItem.Cells[4].Text;
      }
    }

    private int EmployeeID
    {
      get
      {
        return int.Parse(Grid1.SelectedItem.Cells[1].Text);
      }
    }

    protected void Grid1_SelectedIndexChanged1(object sender, EventArgs e)
    {
      RadEditor1.Html = this.Notes;
    }

    protected void RadEditor1_SubmitClicked(object sender, EventArgs e)
    {
      const string commandText =
        "update Employees set Notes = @Notes where EmployeeID = @EmployeeID";

      if ((RadEditor1.Html != string.Empty) && (Grid1.SelectedItem != null))
      {
        SqlConnection connection =
          new SqlConnection(SqlDataSource1.ConnectionString);
        SqlCommand command =
          new SqlCommand(commandText, connection);
        command.Parameters.AddWithValue("Notes", RadEditor1.Html);
        command.Parameters.AddWithValue("EmployeeID", this.EmployeeID);

        connection.Open();
        command.ExecuteNonQuery();
        connection.Close();

        Grid1.DataBind();
      }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
      if (!IsPostBack)
      {
        HasPermission.Checked = RadEditor1.HasPermission;
        Editable.Checked = RadEditor1.Editable; 
      }
    }

    protected void CheckedChanged(object sender, EventArgs e)
    {
      RadEditor1.HasPermission = HasPermission.Checked;
      RadEditor1.Editable = Editable.Checked; 
    }


  }
}
