예제 #1
0
        private void btnRoomsDeserialize_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Inserting a new file will delete all the old data from the Database", "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
            {
                return;
            }

            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter = "JSON | *.json";
            openFileDialog.Title  = "Select JSON file";

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                var         jsonFile = File.ReadAllText(openFileDialog.FileName);
                List <Room> rooms    = new List <Room>();
                rooms = JsonConvert.DeserializeObject <List <Room> >(jsonFile);

                try
                {
                    interpretor.DeleteRooms();
                    foreach (Room room in rooms)
                    {
                        interpretor.AddRoom(room, null);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                btnRoomsShow.PerformClick();
            }
        }
예제 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (tbName.Text.Length == 0 && tbSize.Text.Length == 0)
            {
                return;
            }

            Room room = new Room(tbName.Text, Int32.Parse(tbSize.Text));

            interpretor.AddRoom(room, rooms);
            ClearAdd();
            DisplayRooms();
        }