Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
Logicall y everthing is going wrong
i am trying to filter records based on the experience of the doctor
say i have a table
which retrieved
cs_Id months cs_ConsultationFee DoctorName
1 120 100 Dr Palle
2 100 200 Dr Skora
3 109 300 Dr Luki
4 24 400 Dr Azun
5 60 100 Dr Kamalio


I have 5 check box which filters out expirence according to the checkboxes checked
check box 1 ("Months >= 120 AND Months <= 240 ")
check box 2 ("Months >= 60 AND Months <= 120 ");
check box 3 ("Months >= 24 AND Months <= 60 ");
check box 4 ("Months >= 12 AND Months <= 24 ");
check box 5 ("dt.Select("Months <= 12")");
if i select check box 1 it must filter our all docotrs who have experience between 120 and 240 one can select all check box also

I have another 5 check box which filters out Consulting fees according to the checkboxes checked

SQL
check box 1    ("Months >= 120 AND Months <= 240 ")
  check box 2   ("fees>= 60 AND fees<= 120 ");
  check box 3      ("fees>= 24 AND fees<= 60 ");
  check box 4   ("fees>= 12 AND fees<= 24 ");
  check box 5  ("dt.Select("Months <= 12")");
if i select check box 2 it must filter our all  docotrs who have fees between 24 and 60one can select all check box also


