Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Breaking from the loop
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01572547
Message ID:
01572644
Views:
40
>>I am thinking of the best way to convert the following VFP code
>>So, the problem here is that we have 10 b_pop1_ columns and 15 b_pop2 columns. So, I somehow need to run loop for 10 and for 15.
>
>
>Why do you want to put it in one loop? As far as I can see (and it was painful to look at that code, you owe me Naomi, you owe me big time :)) those were independent values, so I would write two methods with only one loop to do the assignments (and those methods should have a descriptive name, with the names you are currently using nobody can understand what the heck they are pop1 and pop2), this way if tomorrow for some reason there are 11 and 14 columns and you are not there any longer the next person has an easier job maintaining the code. (also I think in the foxpro code you have another set (criteria? I forgot and I already deleted the quoted text) that I would put in yet another method but is missing in your code, I think)
>
>Just my 2c

After I looked more closer yesterday, I discovered 2 things:
1. Somehow when I made a change in VFP code, I left out the whole block of code for pop3 stuff. I restored it in VFP code, but haven't yet asked to build this and test.

2. I also had another problem with logic - the criteria needed to be after the 10 first pop.

Anyway, this is my current code in that method:
 private String FormatInstrInfoDSP(DataSet dataSet)
      {
         StringBuilder displayString = new StringBuilder();
         DataRow row = dataSet.Tables[0].Rows[0];

         displayString.AppendFormat("Instructor: {0} {1}  [{2}]{3}{3}",
            row["first_name"].ToString().Trim(), row["last_name"].ToString().Trim(), row["instr_id"].ToString().Trim(), Environment.NewLine);

         Int16 instr_type = Convert.ToInt16(row["instr_type"]);
         displayString.AppendFormat("Instructor Type: {0}{1}", (instr_type <= 1) ? "Regular" : "TBD", Environment.NewLine);

         DateTime? checkedIn = row.Field<DateTime?>("last_ck_in");

         displayString.AppendFormat("Last Checked in: {0}{1}",
             checkedIn.ToString(), Environment.NewLine);
         DateTime? hire_date = row.Field<DateTime?>("hire_date");

         displayString.AppendFormat("Hired: {0}{1}",
             hire_date.ToString(), Environment.NewLine);

         Int32 experience = Convert.ToInt32(row["experience"]);

         Int32 totalExperience = experience + ((hire_date.HasValue == true) ? (DateTime.Now.Year - hire_date.Value.Year) : 0);
         Int16 sex = Convert.ToInt16(row["sex"]);

         displayString.AppendFormat("Previous Experience: {0}{1}",
             experience, Environment.NewLine);
         displayString.AppendFormat("Total Experience: {0}{1}",
             totalExperience, Environment.NewLine);
         displayString.AppendFormat("Priority Group: {0} #{1}{2}", row["priority1"].ToString(), row["priority2"].ToString(), Environment.NewLine);
         displayString.AppendFormat("Sex: {0}{1}",
            (sex > 1) ? "Male" : "Female", Environment.NewLine);
         displayString.AppendFormat("Alpine Level: {0}{1}",
             row["tch_level"].ToString(), Environment.NewLine);
         displayString.AppendFormat("Snowboard Level: {0}{1}",
             row["snb_level"].ToString(), Environment.NewLine);
         displayString.AppendFormat("Telemark Level: {0}{1}",
             row["tele_level"].ToString(), Environment.NewLine);
         displayString.AppendFormat("Other Level: {0}{1}",
             row["misc_level"].ToString(), Environment.NewLine);

         for (int i = 1; i <= 3; i++)
         {
            displayString.AppendFormat("{0}:{1}", database.GetPreferenceString("prefs_bk", "b_pop" + i.ToString()).Trim(), Environment.NewLine);
            for (int j = 1; j <= 15; j++)
            {
               String prefs_pop = database.GetPreferenceString("prefs_bk", "b_pop" + i.ToString() + "_" + j.ToString()).Trim();
               if (!String.IsNullOrWhiteSpace(prefs_pop))
               {
                  Boolean skills = Convert.ToBoolean(row[String.Format("pop_up{0}_{1}", i, j)]);
                  displayString.AppendFormat("   {0}: {1}{2}", prefs_pop, (skills) ? "YES" : "NO", Environment.NewLine);
               }

               if (1 == i && j >= 10)
                  break;
            }
            if (1 == i)
            {
               for (int k = 2; k <= 5; k++)
               {
                  String criterion = database.GetPreferenceString("prefs_bk", "b_crit" + k.ToString());
                  if (!String.IsNullOrWhiteSpace(criterion))
                  {
                     String criterionValue = "";
                     switch (k)
                     {
                        case 2:
                        case 3:
                           Boolean skillValue = Convert.ToBoolean(row[String.Format("criteria_{0}", k)]);
                           criterionValue = (skillValue) ? "YES" : "NO";
                           break;
                        case 4:
                        case 5:
                           criterionValue = row[String.Format("criteria_{0}", k)].ToString();
                           break;
                        default:
                           break;
                     }
                     displayString.AppendFormat("{0}: {1}{2}", criterion, criterionValue, Environment.NewLine);
                  }
               }
            }
         }

         return displayString.ToString();
      }
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform