Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            string directory        = AppDomain.CurrentDomain.BaseDirectory + "\\LaMarcel\\";
            string selectedFileName = AppDomain.CurrentDomain.BaseDirectory + "\\LaMarcel\\LaMarcel.json";
            string restaurant       = selectedFileName.Split('\\')[selectedFileName.Split('\\').Length - 1].Split('.')[0];
            string path             = selectedFileName;

            #region restaurant_pozitii
            JObject o1 = JObject.Parse(File.ReadAllText(path));

            // read JSON directly from a file
            using (StreamReader file = File.OpenText(path))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject restaurant_pozition_json = (JObject)JToken.ReadFrom(reader);
                    int     width  = Convert.ToInt32(restaurant_pozition_json[restaurant]["Dimensiuni"].ToString().Split(':')[1]);
                    int     height = Convert.ToInt32(restaurant_pozition_json[restaurant]["Dimensiuni"].ToString().Split(':')[0]);
                    pnlRestaurant = new RestaurantView(height, width, this.Size, restaurant);
                    this.Controls.Add(pnlRestaurant);
                    var tables = restaurant_pozition_json[restaurant]["Mese"];
                    int i      = 1;
                    foreach (var table in tables)
                    {
                        pnlRestaurant.AddTable(new Table(new TableModel(table, pnlRestaurant.GetXRatio(), pnlRestaurant.GetYRatio(), i++, lstItems)));
                    }
                }
            #endregion
            #region meniu_restaurant
            using (StreamReader file = File.OpenText(directory + "Menu.json"))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    JObject menu_json = (JObject)JToken.ReadFrom(reader);
                    this.Menu = new Clase.Meniu(directory);
                    foreach (var item in menu_json)
                    {
                        Item MenuItem = new Item(item.Value);
                        Menu.AddItem(MenuItem);
                    }
                }
            #endregion
            btnCloseReciept.Show();
            btnAddItems.Show();
        }
Esempio n. 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFileDialog1 = new OpenFileDialog();

                openFileDialog1.InitialDirectory = "c:\\";
                openFileDialog1.Filter           = "JSON files (*.json)|*.json";
                openFileDialog1.FilterIndex      = 0;
                openFileDialog1.RestoreDirectory = true;
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    if (pnlRestaurant != null)
                    {
                        pnlRestaurant.Hide();
                        pnlRestaurant = null;
                    }
                    string directory        = Resources.Util.GetDirectoryOfFile(openFileDialog1.FileName);
                    string selectedFileName = openFileDialog1.FileName;
                    string restaurant       = selectedFileName.Split('\\')[selectedFileName.Split('\\').Length - 1].Split('.')[0];
                    string path             = selectedFileName;
                    #region restaurant_pozitii
                    JObject o1 = JObject.Parse(File.ReadAllText(path));

                    // read JSON directly from a file
                    using (StreamReader file = File.OpenText(path))
                        using (JsonTextReader reader = new JsonTextReader(file))
                        {
                            JObject restaurant_pozition_json = (JObject)JToken.ReadFrom(reader);
                            int     width  = Convert.ToInt32(restaurant_pozition_json[restaurant]["Dimensiuni"].ToString().Split(':')[1]);
                            int     height = Convert.ToInt32(restaurant_pozition_json[restaurant]["Dimensiuni"].ToString().Split(':')[0]);
                            pnlRestaurant = new RestaurantView(height, width, this.Size, restaurant);
                            this.Controls.Add(pnlRestaurant);
                            var tables = restaurant_pozition_json[restaurant]["Mese"];
                            int i      = 1;
                            foreach (var table in tables)
                            {
                                pnlRestaurant.AddTable(new Table(new TableModel(table, pnlRestaurant.GetXRatio(), pnlRestaurant.GetYRatio(), i++, lstItems)));
                            }
                        }
                    #endregion
                    #region meniu_restaurant
                    using (StreamReader file = File.OpenText(directory + "Menu.json"))
                        using (JsonTextReader reader = new JsonTextReader(file))
                        {
                            JObject menu_json = (JObject)JToken.ReadFrom(reader);
                            this.Menu = new Clase.Meniu(directory);
                            foreach (var item in menu_json)
                            {
                                Item MenuItem = new Item(item.Value);
                                Menu.AddItem(MenuItem);
                            }
                        }
                    #endregion
                    btnCloseReciept.Show();
                    btnAddItems.Show();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }