示例#1
0
        private void bunifuThinButton23_Click(object sender, EventArgs e)
        {
            if (TXT_CAT.Text != "")
            {
                con.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PC\source\BookManegment\BookManegment\BookManegment\DbBook.mdf;Integrated Security=True;User Instance=True");
                con.Open();

                cmd.Connection  = con;
                cmd.CommandText = "INSERT INTO TbCat (Cat) VALUES (@Cat)";
                cmd.Parameters.AddWithValue("@Cat", TXT_CAT.Text);
                cmd.ExecuteNonQuery();
                con.Close();
                Form frm_add = new FRM_DIADD();
                frm_add.Show();
                this.Close();
            }
            else
            {
                MessageBox.Show("Please enter the catagory name");
            }
        }
示例#2
0
        private void bunifuThinButton23_Click(object sender, EventArgs e)
        {
            if (txt_author.Text == "" || txt_name.Text == "" || txt_price.Text == "")
            {
                MessageBox.Show("Please fill all informations!");
            }


            else
            {
                if (state == 0)
                {
                    //insert
                    //for convert image to Binary
                    MemoryStream ma = new MemoryStream();
                    cover.Image.Save(ma, System.Drawing.Imaging.ImageFormat.Jpeg);
                    var _cover = ma.ToArray();

                    // sql command
                    con.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PC\source\BookManegment\BookManegment\BookManegment\DbBook.mdf;Integrated Security=True;User Instance=True");
                    con.Open();

                    cmd.Connection  = con;
                    cmd.CommandText = "INSERT INTO TbBooks (Tittel, Auther, Price, Cat,Date,Rate,Cover) VALUES (@Tittel, @Auther, @Price, @Cat, @Date, @Rate, @Cover)";
                    cmd.Parameters.AddWithValue("@Tittel", txt_name.Text);
                    cmd.Parameters.AddWithValue("@Auther", txt_author.Text);
                    cmd.Parameters.AddWithValue("@Price", txt_price.Text);
                    cmd.Parameters.AddWithValue("@Cat", txt_cat.Text);
                    cmd.Parameters.AddWithValue("@Date", txt_date.Value);
                    cmd.Parameters.AddWithValue("@Rate", txt_rate.Value);
                    cmd.Parameters.AddWithValue("@Cover", _cover);

                    cmd.ExecuteNonQuery();
                    con.Close();
                    Form frm_add = new FRM_DIADD();
                    frm_add.Show();
                    this.Close();
                }
                else
                {
                    // edit

                    //for convert image to Binary
                    MemoryStream ma = new MemoryStream();
                    cover.Image.Save(ma, System.Drawing.Imaging.ImageFormat.Jpeg);
                    var _cover = ma.ToArray();

                    // sql command
                    con.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\PC\source\BookManegment\BookManegment\BookManegment\DbBook.mdf;Integrated Security=True;User Instance=True");
                    con.Open();

                    cmd.Connection  = con;
                    cmd.CommandText = "UPDATE TbBooks SET Tittel=@Tittel, Auther=@Auther, Price=@Price, Cat=@Cat, Date=@Date, Rate=@Rate, Cover=@Cover where ID=@ID";
                    cmd.Parameters.AddWithValue("@Tittel", txt_name.Text);
                    cmd.Parameters.AddWithValue("@Auther", txt_author.Text);
                    cmd.Parameters.AddWithValue("@Price", txt_price.Text);
                    cmd.Parameters.AddWithValue("@Cat", txt_cat.Text);
                    cmd.Parameters.AddWithValue("@Date", txt_date.Value);
                    cmd.Parameters.AddWithValue("@Rate", txt_rate.Value);
                    cmd.Parameters.AddWithValue("@Cover", _cover);
                    cmd.Parameters.AddWithValue("@ID", state);

                    cmd.ExecuteNonQuery();
                    con.Close();
                    Form frm_edit = new FRM_DIEDIT();
                    frm_edit.Show();
                    this.Close();
                }
            }

            cmd.Parameters.Clear();
        }