Beispiel #1
0
        private void btnXoaCT_Click(object sender, EventArgs e)
        {
            int currentRowIndex = this.dgvDanhSachChiTietHoaDon.CurrentCellAddress.Y; //'current row selected

            //Verify that indexing OK
            if (-1 < currentRowIndex && currentRowIndex < dgvDanhSachChiTietHoaDon.RowCount)
            {
                ChiTietHDDTO obj = (ChiTietHDDTO)dgvDanhSachChiTietHoaDon.Rows[currentRowIndex].DataBoundItem;
                //this.txtMaCTPN.Text = obj.MaCT;
                this.txtMaHD.Text = obj.MaHD;
                //this.txtMaSach.Text = obj.MaSach;
                //this.txtSoLuongNhap.Text = obj.SLN;
                string result = this.bus.deleteChiTiet(obj);
                if (result == "0")
                {
                    MessageBox.Show("Xóa hóa đơn thành công", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.buildDanhSach();
                    return;
                }
                else
                {
                    MessageBox.Show("Xóa hóa đơn thất bại.\n" + result, "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                MessageBox.Show("Chưa chọn hóa đơn trên lưới.", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
Beispiel #2
0
        public string insertChiTiet(ChiTietHDDTO obj)
        {
            if (obj.MaCTHD == null || obj.MaHD == string.Empty || obj.MaSach == string.Empty || obj.SLB == '0' || obj.DonGia == '0')
            {
                return("Thêm mã chi tiết hoặc mã hóa đơn hoặc mã sách hoặc số lượng bán hoặc đơn giá không hợp lệ");
            }

            return(dal.insertChiTiet(obj));
        }
Beispiel #3
0
        public string selectAllCT(List <ChiTietHDDTO> lsObj)
        {
            string query = string.Empty;

            //query += " SELECT [MaChiTietPhieuNHap], [MaPhieuNhap], [MaSach], [SoLuongNhap]";
            //query += " FROM [CHITIETPHIEUNHAP]";

            query += " SELECT *";
            query += " FROM [CHITIETHOADON]";
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;

                    try
                    {
                        conn.Open();
                        SqlDataReader reader = comm.ExecuteReader();
                        if (reader.HasRows == true)
                        {
                            lsObj.Clear();
                            while (reader.Read())
                            {
                                ChiTietHDDTO obj = new ChiTietHDDTO();
                                obj.MaCTHD = reader["MaChiTietHoaDon"].ToString();
                                obj.MaHD   = reader["MaHoaDon"].ToString();
                                obj.MaSach = reader["MaSach"].ToString();
                                obj.SLB    = Convert.ToInt32(reader["SoLuongBan"].ToString());
                                obj.DonGia = Convert.ToInt32(reader["DonGiaBan"].ToString());
                                lsObj.Add(obj);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' lấy that bai!!!
                        return("Lấy chi tiết phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
Beispiel #4
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;
                }
            }
        }
Beispiel #5
0
        public string deleteChiTiet(ChiTietHDDTO obj)
        {
            string query = string.Empty;

            query += " DELETE FROM [CHITIETHOADON]  ";
            query += " WHERE ";
            query += " [MaHoaDon] = @MaHoaDon ";
            //query += " [MaChiTietPhieuNhap] = @MaChiTietPhieuNhap ";
            //query += " [MaSach] = @MaSach ";
            //query += " [SoLuongNhap] = @SoLuongNhap ";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaHoaDon", obj.MaHD);
                    //comm.Parameters.AddWithValue("@MaChiTietPhieuNhap", obj.MaCT);
                    //comm.Parameters.AddWithValue("@MaSach", obj.MaSach);
                    //comm.Parameters.AddWithValue("@SoLuongNhap", obj.SLN);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        //' xóa that bai!!!
                        return("Xóa chi tiết hóa đơn thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
Beispiel #6
0
        public string insertChiTiet(ChiTietHDDTO obj)
        {
            string query = string.Empty;

            //query += "INSERT INTO [CHITIETPHIEUNHAP] ([MaChiTietPhieuNHap], [MaPhieuNhap], [MaSach], [SoLuongNhap])";
            //query += "VALUES (@MaChiTietPhieuNHap,@MaPhieuNhap,@MaSach,@SoLuongNhap)";

            query += "INSERT INTO [CHITIETHOADON] ([MaChiTietHoaDon], [MaHoaDon], [MaSach] , [SoLuongBan] , [DonGiaBan])";
            query += "VALUES (@MaChiTietHoaDon,@MaHoaDon,@MaSach,@SoLuongBan,@DonGiaBan)";
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection  = conn;
                    comm.CommandType = CommandType.Text;
                    comm.CommandText = query;
                    comm.Parameters.AddWithValue("@MaChiTietHoaDon", obj.MaCTHD);
                    comm.Parameters.AddWithValue("@MaHoaDon", obj.MaHD);
                    comm.Parameters.AddWithValue("@MaSach", obj.MaSach);
                    comm.Parameters.AddWithValue("@SoLuongBan", obj.SLB);
                    comm.Parameters.AddWithValue("@DonGiaBan", obj.DonGia);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        // them that bai!!!
                        return("Thêm chi tiết hóa đơn thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
Beispiel #7
0
 public string deleteChiTiet(ChiTietHDDTO obj)
 {
     return(dal.deleteChiTiet(obj));
 }