예제 #1
0
 /// <summary>
 /// lay hang hoa theo ma nhom hang
 /// </summary>
 /// <param name="giatri"></param>
 /// <returns></returns>
 public Entities.ThongTinHangHoa[] Select(Entities.TruyenGiaTri giatri)
 {
     Entities.ThongTinHangHoa[] arrC = null;
     try
     {
         string sql = "exec sp_TimHangHoaTheoMaNhomHang @MaNhomHangHoa";
         conn = new Connection();
         cn   = conn.openConnection();
         cmd  = new SqlCommand(sql, cn);
         cmd.Parameters.Add("MaNhomHangHoa", SqlDbType.NVarChar, 20).Value = giatri.Giatritruyen;
         dr  = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         arr = new ArrayList();
         while (dr.Read())
         {
             Entities.ThongTinHangHoa tao = new Entities.ThongTinHangHoa();
             tao.MaNhomHangHoa = dr[0].ToString();
             tao.MaHangHoa     = dr[1].ToString();
             tao.TenHangHoa    = dr[2].ToString();
             tao.GiaNhap       = dr[3].ToString();
             tao.GiaBanBuon    = dr[4].ToString();
             tao.GiaBanLe      = dr[5].ToString();
             arr.Add(tao);
         }
         int n = arr.Count;
         if (n == 0)
         {
             arrC = null;
         }
         arrC = new Entities.ThongTinHangHoa[n];
         for (int i = 0; i < n; i++)
         {
             arrC[i] = (Entities.ThongTinHangHoa)arr[i];
         }
     }
     catch (Exception ex)
     { string s = ex.Message.ToString(); arrC = null; }
     finally
     {
         cmd.Connection.Dispose();
         cn.Close();
         conn.closeConnection();
     }
     return(arrC);
 }
예제 #2
0
 /// <summary>
 /// lay hang hoa theo ma nhom hang
 /// </summary>
 /// <param name="giatri"></param>
 /// <returns></returns>
 public Entities.ThongTinHangHoa[] Select(Entities.TruyenGiaTri giatri)
 {
     Entities.ThongTinHangHoa[] arrC = null;
     try
     {
         string sql = "exec sp_TimHangHoaTheoMaNhomHang @MaNhomHangHoa";
         conn = new Connection();
         cn = conn.openConnection();
         cmd = new SqlCommand(sql, cn);
         cmd.Parameters.Add("MaNhomHangHoa", SqlDbType.NVarChar,20).Value = giatri.Giatritruyen;
         dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
         arr = new ArrayList();
         while (dr.Read())
         {
             Entities.ThongTinHangHoa tao = new Entities.ThongTinHangHoa();
             tao.MaNhomHangHoa = dr[0].ToString();
             tao.MaHangHoa = dr[1].ToString();
             tao.TenHangHoa = dr[2].ToString();
             tao.GiaNhap = dr[3].ToString();
             tao.GiaBanBuon = dr[4].ToString();
             tao.GiaBanLe = dr[5].ToString();
             arr.Add(tao);
         }
         int n = arr.Count;
         if (n == 0) { arrC = null; }
         arrC = new Entities.ThongTinHangHoa[n];
         for (int i = 0; i < n; i++)
         {
             arrC[i] = (Entities.ThongTinHangHoa)arr[i];
         }
     }
     catch (Exception ex)
     { string s = ex.Message.ToString(); arrC = null; }
     finally
     {
         cmd.Connection.Dispose();
         cn.Close();
         conn.closeConnection();
     }
     return arrC;
 }