예제 #1
0
        public string insert_Topic(TopicProvider topic)
        {
            string        user_message;
            SqlConnection sqlConnection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["connection"].ConnectionString);

            try
            {
                SqlCommand sqlCmd = new SqlCommand("[insert_topic]", sqlConnection);
                sqlCmd.CommandType = CommandType.StoredProcedure;
                sqlCmd.Parameters.Add("@topic_title", SqlDbType.NVarChar).Value = topic.topic_title;
                sqlCmd.Parameters.Add("@topic_text", SqlDbType.NVarChar).Value  = topic.topic_text;
                sqlCmd.Parameters.Add("@topic_date", SqlDbType.DateTime).Value  = topic.topic_date;
                sqlCmd.Parameters.Add("@topic_fk_teacher", SqlDbType.Int).Value = topic.topic_fk_teacher;
                sqlCmd.Parameters.Add("@topic_fk_course", SqlDbType.Int).Value  = topic.topic_fk_course;

                sqlConnection.Open();
                sqlCmd.ExecuteNonQuery();
                return(user_message = "Success!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(user_message = "Failure");
            }
            finally
            {
                sqlConnection.Close();
            }
        }
예제 #2
0
        private void bt_Add_Click(object sender, RoutedEventArgs e)
        {
            TopicProvider topic = new TopicProvider();

            topic.topic_title      = txt_Title.Text;
            topic.topic_text       = txt_Content.Text;
            topic.topic_date       = System.DateTime.Now;
            topic.topic_fk_teacher = TeacherLogin.teacher_uid;
            topic.topic_fk_course  = cbox_Course.SelectedIndex + 1;

            AddTopicHandler addTopicHandler = new AddTopicHandler();
            string          user_message    = addTopicHandler.insert_Topic(topic);

            MessageBox.Show(user_message);
        }