Beispiel #1
0
        private void saveBtn_Click(object sender, EventArgs e)
        {
            girl curr = new girl();

            curr.name  = nameBox.Text;
            curr.isBig = false;
            curr.prefs = choicesBox.Lines.ToList();
            parentForm.littles[nameBox.SelectedIndex] = curr;
        }
        private void addLittles_Click(object sender, EventArgs e)
        {
            girl g = new girl();

            g.isBig      = false;
            g.name       = nameBox.Text;
            g.prefs      = prefBox.Lines.ToList();
            g.numMatches = 1;
            parentForm.littles.Add(g);
            resetForm();
        }
Beispiel #3
0
 //deletes a girl from bigs and littles
 public void del(girl g)
 {
     if (g.isBig)
     {
         delBig(g.name, ref littles, ref bigs);
     }
     else
     {
         delLittle(g.name, ref littles, ref bigs);
     }
 }
Beispiel #4
0
 //if a big has > 1 little slots this function will decrement the # of slots
 //otherwise functions as delBig
 public void decreaseBig(int index, ref List <girl> littles, ref List <girl> bigs)
 {
     if (bigs[index].numMatches > 1)
     {
         girl curr = bigs[index];
         curr.numMatches -= 1;
         bigs[index]      = curr;
     }
     else
     {
         delBig(bigs[index].name, ref littles, ref bigs);
     }
 }
Beispiel #5
0
 //function to copy a list of girls from one list to another to avoid passing by reference
 public void copyListsG(List <girl> from, List <girl> to)
 {
     to.Clear();
     foreach (girl o in from)
     {
         girl newG = new girl();
         newG.name       = o.name;
         newG.isBig      = o.isBig;
         newG.numMatches = o.numMatches;
         newG.prefs      = new List <string>();
         copyListsS(o.prefs, newG.prefs);
         to.Add(newG);
     }
 }
Beispiel #6
0
        //opens a file and scans for big/little data
        //overwrites current data
        private void openFile()
        {
            //make sure user knows about overwrite
            bool         open = false;
            DialogResult result;

            if (bigs.Count > 0 || littles.Count > 0)
            {
                result = MessageBox.Show("Importing a file will erase all current data.\nAre you sure you want to import?", "Open?", MessageBoxButtons.OKCancel);
            }
            else
            {
                result = DialogResult.OK;
            }
            if (result == DialogResult.OK)
            {
                open = true;
            }
            if (open)
            {
                //open file and prepare to read
                OpenFileDialog file = new OpenFileDialog();
                file.Filter = "csv files (*.csv)|*.csv|All Files (*.*)|*.*";
                if (file.ShowDialog() == DialogResult.OK)
                {
                    bigs    = new List <girl>();
                    littles = new List <girl>();
                    StreamReader SR = new StreamReader(file.FileName);
                    //read header line;
                    string headers = SR.ReadLine();
                    //try catch to prevent crash on failure to read
                    try
                    {
                        //read each line
                        while (!SR.EndOfStream)
                        {
                            var line = SR.ReadLine();
                            //split line
                            var values = line.Split(',');
                            //make sure there are at least values so we dont go out of bounds
                            if (values.Length >= 4)
                            {
                                //pull values
                                girl curr = new girl();
                                curr.prefs      = new List <string>();
                                curr.name       = values[2];
                                curr.numMatches = 1;
                                //for the remainder of values
                                //last col is email so skips
                                for (int i = 4; i < values.Length - 1; i++)
                                {
                                    curr.prefs.Add(values[i].ToLower());
                                }
                                if (values[3] == "Big")
                                {
                                    curr.isBig = true;
                                    bigs.Add(curr);
                                }
                                else if (values[3] == "Little")
                                {
                                    curr.isBig = false;
                                    littles.Add(curr);
                                }
                            }
                        }
                    } catch {
                        //show error box
                        MessageBox.Show("There was an error loading your data!\nPlease make sure your CSV file is formatted correctly");
                    }
                    SR.Close();
                }
                //update form to show lists
                updateLists();
            }
        }