C#
#region CHECK YEARS
DataTable dt = obj.BindClinic_details(Doctormlid, city, Locality, lblProblem, speciality);

                //check the expirence  and working days and languages before showing if the check box are cheked





                DataTable dtFilter = dt.Clone();
                int chkcount = 0;
          if (chk10to20years.Checked == true)
          {

              DataRow[] drs = null;

              drs = dt.Select("Months >= 120 AND Months <= 240 ");
              foreach (DataRow d in drs)
              {
                  if (dtFilter.Rows.Count != 0)
                  {
                      //check if the row is present  or not if not then only insert
                      int cnt = (from i in dt.AsEnumerable()
                                 where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                 select i).Count();
                      if (cnt == 0)
                      {
                          dtFilter.ImportRow(d);
                      }
                  }
                  else
                  {
                      dtFilter.ImportRow(d);
                  }
              }
              chkcount++;
          }


          if (chk5to10years.Checked == true)
          {
              DataRow[] drs = null;

              drs = dt.Select("Months >= 60 AND Months <= 120 ");

              foreach (DataRow d in drs)
              {
                  if (dtFilter.Rows.Count != 0)
                  {
                      //check if the row is present  or not if not then only insert
                      int cnt = (from i in dt.AsEnumerable()
                                 where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                 select i).Count();
                      if (cnt == 0)
                      {
                          dtFilter.ImportRow(d);
                      }
                  }


                  else
                  {
                      dtFilter.ImportRow(d);
                  }

              }
              chkcount++;
          }

          if (chk2to5years.Checked == true)
          {

              DataRow[] drs = null;


              drs = dt.Select("Months >= 24 AND Months <= 60 ");

              foreach (DataRow d in drs)
              {
                  if (dtFilter.Rows.Count != 0)
                  {
                      //check if the row is present  or not if not then only insert
                      int cnt = (from i in dt.AsEnumerable()
                                 where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                 select i).Count();
                      if (cnt == 0)
                      {
                          dtFilter.ImportRow(d);
                      }
                  }
                  else
                  {
                      dtFilter.ImportRow(d);
                  }

              }
              chkcount++;
          }

          if (chk_1to2years.Checked == true)
          {

              DataRow[] drs = null;
              drs = dt.Select("Months >= 12 AND Months <= 24 ");

              foreach (DataRow d in drs)
              {
                  if (dtFilter.Rows.Count != 0)
                  {
                      //check if the row is present  or not if not then only insert
                      int cnt = (from i in dt.AsEnumerable()
                                 where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                 select i).Count();
                      if (cnt == 0)
                      {
                          dtFilter.ImportRow(d);
                      }
                  }
                  else
                  {
                      dtFilter.ImportRow(d);
                  }

              }
              chkcount++;
          }

          if (chk_0to1years.Checked == true)
          {

              DataRow[] drs = dt.Select("Months <= 12");

              foreach (DataRow d in drs)
              {
                  if (dtFilter.Rows.Count != 0)
                  {
                      //check if the row is present  or not if not then only insert
                      int cnt = (from i in dt.AsEnumerable()
                                 where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                 select i).Count();
                      if (cnt == 0)
                      {
                          dtFilter.ImportRow(d);
                      }
                  }
                  else
                  {
                      dtFilter.ImportRow(d);
                  }

              }
              chkcount++;
          }




          #endregion

          #region CONSULTING FEES

          // DataTable dtFilter = dt.Clone();


          if (chkabove1000.Checked == true)
          {


              DataRow[] drs = null;


                  drs = dt.Select("cs_ConsultationFee >= 1000");

                  foreach (DataRow d in drs)
                  {
                      if (dtFilter.Rows.Count != 0)
                      {
                          //check if the row is present  or not if not then only insert
                          int cnt = (from i in dt.AsEnumerable()
                                     where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                     select i).Count();
                          if (cnt == 0)
                          {
                              dtFilter.ImportRow(d);
                          }
                      }
                      else
                      {
                          dtFilter.ImportRow(d);
                      }

                  }
              chkcount++;
          }
          if (chk700to1000.Checked == true)
          {
              DataRow[] drs = null;

                  drs = dt.Select("cs_ConsultationFee >= 700 AND cs_ConsultationFee <= 1000 ");

                  foreach (DataRow d in drs)
                  {
                      if (dtFilter.Rows.Count != 0)
                      {
                          //check if the row is present  or not if not then only insert
                          int cnt = (from i in dt.AsEnumerable()
                                     where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                     select i).Count();
                          if (cnt == 0)
                          {
                              dtFilter.ImportRow(d);
                          }
                      }
                      else
                      {
                          dtFilter.ImportRow(d);
                      }

                  }
              chkcount++;
          }


          if (chk400to699.Checked == true)
          {

              //DataRow[] drs = dt.Select("cs_ConsultationFee >= 400 AND cs_ConsultationFee <= 699 ");
              DataRow[] drs = null;


                  drs = dt.Select("cs_ConsultationFee >= 400 AND cs_ConsultationFee <= 699 ");

                  drs = dtFilter.Select("cs_ConsultationFee >= 400 AND cs_ConsultationFee <= 699 ");
                  foreach (DataRow d in drs)
                  {
                      if (dtFilter.Rows.Count != 0)
                      {
                          //check if the row is present  or not if not then only insert
                          int cnt = (from i in dt.AsEnumerable()
                                     where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                     select i).Count();
                          if (cnt == 0)
                          {
                              dtFilter.ImportRow(d);
                          }
                      }
                      else
                      {
                          dtFilter.ImportRow(d);
                      }

                  }
              chkcount++;
          }
          if (chk200to399.Checked == true)
          {
              DataRow[] drs = null;


                  drs = dt.Select("cs_ConsultationFee >= 200 AND cs_ConsultationFee <= 399 ");

                  drs = dtFilter.Select("cs_ConsultationFee >= 200 AND cs_ConsultationFee <= 399 ");
                  foreach (DataRow d in drs)
                  {
                      if (dtFilter.Rows.Count != 0)
                      {
                          //check if the row is present  or not if not then only insert
                          int cnt = (from i in dt.AsEnumerable()
                                     where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                     select i).Count();
                          if (cnt == 0)
                          {
                              dtFilter.ImportRow(d);
                          }
                      }
                      else
                      {
                          dtFilter.ImportRow(d);
                      }

                  }

              chkcount++;
          }
          if (chk0to199.Checked == true)
          {
              DataRow[] drs = null;

                  drs = dt.Select("cs_ConsultationFee <= 199");




                  foreach (DataRow d in drs)
                  {
                      if (dtFilter.Rows.Count != 0)
                      {
                          //check if the row is present  or not if not then only insert
                          int cnt = (from i in dt.AsEnumerable()
                                     where i.Field<int>("cs_Id").ToString() == d["cs_Id"].ToString()
                                     select i).Count();
                          if (cnt == 0)
                          {
                              dtFilter.ImportRow(d);
                          }
                      }
                      else
                      {
                          dtFilter.ImportRow(d);
                      }

                  }
              chkcount++;
          }




          #endregion
Posted
Comments
Please don't post all the codes. Who will go through them? Just try to narrow these codes down to problem part only.
rocky_em 4-Oct-13 2:02am    
Ok Next Time I wont Do that i did some what like this conditions are many i narrowed it
Now i can search records from multiple riteria
IEnumerable<datarow> rows = from i in table.AsEnumerable()
where (
(
(p = true ? (((int)i["Price"]) >= 1700 && ((int)i["Price"]) <= 2700) : false)
||
(p = true ? (((int)i["Price"]) >= 2070 && ((int)i["Price"]) <= 3507) : false)
)
&&
(
(filterOnFirstName = true ? ((string)i["Firstname"]).StartsWith("B") : false)
||
(filterOnFirstName = true ? ((string)i["Firstname"]).StartsWith("uiuiuiuiui") : false)
)

)
select i;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900