Ejemplo n.º 1
0
        public static List <CTPhieuNhapDTO> LayDanhSachCTPhieuNhap(int maPhieuNhap)
        {
            SqlConnection connection = DataProvider.GetConnection();
            string        query      = "SELECT ma_phieu_nhap, ma_nguyen_lieu, so_luong, don_gia, don_vi_tinh, ghi_chu FROM CTPhieuNhap WHERE ma_phieu_nhap=@maPhieuNhap";

            SqlCommand command = new SqlCommand();

            command.Parameters.Add("@maPhieuNhap", System.Data.SqlDbType.NVarChar, 255).Value = maPhieuNhap;
            command.CommandText = query;
            command.Connection  = connection;

            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            List <CTPhieuNhapDTO> result = new List <CTPhieuNhapDTO>();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    CTPhieuNhapDTO ctpn = new CTPhieuNhapDTO();
                    ctpn.MaPhieuNhap  = reader.GetInt32(0);
                    ctpn.MaNguyenLieu = reader.GetInt32(1);
                    ctpn.SoLuong      = reader.GetDouble(2);
                    ctpn.DonGia       = reader.GetDouble(3);
                    ctpn.DonViTinh    = reader.GetString(4);
                    ctpn.GhiChu       = reader.GetString(5);
                    result.Add(ctpn);
                }
            }

            connection.Close();
            return(result);
        }
