Esempio n. 1
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (this.CadastralArea == null)
            {
                this.CadastralArea = new CadastralArea(0);
            }

            if (!Int32.TryParse(inputID.Text, out int id))
            {
                goto DoNothing;
            }

            this.CadastralArea.ID = id;
            string oldName = this.CadastralArea.Name;

            this.CadastralArea.Name = inputName.Text;

            if (this.CadastralArea == null || this.CadastralArea.ID == 0)
            {
                MessageBox.Show("ID is mandatory field, please fill it up");
            }
            onDispose?.Invoke(this.CadastralArea, oldName);
            this.Dispose();
            goto Finish;

            DoNothing :;
            MessageBox.Show("ID has to be integer");
            Finish :;
        }
Esempio n. 2
0
 public CadastralView(CadastralArea CadastralArea = null)
 {
     InitializeComponent();
     this.CadastralArea = CadastralArea;
     this.PrintCadastralArea();
     this.dataGridPropertyLists.DataSource = bindingSourcePLs;
     this.ReloadData();
 }
Esempio n. 3
0
 private DataRow CreateCARow(CadastralArea ca)
 {
     this.row    = tableCA.NewRow();
     row["ID"]   = ca.ID;
     row["Name"] = ca.Name;
     row["Property List count"] = ca.PropertyLists.Count;
     row["Properties count"]    = ca.Properties.Count;
     return(this.row);
 }
