Refresh Dashboard Custom button. Pass new parameters

I need to add a new refresh button to a dashboard. The tricky part is that I need to alter the where clause based on the below code. By default the tracker is filtering on 3 fields.

What I need is that if a part number is entered, return that part. If no part number is entered, then return any part that has a value in MinQty, MaxQty, or SafetyQty. Does anyone know how this is possible?

 

if (partnumber.Equals (""))
   {
       filter="(PartPlant.MinimumQty<>0 OR PartPlant.MaximumQty<>0 OR PartPlant.SafetyQty<>0)";
   }
   else
   {
       filter="PartPlant.PartNum = '" + tbxPart.Text + "'";
   }
          
   if (plantvalue.Equals(""))
   {
       filter= filter + "";
   }
   else
   {
       filter= filter + " AND PartPlant.Plant = '" + Plantcmb.Value.ToString() + "'";
   }
   
   if (tplantvalue.Equals(""))
   {
       filter= filter + "";
   }
   else
   {
       filter= filter + " AND PartPlant.TransferPlant = '" + TPlantcmb.Value.ToString() + "'";
   }