コード例 #1
0
        private void giveBook(object sender, RoutedEventArgs e)
        {
            students pr = (students)grid.SelectedItem;

            if (pr != null)
            {
                string id_student = pr.idStud;

                try
                {
                    DateTime CurrentDate = DateTime.Now;

                    string     sqlexpression = "INSERT INTO GIVEBOOK VALUES(@today_date, null, @id_book, @id_reader)";
                    SqlCommand command       = new SqlCommand(sqlexpression, connection);

                    SqlParameter cur_date_par = new SqlParameter("@today_date", CurrentDate);
                    command.Parameters.Add(cur_date_par);

                    SqlParameter book_par = new SqlParameter("@id_book", id_product);
                    command.Parameters.Add(book_par);

                    SqlParameter reader_par = new SqlParameter("@id_reader", id_student);
                    command.Parameters.Add(reader_par);

                    command.ExecuteNonQuery();
                }
                catch (SqlException er)
                {
                    MessageBox.Show(er.Message);
                }
            }
        }
コード例 #2
0
        private void next_step(object sender, RoutedEventArgs e)
        {
            students pr = (students)grid.SelectedItem;

            if (pr != null)
            {
                string id_student = pr.idStud;
                new DebtorBook(connection, this, id_student);
            }
        }
コード例 #3
0
        public Student(SqlConnection connection, Window parent, string id_product)
        {
            InitializeComponent();
            this.Show();
            this.parent       = parent;
            this.connection   = connection;
            this.id_product   = id_product;
            parent.Visibility = Visibility.Hidden;

            try
            {
                List <students> students_list = new List <students>();
                string          sqlexpression = "SELECT * FROM dbo.READERS";
                SqlCommand      command       = new SqlCommand(sqlexpression, connection);
                SqlDataReader   reader        = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        students rec = new students();
                        rec.idStud    = reader.GetValue(0).ToString();
                        rec.LastName  = reader.GetValue(1).ToString();
                        rec.FirstName = reader.GetValue(2).ToString();
                        rec.MidName   = reader.GetValue(3).ToString();

                        students_list.Add(rec);
                    }

                    reader.Close();
                    grid.ItemsSource = students_list;
                }
                else
                {
                    reader.Close();
                }
            }
            catch (SqlException er)
            {
                MessageBox.Show(er.Message);
            }
        }