コード例 #1
0
        private void btnAddContribution_Click(object sender, EventArgs e)
        {
            Contribution newContribution = new Contribution();

            //if (newContribution.ContributionNo = "")
            //{
            //    MessageBox.Show("Please Enter a Contribution #");

            //}
            //else if (newContribution.ContributionNo == Convert.ToInt32(txtContributionNo.Text))
            //{

            //    MessageBox.Show("That Contribution Already Exists!");
            //}
            //else
            //{
            newContribution.ContributionNo = Convert.ToInt32(txtContributionNo);
            newContribution.MemberID       = Convert.ToInt32(txtMemberID.Text);
            //member[i].LastName = txtLastName.Text;
            //member[i].FirstName = txtFirstName.Text;
            newContribution.ContributionDate = dtpContributionDate.Value;
            newContribution.Amount           = Convert.ToDouble(txtAmount.Text);
            newContribution.Method           = txtMethod.Text;
            if (txtCheckNo.Text != "")
            {
                newContribution.CheckNo = Convert.ToInt32(txtCheckNo.Text);
            }
            newContribution.DesignatedFund = cmbDesignatedFund.Text;


            MessageBox.Show("Contribution # " + newContribution.ContributionNo + " Successfully Added!");

            SaveToFile();
            //}
        }
コード例 #2
0
        private void LoadContributionsFromFile()
        {
            //Create FileStream  object (myFile)w / FileMode OPENORCREATE, w / FileAccess READ
            FileStream inFile = new FileStream("contributions.csv", FileMode.OpenOrCreate, FileAccess.Read);

            //Create StreamReader object(reader)
            StreamReader reader = new StreamReader(inFile);

            //Declare a string array(e.g.fieldValues) to hold all of the values of a single record
            string[] fieldValues;

            //Header - read the header record and ignore it
            string inputStr = reader.ReadLine();

            //Lead read(i.e.read first record) – if your file has a header row then you need 2 initial reads
            inputStr = reader.ReadLine();

            //Loop while record not null
            while (inputStr != null)
            {
                //split the record using delimiter into the fieldValuesarray
                fieldValues = inputStr.Split(',');

                //create an empty domain object
                Contribution c = new Contribution();

                //update each field of the domain object
                c.ContributionNo   = Convert.ToInt32(fieldValues[0]);
                c.MemberID         = Convert.ToInt32(fieldValues[1]);
                c.ContributionDate = Convert.ToDateTime(fieldValues[2]);
                c.Amount           = Convert.ToDouble(fieldValues[3]);
                c.Method           = fieldValues[4];
                if (fieldValues[5] != "")
                {
                    c.CheckNo = Convert.ToInt32(fieldValues[5]);
                }
                c.DesignatedFund = fieldValues[6];


                //add this domain object to the list of domain objects
                contributions.Add(c);

                //read next record
                inputStr = reader.ReadLine();
            }

            //End loop

            //Close reader
            reader.Close();

            //Close myFile
            inFile.Close();
        }
コード例 #3
0
        private void loadContributionsFromFile()
        {
            //Create FileStream Object (Contributions)
            FileStream inFile = new FileStream("contributions.csv", FileMode.OpenOrCreate, FileAccess.ReadWrite);


            //Create StreamReader object(reader)
            StreamReader reader = new StreamReader(inFile);

            //Declare a string array (fieldValues) to hold all of the values of a single record
            string[] fieldValues;

            //Header - read the header record and ignore it
            string inputStr = reader.ReadLine();

            inputStr = reader.ReadLine();

            //Loop while record not null
            while (inputStr != null)
            {
                //split the record using delimiter into the fieldValuesArray
                fieldValues = inputStr.Split(',');

                //create an empty domain object
                Contribution aContribution = new Contribution();

                //update each field of the domain object
                aContribution.ContributionNo   = Convert.ToInt32(fieldValues[0]);
                aContribution.MemberID         = Convert.ToInt32(fieldValues[1]);
                aContribution.ContributionDate = Convert.ToDateTime(fieldValues[2]);
                aContribution.Amount           = Convert.ToDouble(fieldValues[3]);
                aContribution.Method           = (fieldValues[4]);
                if (Convert.ToString(fieldValues[5]) != "")
                {
                    aContribution.CheckNo = Convert.ToInt32(fieldValues[5]);
                }
                aContribution.DesignatedFund = (fieldValues[6]);

                //add this domain object ot the list of domain objects
                contributions.Add(aContribution);

                //read next record
                inputStr = reader.ReadLine();
            }
        }