Esempio n. 4
0
 private void btnChangeProperty_Click(object sender, EventArgs e)
 {
     if (form != null)
     {
         InputDialog caid = new InputDialog("Cadastral area id:");
         caid.onDispose += (caID) =>
         {
             if (Int32.TryParse(caID, out int caIDint))
             {
                 CadastralArea ca = new CadastralArea(caIDint);
                 ca = this.form.FindCadastralArea(new CadastralAreaByID(ca));
                 if (ca != null)
                 {
                     InputDialog pid = new InputDialog("Property id:");
                     pid.onDispose += (pID) =>
                     {
                         Property p = ca.FindProperty(pID);
                         if (p != null)
                         {
                             InputDialog ownerId = new InputDialog("New owner (person.id):");
                             ownerId.onDispose += (newOwnerID) =>
                             {
                                 Person per = new Person(newOwnerID);
                                 per = form.FindPerson(per);
                                 if (per != null)
                                 {
                                     p.ChangeOwner(this.Person, per);
                                 }
                                 else
                                 {
                                     MessageBox.Show("Could not find this person/owner");
                                 }
                             };
                             ownerId.ShowDialog();
                         }
                         else
                         {
                             MessageBox.Show("Could not find this property");
                         }
                     };
                     pid.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("This cadastral area doesn't exist");
                 }
             }
             else
             {
                 MessageBox.Show("Input value has to be integer");
             }
         };
         caid.ShowDialog();
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Add cadastral area to structure, this will add it to two structure, by name and by ID
        /// log n + log n where n is count of cadastral areas
        /// </summary>
        /// <param name="CadastralArea"></param>
        /// <returns></returns>
        public bool AddCadastralArea(CadastralArea CadastralArea)
        {
            CadastralAreaByID caID = new CadastralAreaByID(CadastralArea);

            if (!this.CadastralAreasByID.Add(caID))
            {
                return(false);
            }
            if (!this.CadastralAreasByName.Add(new CadastralAreaByName(CadastralArea)))
            {
                this.CadastralAreasByID.Remove(caID);
                return(false);
            }
            return(true);
        }
Esempio n. 6
0
 private void btnChangeAddress_Click(object sender, EventArgs e)
 {
     if (form != null)
     {
         InputDialog caid = new InputDialog("Cadastral area id:");
         caid.onDispose += (caID) =>
         {
             if (Int32.TryParse(caID, out int caIDint))
             {
                 CadastralArea ca = new CadastralArea(caIDint);
                 ca = this.form.FindCadastralArea(new CadastralAreaByID(ca));
                 if (ca != null)
                 {
                     InputDialog pid = new InputDialog("Property id:");
                     pid.onDispose += (pID) =>
                     {
                         Property p = ca.FindProperty(pID);
                         if (p != null)
                         {
                             p.AddOccupant(this.Person);
                             this.inputAddress.Text = p.Address;
                         }
                         else
                         {
                             MessageBox.Show("Could not find this property");
                         }
                     };
                     pid.ShowDialog();
                 }
                 else
                 {
                     MessageBox.Show("This cadastral area doesn't exist");
                 }
             }
             else
             {
                 MessageBox.Show("Input value has to be integer");
             }
         };
         caid.ShowDialog();
     }
 }
Esempio n. 7
0
 public MyProgram(bool Generate, int cadastralCount, int personsCount, int propertyListCount, int propertyCount) : this()
 {
     if (Generate)
     {
         Random personsR = new Random(100);
         Random cadR     = new Random(101);
         for (int i = 0; i < personsCount; i++)
         {
             Persons.Add(new Person(personsR.Next(personsCount * 10).ToString()));
         }
         CadastralArea c  = null;
         PropertyList  pl = null;
         Property      p  = null;
         for (int i = 0; i < cadastralCount; i++)
         {
             c = new CadastralArea(cadR.Next(cadastralCount + 10));
             if (CadastralAreasByID.Add(new CadastralAreaByID(c)))
             {
                 CadastralAreasByName.Add(new CadastralAreaByName(c));
                 for (int j = 1; j <= propertyListCount; j++)
                 {
                     pl = new PropertyList(j, c);
                     if (c.AddPropertyList(pl))
                     {
                         pl.AddOwner(Persons.Find(), 1);
                         for (int k = 0; k < propertyCount; k++)
                         {
                             p = new Property(c.Properties.Count, "Address" + (j + k), "Unknown", pl);
                             p.AddOccupant(pl.Owners.GetRoot().Person);
                             pl.AddProperty(p);
                         }
                     }
                 }
             }
         }
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Save data to csv files in path declared by param
        /// </summary>
        /// <param name="path"></param>
        public void ToCSV(string path)
        {
            using (StreamWriter writer = new StreamWriter(path + "\\persons.csv"))
            {
                writer.AutoFlush = true;
                writer.WriteLine(Person.GetCsvHeaders());
                this.Persons.PreOrder((p) => writer.WriteLine(p.ToCSV()));
            }

            using (StreamWriter writer = new StreamWriter(path + "\\cadastralAreas.csv"))
            {
                writer.AutoFlush = true;
                writer.WriteLine(CadastralArea.GetCsvHeaders());
                StreamWriter writerOwners = new StreamWriter(path + "\\owners.csv");
                writerOwners.AutoFlush = true;
                writerOwners.WriteLine(Owner.GetCsvHeaders());
                StreamWriter writerProperties = new StreamWriter(path + "\\properties.csv");
                writerProperties.AutoFlush = true;
                writerProperties.WriteLine(Property.GetCsvHeaders());
                StreamWriter writerOccupants = new StreamWriter(path + "\\occupants.csv");
                writerOccupants.AutoFlush = true;
                writerOccupants.WriteLine(Property.OccupantsCsvHeader());
                this.CadastralAreasByID.PreOrder((p) => {
                    writer.WriteLine(p.CadastralArea.ToCSV());
                    p.CadastralArea.PropertyLists.PreOrder((pl) =>
                    {
                        pl.Owners.PreOrder((o) => writerOwners.WriteLine(o.ToCSV(pl)));
                        pl.Properties.PreOrder((prop) =>
                        {
                            writerProperties.WriteLine(prop.ToCSV());
                            prop.Occupants.PreOrder((occ) => writerOccupants.WriteLine(prop.OccupantToCsv(occ)));
                        });
                    });
                });
            }
        }
Esempio n. 9
0
        private void btnFind_Click(object sender, EventArgs e)
        {
            switch (comboTypes.SelectedIndex)
            {
            case 0:     // Persons
                Person p = this.Program.Find(new Person(textSearch.Text));
                if (p == null)
                {
                    goto Error;
                }
                PersonView pv = new PersonView(p, this);
                pv.onDispose += (person) => {
                    p = person;
                };
                pv.ShowDialog();
                goto Finish;

            case 1:     // Cadastral Area
                CadastralArea c = null;
                if (Int32.TryParse(textSearch.Text, out int search))
                {
                    c = new CadastralArea(search);
                    c = this.Program.Find(new CadastralAreaByID(new CadastralArea(search)));
                }
                else
                {
                    c = new CadastralArea(0, textSearch.Text);
                    c = this.Program.Find(new CadastralAreaByName(c));
                }
                if (c == null)
                {
                    goto Error;
                }
                CadastralView cv = new CadastralView(c);
                cv.onDispose += (cArea, oldName) =>
                {
                    if (oldName != c.Name)
                    {
                        this.Program.UpdateCadastralArea(c, oldName);
                    }
                };
                cv.ShowDialog();
                goto Finish;

            case 2:     // Property list
                InputDialog id = new InputDialog("Catastral area:");
                id.onDispose += (caId) =>
                {
                    if (caId != "")
                    {
                        CadastralArea ca = null;
                        if (Int32.TryParse(caId, out int s))
                        {
                            ca = this.Program.Find(new CadastralAreaByID(new CadastralArea(s, "")));
                        }
                        else
                        {
                            ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, caId)));
                        }
                        if (ca != null)
                        {
                            PropertyList pl = ca.FindPropertyList(textSearch.Text);
                            if (pl == null)
                            {
                                MessageBox.Show("Property list with this id does not exist");
                            }
                            else
                            {
                                PropertyListView plv = new PropertyListView(pl, this);
                                plv.ShowDialog();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this id/name does not exist");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have to write something");
                    }
                };
                id.ShowDialog();
                goto Finish;

            case 3:     // Property
                InputDialog id2 = new InputDialog("Catastral area:");
                id2.onDispose += (caId) =>
                {
                    if (caId != "")
                    {
                        CadastralArea ca = null;
                        if (Int32.TryParse(caId, out int s))
                        {
                            ca = this.Program.Find(new CadastralAreaByID(new CadastralArea(s, "")));
                        }
                        else
                        {
                            ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, caId)));
                        }
                        if (ca != null)
                        {
                            Property prop = ca.FindProperty(textSearch.Text);
                            if (prop == null)
                            {
                                MessageBox.Show("Property with this id does not exist");
                            }
                            else
                            {
                                PropertyView propv = new PropertyView(prop);
                                propv.ShowDialog();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this id/name does not exist");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have to write something");
                    }
                };
                id2.ShowDialog();
                goto Finish;
            }

Error:
            MessageBox.Show("Could not find specified item");
            Finish :;
        }
