public IEnumerable<Users>Search(SearchUsers HPSRDH_Search) { SqlDataReader reader = null; SqlConnection Con = new SqlConnection(ConfigurationManager.ConnectionStrings["AWWs"].ConnectionString); SqlCommand adp = new SqlCommand(" SELECT top 100 [eid] [Enroll ID],[uid][Aadhaar],[name][Resident Name],[dob][DOB],[gender][Gender],[addr_careof][Care of] ,[addr_building][Address building],[addr_street][Addr Street],[addr_landmark][Addr Landmark],[addr_locality][Addr Locality] ,[addr_vtc_name] [Addr VTC],[addr_district_name] [Addr District] " + " ,[addr_state_name],[addr_pincode],[res_gauardian_name],[res_addr_subdistrict_name],[res_addr_po_name] FROM EID_UID_MAPPING " + " where" + Returnwhare(HPSRDH_Search), Con); adp.CommandType = CommandType.Text; if (Con.State == ConnectionState.Closed) { Con.Open(); } try { reader = adp.ExecuteReader(); Users user = null; while (reader.Read()) { user = new Users(); user.Enroll_ID = reader.GetValue(0).ToString(); user.Aadhaar = reader.GetValue(1).ToString(); user.Resident_Name = reader.GetValue(2).ToString(); user.DOB = reader.GetValue(3).ToString(); user.Gender = reader.GetValue(4).ToString(); user.Care_of = reader.GetValue(5).ToString(); user.Address_Building = reader.GetValue(6).ToString(); user.Addr_Street = reader.GetValue(7).ToString(); user.Addr_Landmark = reader.GetValue(8).ToString(); user.Addr_Locality = reader.GetValue(9).ToString(); user.Addr_VTC = reader.GetValue(10).ToString(); user.Addr_District = reader.GetValue(11).ToString(); user.addr_state_name = reader.GetValue(12).ToString(); user.addr_pincode = reader.GetValue(13).ToString(); user.res_gauardian_name = reader.GetValue(14).ToString(); user.res_addr_subdistrict_name = reader.GetValue(15).ToString(); user.res_addr_po_name = reader.GetValue(16).ToString(); UserList.Add(user); } } catch (Exception ex) { throw ex; } finally { adp.Dispose(); } return UserList; }
private string Returnwhare(SearchUsers HPSRDH_Search) { String Where = ""; try { if (HPSRDH_Search.District.ToString().Trim() != "") { if (Where.Length > 0) { Where = Where + " and addr_district_name like '%" + HPSRDH_Search.District.ToString().Trim() + "%'"; } else { Where = " addr_district_name like '%" + HPSRDH_Search.District.ToString().Trim() + "%'"; } } if (HPSRDH_Search.Name.ToString().Trim() != "") { if (Where.Length > 0) { Where = Where + " and Name like '%" + HPSRDH_Search.Name.ToString().Trim() + "%'"; } else { Where = " Name like '%" + HPSRDH_Search.Name.ToString().Trim() + "%'"; } } if (HPSRDH_Search.F_H_Name.ToString().Trim() != "") { if (Where.Length > 0) { Where = Where + " and addr_careof like '%" + HPSRDH_Search.F_H_Name.ToString().Trim() + "%'"; } else { Where = " addr_careof like '%" + HPSRDH_Search.F_H_Name.ToString().Trim() + "%'"; } } if (HPSRDH_Search.DOB.ToString().Trim() != "") { //string date = DateTime.ParseExact(Gdate, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).ToString("dd-MM-yyyy"); if (Where.Length > 0) { Where = Where + " and CONVERT(varchar(20),DOB,105)='" + HPSRDH_Search.DOB.ToString().Trim() + "'"; } else { Where = " CONVERT(varchar(20),DOB,105)='" + HPSRDH_Search.DOB.ToString().Trim() + "'"; } } if (HPSRDH_Search.Pincode.ToString().Trim() != "") { if (Where.Length > 0) { Where = Where + " and addr_pincode='" + HPSRDH_Search.Pincode.ToString().Trim() + "'"; } else { Where = " addr_pincode ='" + HPSRDH_Search.Pincode.ToString().Trim() + "'"; } } } catch { } return Where; }