示例#1
0
        //Saves a BankAccount object to disk file & Text file
        //*******************************************************************************************************************************************
        public static void WriteBankAccountToDiskAndText(BankAccount account, string FileName)
        //*******************************************************************************************************************************************
        {
            // Open the file and write the Bank object data that you want to serialize to a disk file
            // PLUS it saves a copy  as a Text file in \\Textfiles folder with same root name + ".txt"
            try
            {
                FileStream      fs        = new FileStream(FileName, FileMode.Create);
                BinaryFormatter formatter = new BinaryFormatter( );
                formatter.Serialize(fs, account);
                fs.Close( );                  // clean up

                /*
                 * Now write it out as a named text file in the \\Textfiles folder
                 * */
                string s = account.BankAccountNumber + "," + account.CustAccountNumber + "," + account.AccountType + "," + account.Balance + "," + account.DateOpened.ToShortDateString( )
                           + "," + account.DateClosed.ToShortDateString( ) + "," + account.InterestRate + "," + account.Status + "\r\n";
                // This writes the Bank Account object as a std string [record] out in text format in \\textfiles folder
                string newfname = FileName.Substring(FileName.Length - 21);
                string path     = BankAccount.ReadBankFilePath( ) + "Textfiles\\" + newfname.Substring(0, newfname.Length - 4) + ".txt";
                if (File.Exists(path))
                {
                    File.Delete(path);                           // you gotta delete them first, else it appends the data constantly
                }
                File.AppendAllText(path, s);
            }
            catch { throw new Exception("Failed to handle file in WriteBankAccount Function, line 98 in Serialize.cs"); }
        }
示例#2
0
        //*******************************************************************************************************************************************
        public static StringBuilder ReadAllBankTransactions( )
        //*******************************************************************************************************************************************
        {           // read data from binary disk object
            StringBuilder SB = new StringBuilder( );
            string        fi = BankAccount.ReadBankFilePath( ) + "BankTransData.bnk";

            if (!File.Exists(fi))
            {             // file  not found !!//
                MessageBox.Show("Transactions File not found on disk\nNo Transactions History will be available !", "Transactions ERROR");
                return(null);
            }
            try
            {
                SB = Utils.GetDataFromDiskFile(SB, fi);

/*				BinaryFormatter formatter = new BinaryFormatter ( );
 *                              FileStream fs = new FileStream (fi, FileMode.Open);
 *                              var v = formatter.Deserialize (fs).ToString ( );
 *                              SB.Append (v);
 *                              fs.Close ( );
 */
            }

            catch
            { throw new Exception("Failed to open file in ReadBankTransactions Function, line 158 in Serialize.cs"); }

            if (SB.Length == 0)
            {
                return(null);
            }
            else
            {
                return(SB);
            }
        }
示例#3
0
        //*******************************************************************************************************************************************
        public static int BuildBankTransactionsFromTextfile( )
        {
            //*******************************************************************************************************************************************
            string fi    = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankTransData.txt";
            int    count = 0;

            if (File.Exists(fi))
            {
                string   input  = File.ReadAllText(fi);                     // you gotta delete them first, else it appends the data constantly
                char[]   ch1    = { '\t' };
                char[]   ch2    = { ',' };
                string[] record = input.Split(ch1);
                int      x      = 0;

                for (int i = 0; i < record.Length - 1; i++)
                {                   // There is n empty record for some reason, hence Length - 1
                    string          str  = record[i];
                    string[]        Item = str.Split(ch2);
                    BankTransaction BT   = new BankTransaction(
                        Convert.ToDateTime(Item[x]),
                        Convert.ToInt16(Item[x + 1]),
                        Convert.ToInt32(Item[x + 2]),
                        Convert.ToInt32(Item[x + 3]),
                        Convert.ToDecimal(Item[x + 4]),
                        Item[x + 5],
                        Convert.ToInt16(Item[x + 6]));
                    BankTransaction.allBankTransactions.AddLast((BankTransaction)BT);
                    count++;
                }
            }
            return(count);
        }
