Exemple #1
0
        private void DeleteComplaint()
        {
            DialogResult dr = MessageBox.Show("Do you wish to delete this record?", "Suggestion", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk);

            if (dr == DialogResult.Yes)
            {
                storageList.Remove(storageList[selectedindex]);

                dgvTestComplaints.DataSource = null;
                dgvTestComplaints.DataSource = storageList;

                bndSourceCust.MovePrevious();
                bndSourceCust.ResetItem(selectedindex);

                if (selectedindex > 0)
                {
                    bndNavCust.Refresh();
                    selectedindex--;
                    Complaint c = new Complaint();
                    c = storageList[selectedindex];
                    txtCompNo.Text    = c.ComplaintNo.ToString();
                    txtCustID.Text    = c.CustomerID.ToString();
                    cmbCompType.Text  = c.ComplaintType;
                    txtCompDesc.Text  = c.ComplaintDesc;
                    dateRec.Value     = c.DateRecorded;
                    dateOccured.Value = c.DateOccured;
                    cmbCustExp.Text   = c.CustExpectation;
                    txtStatus.Text    = c.Status;
                    if (c.ResolutionDate > dateResolution.MinDate)
                    {
                        dateResolution.Value = c.ResolutionDate;
                    }
                    else
                    {
                        dateResolution.Value = DateTime.Today;
                    }
                    txtResolutionDesc.Text = c.ResolutionDesc;
                }
                else
                {
                    Complaint c = new Complaint();
                    c = storageList[selectedindex];
                    txtCompNo.Text    = c.ComplaintNo.ToString();
                    txtCustID.Text    = c.CustomerID.ToString();
                    cmbCompType.Text  = c.ComplaintType;
                    txtCompDesc.Text  = c.ComplaintDesc;
                    dateRec.Value     = c.DateRecorded;
                    dateOccured.Value = c.DateOccured;
                    cmbCustExp.Text   = c.CustExpectation;
                    txtStatus.Text    = c.Status;
                    if (c.ResolutionDate > dateResolution.MinDate)
                    {
                        dateResolution.Value = c.ResolutionDate;
                    }
                    else
                    {
                        dateResolution.Value = DateTime.Today;
                    }
                    txtResolutionDesc.Text = c.ResolutionDesc;
                }
            }
        }
        private void LoadComplaintListFromFile()
        {
            string inputStr;                    //holds one record that was read in

            string[]   CompRecIN;               //string array to hold ONE player record parsed/split
            const char DELIM = ',';             //NOTE: this must be a CHAR for the SPLIT() method used later
            Complaint  aComp = new Complaint(); //create a player object


            //Clear the players list
            compList.Clear();

            //Create the FileStream object
            FileStream fs = new FileStream("Complaints.csv", FileMode.Open, FileAccess.Read);


            //Create the StreamWriter object
            StreamReader reader = new StreamReader(fs);

            //LEAD READ - i.e. 1st record
            inputStr = reader.ReadLine();

            //WHILE: Loop through the file (until an empty record)
            while (inputStr != null)
            {
                //split the record that was read (into a String array)
                CompRecIN = inputStr.Split(DELIM);

                //create a new player object (each time it loops!)
                Complaint c = new Complaint();

                //Load the player object with the string array -playerRecIN[]
                c.ComplaintNo     = Convert.ToInt32(CompRecIN[0]);
                c.CustomerID      = Convert.ToInt32(CompRecIN[1]);
                c.ComplaintType   = CompRecIN[2];
                c.ComplaintDesc   = CompRecIN[3];
                c.DateRecorded    = Convert.ToDateTime(CompRecIN[4]);
                c.DateOccured     = Convert.ToDateTime(CompRecIN[5]);
                c.CustExpectation = CompRecIN[6];
                c.Status          = CompRecIN[7];
                if (CompRecIN[8] != "")
                {
                    c.ResolutionDate = Convert.ToDateTime(CompRecIN[8]);
                }
                c.ResolutionDesc = CompRecIN[9];



                //add the new player to the list
                compList.Add(c);

                //display the new player on the form
                DisplayComplaintData();

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

            //Close the StreamReader & FileStream objects
            reader.Close();
            fs.Close();
            //Clear any labels
        }