Пример #1
0
 public void ShowBookForm(BookForm BookForm)
 {
     BookForm.TopLevel        = false;                    //取消顶层
     BookForm.FormBorderStyle = FormBorderStyle.None;     //取消标题栏
     this.panel1.Controls.Clear();                        //清除之前的控制
     BookForm.Dock = System.Windows.Forms.DockStyle.Fill; //填充panel
     this.panel1.Controls.Add(BookForm);
     BookForm.Show();
 }
Пример #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (searchid == null || searchid == "")
            {
                MessageBox.Show("编号不能为空", "提示");
                return;
            }
            int i = 0;

            //DataTable dt = (DataTable)dataGridView1.DataSource;
            for (i = 0; i < this.dataGridView2.Rows.Count; i++)
            {
                if ((string)dataGridView2.Rows[i].Cells["id"].Value == searchid)
                {
                    dataGridView2.Rows[i].Selected = true;
                    dataGridView2.FirstDisplayedScrollingRowIndex = i;
                    break;
                }
            }
            try
            {
                id       = dataGridView2.Rows[i].Cells[0].Value.ToString();                   //获得当前行的第0列的值
                name     = dataGridView2.Rows[i].Cells[1].Value.ToString();                   //获得当前行的第1列的值
                publish  = dataGridView2.Rows[i].Cells[2].Value.ToString();                   //获得当前行的第2列的值
                isbn     = dataGridView2.Rows[i].Cells[3].Value.ToString();                   //获得当前行的第3列的值
                state    = Convert.ToInt32(dataGridView2.Rows[i].Cells[4].Value.ToString());  //获得当前行的第4列的值
                opendate = dataGridView2.Rows[i].Cells[5].Value.ToString();                   //获得当前行的第5列的值
                price    = Convert.ToDouble(dataGridView2.Rows[i].Cells[6].Value.ToString()); //获得当前行的第6列的值
                BookForm bf = new BookForm();
                Console.WriteLine("新建bookform窗体...");
                bf.id       = searchid;
                bf.name     = name;
                bf.publish  = publish;
                bf.isbn     = isbn;
                bf.state    = state;
                bf.opendate = opendate;
                bf.price    = Convert.ToDouble(price);
                bf.InitRecord(searchid);
                ShowBookForm(bf);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
            }
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (id == null || id == "")
            {
                MessageBox.Show("编号不能为空", "提示");
                return;
            }
            id = textBox1.Text;
            String          connstr = "SslMode=None;datasource=127.0.0.1;port=3306;userid=root;password=123456;pooling=false; database=library;";
            MySqlConnection conn    = new MySqlConnection(connstr);
            string          sql     = "SELECT * FROM book WHERE id='" + id + "';";

            try
            {
                conn.Open();
                Console.WriteLine("数据库连接成功...");
                MySqlCommand    cmd    = new MySqlCommand(sql, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    name     = reader.GetString("name");
                    publish  = reader.GetString("publish");
                    isbn     = reader.GetString("isbn");
                    state    = Convert.ToInt32(reader.GetString("state"));
                    opendate = reader.GetString("opendate");
                    price    = Convert.ToDouble(reader.GetString("price"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                conn.Close();
            }
            BookForm bf = new BookForm();

            bf.id       = id;
            bf.name     = name;
            bf.publish  = publish;
            bf.isbn     = isbn;
            bf.state    = state;
            bf.opendate = opendate;
            bf.price    = price;
            Login.main.ShowBookForm(bf);  //调用login类中静态全局变量main,保证调用对象相同
        }
Пример #4
0
        private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int rowindex = e.RowIndex;

            Console.WriteLine("切换到图书...");
            try
            {
                id       = dataGridView2.Rows[rowindex].Cells[0].Value.ToString();                   //获得当前行的第0列的值
                name     = dataGridView2.Rows[rowindex].Cells[1].Value.ToString();                   //获得当前行的第1列的值
                publish  = dataGridView2.Rows[rowindex].Cells[2].Value.ToString();                   //获得当前行的第2列的值
                isbn     = dataGridView2.Rows[rowindex].Cells[3].Value.ToString();                   //获得当前行的第3列的值
                state    = Convert.ToInt32(dataGridView2.Rows[rowindex].Cells[4].Value.ToString());  //获得当前行的第4列的值
                opendate = dataGridView2.Rows[rowindex].Cells[5].Value.ToString();                   //获得当前行的第5列的值
                price    = Convert.ToDouble(dataGridView2.Rows[rowindex].Cells[6].Value.ToString()); //获得当前行的第6列的值
                Console.WriteLine(id);                                                               //debugging...
                Console.WriteLine(name);
                Console.WriteLine(publish);
                Console.WriteLine(isbn);
                Console.WriteLine(state);
                Console.WriteLine(opendate);
                Console.WriteLine(price);
                BookForm bf = new BookForm();
                Console.WriteLine("新建bookform窗体...");
                bf.id       = id;
                bf.name     = name;
                bf.publish  = publish;
                bf.isbn     = isbn;
                bf.state    = state;
                bf.opendate = opendate;
                bf.price    = Convert.ToDouble(price);
                ShowBookForm(bf);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }