Ejemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            // get the data from ui and check if all data are valid
            bool validData = getDataFromUI();

            if (validData)
            {
                tipsLabel.Text      = notes;
                tipsLabel.ForeColor = Color.Black;
                // get the time when save was pressed
                saveTime = DateTime.Now.ToString("HH:mm:ss");
                //
                RebateData data  = new RebateData(first, middle, last, address1, address2, city, state, zipcode, gender, phone, email, proof, dateRecieve, firstCharTime, saveTime, backspaceCount);
                bool       exist = checkExist(data);
                // if not exist, then add it to the list
                if (!exist)
                {
                    datas.Add(data);        // add to data list
                    addToNameList(data);    // add to list view
                    DataIO.saveData(datas); // save the data to file
                    tipsLabel.ForeColor = Color.Black;
                    cleanUILabel();
                    tipsLabel.Text = "Record has been saved";
                }
                else
                {   // if already exist, then tell the user it is already exist through the tips label
                    tipsLabel.ForeColor = Color.Red;
                    tipsLabel.Text      = "This record is already exist.";
                }
            }
            else
            {
                tipsLabel.ForeColor = Color.Red;
            }
        }
Ejemplo n.º 2
0
        private void addToNameList(RebateData s)
        {
            // design the listviewItem
            ListViewItem item = new ListViewItem(s.getFirstName()); // first name

            item.SubItems.Add(s.getLastName());                     // add last name into column
            item.SubItems.Add(s.getPhoneNumber());                  // add phone number into column
            nameList.Items.Add(item);                               // add the item into listview
        }
Ejemplo n.º 3
0
 private bool checkExist(RebateData data)
 {
     foreach (RebateData d in datas)
     {// check if this new record is already exist in the collection
         if (d.Equals(data))
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
 private void ModifyButton_Click(object sender, EventArgs e)
 {
     // check if a record is been selected
     if (selectedIndex != -1)
     {                                       // find the selected record
         RebateData rb    = datas[selectedIndex];
         bool       valid = getDataFromUI(); // get the data and check if is valid
         if (!valid)
         {                                   // if is not valid data, then cancel the modify action
             tipsLabel.ForeColor = Color.Red;
             tipsLabel.Text      = tipsLabel.Text + $" Modify failed";
         }
         else
         {   // set all fields except the last 3 field and save the data
             RebateData d = new RebateData(first, last, phone);
             if (checkExist(d))
             {
                 tipsLabel.ForeColor = Color.Red;
                 tipsLabel.Text      = "Modify failed, Record already exist";
             }
             else
             {
                 rb.setFirstName(first);
                 rb.setMiddleName(middle);
                 rb.setLastName(last);
                 rb.setAddress1(address1);
                 rb.setAddress2(address2);
                 rb.setCity(city);
                 rb.setState(state);
                 rb.setZipCode(zipcode);
                 rb.setGender(gender);
                 rb.setPhoneNumber(phone);
                 rb.setEmailAddress(email);
                 rb.setProofPurchased(proof);
                 ListViewItem item = nameList.Items[selectedIndex];
                 item.SubItems[0].Text = first;
                 item.SubItems[1].Text = last;
                 item.SubItems[2].Text = phone;
                 DataIO.saveData(datas);
                 tipsLabel.ForeColor = Color.Black;
                 tipsLabel.Text      = "Modify Completed";
             }
         }
     }
     else
     {
         tipsLabel.ForeColor = Color.Red;
         tipsLabel.Text      = "Please select an item first";
     }
 }
Ejemplo n.º 5
0
        public List <RebateData> LoadData()
        {
            List <RebateData> datas = new List <RebateData>();

            try
            {
                System.IO.StreamReader file = new System.IO.StreamReader(filename);
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    string[]   obj            = line.Split(',');
                    string     first          = obj[0];
                    char       middle         = obj[1][0];
                    string     last           = obj[2];
                    string     address1       = obj[3];
                    string     address2       = obj[4];
                    string     city           = obj[5];
                    string     state          = obj[6];
                    string     zipcode        = obj[7];
                    char       gender         = obj[8][0];
                    string     phone          = obj[9];
                    string     email          = obj[10];
                    bool       proof          = obj[11].Equals("True");
                    DateTime   dateRecieve    = DateTime.Parse(obj[12]);
                    string     firstCharTime  = obj[13];
                    string     saveTime       = obj[14];
                    int        backspaceCount = Int32.Parse(obj[15]);
                    RebateData data           = new RebateData(first, middle, last, address1, address2,
                                                               city, state, zipcode, gender, phone, email, proof, dateRecieve,
                                                               firstCharTime, saveTime, backspaceCount);
                    datas.Add(data);
                }
                file.Close();
                return(datas);
            }
            catch (System.IO.FileNotFoundException ex)
            {
                // Write error.
                Console.WriteLine(ex);
                return(datas);
            }
        }
Ejemplo n.º 6
0
 private void setLabels(RebateData d)
 {
     // set all UI labels to the correct data base on d
     firstNameText.Text = d.getFirstName();
     if (d.getMiddleName().Equals(' '))
     {
         middleNameText.Text = "";
     }
     else
     {
         middleNameText.Text = $"{d.getMiddleName()}";
     }
     lastNameText.Text     = d.getLastName();
     addressText1.Text     = d.getAddressLine1();
     addressText2.Text     = d.getAddressLine2();
     cityText.Text         = d.getCity();
     stateText.Text        = d.getState();
     zipCodeText.Text      = d.getZipCode();
     genderText.Text       = $"{d.getGender()}";;
     phoneNumber.Text      = d.getPhoneNumber();
     emailAddressText.Text = d.getEmailAddress();
     proofChecker.Checked  = d.getProofPurchased();
     dateTimePicker1.Value = d.getDateRecieve();
 }