Exemplo n.º 1
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            btnXoa.Enabled     = true;
            BtnCapnhat.Enabled = true;
            btnThem.Enabled    = false;
            foreach (DataGridViewRow row in dataGridView1.SelectedRows)
            {
                int         rowId = int.Parse(row.Cells[0].Value.ToString());
                DAL.SanPham sp    = bus_sanpham.GetSanPhamByID(rowId);

                if (sp != null)
                {
                    txtMasp.Text = sp.MaSP.ToString();
                    if (sp.MaLoai == 1)
                    {
                        rbHoathat.Checked = true;
                    }
                    else
                    {
                        rbHoaGia.Checked = true;
                    }
                    txtTensp.Text         = sp.TenSP;
                    txtDvt.Text           = sp.DVT;
                    txtNoisanxuat.Text    = sp.NoiSanXuat;
                    txtGianhap.Text       = sp.GiaNhap.ToString();
                    txtGiaban.Text        = sp.GiaBan.ToString();
                    dateTimePicker1.Value = sp.NgayNhap;

                    if (sp.HinhAnh != null)
                    {
                        Byte[] img = sp.HinhAnh;

                        MemoryStream ms = new MemoryStream(img);

                        pictureBox1.Image = Image.FromStream(ms);
                    }
                }
                else
                {
                    MessageBox.Show("Lỗi trong quá trình xử lý");
                }
            }
        }
Exemplo n.º 2
0
 partial void DeleteSanPham(SanPham instance);
Exemplo n.º 3
0
 partial void UpdateSanPham(SanPham instance);
Exemplo n.º 4
0
 partial void InsertSanPham(SanPham instance);
Exemplo n.º 5
0
        // Loc San Pham
        public List <SanPham> LocDanhSachSanhPham(SanPham sp)
        {
            try
            {
                OpenConnection();
                List <SanPham> splist     = new List <SanPham>();
                SqlCommand     sqlCommand = new SqlCommand();
                SqlDataReader  sqlReader  = null;
                DataTable      dt         = new DataTable();

                if (sp.Search == "Mã Sản Phẩm")
                {
                    sqlCommand.CommandType = CommandType.Text;
                    sqlCommand.CommandText = "SELECT MASP FROM dbo.SANPHAM";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();

                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        SanPham sps = new SanPham();
                        sps.MaSp = int.Parse(dt.Rows[i][0].ToString());

                        splist.Add(sps);
                    }
                }
                else if (sp.Search == "Tên Sản Phẩm")
                {
                    sqlCommand.CommandText = "SELECT TENSP FROM dbo.SANPHAM";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();

                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        SanPham sps = new SanPham();
                        sps.TenSp = dt.Rows[i][0].ToString();

                        splist.Add(sps);
                    }
                }
                else if (sp.Search == "Mã Sản Xuất")
                {
                    sqlCommand.CommandText = "SELECT DISTINCT(MASX) FROM dbo.SANPHAM";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();
                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        SanPham sps = new SanPham();
                        sps.MaSx = int.Parse(dt.Rows[i][0].ToString());

                        splist.Add(sps);
                    }
                }
                else if (sp.Search == "Mã Loại")
                {
                    sqlCommand.CommandText = "SELECT DISTINCT(MALOAI) FROM dbo.SANPHAM";
                    sqlCommand.Connection  = conn;
                    sqlReader = sqlCommand.ExecuteReader();
                    dt.Load(sqlReader);

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        SanPham sps = new SanPham();
                        sps.MaLoai = int.Parse(dt.Rows[i][0].ToString());

                        splist.Add(sps);
                    }
                }
                sqlReader.Close();
                return(splist);
            }
            catch
            {
                throw;
            }
            finally
            {
                CloseConnection();
            }
        }
Exemplo n.º 6
0
        // Search Sản Phẩm Theo Mã Sản Phẩm TABLE SANPHAM
        #region Search Sản Phẩm Theo Mã Sản Phẩm TABLE SANPHAM
        public DataTable TimKiemSanPham1(SanPham sp)
        {
            try
            {
                OpenConnection();

                DataTable dt1 = new DataTable();

                SqlCommand command = new SqlCommand();
                command.CommandType = CommandType.Text;
                command.CommandText = "SELECT *FROM SANPHAM WHERE MASP=@masp";
                command.Connection  = conn;

                command.Parameters.Add("@masp", SqlDbType.Int).Value = sp.MaSp;

                SqlDataAdapter adapter1 = new SqlDataAdapter(command);

                adapter1.Fill(dt1);

                return(dt1);
            }
            catch
            {
                throw;
            }
            finally
            {
                CloseConnection();
            }

            #region
            //            SqlCommand command = new SqlCommand();
            //            command.CommandType = CommandType.StoredProcedure;
            //            command.CommandText = "sp_Search_SanPham_Theo_MaSp";
            //            command.Connection = conn;

            //            command.Parameters.Add("@Masp", SqlDbType.Int).Value = sp.MaSp;

            //            SqlDataAdapter adapter = new SqlDataAdapter(command);
            //            adapter.Fill(dt);
            //            //SqlDataReader reader = command.ExecuteReader();
            //            //dt.Load(reader);
            //            for (int i = 0; i < dt.Rows.Count; i++)
            //            {
            //                sp.MaSp = int.Parse(dt.Rows[i][0].ToString());
            //                sp.TenSp = dt.Rows[i][1].ToString();
            //                sp.MaSx = int.Parse(dt.Rows[i][2].ToString());
            //                sp.MaLoai = int.Parse(dt.Rows[i][3].ToString());
            //                sp.GiaThanh = float.Parse(dt.Rows[i][4].ToString());
            //                sp.Cpu = dt.Rows[i][5].ToString();
            //                sp.Ram = dt.Rows[i][6].ToString();
            //                sp.Ocung = dt.Rows[i][7].ToString();
            //                sp.ManHinh = dt.Rows[i][8].ToString();
            //                sp.CardManHinh = dt.Rows[i][9].ToString();
            //                sp.CongKetNoi = dt.Rows[i][10].ToString();
            //                sp.Hdt = dt.Rows[i][11].ToString();
            //                sp.AmThanh = dt.Rows[i][12].ToString();
            //                sp.DiaQuang = dt.Rows[i][13].ToString();
            //                sp.GiaoTiepMang = dt.Rows[i][14].ToString();
            //                sp.WebCam = dt.Rows[i][15].ToString();
            //                sp.Pin = dt.Rows[i][16].ToString();
            //                sp.TrongLuong = dt.Rows[i][17].ToString();
            //                sp.BaoHanh = dt.Rows[i][18].ToString();


            //            }

            ////            reader.Close();
            //            return dt;
            #endregion
        }