public string delete(QuanLySachDTO obj)
        {
            string query = string.Empty;

            query += "DELETE FROM [SACH]";
            query += "WHERE";
            query += "[MaSach] = @MaSach";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaSach", obj.MaSach);

                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' xóa that bai!!!
                        return("Xóa phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
        private void btnXoaCT_Click(object sender, EventArgs e)
        {
            //CTPhieuNhapSachDTO obj = new CTPhieuNhapSachDTO();
            string        result;
            QuanLySachDTO Sach            = new QuanLySachDTO();
            int           currentRowIndex = this.dgvDanhSachCTPN.CurrentCellAddress.Y; //'current row selected

            //Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachCTPN.RowCount)
            {
                CTPhieuNhapSachDTO obj = (CTPhieuNhapSachDTO)dgvDanhSachCTPN.Rows[currentRowIndex].DataBoundItem;
                this.txtMaPhieuNhap.Text = obj.MaPN;

                //obj.MaSach = this.txtMaSach.Text;
                result = this.bus.deleteChiTiet(obj);
                if (result == "0")
                {
                    MessageBox.Show("Xóa chi tiết phiếu nhập thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.buildDanhSach();
                    return;
                }
                else
                {
                    MessageBox.Show("Xóa chi tiết phiếu nhập thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn chi tiết phiếu nhập trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
        public string insert(QuanLySachDTO obj)
        {
            string query = string.Empty;

            query += "INSERT INTO [SACH] ( [MaSach] , [TenSach], [TheLoai] , [TacGia] , [SoLuongTon] , [DonGiaNhap])";
            query += "VALUES (@MaSach,@TenSach,@TheLoai,@TacGia,@SoLuongTon,@DonGiaNhap)";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaSach", obj.MaSach);
                    comm.Parameters.AddWithValue("@TenSach", obj.TenSach);
                    comm.Parameters.AddWithValue("@TheLoai", obj.TheLoai);
                    comm.Parameters.AddWithValue("@TacGia", obj.TacGia);
                    comm.Parameters.AddWithValue("@SoLuongTon", obj.SoLuongTon);
                    comm.Parameters.AddWithValue("@DonGiaNhap", obj.DonGiaNhap);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        // them that bai!!!
                        return("Thêm sách thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            QuanLySachDTO obj = new QuanLySachDTO();

            obj.MaSach     = this.txtMaSach.Text;
            obj.TenSach    = this.txtTenSach.Text;
            obj.TheLoai    = this.txtTheLoai.Text;
            obj.TacGia     = this.txtTacGia.Text;
            obj.SoLuongTon = Convert.ToInt32(this.txtSoLuongTon.Text);
            obj.DonGiaNhap = Convert.ToInt32(this.txtDonGia.Text);

            string result = this.bus.update(obj);

            if (result == "0")
            {
                MessageBox.Show("Cập nhật thông tin thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                //this.isThemMoi = 0;
                //this.tcQLNH.SelectedIndex = 0;
                this.buildDanhSach();
                return;
            }
            else
            {
                MessageBox.Show("Cập nhật thông tin thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }
        }
        private void btnXoa_Click(object sender, EventArgs e)
        {
            int currentRowIndex = this.dgvDanhSachSach.CurrentCellAddress.Y; //'current row selected

            //Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachSach.RowCount)
            {
                QuanLySachDTO obj = (QuanLySachDTO)dgvDanhSachSach.Rows[currentRowIndex].DataBoundItem;
                this.txtMaSach.Text     = obj.MaSach;
                this.txtTenSach.Text    = obj.TenSach;
                this.txtTheLoai.Text    = obj.TheLoai;
                this.txtTacGia.Text     = obj.TacGia;
                this.txtSoLuongTon.Text = obj.SoLuongTon.ToString();
                this.txtDonGia.Text     = obj.DonGiaNhap.ToString();
                string result = this.bus.delete(obj);
                if (result == "0")
                {
                    MessageBox.Show("Xóa sách thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.buildDanhSach();
                    return;
                }
                else
                {
                    MessageBox.Show("Xóa sách thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn sách trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Beispiel #6
0
 public string insert(QuanLySachDTO obj)
 {
     if (obj.MaSach == string.Empty || obj.TenSach == string.Empty || obj.TheLoai == string.Empty || obj.TacGia == string.Empty || obj.SoLuongTon == null || obj.DonGiaNhap == null)
     {
         return("Thêm Sách thất bại");
     }
     return(dal.insert(obj));
 }
        private void btnThemCT_Click(object sender, EventArgs e)
        {
            CTPhieuNhapSachDTO obj    = new CTPhieuNhapSachDTO();
            ThamSoDTO          ThamSo = new ThamSoDTO();

            ThamSo = busThamSo.QuyDinh();
            string        result;
            QuanLySachDTO Sach = new QuanLySachDTO();

            //List<QuanLySachDTO> lsSach = new List<QuanLySachDTO>();


            obj.MaCT   = this.txtMaCTPN.Text;
            obj.MaPN   = this.txtMaPN.Text;
            obj.MaSach = this.txtMaSach.Text;
            obj.SLN    = Convert.ToInt32(this.txtSoLuongNhap.Text);
            if (obj.SLN < ThamSo.SoLuongNhapItNhat) // quy định 1.1
            {
                MessageBox.Show(string.Format("Số lượng nhập phải lớn hơn số lượng quy định ({0} quyển)", ThamSo.SoLuongNhapItNhat), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                obj.SLN     = Convert.ToInt32(this.txtSoLuongNhap.Text);
                Sach.MaSach = this.txtMaSach.Text;
                Sach        = this.busSach.laySach(Sach.MaSach, Sach);

                luongton    = Sach.SoLuongTon;
                luongtonTam = luongton;
                //Tính lượng tồn mới
                luongtonMoi = luongton + int.Parse(this.txtSoLuongNhap.Text);
                luongtonMax = ThamSo.SoLuongTonToiDaTruocNhap;
                //Kiểm tra qui định số lượng tồn tối đa trước nhập
                if (luongton < luongtonMax)
                {
                    result = this.bus.insertChiTiet(obj);
                    if (result == "0")
                    {
                        Sach.SoLuongTon = luongtonMoi;
                        busSach.capnhatLuongTon(Sach);
                        MessageBox.Show("Thêm mới chi tiết phiếu nhập thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        buildDanhSachCT();
                        return;
                    }
                    else
                    {
                        MessageBox.Show("Thêm mới chi tiết phiếu nhập thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Chỉ nhập các đầu sách có lượng tồn ít hơn theo quy định ({0} quyển)", ThamSo.SoLuongTonToiDaTruocNhap), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
            }
        }
        public QuanLySachDTO laySach(string ms, QuanLySachDTO obj)
        {
            //List<QuanLySachDTO> lsObj = new List<QuanLySachDTO>();

            string query = string.Empty;

            query += "SELECT * FROM [SACH]";
            query += "WHERE [MaSach] like @MaSach";
            obj    = new QuanLySachDTO();
            //QuanLySachDTO ls = new QuanLySachDTO();

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;
                    cmd.Parameters.AddWithValue("@MaSach", "%" + ms.ToString() + "%");

                    try
                    {
                        conn.Open();
                        SqlDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                obj.MaSach     = reader["MaSach"].ToString();
                                obj.TenSach    = reader["TenSach"].ToString();
                                obj.TheLoai    = reader["TheLoai"].ToString();
                                obj.TacGia     = reader["TacGia"].ToString();
                                obj.SoLuongTon = Convert.ToInt32(reader["SoLuongTon"].ToString());
                                obj.DonGiaNhap = Convert.ToInt32(reader["DonGiaNhap"].ToString());
                                //lsObj.Add(obj);
                            }
                            conn.Close();
                            conn.Dispose();
                            //return ls;
                            return(obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        Console.WriteLine("Lấy sách thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                        //return null;
                    }
                }
            }
            return(obj);
        }
        public string searchTacGia(string kw, List <QuanLySachDTO> lsObj)
        {
            string query = string.Empty;

            query += "SELECT *";
            query += " FROM [SACH]";
            query += " WHERE ";
            query += " [TacGia] like @TacGia ";


            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@TacGia", "%" + kw.ToString() + "%");
                    try
                    {
                        conn.Open();
                        SqlDataReader reader = comm.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            lsObj.Clear();
                            while (reader.Read())
                            {
                                QuanLySachDTO obj = new QuanLySachDTO();

                                obj.MaSach     = reader["MaSach"].ToString();
                                obj.TenSach    = reader["TenSach"].ToString();
                                obj.TheLoai    = reader["TheLoai"].ToString();
                                obj.TacGia     = reader["TacGia"].ToString();
                                obj.SoLuongTon = Convert.ToInt32(reader["SoLuongTon"].ToString());
                                obj.DonGiaNhap = Convert.ToInt32(reader["DonGiaNhap"].ToString());
                                lsObj.Add(obj);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' lấy that bai!!!
                        return("Tìm sách thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
        public string update(QuanLySachDTO obj)
        {
            string query = string.Empty;

            query += " UPDATE [SACH] SET";
            query += " [MaSach] = @MaSach,  ";
            query += " [TenSach] = @TenSach, ";
            query += " [TheLoai] = @TheLoai, ";
            query += " [TacGia] = @TacGia, ";
            query += " [SoLuongTon] = @SoLuongTon, ";
            query += "[DonGiaNhap] = @DonGiaNhap ";
            query += " WHERE ";
            query += " [MaSach] = @MaSach ";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaSach", obj.MaSach);
                    comm.Parameters.AddWithValue("@TenSach", obj.TenSach);
                    comm.Parameters.AddWithValue("@TheLoai", obj.TheLoai);
                    comm.Parameters.AddWithValue("@TacGia", obj.TacGia);
                    comm.Parameters.AddWithValue("@SoLuongTon", obj.SoLuongTon);
                    comm.Parameters.AddWithValue("@DonGiaNhap", obj.DonGiaNhap);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' Cập nhật that bai!!!
                        return("Sửa thông tin thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
        private void btnSua_Click(object sender, EventArgs e)
        {
            int currentRowIndex = this.dgvDanhSachSach.CurrentCellAddress.Y; //'current row selected

            //Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachSach.RowCount)
            {
                QuanLySachDTO obj = (QuanLySachDTO)dgvDanhSachSach.Rows[currentRowIndex].DataBoundItem;
                this.txtMaSach.Text     = obj.MaSach;
                this.txtTenSach.Text    = obj.TenSach;
                this.txtTheLoai.Text    = obj.TheLoai;
                this.txtTacGia.Text     = obj.TacGia;
                this.txtSoLuongTon.Text = obj.SoLuongTon.ToString();
                this.txtDonGia.Text     = obj.DonGiaNhap.ToString();
            }
            else
            {
                MessageBox.Show("Chưa chọn sách trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Beispiel #12
0
        private void btnThemCT_Click(object sender, EventArgs e)
        {
            ChiTietHDDTO obj    = new ChiTietHDDTO();
            ThamSoDTO    ThamSo = new ThamSoDTO();

            ThamSo    = busThamSo.QuyDinh();
            tonSauBan = ThamSo.SoLuongTonSauToiThieu;
            QuanLySachDTO Sach = new QuanLySachDTO();
            string        result;

            obj.MaCTHD  = this.txtMaCTHD.Text;
            obj.MaHD    = this.txtMaHD1.Text;
            obj.MaSach  = this.txtMaSach.Text;
            obj.DonGia  = Convert.ToInt32(this.txtĐonGia.Text);
            obj.SLB     = Convert.ToInt32(this.txtSoLuong.Text);
            Sach.MaSach = this.txtMaSach.Text;
            Sach        = this.busSach.laySach(Sach.MaSach, Sach);
            luongTon    = Sach.SoLuongTon;
            luongTonMoi = luongTon - obj.SLB;
            if ((luongTon - obj.SLB) < tonSauBan)
            {
                MessageBox.Show(string.Format("Số lượng tồn của sách này sau khi bán đã nhỏ hơn quy định ({0} quyển)", tonSauBan), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                result = this.bus.insertChiTiet(obj);
                if (result == "0")
                {
                    MessageBox.Show("Thêm mới chi tiết hóa đơn thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    buildDanhSachCT();
                    return;
                }
                else
                {
                    MessageBox.Show("Thêm mới chi tiết hóa đơn thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
        }
        public bool capnhatLuongTon(QuanLySachDTO sach)
        {
            string query = string.Empty;

            query += "UPDATE [SACH] ";
            query += "SET [SoLuongTon] = @SoLuongTon";
            query += "WHERE [MaSach] = @MaSach";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.CommandText = query;

                    //cmd.Parameters.AddWithValue("@MaThamSo", qd.Mathamso);
                    cmd.Parameters.AddWithValue("@SoLuongTon", sach.SoLuongTon);

                    try
                    {
                        conn.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            conn.Close();
                            conn.Dispose();
                            return(true);
                        }
                    }
                    catch
                    {
                        conn.Close();
                        return(false);
                    }
                }
            }

            return(true);
        }
        private void btnThem_Click(object sender, EventArgs e)
        {
            QuanLySachDTO obj = new QuanLySachDTO();

            obj.MaSach = this.txtMaSach.Text;
            //obj.NgayNhap = this.dtpNgayNhap.Text; //xem cách get ngày nhập trong c# .net nha bây
            obj.TenSach    = this.txtTenSach.Text;
            obj.TheLoai    = this.txtTheLoai.Text;
            obj.TacGia     = this.txtTacGia.Text;
            obj.SoLuongTon = Convert.ToInt32(this.txtSoLuongTon.Text);
            obj.DonGiaNhap = Convert.ToInt32(this.txtDonGia.Text);
            string result = this.bus.insert(obj);

            if (result == "0")
            {
                MessageBox.Show("Thêm sách thành công");
                return;
            }
            else
            {
                MessageBox.Show("Thêm sách thất bại.\n" + result);
                return;
            }
        }
Beispiel #15
0
 public string delete(QuanLySachDTO obj)
 {
     return(dal.delete(obj));
 }
Beispiel #16
0
 public bool capnhatLuongTon(QuanLySachDTO sach)
 {
     return(dal.capnhatLuongTon(sach));
 }
Beispiel #17
0
 public QuanLySachDTO laySach(string ms, QuanLySachDTO obj)
 {
     return(dal.laySach(ms, obj));
 }
Beispiel #18
0
 public string update(QuanLySachDTO obj)
 {
     return(dal.update(obj));
 }