Esempio n. 10
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            CadastralArea c = null, c2 = null;
            int           search = 0;
            InputDialog   id     = null;

            switch (comboTypes.SelectedIndex)
            {
            case 1:     // cadastral area
                if (Int32.TryParse(textSearch.Text, out search))
                {
                    c = new CadastralArea(search);
                    c = this.Program.Find(new CadastralAreaByID(new CadastralArea(search)));
                }
                else
                {
                    c = new CadastralArea(0, textSearch.Text);
                    c = this.Program.Find(new CadastralAreaByName(c));
                }
                if (c == null)
                {
                    MessageBox.Show("This cadastral area does not exists");
                }
                else
                {
                    id            = new InputDialog("Cadastral area to add this one (ID):");
                    id.onDispose += (idCa) =>
                    {
                        if (Int32.TryParse(idCa, out int idCAint) && c.ID != idCAint)
                        {
                            c2 = new CadastralArea(idCAint);
                            c2 = this.Program.Find(new CadastralAreaByID(c2));
                            if (c2 != null)
                            {
                                this.Program.Merge(c, c2);
                                this.InitCadastralAreas();
                                MessageBox.Show(String.Format("Cadastal area {0} was remove and its property lists was moved under {1} ", c.Name, c2.Name));
                            }
                            else
                            {
                                MessageBox.Show("Cadastral area does not exist");
                            }
                        }
                        else
                        {
                            MessageBox.Show("New cadastral are cannot be the same as removing one");
                        }
                    };
                    id.ShowDialog();
                }
                break;

            case 2:     // Property list
                id            = new InputDialog("Catastral area:");
                id.onDispose += (caId) =>
                {
                    if (caId != "")
                    {
                        if (Int32.TryParse(caId, out search))
                        {
                            c = new CadastralArea(search, "");
                            c = this.Program.Find(new CadastralAreaByID(c));
                        }
                        else
                        {
                            c = new CadastralArea(0, caId);
                            c = this.Program.Find(new CadastralAreaByName(c));
                        }
                        if (c != null)
                        {
                            PropertyList pl = c.FindPropertyList(textSearch.Text);
                            if (pl == null)
                            {
                                MessageBox.Show("Property list with this id does not exist");
                            }
                            else
                            {
                                InputDialog id2 = new InputDialog("Property list to move under");
                                id2.onDispose += (plId) =>
                                {
                                    PropertyList pl2 = c.FindPropertyList(plId);
                                    if (pl.CompareTo(pl2) == 0)
                                    {
                                        MessageBox.Show("Properties cannot be same");
                                    }
                                    else
                                    {
                                        this.Program.Merge(pl, pl2);
                                        //this.InitPersons(); // possibility to remove property list from person
                                        //this.InitCadastralAreas(); // one cadastral area removed one property list
                                        MessageBox.Show(String.Format("Property list was successfully removed. Owners and properties was moved under CA.ID({0}) PL.ID({1})", c.ID, pl2.ID));
                                    }
                                };
                                id2.ShowDialog();
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this id/name does not exist");
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have to write something");
                    }
                };
                id.ShowDialog();
                break;

            default:
                MessageBox.Show("This option is not supported yet!");
                break;
            }
        }
Esempio n. 11
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            switch (comboTypes.SelectedIndex)
            {
            case 0 :    // Persons
                PersonView pv = new PersonView(null, this);
                pv.onDispose += (person) =>
                {
                    if (this.Program.AddPerson(person))
                    {
                        MessageBox.Show("Person was successfully added!");
                        this.InitPersons();
                    }
                    else
                    {
                        MessageBox.Show("Person could not be added, probably already added!");
                    }
                };
                pv.ShowDialog();
                break;

            case 1:     // Cadastral Area
                CadastralView cv = new CadastralView();
                cv.onDispose += (cArea, name) =>
                {
                    if (this.Program.AddCadastralArea(cArea))
                    {
                        MessageBox.Show("Cadastral area was successfully added!");
                        this.InitCadastralAreas();
                    }
                    else
                    {
                        MessageBox.Show("Cadastral area could not be added, probably already added!");
                    }
                };
                cv.ShowDialog();
                break;

            case 2:     // Property list
                InputDialog id = new InputDialog("Catastral area name:");
                id.onDispose += (search) =>
                {
                    if (search != "")
                    {
                        CadastralArea ca = this.Program.Find(new CadastralAreaByName(new CadastralArea(0, (string)search)));
                        if (ca != null)
                        {
                            PropertyListView plv = new PropertyListView(new PropertyList(-1, ca), this);
                            plv.onDispose += (pl) =>
                            {
                                if (pl.ID >= 0)
                                {
                                    if (this.Program.AddPropertyList(pl))
                                    {
                                        MessageBox.Show("Property list was successfully added!");
                                    }
                                    else
                                    {
                                        MessageBox.Show("Cadastral area could not be added, probably already added!");
                                    }
                                }
                            };
                            plv.ShowDialog();
                        }
                        else
                        {
                            MessageBox.Show("Cadastral area with this name does not exist");
                        }
                    }
                };
                id.ShowDialog();
                break;

            default:
                MessageBox.Show("This option is not supported");
                break;
            }
        }
Esempio n. 12
0
 /// <summary>
 /// If was cadastral area's name updated, need to remove and insert to tree
 /// log n + log (n - 1)
 /// </summary>
 /// <param name="c"></param>
 /// <param name="oldName"></param>
 public void UpdateCadastralArea(CadastralArea c, string oldName)
 {
     this.CadastralAreasByName.Remove(new CadastralAreaByName(new CadastralArea(0, oldName)));
     this.CadastralAreasByName.Add(new CadastralAreaByName(c));
 }
Esempio n. 13
0
 /// <summary>
 /// Delete cadastral area and all its data move under another cadastral area (probably changing of property lists ID because of duplicates)
 /// </summary>
 /// <param name="c"></param>
 /// <param name="c2"></param>
 public void Merge(CadastralArea c, CadastralArea c2)
 {
     c2.Merge(c);
     this.CadastralAreasByID.Remove(new CadastralAreaByID(c));     // log n remove
     this.CadastralAreasByName.Remove(new CadastralAreaByName(c)); // log n remove
 }