示例#4
0
        public static int RebuildBankDataFromTextFiles( )
        //************************************************************************************************************************************************
        {
            // iterate thru reading bankaccount objects from disk and add them to our LinkedList and /BankArray
            int    count = 0;
            string dir   = BankAccount.ReadBankFilePath( );

            dir += "Textfiles\\";
            string[] files = Directory.GetFiles(dir);
            // clear the lists- JIC
            DataArray.ArrayClearBank( );                 // Clear ( );
            BankAccount.BankAccountsLinkedList.Clear( );

            foreach (var fi in files)
            {
                bool result = fi.Contains("BankObject");
                if (!result)
                {
                    continue;
                }
                else
                {
                    string      input = File.ReadAllText(fi);
                    char[]      ch    = { ',' };
                    string[]    items = input.Split(ch);
                    BankAccount B     = new BankAccount( );
                    B.BankAccountNumber = Convert.ToInt32(items[0]);
                    B.CustAccountNumber = Convert.ToInt32(items[1]);
                    B.AccountType       = Convert.ToInt16(items[2]);
                    B.Balance           = Convert.ToDecimal(items[3]);
                    B.DateOpened        = Convert.ToDateTime(items[4]);
                    B.DateClosed        = Convert.ToDateTime(items[5]);
                    B.Balance           = Convert.ToDecimal(items[6]);
                    B.Status            = Convert.ToInt16(items[7]);
                    //Write it back as OBj and TXT - yes even though we onlt just read it in.
                    SerializeData.WriteBankAccountToDiskAndText(B, B.FullFileName);
                    // add each one to our new List so we cna use the Enumeration later
                    try
                    {
                        BankAccount.BankAccountsLinkedList.AddLast(B);
                        DataArray.ArrayAddBank(B);
                        if (BankAccount.BankDict != null)
                        {
                            if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                            {
                                BankAccount.BankDict.Add(B.BankAccountNumber, B);
                            }
                        }
                    }
                    catch
                    { new Exception(" Failed to update LinkeList or Bank array in RebuildBankDataFromTextFiles at line 311"); }
                    count++;
                    B.Dispose( );
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData( );
            BankListChangedEvent?.Invoke(null, "ALLDATA REBUILT FROM TEXTFILES");
            return(count);
        }
示例#5
0
        //*******************************************************************************************************************************************
        public static StringBuilder ReadAllBankTransactions( )
        //*******************************************************************************************************************************************
        {           // read data from binary disk object
            StringBuilder SB = new StringBuilder( );
            string        fi = BankAccount.ReadBankFilePath( ) + "BankTransData.bnk";

            if (!File.Exists(fi))
            {             // file  not found !!//
                Bank.form1.Output2.AppendText("Transactions File not found on disk\nNo Transactions History will be available !");
                Bank.form1.Output2.ScrollToCaret( );
                return(null);
            }
            try
            {
                BinaryFormatter formatter = new BinaryFormatter( );
                FileStream      fs        = new FileStream(fi, FileMode.Open);
                var             v         = formatter.Deserialize(fs).ToString( );
                SB.Append(v);
                fs.Close( );
            }

            catch
            { throw new Exception("Failed to open file in ReadBankTransactions Function, line 158 in Serialize.cs"); }

            if (SB.Length == 0)
            {
                return(null);
            }
            else
            {
                return(SB);
            }
        }
示例#6
0
        //************************************************************************************************************************************************//
        public static void SaveAllBankAccountListData( )
        //************************************************************************************************************************************************//
        {
            // serialize the Bankaccountlist
            // null our string out again
            string        Filename = BankAccount.ReadBankFilePath( ) + "BankAccountListData.bnk";
            string        record   = "";
            StringBuilder SBdata   = new StringBuilder( );

            // THIS CREATES A  NEW FILE ON DISK FOR EACH OF THE BANK ACCOUNTS IN OUR LINKEDLIST
            // We "could" recreate all existing bank accounts from this fileif we have a valid LinkedList file !!
            // we build a very large string, then pass it to our generic serialize Fn() to save to disk
            foreach (BankAccount Item in BankAccount.BankAccountsLinkedList)
            {
                // Now serialize it
                SBdata.Append(Item.AccountType + "\r\n");          // minor key
                SBdata.Append(Item.CustAccountNumber + "\r\n");    // major key
                SBdata.Append(Item.Balance + "\r\n");
                SBdata.Append(Item.DateOpened.ToShortDateString( ) + "\r\n");
                SBdata.Append(Item.DateClosed.ToShortDateString( ) + "\r\n"); // We do not fill this out.
                SBdata.Append(Item.InterestRate + "\r\n");                    // Default value only
                SBdata.Append(Item.Status + "\r\n");                          //
                                                                              //					SBdata.Clear();
                record += Item.AccountType.ToString( ) + "," + Item.CustAccountNumber.ToString( ) + "," + Item.BankAccountNumber.ToString( ) + "," + Item.Balance.ToString( )
                          + "," + Item.DateOpened.ToShortDateString( ) + "," + Item.DateClosed.ToShortDateString( ) + "," + Item.InterestRate.ToString( ) + "," + Item.Status.ToString( ) + "\r";
            }
            SerializeData.SBSerialize(SBdata, Filename);
            SBdata.Clear( );
            // This writes the std string [record] out in text format to the \\textfiles folder
            SaveBankAccountListDateToText(record);
        }
示例#7
0
        //======================================================================
        private void FindFile_Click_1(object sender, EventArgs e)
        //======================================================================
        {
            if (AccountNumber.SelectedItem == null)
            {
                return;
            }
            string sel = AccountNumber.SelectedItem.ToString();

            if (Convert.ToInt32(AccountNumber.Text) < Bank.V || Convert.ToInt32(AccountNumber.Text) > Bank.V)
            {
                MessageBox.Show("Invalid Bank Account # entered. range is " + Bank.V.ToString() + " and upwards !"); return;
            }
            string path = BankAccount.ReadBankFilePath() + "Textfiles\\bankobject" + sel + ".txt";

            if (!File.Exists(path))
            {
                MessageBox.Show("Invalid Bank Account # entered. range is " + Bank.V.ToString() + " and upwards !"); return;
            }

            /*
             *                                  Customer C = ( Customer ) DataArray.FindCustFromArray( sel );
             *                                  SB = SerializeData . ReadBankFromDisk ( AccountNumber . Text );
             *                                  string str = SB . ToString ( );
             */

            notes.Text = "DO NOT edit the data in this window, just edit it in the data fields.\r\n"
                         + "All/Any available data item can be changed, and once saved, it will be changed permanently throughout the System.\n\r\n";
            string input = File.ReadAllText(path);

            string[] data = input.Split(',');
            if (data.Length > 0)
            {
                notes.Text += input;
                custno.Text = data[1];
                Int16 selindx = Convert.ToInt16(data[2]);
                if (selindx == -1)
                {
                    AccountType.SelectedIndex = 0;
                }
                else
                {
                    AccountType.SelectedIndex = selindx - 1;
                }
                AccountBalance.Text = data[3];
                OpenDate.Text       = data[4];
                Interest.Text       = data[6];
                if (data[7] == "1\r\n")
                {
                    status.Text = "Active";
                }
                else
                {
                    status.Text = "Suspended";
                }
            }
            info.Text = "Your Bank Account selection for A/C " + AccountNumber.Text + " has been loaded successfully...";
        }
示例#8
0
 // Called on CLOSEDOWN
 public static void SaveBankAccountListDateToText(string listdata)
 {
     if (listdata.Length > 0)
     {
         string fi = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankAccountListData.txt";
         if (File.Exists(fi))
         {
             File.Delete(fi);          // you gotta delete them first, else it appends the data constantly
         }
         File.AppendAllText(fi, listdata);
     }
 }
示例#9
0
        public static void ReadTransactionsFromTextfile( )
        {
            string fi = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankTransData.txt";

            if (File.Exists(fi))
            {
                string   input  = File.ReadAllText(fi);                     // you gotta delete them first, else it appends the data constantly
                string   datain = fi;
                string[] item   = datain.Split(',');
                int      i      = 0;
                while (true)
                {
                    try
                    {
                        DateTime d    = Convert.ToDateTime(item[i]);       // Transaction Date
                        Int16    b    = Convert.ToInt16(item[i + 1]);      // Account Type
                        Int32    c    = Convert.ToInt32(item[i + 2]);      // Cust Account #
                        Int32    f    = Convert.ToInt32(item[i + 3]);      // Bank Account #
                        decimal  e    = Convert.ToDecimal(item[i + 4]);    // Transaction Amount
                        string   s    = item[i + 5];                       // Notes
                        string   temp = item[i + 6];
                        char[]   ch   = { '\t' };
                        string[] str  = temp.Split(ch);

                        Int16 a = Convert.ToInt16(str[0]);
                        //						a = Convert . ToInt16 ( actype );
                        //						format of data proecessed is :-

                        /*												   d,    // Transaction Date
                         *                         b,           // Account Type
                         *                         c,          // Cust Account #
                         *                         f,           // Bank Account #
                         *                         e,          // Transaction Amount
                         *                         s,                                        // Notes
                         *                         a );           // Status
                         *
                         * //						allBankTransactions . AddLast ( newtransrecord );
                         */
                        i += 7;
                        if (i + 1 >= item.Count( ))
                        {
                            break;
                        }
                    }
                    catch
                    { throw new Exception("Failed to handle data in ReadBankTransactions Function, line 163 in Serialize.cs"); }
                }
            }
        }
示例#10
0
 public static void SaveBankDictionaryToDisk( )
 {
     try
     {
         string          FileName  = BankAccount.ReadBankFilePath( ) + "BankDictionary.dict";
         FileStream      fs        = new FileStream(FileName, FileMode.Create);
         BinaryFormatter formatter = new BinaryFormatter( );
         formatter.Serialize(fs, BankAccount.BankDict);
         fs.Close( );                  // clean up
     }
     catch
     {
         throw new Exception("Failed to handle file in SaveDictionaryToDisk Function, line 60 in Serialize.cs");
     }
 }
示例#11
0
        //*******************************************************************************************************************************************
        // Read a Customer Object from Disk
        // & return a Customer Object containing that data
        public static StringBuilder ReadBankFromDiskAsStringBuilder(string FileNumber)
        //*******************************************************************************************************************************************
        {
            // Open the file containing the txt data that you want to deserialize.
            string FileName = BankAccount.ReadBankFilePath( ) + "Textfiles\\bankobject" + FileNumber + ".txt";

            try
            {
                StringBuilder StringData = new StringBuilder( );
                StringData.Append(File.ReadAllText(FileName));
                return(StringData);
            }
            catch
            { throw new Exception("Failed to Read data from file in ReadBankFromDisk Function, line 224 in Serialize.cs"); }
        }
示例#12
0
        public static bool ReadBankDictionaryFromDisk()
        {
            string FileName = BankAccount.ReadBankFilePath( ) + "BankDictionary.dict";

            if (!File.Exists(FileName))
            {
                return(false);
            }
            // Get a Bank Dictionary object for our data
            BinaryFormatter formatter = new BinaryFormatter( );
            FileStream      fs        = new FileStream(FileName, FileMode.Open);

            BankAccount.BankDict = (Dictionary <Int32, BankAccount>)formatter.Deserialize(fs);
            fs.Close( );
            return(true);
        }
 //**********************************************************************************************************************************************
 public static void SaveHashCustBalTable( )
 //**********************************************************************************************************************************************
 {
     try
     {
         FileStream      fs        = new FileStream(HashFileTableName, FileMode.Create);
         BinaryFormatter formatter = new BinaryFormatter( );
         formatter.Serialize(fs, CustNoBalHashTable);
         fs.Close( );                  // clean up
         string[] txt = null;
         foreach (var v in HashFileTableName)
         {
             txt.Append(v.ToString( ) + ",\t");
         }
         string dir = BankAccount.ReadBankFilePath( ) + "BankTransDataText.txt";
         File.AppendAllLines(dir, txt);
     }
     catch { }
 }
示例#14
0
        public static int RebuildBankListFromText( )
        {
            int    count = 0;
            string fi    = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankAccountListData.txt";

            if (File.Exists(fi))
            {
                string   input  = File.ReadAllText(fi);       // you gotta delete them first, else it appends the data constantly
                char[]   ch1    = { '\r' };
                char[]   ch2    = { ',' };
                string[] record = input.Split(ch1);
                for (int i = 0; i < record.Length; i++)
                {
                    string   str   = record[i];
                    string[] Item2 = str.Split(ch2);
                    if (record.Length < 6)
                    {
                        break;
                    }
                    for (int x = 0; x < record.Length; x++)
                    {
                        // get a sring from string[] array Item1[]
                        BankAccount B = new BankAccount( );
                        if (B != null)
                        {
                            B.AccountType       = Convert.ToInt16(Item2[x]);
                            B.CustAccountNumber = Convert.ToInt32(Item2[x + 1]);
                            B.Balance           = Convert.ToInt32(Item2[x + 2]);
                            B.DateClosed        = Convert.ToDateTime(Item2[x + 3]);
                            B.InterestRate      = Convert.ToDecimal(Item2[x + 5]);
                            B.Status            = Convert.ToInt16(Item2[x + 6]);
                            B.Status            = Convert.ToInt16(Item2[x + 6]);
                            BankAccount.BankAccountsLinkedList.AddLast(B);     // Add this one to our linked list of customers.
                            count++;
                            break;
                        }
                    }
                    // save linked list to disk in text format
                    Lists.SaveAllBankAccountListData( );
                }
            }
            return(count);
        }
示例#15
0
        /*		//*******************************************************************************************************************************************
         * public static StringBuilder ReturnCustDataAsStringbuilder ( string FileName )
         * //*******************************************************************************************************************************************
         * {
         *  // Reads a file from disk and returns its data in a StringBuilder object
         *  StringBuilder StringData = new StringBuilder ( );
         *  if ( !File . Exists ( FileName ) ) // file  not found !!
         *      return StringData;  // return an empty ~StringBuilder object
         *
         *  // Open the file containing the data that you want to deserialize.
         *  FileStream fs = new FileStream ( FileName, FileMode . Open );
         *  try
         *  {
         *      BinaryFormatter formatter = new BinaryFormatter ( );
         *      // Deserialize the object file and
         *      // assign the data to a <StringBuilder> object
         *      var v = formatter . Deserialize ( fs ) . ToString ( );
         *      StringData . Append ( v );
         *      fs . Close ( );
         *  }
         *  catch ( SerializationException e )
         *  {
         *      fs . Close ( );
         *      StringData . Append ( "Error - Exception encountered - Unable to read file " + FileName );
         *  }
         *  return StringData;
         * }
         *
         */
        //*******************************************************************************************************************************************
        public static void WriteBankTransactionsToDisk( )
        //*******************************************************************************************************************************************
        {
            string record = "";

            // Sanity check = maybe we have not done any work in the app yet ?
            // so we do not have LinkedList, Transactions etc avaialbel yet.
            if (BankTransaction.allBankTransactions != null)
            {
                foreach (var bt in BankTransaction.allBankTransactions)
                {                   // this gives us an array in bt[];
                    // parse bt out to fields & build   the data string I want to use - my design

                    if (bt != null)
                    {
                        //string strout = string.Format("{0:2C}", BT.Transamount);
                        string CurrencyAmount = Utils.GetCurrencyString(bt.Transamount.ToString( ));
                        record += bt.TransDate + "," + bt.AccountType + "," + bt.CustAccountNumber + "," + bt.BankAccountNumber
                                  + "," + bt.Transamount.ToString( ) + "," + bt.Notes + "," + bt.Status + ",\t";
                    }
                }
                try
                {
                    string          fi        = BankAccount.ReadBankFilePath( ) + "BankTransData.bnk";
                    BinaryFormatter formatter = new BinaryFormatter( );
                    FileStream      fs        = new FileStream(fi, FileMode.Create);
                    formatter.Serialize(fs, record);
                    fs.Close( );
                    // This writes the std string [record] out in text format in \\textfiles folder
                    fi = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankTransData.txt";
                    if (File.Exists(fi))
                    {
                        File.Delete(fi);                               // you gotta delete them first, else it appends the data constantly
                    }
                    File.AppendAllText(fi, record);
                }
                catch
                {
                    throw new Exception("Failed to handle file in WriteBankTransactions Function, line 138 in Serialize.cs");
                }
            }
        }
示例#16
0
        //************************************************************************************************************************************************
        public static void ReWriteBankLinkedList( )
        //************************************************************************************************************************************************
        {
            // iterate thru bankaccount objects and add threm to our linkedList
            string dir = BankAccount.ReadBankFilePath( );

            string[] files = System.IO.Directory.GetFiles(dir, "*.bnk");
            // iterate thru all the files on disk, startinmg at 1
            // Iterate trhu them and handle as required
            int count = 0;

            foreach (var fi in files)
            {
                bool result = fi.Contains("BankObject");
                if (!result)
                {
                    continue;
                }
                {
                    using
                        BankAccount B = (BankAccount)SerializeData.ReadBankAccountFromDisk(fi);

                    // As we have red it in, we need to delete it so we do not
                    // duplicate it when saving all files at end of a user sessoin.
                    if (B != null)
                    {
                        BankAccount.BankAccountsLinkedList.AddLast(B);     // Add this one to our linked list of customers.
                        BankTransaction newbankaccount = new BankTransaction(B.DateOpened, B.AccountType, B.CustAccountNumber,
                                                                             B.BankAccountNumber, B.Balance, "Customer account updated successfuly", B.Status);
                        BankTransaction.allBankTransactions.AddLast(newbankaccount);
                    }
                    count++;
                }
            }
            // save linked list to disk in text format
            Lists.SaveAllBankAccountListData( );
        }
示例#17
0
        //======================================================================
        public ReadBankTextFile()
        //======================================================================
        {
            InitializeComponent();
            string[] fullpath = null;
            char[]   c        = { '\\' };
            string   path     = BankAccount.ReadBankFilePath();

            path += "Textfiles\\";
            string[] files = Directory.GetFiles(path);
            if (files.Length > 0)
            {
                foreach (string s in files)
                {
                    if (!s.Contains("BankObject"))
                    {
                        continue;
                    }
                    fullpath = s.Split(c);
                    string fn   = fullpath[7];
                    string numb = fn.Substring(10);
                    fn = numb.Substring(0, 7);
                    AccountNumber.Items.Add(fn);
                }
                try
                {
                    AccountType.SelectedIndex   = 0;
                    AccountNumber.SelectedIndex = 0;
                    currentaccount = AccountNumber.SelectedItem.ToString();
                    object    sender = null;
                    EventArgs e      = null;
                    FindFile_Click_1(sender, e);
                    info.Text = "Select the Bank Account to View/Edit  from dropdown list above...";
                }
                catch { return; }
            }
        }
示例#18
0
        //=========================================================================//
        //EXTERNAL
        public Int16 LoadArraysFromDisk(out int Bcount, out int Ccount)
        //=========================================================================//
        {
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // We iterate through all Bank .BNK files cos we can also read the relevant
            // Customer #  from it, and then load that to the Customer array - Clever eh ?
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            Int16 count = 0;

            Bcount = 0;
            Ccount = 0;
            Int32[] custno     = new int[100];
            int     custcount  = 0;
            bool    duplicated = false;
            // start with BankAccounts
            string dir  = BankAccount.ReadBankFilePath();
            string dir2 = Customer.GetCustFilePath();

            string[] bankfiles = System.IO.Directory.GetFiles(dir, "Bankobject*.bnk");
            // initilaize our check array
            for (int i = 0; i < 100; i++)
            {
                custno[i] = 0;
            }
            // Iterate trhu them and handle as required
            foreach (var fi in bankfiles)
            {
                bool result = fi.Contains("BankObject");
                if (result)
                {
                    // Got a bank account object
                    BankAccount B = (BankAccount)SerializeData.ReadBankAccountFromDisk(fi);
                    if (B != null)
                    {
                        DataArray.ArrayAddBank(B);     // Add to bank ArrayList
                        if (BankAccount.BankDict != null)
                        {
                            if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                            {
                                BankAccount.BankDict.Add(B.BankAccountNumber, B);
                            }
                        }
                        Bcount++;
                        BankAccount.BankAccountsLinkedList.AddLast(B);
                        Customer C = (Customer)SerializeData.ReadCustomerDiskObject(dir2 + "Custobj" + B.CustAccountNumber + ".cust");
                        if (C != null)
                        {
                            // add to our test array
                            // check to see if it has been added before ?
                            for (int i = 0; i < custcount; i++)
                            {
                                if (custno[i] == C.CustomerNumber)
                                {
                                    duplicated = true;
                                    break;
                                }
                            }
                            custno[custcount++] = C.CustomerNumber;
                            if (!duplicated)
                            {
                                DataArray.ArrayAddCust(C);     // The one and only Customer ArrayList addition in this Fn()
                                if (Customer.CustDict != null)
                                {
                                    if (!Customer.CustDict.ContainsKey(C.CustomerNumber))
                                    {
                                        Customer.CustDict.Add(C.CustomerNumber, C);
                                    }
                                }

                                Ccount++;
                                Customer.CustomersLinkedList.AddLast(C);
                            }

                            /*							// Handle multiple a/c's held by this customer
                             *                                                                                  if ( C . accountnums [ 1 ] != 0 )
                             *                                                                                  {
                             *                                                                                          BankAccount Bk = ( BankAccount ) SerializeData . ReadBankAccountFromDisk ( dir + "Bankobject" + C . accountnums [ 1 ] + ".bnk" );
                             *                                                                                          DataArray . ArrayAddBank ( Bk );// Add to bank ArrayList
                             *                                                                                          Bcount++;
                             *                                                                                          Bk . Dispose ( );
                             *                                                                                  }
                             *                                                                                  if ( C . accountnums [ 2 ] != 0 )
                             *                                                                                  {
                             *                                                                                          BankAccount Bk = ( BankAccount ) SerializeData . ReadBankAccountFromDisk ( dir + "Bankobject" + C . accountnums [ 2 ] + ".bnk" );
                             *                                                                                          DataArray . ArrayAddBank ( Bk );// Add to bank ArrayList
                             *                                                                                          Bcount++;
                             *                                                                                          Bk . Dispose ( );
                             *                                                                                  }
                             *                                                                                  if ( C . accountnums [ 3 ] != 0 )
                             *                                                                                  {
                             *                                                                                          BankAccount Bk = ( BankAccount ) SerializeData . ReadBankAccountFromDisk ( dir + "Bankobject" + C . accountnums [ 3 ] + ".bnk" );
                             *                                                                                          DataArray . ArrayAddBank ( Bk );// Add to bank ArrayList
                             *                                                                                          Bcount++;
                             *                                                                                          Bk . Dispose ( );
                             *                                                                                  }
                             */
//                            if (C != null)
//                             C.Dispose();
                        }
                        //                  if (B != null)
                        //                   B.Dispose();
                    }
                    count++;
                }
            }
            // save our Customer LinkedList to disk as binary and txt files
            Lists.SaveAllCustomerListData(Customer.CustomerFilePath + "CustSortedListData.cust");
            // sort the arrays in Ascending v0 - 9
            SortArray.SortBankArray(0);
            return(count);
        }
示例#19
0
        //======================================================================
        private void rewrite_Click(object sender, EventArgs e)
        //======================================================================
        {
            string output = "";

            if (notes.Text == "" || AccountNumber.Text == "" || AccountBalance.Text == "" || OpenDate.Text == "" || Interest.Text == "" || custno.Text == "")
            {
                MessageBox.Show("One or more data items are Empty - All fields must be completed before saving it ..." +
                                "\nRecommeded action is to use the DropDown list to reselect a valid Bank Account", "Data Validation ERROR");
                info.Text = "One or more data items are Empty - All fields must be completed before saving it ..."; return;
            }
            string stat;

            if (status.Text == "Active")
            {
                stat = "1";
            }
            else
            {
                stat = "0";
            }
            int type = AccountType.SelectedIndex + 1;

            // format is "Bank A/c #  + "," + Customer A/c # + "," + A/c Type + "," + Balance + "," + Date Opened (short) + "," + Date Closed (short) + "," + Interest + "," + Status (0/1)+ "\r\n"
            output  = AccountNumber.Text + "," + custno.Text + "," + type.ToString() + "," + AccountBalance.Text + ",";
            output += Convert.ToDateTime(OpenDate.Text).ToShortDateString() + "," + Convert.ToDateTime("01/01/0001").ToShortDateString() + "," + Interest.Text;
            output += "," + stat + "\r\n";
            string path = BankAccount.ReadBankFilePath();

            path += "Textfiles\\BankObject" + AccountNumber.Text + ".txt";
            if (File.Exists(path))
            {
                File.Delete(path);      // you gotta delete them first, else it appends the data constantly
            }
            File.AppendAllText(path, output);

            // update the bank object
            path  = BankAccount.ReadBankFilePath();
            path += "Bankobject" + AccountNumber.Text + ".bnk";

            // read the bank a/c in fresh from disk so it is clean
            BankAccount Bank = SerializeData.ReadBankAccountFromDisk(path);

            if (Bank == null)
            {
                MessageBox.Show("Bank Account Object file cannot be loaded (or saved)!", "Bank Object Error"); return;
            }
            Int32 bankno = Bank.BankAccountNumber;

            // update the Bank object
            Bank.AccountType = Convert.ToInt16(AccountType.SelectedIndex);
            Bank.AccountType++;// cos th reindex starts at ZERO !!
            Bank.Balance      = Convert.ToDecimal(AccountBalance.Text);
            Bank.InterestRate = Convert.ToDecimal(Interest.Text);
            string banknostring = Bank.BankAccountNumber.ToString();

            //Update the version in Bank Array
            int index = DataArray.ArrayFindBank(Bank);

            DataArray.BankNo[index] = Bank;

            // Update the version in our Bank LinkedList
            foreach (var B in BankAccount.BankAccountsLinkedList)
            {
                if (B.BankAccountNumber == bankno)
                {   // got it, rpelace with our new one
                    BankAccount.BankAccountsLinkedList.Remove(B);
                    BankAccount.BankAccountsLinkedList.AddLast(Bank);
                    break;
                }
            }
            // This saves the bank LinkedList to both an object file and a Text file
            Lists.SaveAllBankAccountListData();
            // write theBank object to disk
            SerializeData.WriteBankAccountToDiskAndText(Bank, path);
            // Add a bank Transaction
            BankTransaction newbankaccount = new BankTransaction(Bank.DateOpened, Bank.AccountType, Bank.CustAccountNumber,
                                                                 Bank.BankAccountNumber, Bank.Balance, "Bank details edited from Textfile input", Bank.Status);

            BankTransaction.allBankTransactions.AddLast(newbankaccount);
            // that's it ***ALL***all Bank Data structures have been updated
            info.Text = "Bank Account data has been fully updated throughout System";
        }
示例#20
0
        public static int RebuildBankListsFromText( )
        {
            int    count = 0;
            string fi    = BankAccount.ReadBankFilePath( ) + "Textfiles\\BankAccountListData.txt";

            if (File.Exists(fi))
            {
                string input = File.ReadAllText(fi);          // you gotta delete them first, else it appends the data constantly
                char[] ch1   = { '\r' };
                char[] ch2   = { ',' };
                //				char [ ] ch3 = { '~' };
                string[] record = input.Split(ch1);
                string[] BAccts;

                DataArray.ArrayClearBank( );
                BankAccount.BankAccountsLinkedList.Clear( );
                // record now has an array of strings that were split on \t
                // this means we should have at least one, possibly multiple  B.Accs  in the last element
                // iterate through and split these out of record into string[] Item2
                for (int i = 0; i < record.Length; i++)
                {
                    string str = record[i];
                    //This should give us x strings,, the first one can be ignored
                    //, the rest will be bank account numbers cos the format is  "xxxxxx,xxxx,yyyy,~4455554544~65645
                    // and we are after the data immediately past the first ~
                    string[] Item2 = str.Split(ch2);
                    // check.  The plit always gives us ~ONE element, even though it is empty
                    if (Item2.Length == 1 && Item2[0].Length == 0)
                    {
                        break;  // Were all done here
                    }
                    BAccts = Item2[7].Split('~');
                    // go get em (one or more B Accts in a BAccts[] string[]
                    if (BAccts.Length > 1)
                    {   // got one or more - do something with them ?
                    }
                    //Baacts MAY contain a leading EMPTY string, so beware
                    // by here , we have an array of strings of Bank accounts owned by this customer. ?
                    for (int x = 0; x < record.Length; x++)
                    {
                        // get a string from string[] array Item1[]
                        BankAccount B = new BankAccount( );
                        if (B != null)
                        {
                            B.AccountType       = Convert.ToInt16(Item2[x]);
                            B.CustAccountNumber = Convert.ToInt32(Item2[x + 1]);
                            B.BankAccountNumber = Convert.ToInt32(Item2[x + 2]);
                            B.Balance           = Convert.ToDecimal(Item2[x + 3]);
                            B.DateClosed        = Convert.ToDateTime(Item2[x + 4]);
                            B.InterestRate      = Convert.ToDecimal(Item2[x + 6]);
                            // We dont seem to save this ?????
                            B.Status = 1;
                            BankAccount.BankAccountsLinkedList.AddLast(B);     // Add this one to our linked list of customers.
                            DataArray.ArrayAddBank(B);
                            if (BankAccount.BankDict != null)
                            {
                                if (!BankAccount.BankDict.ContainsKey(B.BankAccountNumber))
                                {
                                    BankAccount.BankDict.Add(B.BankAccountNumber, B);
                                }
                            }
                            SerializeData.WriteBankAccountToDiskAndText(B, fi);
                            count++;
                            break;
                        }
                    }
                    // save linked list to disk in text format
                    Lists.SaveAllBankAccountListData( );
                }
            }
            return(count);
        }