public static List<SanPham> Search(string content, string lsp, string ncc, bool isNum)
 {
     if (conn.State == ConnectionState.Open) conn.Close();
     conn.Open();
     SqlCommand sc = new SqlCommand("Sanpham_ProcSearch", conn);
     sc.CommandType = CommandType.StoredProcedure;
     sc.Parameters.Add(new SqlParameter("@ContentSearch", content));
     sc.Parameters.Add(new SqlParameter("@Loaisanpham", lsp));
     sc.Parameters.Add(new SqlParameter("@Nhacungcap", ncc));
     sc.Parameters.Add(new SqlParameter("@IsNumeric", isNum));
     SqlDataReader reader = sc.ExecuteReader();
     List<SanPham> lstSp = new List<SanPham>();
     while (reader.Read())
     {
         SanPham sp = new SanPham();
         sp.SanphamID = (reader["SanphamID"] != null ? int.Parse(reader["SanphamID"].ToString()) : 0);
         sp.Tenloaisanpham = (reader["Tenloaisanpham"] != null ? reader["Tenloaisanpham"].ToString() : "");
         sp.Tensanpham = (reader["Tensanpham"] != null ? reader["Tensanpham"].ToString() : "");
         sp.Tennhacungcap = (reader["Tennhacungcap"] != null ? reader["Tennhacungcap"].ToString() : "");
         sp.Donvitinh = (reader["Donvitinh"] != null ? reader["Donvitinh"].ToString() : "");
         sp.Giaban = (reader["Giaban"] != null ? double.Parse(reader["Giaban"].ToString()) : 0);
         sp.Soluong = (reader["Soluong"] != null ? int.Parse(reader["Soluong"].ToString()) : 0);
         sp.NhacungcapID = (reader["NhacungcapID"] != null ? int.Parse(reader["NhacungcapID"].ToString()) : 0);
         sp.LoaisanphamID = (reader["LoaisanphamID"] != null ? int.Parse(reader["LoaisanphamID"].ToString()) : 0);
         lstSp.Add(sp);
     }
     reader.Close();
     conn.Close();
     return lstSp;
 }
        public static List<SanPham> View(int PageSize, int PageNumber)
        {
            if (conn.State == ConnectionState.Open) conn.Close();
            conn.Open();
            SqlCommand sc = new SqlCommand("Sanpham_ProcView", conn);
            sc.CommandType = CommandType.StoredProcedure;
            sc.Parameters.Add(new SqlParameter("@PageSize", PageSize));
            sc.Parameters.Add(new SqlParameter("@PageNumber", PageNumber));
            SqlDataReader reader = sc.ExecuteReader();
            List<SanPham> lstSp = new List<SanPham>();
            while (reader.Read())
            {
                SanPham sp = new SanPham();
                sp.SanphamID = (reader["SanphamID"] != null ? int.Parse(reader["SanphamID"].ToString()) : 0);
                sp.Tenloaisanpham = (reader["Tenloaisanpham"] != null ? reader["Tenloaisanpham"].ToString() : "");
                sp.Tensanpham = (reader["Tensanpham"] != null ? reader["Tensanpham"].ToString() : "");
                sp.Tennhacungcap = (reader["Tennhacungcap"] != null ? reader["Tennhacungcap"].ToString() : "");
                sp.Donvitinh = (reader["Donvitinh"] != null ? reader["Donvitinh"].ToString() : "");
                sp.Giaban = (reader["Giaban"] != null ? double.Parse(reader["Giaban"].ToString()) : 0);
                sp.Soluong = (reader["Soluong"] != null ? int.Parse(reader["Soluong"].ToString()) : 0);
                sp.NhacungcapID = (reader["NhacungcapID"] != null ? int.Parse(reader["NhacungcapID"].ToString()) : 0);
                sp.LoaisanphamID = (reader["LoaisanphamID"] != null ? int.Parse(reader["LoaisanphamID"].ToString()) : 0);

                lstSp.Add(sp);
            }
            conn.Close();
            reader.Close();
            return lstSp;
        }
 private void AddtoListView(SanPham sp,int Soluongmua)
 {
     foreach (ListViewItem it in listView1.Items)
     {
         if (it.Text.Equals(sp.SanphamID.ToString()))
         {
             int sl = int.Parse(it.SubItems[2].Text) +Soluongmua;
             it.SubItems[2].Text = sl.ToString();
             return;
         }
     }
     ListViewItem item = new ListViewItem();
     item.Text = sp.SanphamID.ToString();
     item.SubItems.Add(sp.Tensanpham);
     item.SubItems.Add(Soluongmua.ToString());
     item.SubItems.Add(sp.Giaban.ToString());
     listView1.Items.Add(item);
 }
 public SanPhamCollection(int KhoID)
 {
     Items.Clear();
     DataTable dt = DataAccess.ViewForGridView("Sanpham_ViewByKho", new SqlParameter("@KhoID", KhoID));
     if (dt.Rows.Count > 0)
     {
         foreach (DataRow dr in dt.Rows)
         {
             SanPham sp = new SanPham();
             sp.SanphamID = int.Parse(dr["SanphamID"].ToString());
             sp.Tenloaisanpham = dr["Tenloaisanpham"].ToString();
             sp.Tennhacungcap = dr["Tennhacungcap"].ToString();
             sp.Tensanpham = dr["Tensanpham"].ToString();
             sp.Soluong = int.Parse(dr["Soluong"].ToString());
             sp.Giaban = double.Parse(dr["Giaban"].ToString());
             sp.Donvitinh = dr["Donvitinh"].ToString();
             sp.NhacungcapID = int.Parse(dr["NhacungcapID"].ToString());
             sp.LoaisanphamID = int.Parse(dr["LoaisanphamID"].ToString());
             Items.Add(sp);
         }
     }
 }
 public void Delete(SanPham sp)
 {
     int index = Items.FindIndex(x => x.SanphamID == sp.SanphamID);
     DataAccess.ExecuteNonQuery("Sanpham_Delete",
                                      new SqlParameter("@SanphamID", sp.SanphamID)
                                      );
 }
 public void Update(SanPham sp)
 {
     int index = Items.FindIndex(x => x.SanphamID == sp.SanphamID);
     DataAccess.ExecuteNonQuery("Sanpham_Update",
                                      new SqlParameter("@SanphamID", sp.SanphamID),
                                      new SqlParameter("@Tensanpham", sp.Tensanpham),
                                      new SqlParameter("@Donvitinh", sp.Donvitinh),
                                      new SqlParameter("@Giaban", sp.Giaban),
                                      new SqlParameter("@NhacungcapID", sp.NhacungcapID),
                                      new SqlParameter("@LoaisanphamID", sp.LoaisanphamID),
                                      new SqlParameter("@Soluong", sp.Soluong)
                                      );
 }
 public List<SanPham> Search(string content,string Loai,string Nhacungcap)
 {
     List<SanPham> lst = new List<SanPham>();
     DataTable dt = DataAccess.ViewForGridView("Sanpham_ViewByFilter", new SqlParameter("@Content", content),
                                                                new SqlParameter("@Loaisanpham", Loai),
                                                                new SqlParameter("@Nhasanxuat", Nhacungcap)
                                                     );
     if (dt.Rows.Count > 0)
     {
         foreach (DataRow dr in dt.Rows)
         {
             SanPham sp = new SanPham();
             sp.SanphamID = int.Parse(dr["SanphamID"].ToString());
             sp.Tenloaisanpham = dr["Tenloaisanpham"].ToString();
             sp.Tennhacungcap = dr["Tennhacungcap"].ToString();
             sp.Tensanpham = dr["Tensanpham"].ToString();
             sp.Soluong = int.Parse(dr["Soluong"].ToString());
             sp.Giaban = double.Parse(dr["Giaban"].ToString());
             sp.Donvitinh = dr["Donvitinh"].ToString();
             sp.NhacungcapID = int.Parse(dr["NhacungcapID"].ToString());
             sp.LoaisanphamID = int.Parse(dr["LoaisanphamID"].ToString());
             lst.Add(sp);
         }
     }
     return lst;
 }
 public void Insert(SanPham sp)
 {
     DataAccess.ExecuteNonQuery("Sanpham_Insert",
                                      new SqlParameter("@Tensanpham", sp.Tensanpham),
                                      new SqlParameter("@Donvitinh", sp.Donvitinh),
                                      new SqlParameter("@Giaban", sp.Giaban),
                                      new SqlParameter("@NhacungcapID", sp.NhacungcapID),
                                      new SqlParameter("@LoaisanphamID", sp.LoaisanphamID),
                                      new SqlParameter("@Soluong", sp.Soluong)
                                      );
     Items.Add(sp);
 }
 private void Viewdata(SanPham sp,int Soluongmua)
 {
     label20.Text = (sp!=null?sp.SanphamID.ToString():"");
     label21.Text = (sp!=null?sp.Tensanpham:"");
     label22.Text = (sp!=null?sp.Tenloaisanpham:"");
     label23.Text = (sp!=null?sp.Tennhacungcap:"");
     numericUpDown2.Value = Soluongmua;
     button4.Enabled = true;
 }
 private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     if (listView1.SelectedItems.Count != 0)
     {
         int id = int.Parse(listView1.SelectedItems[0].Text);
         spNow = lstSanpham.Find(x => x.SanphamID.Equals(id));
         int Soluongmua = int.Parse(listView1.SelectedItems[0].SubItems[2].Text);
         Viewdata(spNow, Soluongmua);
         button4.Text = "Cập nhật";
         status = 2;
         button5.Enabled = true;
     }
 }
 private void dataGridView1_SelectionChanged(object sender, EventArgs e)
 {
     RfInfoProduct();
     if (dataGridView1.CurrentRow != null)
     {
         int id = int.Parse(dataGridView1.CurrentRow.Cells["col_SanPhamID"].Value.ToString());
         spNow = lstSanpham.Find(x => x.SanphamID.Equals(id));
         Viewdata(spNow, 1);
         status = 1;
         button4.Text = "Chọn mua";
         button5.Enabled = false;
     }
 }