views:

60

answers:

1

Hi all i am having a form namely addbatch and i will have some textboxes and 3 buttons namely save cancel addentry. When i given some sort of values on my form i will check for a condition as

   if(file.Length<95)
   {
      // I will raise an error
    }

When the user clicks on Addentry button i would like to show a new form and if the use fills some sort of details and click on save i would like to append all the data to the previous form after the last entry of the previous form.

I have my class file for batch as follows

public bool saveBatchHeader(string m_strPath)
    {
        StringBuilder sb = new StringBuilder();
        sb.AppendLine();
        sb.Append(m_strRecordTypeCode.PadLeft(1, '0'));
        sb.Append(m_strServiceClassCode.PadLeft(3, '0'));
        sb.Append(m_strCompanyName.PadRight(16, ' '));
        sb.Append(m_strCompanyDiscretionaryData.PadRight(20, ' '));
        sb.Append(m_strCompanyIdentification.PadRight(10, ' '));
        sb.Append(m_strStandardEntryClassCode.PadRight(3, ' '));
        sb.Append(m_strCompanyEntryDescription.PadRight(10, ' '));
        string m_strCompanyDescripDate = m_strCompanyDescriptiveDate.Replace("/", "");
        sb.Append(m_strCompanyDescripDate.PadLeft(6, '0'));
        string m_strEffDate = m_strEffectiveEntryDate.Replace("/", "");
        sb.Append(m_strEffDate.PadLeft(6, '0'));
        sb.Append(m_strJulianDate.PadRight(3, ' '));
        sb.Append(m_strOriginatorStatusCode.PadRight(1, ' '));
        sb.Append(m_strOriginationDFIIdentification.PadLeft(8, '0'));
        sb.Append(m_strBatchNumber.PadLeft(7, '0'));
        sb.Replace("\r\n", String.Empty);
        **int len = sb.Length;
        if (len < 95)
        {
            m_flag = false;
        }**
        else
        {
            StreamWriter sw = File.AppendText(m_strPath);
            sw.Write(sb);
            sw.Close();

        }
        return m_flag;
    }

How to append the next form data to that string builder and how can i save my file

Hi this is my second code

   public bool saveEntry(string strPath)
    {
        m_flag = true;
        string FileName = strPath;
        string m_strDate = DateTime.Now.ToString("MM/dd/yyyy");
        m_strDate = m_strDate.Replace("/", "");
        strPath += "/CCD_EntryDetailRecord_" + m_strDate + ".txt";

        using (TextWriter tw = new StreamWriter(strPath))
        {
            tw.Write(m_strRecordTypeCode.PadLeft(1, '0'));
            tw.Write(m_strTransactionCode.PadLeft(2, '0'));
            tw.Write(m_strRecievingDFIIdentification.PadLeft(9, '0'));
            tw.Write(m_strDFIAccountNumber.PadRight(17, ' '));
            tw.Write(m_strAmount.PadLeft(10, '0'));
            tw.Write(m_strIdentificationNumber.PadRight(15, ' '));
            tw.Write(m_strRecievingcompanyName.PadRight(22, ' '));
            tw.Write(m_strDiscretionaryData.PadRight(2, ' '));
            tw.Write(m_strAddendaRecordIndicator.PadLeft(1, '0'));
            tw.Write("TTTTBBBBZZZZZZZ");
            tw.WriteLine();
            tw.Flush();
            tw.Close();
    }

What ever data here entered should be appended after sb.Append(m_strBatchNumber.PadLeft(7, '0')); whcih was in the first code. AFter that i have to recheck my condition if it is ok i will write it to the required file..

+1  A: 

You should create the StringBuilder in your first form and pass it to the second form (instead of creating it there). You can do it either in the form's constructor, or create a separate setter property.

Grzenio
Hi how can i pass in between class files.
Dorababu
@Dorababu, please paste the code where you create and open the second form and I will change it appropriately.
Grzenio
@Grzenio : I have updated my question please check once
Dorababu
Got the answer just declared static class and append the required text for SB
Dorababu