Beispiel #1
0
        private void setSelected()
        {
            if (dgrMain.SelectedIndex != -1)
            {
                classroom.Copy(classroomShow[dgrMain.SelectedIndex]);
                softwares.Clear();
                foreach (Software s in classroomShow[dgrMain.SelectedIndex].Softver)
                {
                    softwares.Add(s);
                }
                softwareShow.Clear();
                foreach (Software ss in MainWindow.softwares)
                {
                    if (!softwares.Contains(ss))
                    {
                        softwareShow.Add(ss);
                    }
                }
            }

            else
            {
                //deep copy
                classroom.Id                    = "";
                classroom.Opis                  = "";
                classroom.BrRadnihMesta         = 0;
                classroom.PrisustvoProjektora   = false;
                classroom.PrisustvoTable        = false;
                classroom.PrisustvoPametneTable = false;
                classroom.Os                    = "Windows";
                classroom.Softver               = new List <Software>();
                classroom.Termini               = new List <Appointment>();
                softwares.Clear();
                os.SelectedValue        = "Windows";
                classroom.ImenaSoftvera = "";

                softwareShow.Clear();
                foreach (Software ss in MainWindow.softwares)
                {
                    if (!softwares.Contains(ss))
                    {
                        softwareShow.Add(ss);
                    }
                }
            }
        }
Beispiel #2
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (!addNew && dgrMain.SelectedIndex == -1)
            {
                return;
            }
            Boolean hasError = false;

            if (addNew || !currId.Equals(classroom.Id))
            {
                foreach (Classroom s in MainWindow.classrooms)
                {
                    if (classroom.Equals(s))
                    {
                        MessageBox.Show("ID allready exists. ID must be unique.");
                        hasError = true;
                        return;
                    }
                }
            }
            if (classroom.Id.Equals(""))
            {
                MessageBox.Show("ID must be set.");
                hasError = true;
                return;
            }
            if (classroom.Opis.Equals("") || classroom.BrRadnihMesta.Equals("") || classroom.PrisustvoProjektora.Equals("") || classroom.PrisustvoTable.Equals("") ||
                classroom.PrisustvoPametneTable.Equals("") || classroom.Os.Equals("") || classroom.Softver.Count == 0)
            {
                MessageBox.Show("One or more values doesn't set. All values must be set.");
                hasError = true;
                return;
            }
            foreach (Software s in classroom.Softver)
            {
                Console.WriteLine(s.Naziv);
                Console.WriteLine(classroom.Os);
                if (!s.Os.Equals(classroom.Os))
                {
                    if (!classroom.Os.Equals("Both") && !s.Os.Equals("Cross platform"))
                    {
                        softwares.Clear();
                        classroom.Softver.Clear();
                        softwareShow.Clear();
                        o.SelectedIndex = -1;
                        foreach (Software ss in MainWindow.softwares)
                        {
                            if (!softwares.Contains(ss))
                            {
                                softwareShow.Add(ss);
                            }
                        }
                        MessageBox.Show("Classroom has " + classroom.Os + " and Softver that you chose has " + s.Os + ". This two values must be the same");
                        hasError = true;
                        return;
                    }
                }
            }
            int d;

            if (int.TryParse(brRadnihMesta.Text, out d))
            {
                //valid
            }
            else
            {
                //invalid
                MessageBox.Show("Please enter a valid number for number of workers!");
                return;
            }

            if (!hasError)
            {
                if (addNew)
                {
                    Classroom c = new Classroom();
                    c.Copy(classroom);
                    String s = "";
                    foreach (Software sp in classroom.Softver)
                    {
                        s += sp.Naziv + " ";
                        Console.WriteLine("ddd " + s);
                    }
                    c.ImenaSoftvera = s;
                    Console.WriteLine(c.Termini.Count);
                    MainWindow.classrooms.Add(c);
                    addNew = false;
                }
                else if (dgrMain.SelectedIndex != -1)
                {
                    int    sIndex = dgrMain.SelectedIndex;
                    String s      = "";
                    foreach (Software sp in classroom.Softver)
                    {
                        s += sp.Naziv + " ";
                    }
                    classroom.ImenaSoftvera = s;
                    classroomShow[dgrMain.SelectedIndex].Copy(classroom);
                    Classroom currClassroom = classroomShow[dgrMain.SelectedIndex];

                    bool b = false;
                    for (int i = currClassroom.Termini.Count - 1; i > -1; i--)
                    {
                        Console.WriteLine(i);
                        foreach (Subject sub in MainWindow.subjects)
                        {
                            if (sub.Naziv.Equals(currClassroom.Termini[i].Predmet))
                            {
                                if (!currClassroom.PrisustvoProjektora && sub.PrisustvoProjektora)
                                {
                                    b = true;
                                    break;
                                }
                                if (!currClassroom.PrisustvoTable && sub.PrisustvoTable)
                                {
                                    b = true;
                                    break;
                                }
                                if (!currClassroom.PrisustvoPametneTable && sub.PrisustvoPametneTable)
                                {
                                    b = true;
                                    break;
                                }
                                if (!currClassroom.Os.Equals("Both") && !sub.Os.Equals("Both"))
                                {
                                    if (!currClassroom.Os.Equals(sub.Os))
                                    {
                                        b = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (b)
                    {
                        if (MessageBox.Show("This action will remove appointments on schedule, delete anyway?", "Delete classroom", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No)
                        {
                            //do no stuff
                            return;
                        }
                        else
                        {
                            //do yes stuff
                            for (int i = currClassroom.Termini.Count - 1; i > -1; i--)
                            {
                                Console.WriteLine(i);
                                foreach (Subject sub in MainWindow.subjects)
                                {
                                    if (sub.Naziv.Equals(currClassroom.Termini[i].Predmet))
                                    {
                                        if (!currClassroom.PrisustvoProjektora && sub.PrisustvoProjektora)
                                        {
                                            Console.WriteLine("Subject has projector, but classroom don't!");
                                            currClassroom.Termini.RemoveAt(i);
                                            sub.BrTermina += 1;
                                            break;
                                        }
                                        if (!currClassroom.PrisustvoTable && sub.PrisustvoTable)
                                        {
                                            Console.WriteLine("Subject has table, but classroom don't!");
                                            currClassroom.Termini.RemoveAt(i);
                                            sub.BrTermina += 1;
                                            break;
                                        }
                                        if (!currClassroom.PrisustvoPametneTable && sub.PrisustvoPametneTable)
                                        {
                                            Console.WriteLine("Subject has smart table, but classroom don't!");
                                            currClassroom.Termini.RemoveAt(i);
                                            sub.BrTermina += 1;
                                            break;
                                        }
                                        if (!currClassroom.Os.Equals("Both") && !sub.Os.Equals("Both"))
                                        {
                                            if (!currClassroom.Os.Equals(sub.Os))
                                            {
                                                Console.WriteLine("Subject has " + sub.Os + " but classroom has " + currClassroom.Os);

                                                currClassroom.Termini.RemoveAt(i);
                                                sub.BrTermina += 1;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    dgrMain.SelectedIndex = sIndex;
                }

                save();
            }
        }