public static bool Sach_TheLoai_CreateNewRecord(SQL.Struct.Sach_TheLoai _value)
 {
     try
     {
         commandSQL.CommandText = "insert into Sach_TheLoai(MaSach, MaTheLoai) values (N'" + _value.MaSach + "', N'" + _value.MaTheLoai + "')";
         commandSQL.Connection  = connSQL;
         connSQL.Open();
         commandSQL.ExecuteNonQuery();
         connSQL.Close();
         return(true);
     }
     catch
     {
         connSQL.Close();
         return(false);
     }
 }
Esempio n. 2
0
        private void button2_AddNew_Click(object sender, EventArgs e)
        {
            if (!_bCheckClick_AddNewBook)
            {
                _bCheckClick_AddNewBook  = true;
                this.button2_AddNew.Text = "Lưu bản ghi";

                EditMode(true);
                SetStatus_TextBox(ref lTextBox, true);

                dataGridView1_Info.Enabled  = false;
                this.button3_Edit.Enabled   = false;
                this.button4_Delete.Enabled = false;
                this.button7_Save.Enabled   = false;

                textBox8.Text = "True";
                EmptyInfo();
                textBox1.Text = SQL.ListData.GetDataFromSQL.Sach_GetNextIndex();


                //dataGridView2_DSTheLoai.DataSource = null;
                //dataGridView2_DSTheLoai.Refresh();

                button8_AddNewTypeBook.Show();
            }
            else
            {
                _bCheckClick_AddNewBook   = false;
                this.button2_AddNew.Text  = "Thêm mới";
                this.button7_Save.Enabled = true;
                button8_AddNewTypeBook.Hide();

                dataGridView1_Info.Enabled  = true;
                this.button3_Edit.Enabled   = true;
                this.button4_Delete.Enabled = true;

                string sErrorMessage = "Tình trạng:\n\n";

                // tạo bản ghi cho cuốn sách mới
                SQL.Struct.Sach t = TextboxTo_Sach();
                if (SQL.ListData.GetDataFromSQL.Sach_CreateNewRecord(t))
                {
                    sErrorMessage += "\n- Tạo bản ghi sách mới thành công!\n";
                }
                else
                {
                    sErrorMessage += "\n- Tạo bản ghi sách thất bại!\n";
                }

                // lưu thể loại cho cuốn sách mới
                SQL.Struct.Sach_TheLoai stl;
                for (int i = 0; i < chooseTypeBook.Items.Count; i++)
                {
                    if (chooseTypeBook.GetItemChecked(i))
                    {
                        stl           = new SQL.Struct.Sach_TheLoai();
                        stl.MaSach    = textBox1.Text;
                        stl.MaTheLoai = lMaTheLoai[i];

                        if (SQL.ListData.GetDataFromSQL.Sach_TheLoai_CreateNewRecord(stl))
                        {
                            sErrorMessage += "\n- Tạo thể loại \"" + lTenTheLoai[i] + "\" thành công!";
                        }
                        else
                        {
                            sErrorMessage += "\n- Thất bại tạo thể loại \"" + lTenTheLoai[i] + "\"!";
                        }
                    }
                }
                dataGridView2_DSTheLoai.DataSource = null;
                dataGridView2_DSTheLoai.Columns.Remove("TheLoai");
                MessageBox.Show(sErrorMessage);
            }
        }