Пример #1
0
        private void EditBook_Load(object sender, EventArgs e)
        {
            for (int i = 0; i <= 10; i++)
            {
                cmbQuantity.Items.Add(i);
            }
            for (int i = 1900; i <= DateTime.Now.Year; i++)
            {
                cmbYear.Items.Add(i);
            }

            string     commString = "SELECT * FROM BooksInfo";
            SqlCommand comm       = new SqlCommand(commString, SQLConnection.Connection);

            comm.Connection.Open();

            SqlDataReader zaList = comm.ExecuteReader();

            while (zaList.Read())
            {
                BookEdit b = new BookEdit();

                b.ISBN     = zaList.GetInt32(0);
                b.BookName = zaList.GetString(1);
                b.Author   = zaList.GetString(2);
                b.Year     = zaList.GetInt32(3);
                b.Language = zaList.GetInt32(4);
                b.Category = zaList.GetInt32(5);
                b.Quantity = zaList.GetInt32(6);

                listBookID.Items.Add(b);
            }
            SQLConnection.Connection.Close();

            string         forCategory = "Select CategoryID, Description from Categories";
            SqlDataAdapter adapter     = new SqlDataAdapter(forCategory, SQLConnection.Connection);
            DataTable      dtable      = new DataTable();

            adapter.Fill(dtable);

            cmbCategory.DataSource    = dtable;
            cmbCategory.DisplayMember = "Description";
            cmbCategory.ValueMember   = "CategoryID";


            string         zaLanguage = "Select ID, Language from Language";
            SqlDataAdapter da         = new SqlDataAdapter(zaLanguage, SQLConnection.Connection);
            DataTable      dt         = new DataTable();

            da.Fill(dt);

            cmbLanguage.DataSource    = dt;
            cmbLanguage.DisplayMember = "Language";
            cmbLanguage.ValueMember   = "ID";
        }
Пример #2
0
 private void listBookID_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (listBookID.SelectedIndex != -1)
     {
         BookEdit obj = (BookEdit)listBookID.SelectedItem;
         txtISBN.Text              = obj.ISBN.ToString();
         txtAuthor.Text            = obj.Author.ToString();
         txtName.Text              = obj.BookName.ToString();
         cmbYear.Text              = obj.Year.ToString();
         cmbCategory.SelectedValue = obj.Category.ToString();
         cmbLanguage.SelectedValue = obj.Language.ToString();
         cmbQuantity.Text          = obj.Quantity.ToString();
     }
 }
Пример #3
0
        private void EditBook_Load(object sender, EventArgs e)
        {
            for (int i = 0; i <= 10; i++)
            {
                cmbQuantity.Items.Add(i);
            }
            for (int i = 1900; i <= DateTime.Now.Year; i++)
            {
                cmbYear.Items.Add(i);
            }

            string commString = "SELECT * FROM BooksInfo";
            SqlCommand comm = new SqlCommand(commString, SQLConnection.Connection);
            comm.Connection.Open();

            SqlDataReader zaList = comm.ExecuteReader();
            while (zaList.Read())
            {
                BookEdit b = new BookEdit();

                b.ISBN = zaList.GetInt32(0);
                b.BookName = zaList.GetString(1);
                b.Author = zaList.GetString(2);
                b.Year = zaList.GetInt32(3);
                b.Language = zaList.GetInt32(4);
                b.Category = zaList.GetInt32(5);
                b.Quantity = zaList.GetInt32(6);

                listBookID.Items.Add(b);

            }
            SQLConnection.Connection.Close();

            string forCategory = "Select CategoryID, Description from Categories";
            SqlDataAdapter adapter = new SqlDataAdapter(forCategory, SQLConnection.Connection);
            DataTable dtable = new DataTable();
            adapter.Fill(dtable);

            cmbCategory.DataSource = dtable;
            cmbCategory.DisplayMember = "Description";
            cmbCategory.ValueMember = "CategoryID";

            string zaLanguage = "Select ID, Language from Language";
            SqlDataAdapter da = new SqlDataAdapter(zaLanguage, SQLConnection.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);

            cmbLanguage.DataSource = dt;
            cmbLanguage.DisplayMember = "Language";
            cmbLanguage.ValueMember = "ID";
        }