Ejemplo n.º 2
0
        private void btnKhoiPhucPhieuNhap_Click(object sender, EventArgs e)
        {
            List <CTPhieuNhapDTO> lsCTPhieuNhap = new List <CTPhieuNhapDTO>();

            foreach (DataGridViewRow row in dgvCTPhieuNhap.Rows)
            {
                CTPhieuNhapDTO ctPhieuNhap = new CTPhieuNhapDTO();
                ctPhieuNhap.MaNguyenLieu = Convert.ToInt32(row.Cells["colCTPN_MaNguyenLieu"].Value);
                ctPhieuNhap.SoLuong      = Convert.ToInt32(row.Cells["colCTPN_SoLuong"].Value);

                lsCTPhieuNhap.Add(ctPhieuNhap);
            }
            if (PhieuNhapBUS.KhoiPhucPhieuNhap(Convert.ToInt32(dgvPhieuNhap.SelectedRows[0].Cells["colPN_MaPhieuNhap"].Value), lsCTPhieuNhap))
            {
                MessageBox.Show("Khôi phục thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                LSPN_LoadDanhSachPhieuNhapDaXoa();
                dgvCTPhieuNhap.DataSource = null;
                dgvPhieuNhap.ClearSelection();
                btnKhoiPhucPhieuNhap.Enabled = false;
            }
            else
            {
                MessageBox.Show("Khôi phục thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 3
0
        public static bool LuuCTPhieuNhap(CTPhieuNhapDTO ctpn)
        {
            SqlConnection connection = DataProvider.GetConnection();
            string        query      = "INSERT INTO CTPhieuNhap (ma_phieu_nhap, ma_nguyen_lieu, so_luong, don_vi_tinh, don_gia, ghi_chu) VALUES (@maPhieuNhap, @maNguyenLieu, @soLuong, @donViTinh, @donGia, @ghiChu)";
            SqlCommand    command    = new SqlCommand(query, connection);

            command.Parameters.Add("@maPhieuNhap", System.Data.SqlDbType.Int, 0).Value      = ctpn.MaPhieuNhap;
            command.Parameters.Add("@maNguyenLieu", System.Data.SqlDbType.Int, 0).Value     = ctpn.MaNguyenLieu;
            command.Parameters.Add("@soLuong", System.Data.SqlDbType.Float, 0).Value        = ctpn.SoLuong;
            command.Parameters.Add("@donViTinh", System.Data.SqlDbType.NVarChar, 255).Value = ctpn.DonViTinh;
            command.Parameters.Add("@donGia", System.Data.SqlDbType.Float, 0).Value         = ctpn.DonGia;
            command.Parameters.Add("@ghiChu", System.Data.SqlDbType.NVarChar, 255).Value    = ctpn.GhiChu;

            connection.Open();

            int reader = command.ExecuteNonQuery();

            connection.Close();

            if (reader > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
        private void btnXoaPhieuNhap_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("Xoá phiếu nhập sẽ đồng thời trừ đi số lượng tồn kho của các nguyên liệu có trong danh sách phiếu.\n\nBạn có chắc chắn muốn xoá phiếu nhập này không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Warning))
            {
                List <CTPhieuNhapDTO> lsCTPhieuNhap = new List <CTPhieuNhapDTO>();
                foreach (DataGridViewRow row in dgvCTPhieuNhap.Rows)
                {
                    CTPhieuNhapDTO ctPhieuNhap = new CTPhieuNhapDTO();
                    ctPhieuNhap.MaNguyenLieu = Convert.ToInt32(row.Cells["colCTPN_MaNguyenLieu"].Value);
                    ctPhieuNhap.SoLuong      = Convert.ToInt32(row.Cells["colCTPN_SoLuong"].Value);

                    lsCTPhieuNhap.Add(ctPhieuNhap);
                }
                if (PhieuNhapBUS.XoaPhieuNhap(Convert.ToInt32(dgvPhieuNhap.SelectedRows[0].Cells["colPN_MaPhieuNhap"].Value), lsCTPhieuNhap))
                {
                    MessageBox.Show("Xoá thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    LSPN_LoadDanhSachPhieuNhap();
                    dgvCTPhieuNhap.DataSource = null;
                    dgvPhieuNhap.ClearSelection();
                    btnXoaPhieuNhap.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Xoá thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 5
0
        public static List <CTPhieuNhapDTO> GetCTPN(string mapn)
        {
            List <CTPhieuNhapDTO> CTPN = new List <CTPhieuNhapDTO>();

            using (dbMainDataContext dbMain = new dbMainDataContext())
            {
                var query = from p in dbMain.ChiTietPhieuNhaps where p.MaPhieuNhap == mapn select p;

                foreach (var row in query)
                {
                    CTPhieuNhapDTO ctpn = new CTPhieuNhapDTO();
                    ctpn.Mapn       = row.MaPhieuNhap;
                    ctpn.Masachnhap = row.MaSach;
                    var getSach = from d in dbMain.Saches where d.MaSach == row.MaSach select d;
                    foreach (var row3 in getSach)
                    {
                        ctpn.Tensach = row3.TenSach;
                    }
                    ctpn.Soluongnhap = row.SoLuong.ToString();
                    ctpn.Dongianhap  = row.DonGia.ToString();
                    ctpn.Tongtien    = row.TongTien.ToString();
                    CTPN.Add(ctpn);
                }
            }
            return(CTPN);
        }
Ejemplo n.º 6
0
        private void btnNhapHang_Click(object sender, EventArgs e)
        {
            PhieuNhapDTO phieuNhap = new PhieuNhapDTO();

            phieuNhap.NhaCungCap = (int)cmbNhaCungCap.SelectedValue;
            phieuNhap.NgayLap    = DateTime.Now;
            phieuNhap.TongTien   = Convert.ToDouble(lblTongTien.Text.Remove(lblTongTien.Text.Length - 1));
            phieuNhap.TrangThai  = true;

            List <CTPhieuNhapDTO> lsCTPhieuNhap = new List <CTPhieuNhapDTO>();

            foreach (DataGridViewRow row in dgvCTPhieuNhap.Rows)
            {
                string donGia = row.Cells["colDonGia"].Value.ToString();

                CTPhieuNhapDTO ctPhieuNhap = new CTPhieuNhapDTO();
                ctPhieuNhap.MaPhieuNhap  = Convert.ToInt32(lblMaPhieu.Text);
                ctPhieuNhap.MaNguyenLieu = Convert.ToInt32(row.Cells["colMaNguyenLieu"].Value);
                ctPhieuNhap.SoLuong      = Convert.ToDouble(row.Cells["colSoLuong"].Value);
                ctPhieuNhap.DonViTinh    = row.Cells["colDonViTinh"].Value.ToString();
                ctPhieuNhap.DonGia       = Convert.ToDouble(donGia.Remove(donGia.Length - 1));
                if (row.Cells["colGhiChu"].Value != null)
                {
                    ctPhieuNhap.GhiChu = row.Cells["colGhiChu"].Value.ToString();
                }
                else
                {
                    ctPhieuNhap.GhiChu = string.Empty;
                }

                lsCTPhieuNhap.Add(ctPhieuNhap);
            }

            if (PhieuNhapBUS.LuuPhieuNhap(phieuNhap, lsCTPhieuNhap))
            {
                if (DialogResult.Yes == MessageBox.Show("Bạn có muốn in phiếu nhập?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                {
                    FrmHienThiBaoCao frm = new FrmHienThiBaoCao();
                    frm.HienThiPhieuNhapMoiNhat();
                    FrmMain.Instance.TopMost = false;
                    frm.Show();
                }
                LamMoi();
                dgvCTPhieuNhap.Rows.Clear();
            }
            else
            {
                MessageBox.Show("Lưu phiếu nhập thất bại!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 7
0
        public static bool GiamSoLuongTonKho(CTPhieuNhapDTO ctpn)
        {
            SqlConnection connection = DataProvider.GetConnection();
            string        query      = "UPDATE NguyenLieu SET so_luong=so_luong-@soLuong WHERE ma_nguyen_lieu=@maNguyenLieu";
            SqlCommand    command    = new SqlCommand(query, connection);

            command.Parameters.Add("@maNguyenLieu", System.Data.SqlDbType.Int, 0).Value = ctpn.MaNguyenLieu;
            command.Parameters.Add("@soLuong", System.Data.SqlDbType.Float, 0).Value    = ctpn.SoLuong;

            connection.Open();

            int reader = command.ExecuteNonQuery();

            connection.Close();

            if (reader == 1)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 8
0
        public bool them(CTPhieuNhapDTO lb)
        {
            bool re = bdal.them(lb);

            return(re);
        }