Example #1
0
        private void bunifuThinButton21_Click(object sender, EventArgs e)
        {
            FRM_ADD frm_add = new FRM_ADD();

            frm_add.btnadd.ButtonText = "ADD ";
            frm_add.state             = 0;
            frm_add.Show();
            //bunifuTransition1.ShowSync(frm_add);
        }
Example #2
0
        private void bunifuThinButton22_Click(object sender, EventArgs e)
        {
            //EDIT
            FRM_ADD frm_add = new FRM_ADD();

            frm_add.btnadd.ButtonText = "Edit ";
            frm_add.state             = Convert.ToInt16(dataGridView1.CurrentRow.Cells[0].Value);

            frm_add.Show();

            try
            {
                con.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PC\source\BookManegment\BookManegment\BookManegment\DbBook.mdf;Integrated Security=True;User Instance=True");
                cmd.Connection       = con;
                con.Open();
                cmd.CommandText = " SELECT Tittel, Auther, Price, Cat,Date,Rate FROM TbBooks where ID=@ID";
                cmd.Parameters.AddWithValue("@ID", Convert.ToInt32(frm_add.state));



                con.Close();
                con.Open();
                var rd = cmd.ExecuteReader();
                while (rd.Read())
                {
                    List.Add(Convert.ToString(rd[0]));
                    List.Add(Convert.ToString(rd[1]));
                    List.Add(Convert.ToString(rd[2]));
                    List.Add(Convert.ToString(rd[3]));
                    List.Add(Convert.ToString(rd[4]));
                    List.Add(Convert.ToString(rd[5]));
                }


                frm_add.txt_name.Text   = List[0];
                frm_add.txt_author.Text = List[1];
                frm_add.txt_price.Text  = List[2];
                frm_add.txt_cat.Text    = List[3];
                frm_add.txt_date.Value  = Convert.ToDateTime(List[4]);
                frm_add.txt_rate.Value  = Convert.ToInt32(List[5]);
                List.Clear();
                con.Close();

                // Read Image from database

                cmd.CommandText = "SELECT COVER FROM TBBOOKS WHERE ID=@IDIMAGE";
                cmd.Parameters.AddWithValue("@IDIMAGE", Convert.ToInt16(dataGridView1.CurrentRow.Cells[0].Value));

                con.Open();
                byte[]       img = (byte[])cmd.ExecuteScalar();
                MemoryStream ma  = new MemoryStream();
                ma.Write(img, 0, img.Length);
                frm_add.cover.Image = Image.FromStream(ma);
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
            }
            finally
            {
                con.Close();
            }

            cmd.Parameters.Clear();
        }