Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Code In Need Of Cleanup [modified]

Code In Need Of Cleanup [modified]

Scheduled Pinned Locked Moved The Weird and The Wonderful
sales
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kevin Marois
    wrote on last edited by
    #1

    Not the worst code I've seen, but it's bad. This is typical code worked on by multiple developers over time. The class this is in has over 5000 lines of code. All of it looks like this.

    /* Get Shop Order Details.*/
    DataTable dtShopOrder;

    if(sSNInPK.ToLower()=="yes;")
    dtShopOrder = new ERP().GetShopOrderDetails(txtSerialNum.Text);
    else
    dtShopOrder = new Operation().GetShopOrderDetails(txtSerialNum.Text);

    if(dtShopOrder == null || dtShopOrder.Rows.Count <=0)
    {
    this.showMessage("Cannot find the serial number. Please contact your System Administrator.", MessageType.Warning);
    return;
    }

    txtShopOrder.Text = dtShopOrder.Rows[0]["ShopOrder"].ToString();
    txtAssembly.Text = dtShopOrder.Rows[0]["Assembly"].ToString();
    txtRev.Text = dtShopOrder.Rows[0]["Revision"].ToString();
    txtCUCode.Text = dtShopOrder.Rows[0]["CUCODE"].ToString();
    txtCustomer.Text = dtShopOrder.Rows[0]["CUNAME"].ToString();
    txtQty.Text = dtShopOrder.Rows[0]["Qty"].ToString();

    /*START >> For enhancement - Sub assembly serial number management(9th June 2009)*/

    strSubAsmWC = "";
    try
    {

    if(dtShopOrder.Rows\[0\]\["SubAsmWC"\] != null)
    {
    	strSubAsmWC = dtShopOrder.Rows\[0\]\["SubAsmWC"\].ToString();
    }
    

    }
    catch
    {
    strSubAsmWC = "";
    }

    /*End >> For enhancement - Sub assembly serial number management (9th June 2009)*/

    /*START >> For enhancement - assigning Customer Label/MAC Addresses (1st Feb 2007)*/

    iCustOpNum = -1;
    iMACOpNum = -1;
    iMACCount = -1;
    strCustLabel = "";
    strMACAddress = "";

    if(dtShopOrder.Rows[0]["iCustLabelOpNum"] != null)
    {
    try
    {
    iCustOpNum = int.Parse(dtShopOrder.Rows[0]["iCustLabelOpNum"].ToString());
    }
    catch
    {

    }
    

    }

    if(dtShopOrder.Rows[0]["iMacAddressOpNum"] != null)
    {
    try
    {
    iMACOpNum = int.Parse(dtShopOrder.Rows[0]["iMacAddressOpNum"].ToString());
    }
    catch
    {

    }
    

    }

    if(dtShopOrder.Rows[0]["iMacAddressCount"] != null)
    {
    try
    {
    iMACCount = int.Parse(dtShopOrder.Rows[0]["iMacAddressCount"].ToString());
    }
    catch
    {

    }
    

    }

    if(dtShopOrder.Rows[0]["CustLabel"] != null)
    strCustLabel = dtShopOrder.Rows[0]["CustLabel"].ToString();

    if(dtShopOrder.Rows[0]["MacAddress"] != null)
    strMACAddress = dtShopOrder.Rows[0]["MacAddress"].ToString();

    /*END >> For enhancement - assigning Customer Label/MAC Addresses (1st Feb 2007)*/

    Found this in there also

    if(slAppConfig[AppConfig.Keys.address_defect_wc.ToString()].ToString().IndexOf(lblWCKey.Text + ";",0)>=0
    || lblWCKey.Text == this.GetC

    G 1 Reply Last reply
    0
    • K Kevin Marois

      Not the worst code I've seen, but it's bad. This is typical code worked on by multiple developers over time. The class this is in has over 5000 lines of code. All of it looks like this.

      /* Get Shop Order Details.*/
      DataTable dtShopOrder;

      if(sSNInPK.ToLower()=="yes;")
      dtShopOrder = new ERP().GetShopOrderDetails(txtSerialNum.Text);
      else
      dtShopOrder = new Operation().GetShopOrderDetails(txtSerialNum.Text);

      if(dtShopOrder == null || dtShopOrder.Rows.Count <=0)
      {
      this.showMessage("Cannot find the serial number. Please contact your System Administrator.", MessageType.Warning);
      return;
      }

      txtShopOrder.Text = dtShopOrder.Rows[0]["ShopOrder"].ToString();
      txtAssembly.Text = dtShopOrder.Rows[0]["Assembly"].ToString();
      txtRev.Text = dtShopOrder.Rows[0]["Revision"].ToString();
      txtCUCode.Text = dtShopOrder.Rows[0]["CUCODE"].ToString();
      txtCustomer.Text = dtShopOrder.Rows[0]["CUNAME"].ToString();
      txtQty.Text = dtShopOrder.Rows[0]["Qty"].ToString();

      /*START >> For enhancement - Sub assembly serial number management(9th June 2009)*/

      strSubAsmWC = "";
      try
      {

      if(dtShopOrder.Rows\[0\]\["SubAsmWC"\] != null)
      {
      	strSubAsmWC = dtShopOrder.Rows\[0\]\["SubAsmWC"\].ToString();
      }
      

      }
      catch
      {
      strSubAsmWC = "";
      }

      /*End >> For enhancement - Sub assembly serial number management (9th June 2009)*/

      /*START >> For enhancement - assigning Customer Label/MAC Addresses (1st Feb 2007)*/

      iCustOpNum = -1;
      iMACOpNum = -1;
      iMACCount = -1;
      strCustLabel = "";
      strMACAddress = "";

      if(dtShopOrder.Rows[0]["iCustLabelOpNum"] != null)
      {
      try
      {
      iCustOpNum = int.Parse(dtShopOrder.Rows[0]["iCustLabelOpNum"].ToString());
      }
      catch
      {

      }
      

      }

      if(dtShopOrder.Rows[0]["iMacAddressOpNum"] != null)
      {
      try
      {
      iMACOpNum = int.Parse(dtShopOrder.Rows[0]["iMacAddressOpNum"].ToString());
      }
      catch
      {

      }
      

      }

      if(dtShopOrder.Rows[0]["iMacAddressCount"] != null)
      {
      try
      {
      iMACCount = int.Parse(dtShopOrder.Rows[0]["iMacAddressCount"].ToString());
      }
      catch
      {

      }
      

      }

      if(dtShopOrder.Rows[0]["CustLabel"] != null)
      strCustLabel = dtShopOrder.Rows[0]["CustLabel"].ToString();

      if(dtShopOrder.Rows[0]["MacAddress"] != null)
      strMACAddress = dtShopOrder.Rows[0]["MacAddress"].ToString();

      /*END >> For enhancement - assigning Customer Label/MAC Addresses (1st Feb 2007)*/

      Found this in there also

      if(slAppConfig[AppConfig.Keys.address_defect_wc.ToString()].ToString().IndexOf(lblWCKey.Text + ";",0)>=0
      || lblWCKey.Text == this.GetC

      G Offline
      G Offline
      GibbleCH
      wrote on last edited by
      #2

      Looks like you maintain the same persons code I do! :laugh: I swear this guy has only heard of the string datatype. Everything is in strings, booleans "true", "false". And my favorite, arrays "1|12|34|56|". :^)

      A 1 Reply Last reply
      0
      • G GibbleCH

        Looks like you maintain the same persons code I do! :laugh: I swear this guy has only heard of the string datatype. Everything is in strings, booleans "true", "false". And my favorite, arrays "1|12|34|56|". :^)

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        GibbleCH wrote:

        arrays "1|12|34|56|"

        Depends on the language. In VB6, you do not have array initializers. Loading a list by parsing a string can be a very compact way of presenting code. Not as fast as manually setting each array element, but it does make the code shorter and still readable.

        Visual Studio is an excellent GUIIDE.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups