示例#1
0
 private void cmdInsert_Click(object sender, EventArgs e)
 {
     if (dataGood())
     {
         int acct = Convert.ToInt32(txtAcctNum.Text);
         if (isValidAccount(acct))
         {
             string          fn  = txtFName.Text;
             string          ln  = txtFName.Text;
             double          bal = Convert.ToDouble(txtBalance.Text);
             AccountRecordRA ra  = new AccountRecordRA(acct, fn, ln, bal);
             try
             {
                 raFile.Seek((acct - 1) * 44, SeekOrigin.Begin);
                 ra.write(raFile);
                 readFile();
                 clearText();
             }
             catch (IOException ex)
             {
                 MessageBox.Show(ex.Message, "error inserting record");
             }
         }
     }
 }
示例#2
0
 private void cmdUpdate_Click(object sender, EventArgs e)
 {
     if (dataGood())
     {
         int    acct = Convert.ToInt32(txtAcctNum.Text);
         string fn   = txtFName.Text;
         string ln   = txtLName.Text;
         string sBal = txtBalance.Text;
         if (sBal[0] == '$')
         {
             sBal = sBal.Remove(0, 1);
         }
         double          bal = Convert.ToDouble(sBal);
         AccountRecordRA ra  = new AccountRecordRA(acct, fn, ln, bal);
         try
         {
             raFile.Seek((acct - 1) * 44, SeekOrigin.Begin);
             ra.write(raFile);
             readFile();
         }
         catch (IOException ex)
         {
             MessageBox.Show(ex.Message, "error Updating");
         }
         setControlState("i");
     }
 }
示例#3
0
        private void initializeFile()
        {
            MessageBox.Show("InitializeFile() called");
            AccountRecordRA ra = new AccountRecordRA();

            try
            {
                // position file pointer
                raFile.Seek(0, SeekOrigin.Begin);
                for (int i = 0; i < 100; i++)
                {
                    ra.write(raFile);
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "Error initilizing File");
            }
        }
示例#4
0
 private void cmdDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are you sure you want to delete this record ?", "Confirm record delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
     {
         // delete record
         int             acct = Convert.ToInt32(txtAcctNum.Text);
         AccountRecordRA ra   = new AccountRecordRA();
         try
         {
             //potition file pointer
             raFile.Seek((acct - 1) * 44, SeekOrigin.Begin);
             ra.write(raFile);
             readFile();
         }
         catch (IOException ex)
         {
             MessageBox.Show(ex.Message, "error deleting record");
         }
     }
 }
示例#5
0
        private void readFile()
        {
            listBox1.Items.Clear();
            AccountRecordRA ra = new AccountRecordRA();

            try
            {
                raFile.Seek(0, SeekOrigin.Begin);
                for (int i = 0; i < 100; i++)
                {
                    ra.read(raFile);
                    if (ra.Account > 0)
                    {
                        listBox1.Items.Add(ra.Account + ";" + ra.FirstName + ";" + ra.LastName + ";" + ra.Balance.ToString("c"));
                    }
                }
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.Message, "Error reading file");
            }
        }