2 Replies - 670 Views - Last Post: 04 June 2009 - 08:47 PM Rate Topic: -----

#1 indhu_rama  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-June 09

Modifying the code to accept multiple values

Post icon  Posted 04 June 2009 - 03:34 PM

Hi all,
I'm new to C#. I'm doing code change based on code review.
In below code , we are getting values for lane_numbers_d1 and lane_numbers_d2 from pl/sql returning thru refcursor. But in code review, my manager asked me to do this more generic.
They dont want it to be looking for only 2 lane numbers.It should look for as many as lanes in each direction.
I did changes in pl/sql to retrive values using single parameter called lane_numbers_d.
How could I made corresponding changes in c# part?
Please help me.
Thanks in advance.

  #region Set Site And Direction Lanes
		/// <summary>
		/// Set site name and if the lane grouping is direction
		/// add string representation of all selected lanes for each direction 
		/// to _laneHeaderSelectedLanes hashtable where the keys are 1 and 2
		/// </summary>   
		private void SetSiteAndDirectionLanes(IRD.EnterpriseReporting.Framework.ReportingFramework
				.ReportingUnits.LaneGroupingType laneGroupingType)
		{
			_siteShortName = Convert.ToString(_siteData.Rows[0]["site_name"]);

			if (laneGroupingType == IRD.EnterpriseReporting.Framework.ReportingFramework
				.ReportingUnits.LaneGroupingType.Direction)
			{
				string lane_numbers_d1 = Convert.ToString(_siteData.Rows[0]["lane_numbers_d1"]);
				string lane_numbers_d2 = Convert.ToString(_siteData.Rows[0]["lane_numbers_d2"]);

				if (lane_numbers_d1.Trim() != "")
				{
					lane_numbers_d1 = "#" + lane_numbers_d1.Replace(",", ", #");
				}
				if (lane_numbers_d2.Trim() != "")
				{
					lane_numbers_d2 = "#" + lane_numbers_d2.Replace(",", ", #");
				}

				_laneHeaderSelectedLanes.Add(1, lane_numbers_d1);
				_laneHeaderSelectedLanes.Add(2, lane_numbers_d2);
			}
		}
		#endregion


This post has been edited by Core: 04 June 2009 - 08:53 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Modifying the code to accept multiple values

#2 indrora  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 100
  • Joined: 25-July 08

Re: Modifying the code to accept multiple values

Posted 04 June 2009 - 07:10 PM

first, "More generic" -- what does that mean?
second, Learn What Your Functions Return In .NET.
*how* is your data returned from your SQL database?
Because if you say
Get_Lane_numbers 4

and get back
"1,3,5,7,9"

you're essentially writing
def("get_lane_numbers %i",lane, Callfunc("get_lane_numbers_d"+(string)lane);


How it looks you have it, the code you have provided is adequate for any task (from what i can tell, I cant understand any of the variable names as they're primarily '_' prefixed, a C++ism for 'private' and many of them are global variables that will probably go away later, and thats Bad Practice to me)
Was This Post Helpful? 0
  • +
  • -

#3 masteryee  Icon User is offline

  • D.I.C Regular

Reputation: 40
  • View blog
  • Posts: 271
  • Joined: 16-May 09

Re: Modifying the code to accept multiple values

Posted 04 June 2009 - 08:47 PM

What are you storing in the _siteData.Rows collection? Is that supposed to be a DataRowCollection? How are you going to be entering in X number of lanes?

If we try and stick with your original code, you can do something like this:
        private void SetSiteAndDirectionLanes(IRD.EnterpriseReporting.Framework.ReportingFramework
                .ReportingUnits.LaneGroupingType laneGroupingType)
        {
            _siteShortName = Convert.ToString(_siteData.Rows[0]["site_name"]);

            if (laneGroupingType == IRD.EnterpriseReporting.Framework.ReportingFramework
                .ReportingUnits.LaneGroupingType.Direction)
            {
                int i = 0;
                while (true)
                {
                   i++;
                   try
                   {
                      string lane = _siteData.Rows[0]["lane_numbers_d" + i.ToString()];
                      if (lane.Trim() != "")
                        lane = "#" + lane.Replace(",", ", #");
                      _laneHeaderSelectedLanes.Add(i,, lane);
                   }
                   catch()
                   {
                      break;
                   }
                }
            }
        }



I think that's how you write a try/catch...lol, sorry if it doesn't compile. You need it in order to catch the error that will occur when you try to access a column that doesn't exist. At least this allows you to add X number of lanes to your row, but the drawback is that this will only work as long as your lane columns are sequential (i.e. the columns are named lane1, lane2, ... and not something like laneBig, laneSmall...)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1