コード例 #1
0
        public string insertChiTiet(CTPhieuNhapSachDTO obj)
        {
            string query = string.Empty;

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

            query += "INSERT INTO [CHITIETPHIEUNHAP] ([MaChiTietPhieuNHap], [MaPhieuNhap], [MaSach], [SoLuongNhap])";
            query += "VALUES (@MaChiTietPhieuNHap,@MaPhieuNhap,@MaSach,@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("@MaChiTietPhieuNHap", obj.MaCT);
                    comm.Parameters.AddWithValue("@MaPhieuNhap", obj.MaPN);
                    comm.Parameters.AddWithValue("@MaSach", obj.MaSach);
                    comm.Parameters.AddWithValue("@SoLuongNhap", obj.SLN);
                    try
                    {
                        conn.Open();
                        comm.ExecuteNonQuery();
                    }
                    catch (Exception ex)
                    {
                        conn.Close();
                        // them that bai!!!
                        return("Thêm chi tiết phiếu thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
コード例 #2
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);
            }
        }
コード例 #3
0
        public string insertChiTiet(CTPhieuNhapSachDTO obj)
        {
            if (obj.MaCT == null || obj.MaPN == string.Empty || obj.MaSach == string.Empty || obj.SLN == null)
            {
                return("Thêm mã chi tiết hoặc mã phiếu nhập hoặc mã sách hoặc số lượng nhập không hợp lệ");
            }

            return(dal.insertChiTiet(obj));
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
        public string selectAllCT(List <CTPhieuNhapSachDTO> lsObj)
        {
            string query = string.Empty;

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

            query += " SELECT ct.MaChiTietPhieuNHap, ct.MaPhieuNhap, ct.MaSach, ct.SoLuongNhap";
            query += " FROM CHITIETPHIEUNHAP ct, Sach s";
            query += " WHERE ct.MaSach = s.MaSach";
            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())
                            {
                                CTPhieuNhapSachDTO obj = new CTPhieuNhapSachDTO();
                                obj.MaCT   = reader["MaChiTietPhieuNHap"].ToString();
                                obj.MaPN   = reader["MaPhieuNhap"].ToString();
                                obj.MaSach = reader["MaSach"].ToString();
                                obj.SLN    = Convert.ToInt32(reader["SoLuongNhap"].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");
        }
コード例 #6
0
        public string deleteChiTiet(CTPhieuNhapSachDTO obj)
        {
            string query = string.Empty;

            query += " DELETE FROM [CHITIETPHIEUNHAP]  ";
            query += " WHERE ";
            query += " [MaPhieuNhap] = @MaPhieuNhap ";
            //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("@MaPhieuNhap", obj.MaPN);
                    //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 phiếu nhập thất bại\n" + ex.Message + "\n" + ex.StackTrace);
                    }
                }
            }
            return("0");
        }
コード例 #7
0
 public string deleteChiTiet(CTPhieuNhapSachDTO obj)
 {
     return(dal.deleteChiTiet(obj));
 }