adding records StreamWriter PROBLEM

Dec 18 2007 9:31 AM

Well, Here is my current codes in the Windows Application program

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;


// add private fields
private string[] lines;
private int currentLine = -1; // dummy value


        private void frmCustomerDetails_Load(object sender, EventArgs e)
        {

            //Reads records from a file
            lines = File.ReadAllLines(@"C:\mp2.txt");
            // display first one
            DisplayRecord(0);

        }

        private void DisplayRecord(int index)
        {
            // don't do anything if index is outside bounds of lines array
            // or if requested line is already displayed
            if (index < 0 || index >= lines.Length || index == currentLine)
               return;
            string[] records = lines[index].Split('#');
            txtCustomerID.Text = records[0];
            txtContactPerson.Text = records[1];
            txtAddress.Text = records[2];
            txtContactPerson.Text = records[3];
            txtContactNo.Text = records[4];
            currentLine = index; // update currentline 
        }


        private void btnFirst_Click( object sender, EventArgs e)
        {
             DisplayRecord(0);
        }

        private void btnNext_Click( object sender, EventArgs e)
        {
             DisplayRecord(currentLine + 1);  
        }

        private void btnPrev_Click( object sender, EventArgs e)
        {
            
             DisplayRecord(currentLine - 1);  

        }
 
        private void btnLast_Click( object sender, EventArgs e)
        {
              DisplayRecord(lines.Length - 1);
        }

 

Is there a way I could add records from the existing notepad (mp2.txt), wherein, you could still display all the previous items

plus the one you've added? Another, is there a possibilty that I could still edit my previous record from the 'mp2.txt' and save it

afterwards?

here's the thing

btn_Add - Adds a new record...then put on the last record of mp2

btn_Edit - edits the the one who is currently displayed by the textboxes...

btn_Save - saves the changes when Edit process was finished already....

btn_Cancel - if you wish to cancel the edit process..

 

(by the way, once added a new record, there should have an input recorded to the mp2.txt as well at the last part)
 

 

Sorry if I ask too much. I'm kinda confused with all these stuff. Noob me.
 
 
 
  
 


Answers (9)