It's gotta be a relief for our dear friend Nikolay Simeonov to scream "WTF" at today's example of coupling. Not only is it not as horrendous as other things he's come across, but this time he was actually in a position to stop this from ever making it to production. Here's what he discovered in the source tree from one of his employees...

Notice how well commented this code is, and how it actually prints a report by writing it to a file then calling the print function which takes the filename, reads it and then does the actual printing. And no, the printing function wasn't taken from another system, nor was done so but another reason - it was just the only way to send information between different functions, which this lady found out for the moment.

private void btnPrint_Click(object sender, System.EventArgs e)
{
  if(tblItem.Rows.Count == 0)
    return;
  try
  {
    string fileName = "C:/QueryReport/" + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() + ".txt";
    File.Delete(fileName);
    StreamWriter sw = new StreamWriter(fileName);

    //
    //Printing Column Names
    string str = "";
    foreach(GridColumn c in gridView1.Columns)
    {
      if(c.VisibleIndex >= 0)
      {
        string fieldValue = gridView1.Columns[c.FieldName].Caption.ToLower();
        if(c.FieldName == "NN")
          str += fieldValue.PadRight(5);
        if(c.FieldName == "itemName")
        {
          if(fieldValue.Length > 34)
            fieldValue = fieldValue.Substring(0, 34);
          str += fieldValue.PadRight(35);
        }
        if(c.FieldName == "ExpDate")
          str += fieldValue.PadRight(10);
        if(c.FieldName == "Qty")
          str += fieldValue.PadLeft(8);
        if(c.FieldName == "DeliveryPr")
          str += fieldValue.PadRight(8);
        if(c.FieldName == "Discount")
          str += fieldValue.PadRight(6);
        if(c.FieldName == "Measure")
          str += fieldValue.PadRight(7);
        if(c.FieldName == "SalePr")
          str += fieldValue.PadLeft(7);
        if(c.FieldName == "Value")
          str += fieldValue.PadLeft(9);
      }
    }
    sw.WriteLine(str);
    //

    for(int ndx = 0; ndx < this.tblItem.Rows.Count; ndx ++)
    {
      str = "";
      foreach(GridColumn c in gridView1.Columns)
      {
        if(c.VisibleIndex >= 0)
        {
          string fieldValue = gridView1.GetRowCellDisplayText(ndx, c);
          if(c.FieldName == "NN")
            str += fieldValue.PadRight(5);
          if(c.FieldName == "itemName")
          {
            if(fieldValue.Length > 34)
              fieldValue = fieldValue.Substring(0, 34);
            str += fieldValue.PadRight(35);
          }
          if(c.FieldName == "Measure")
            str += fieldValue.PadRight(7);
          if(c.FieldName == "ExpDate")
            str += fieldValue.PadRight(10);
          if(c.FieldName == "Qty")
            str += fieldValue.PadLeft(8);
          if(c.FieldName == "DeliveryPr")
            str += fieldValue.PadLeft(8);
          if(c.FieldName == "Discount")
            str += fieldValue.PadLeft(6);
          if(c.FieldName == "SalePr")
            str += fieldValue.PadLeft(7);
          if(c.FieldName == "Value")
            str += fieldValue.PadLeft(9);
        }
      }
      sw.WriteLine(str);
    }
    sw.Flush();
    sw.Close();
    Printing(fileName);
  }
  catch(Exception err)
  {
    MessageBox.Show(err.ToString());
  }
}

Also, this code is actually printing a report using a monospaced font. Nothing like a return to the dot-matrix printer days!  Oh, and this masterpiece also produces a print preview as well ...

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!