Exemplo n.º 1
0
        public static bool Update_ARecord_Sach(SQL.Struct.Sach s)
        {
            try
            {
                lstring.Clear();
                lstring.Add(@"TenSach = N'" + s.TenSach + "'");
                lstring.Add(@"TacGia = N'" + s.TacGia + "'");
                lstring.Add(@"NamXuatBan = " + s.NamXuatBan.ToString());
                lstring.Add(@"Gia = " + s.Gia.ToString());
                lstring.Add(@"NhaXuatBan = N'" + s.NhaXuatBan + "'");
                lstring.Add(@"GioiHanTuoi = " + s.GioiHanTuoi.ToString());
                lstring.Add(@"DuongDanAnhDaiDien = N'" + s.DuongDanAnhDaiDien + "'");

                commandSQL.CommandText = EditString(@"update Sach set ", @"where MaSach = N'" + s.MaSach + "'", ref lstring);
                commandSQL.Connection  = connSQL;
                connSQL.Open();
                commandSQL.ExecuteNonQuery();

                connSQL.Close();

                lstring.Clear();
                return(true);
            }
            catch
            {
                MessageBox.Show("Cant update the record!");

                connSQL.Close();

                return(false);
            }
        }
Exemplo n.º 2
0
        private void button7_Save_Click(object sender, EventArgs e)
        {
            try
            {
                SQL.Struct.Sach s = new SQL.Struct.Sach();
                s.MaSach             = this.textBox1.Text;
                s.TenSach            = this.textBox2.Text;
                s.TacGia             = this.textBox3.Text;
                s.NamXuatBan         = int.Parse(this.textBox4.Text);
                s.Gia                = int.Parse(this.textBox5.Text);
                s.NhaXuatBan         = this.textBox6.Text;
                s.GioiHanTuoi        = int.Parse(this.textBox7.Text);
                s.DuongDanAnhDaiDien = _pathAvatar;

                if (SQL.ListData.GetDataFromSQL.Update_ARecord_Sach(s))
                {
                    MessageBox.Show("Lưu thành công!");
                    this.button1_Refresh_Click(sender, e);
                }
            }
            catch
            {
                MessageBox.Show("Không thể lưu vì một hoặc nhiều mục đang để trống");
            }
        }
Exemplo n.º 3
0
 private SQL.Struct.Sach TextboxTo_Sach()
 {
     SQL.Struct.Sach t = new SQL.Struct.Sach();
     t.MaSach      = textBox1.Text;
     t.TenSach     = textBox2.Text;
     t.TacGia      = textBox3.Text;
     t.NamXuatBan  = string.IsNullOrWhiteSpace(textBox4.Text) ? 0 : int.Parse(textBox4.Text);
     t.Gia         = string.IsNullOrWhiteSpace(textBox5.Text) ? 0 : int.Parse(textBox5.Text);
     t.NhaXuatBan  = textBox6.Text;
     t.GioiHanTuoi = string.IsNullOrWhiteSpace(textBox7.Text) ? 0 : int.Parse(textBox7.Text);
     return(t);
 }
Exemplo n.º 4
0
        public static bool Sach_CreateNewRecord(SQL.Struct.Sach _value)
        {
            try
            {
                string t1 = "insert into Sach (MaSach";
                string t2 = "(N'" + _value.MaSach + "'";

                if (_value.TenSach != null)
                {
                    t1 += ", TenSach";
                    t2 += ", N'" + _value.TenSach + "'";
                }
                if (_value.TacGia != null)
                {
                    t1 += ", TacGia";
                    t2 += ", N'" + _value.TacGia + "'";
                }
                if (_value.NamXuatBan != null)
                {
                    t1 += ", NamXuatBan";
                    t2 += ", " + _value.NamXuatBan;
                }

                if (_value.Gia != null)
                {
                    t1 += ", Gia";
                    t2 += ", " + _value.Gia;
                }
                if (_value.NhaXuatBan != null)
                {
                    t1 += ", NhaXuatBan";
                    t2 += ", N'" + _value.NhaXuatBan + "'";
                }
                if (_value.GioiHanTuoi != null)
                {
                    t1 += ", GioiHanTuoi";
                    t2 += ", " + _value.GioiHanTuoi;
                }

                if (_value.DuongDanAnhDaiDien != null)
                {
                    t1 += ", DuongDanAnhDaiDien";
                    t2 += ", N'" + _value.DuongDanAnhDaiDien + "'";
                }

                t1 += ") values " + t2 + ")";

                commandSQL.CommandText = t1;
                commandSQL.Connection  = connSQL;
                connSQL.Open();
                commandSQL.ExecuteNonQuery();

                connSQL.Close();
                return(true);
            }
            catch
            {
                connSQL.Close();
                return(false);
            }
        }
Exemplo n.º 5
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);
            }
        }