private void button1_Click(object sender, EventArgs e) { LessonSchool lesson = new LessonSchool(); // bool check= ValidateForm(); // if (check == true) // { string nameNew = LessonsName.Text; string nameEx = LessonsList.GetItemText(LessonsList.SelectedItem); string date = DateTbx.Text; string time = TimeTbx.Text; // var date = DateTime.ParseExact(dateS, "yyyyMMdd", null); //DateTime date = DateTime.Parse(DateTbx.Text); //DateTime time = DateTime.Parse(TimeTbx.Text); string groupName = GroupList.GetItemText(GroupList.SelectedItem); string courseName = CourseList.GetItemText(CourseList.SelectedItem); string roomName = RoomList.GetItemText(RoomList.SelectedItem); if (choose == 2) { ValidateForm(); string text = lesson.addNewLesson(nameNew, date, time, courseName, groupName, roomName); MessageBox.Show(text); } if (choose == 1) { ValidateForm(); string text = lesson.changeLesson(nameEx, date, time, courseName, groupName, roomName); MessageBox.Show(text); } //} }
protected void Page_Load(object sender, EventArgs e) { string var_id = Request.QueryString["id"]; string action_id = Request.QueryString["action"]; //manage page content if (var_id != null) { LessonsList_Form.Visible = false; if (var_id == "new") { if (Session["teacher"] == null) { Response.Redirect("~/Content/Lessons.aspx"); } NewLesson_Form.Visible = true; LessonsList.Visible = false; DisplayLesson_Content.Visible = true; } else { if (Session["teacher"] != null) { DisplayLesson_AddLesson.Visible = true; DisplayLesson_EditPage.Visible = true; DisplayLesson_DeleteLesson.Visible = true; DisplayLesson_AddPage.Visible = true; DisplayLesson_DeletePage.Visible = true; } string SQL_SELECT = "SELECT LessonIndex,Title,Subtitle,Content,Page FROM " + LessonsDB + " WHERE LessonIndex=" + var_id; SqlCommand CMD_SELECT = new SqlCommand(SQL_SELECT, DB_Connection); CMD_SELECT.CommandType = CommandType.Text; string SQL_SELECT_A = "SELECT count(*) FROM " + LessonsDB + " WHERE LessonIndex=" + var_id; SqlCommand CMD_SELECT_A = new SqlCommand(SQL_SELECT_A, DB_Connection); CMD_SELECT_A.CommandType = CommandType.Text; string SQL_SELECT_P = "SELECT LessonIndex FROM " + LessonsDB + " WHERE LessonIndex=" + (Convert.ToInt32(var_id) - 1); SqlCommand CMD_SELECT_P = new SqlCommand(SQL_SELECT_P, DB_Connection); CMD_SELECT_P.CommandType = CommandType.Text; string SQL_SELECT_N = "SELECT LessonIndex FROM " + LessonsDB + " WHERE LessonIndex=" + (Convert.ToInt32(var_id) + 1); SqlCommand CMD_SELECT_N = new SqlCommand(SQL_SELECT_N, DB_Connection); CMD_SELECT_P.CommandType = CommandType.Text; DB_Connection.Open(); using (SqlDataReader Reader = CMD_SELECT.ExecuteReader()) { if (Reader.Read() && !NewLesson_Form.Visible) //2nd check correct [?] { DisplayLesson_Form.Visible = true; DisplayLesson_Title.Text = Reader["Title"].ToString(); DisplayLesson_Subtitle.Text = Reader["Subtitle"].ToString(); DisplayLesson_DataSource.SelectCommand = "SELECT Content FROM " + LessonsDB + " WHERE LessonIndex=" + var_id; } } // disable "Delete Page" button if only 1 page found if (Convert.ToInt32(CMD_SELECT_A.ExecuteScalar().ToString()) < 2) { DisplayLesson_DeletePage.Enabled = false; DisplayLesson_DeletePage.ImageUrl = "~/Source/img/document-remove-disabled.png"; DisplayLesson_DeletePage.ToolTip = ""; } // display previous Lesson button using (SqlDataReader Reader2 = CMD_SELECT_P.ExecuteReader()) { if (Reader2.Read() && Reader2.HasRows) { DisplayLesson_Previous.NavigateUrl = "~/Content/Lessons.aspx?id=" + Reader2["LessonIndex"].ToString(); } else { DisplayLesson_Previous.Visible = false; } Reader2.Close(); } // display next Lesson button using (SqlDataReader Reader3 = CMD_SELECT_N.ExecuteReader()) { if (Reader3.Read() && Reader3.HasRows) { DisplayLesson_Next.NavigateUrl = "~/Content/Lessons.aspx?id=" + Reader3["LessonIndex"].ToString(); } else { DisplayLesson_Next.Visible = false; } Reader3.Close(); } LessonsList.Visible = false; DB_Connection.Close(); } } else //display list of Lessons { //need to prevent postback callback reimplementation if (Page.IsPostBack) { return; } LessonsList.Visible = true; Button_Return.Visible = false; if (Session["teacher"] == null) { LessonsList.Columns[4].Visible = false; LessonsList.ShowFooter = false; } string SQL_SELECT = "SELECT Surname, Name, LessonIndex, DateCreated, Title FROM " + LessonsDB + " INNER JOIN " + UsersDB + " ON " + LessonsDB + ".AuthorID=" + UsersDB + ".Username WHERE Page=1"; SqlDataAdapter da = new SqlDataAdapter(SQL_SELECT, DB_Connection); DataTable dt = new DataTable(); DB_Connection.Open(); da.Fill(dt); LessonsList.DataSource = dt; LessonsList.DataBind(); DB_Connection.Close(); } }