private void morningFoodSource_SelectedIndexChanged(object sender, EventArgs e) { morningDrink.Visible = false; morningDrinkLabel.Visible = false; morningSide.Visible = false; morningSideLabel.Visible = false; morningMain.Visible = false; morningMainLabel.Visible = false; if (morningFoodSource.SelectedIndex != 0) { morningDrink.Items.Clear(); MorningFoodSource fs = (MorningFoodSource)morningFoodSource.SelectedItem; foreach (string drink in fs.drinks) { morningDrink.Items.Add(drink); } if (fs.drinks.ToArray().Length > 0) { morningDrink.Visible = true; morningDrinkLabel.Visible = true; morningDrink.SelectedIndex = 0; } morningMain.Items.Clear(); foreach (MorningMeal meal in fs.meals) { morningMain.Items.Add(meal); } if (fs.meals.ToArray().Length > 0) { morningMain.Visible = true; morningMainLabel.Visible = true; morningMain.SelectedIndex = 0; morningSide.Items.Clear(); MorningMeal m = (MorningMeal)morningMain.SelectedItem; if (m.hasSubtype) { morningSide.Visible = true; morningSideLabel.Visible = true; morningSideLabel.Text = m.subtypeName; foreach (string side in m.subtypes) { morningSide.Items.Add(side); } morningSide.SelectedIndex = 0; } else { morningSide.Visible = false; morningSideLabel.Visible = false; } } } }
private void Form1_Load(object sender, EventArgs e) { string[] dateString = System.DateTime.Now.ToShortDateString().Split("/".ToCharArray()); for (int i = 0; i < dateString.Length; i++) { if (dateString[i].Length < 2) { dateString[i] = "0" + dateString[i]; } } date.Text = string.Join(".", dateString); if (!File.Exists("users.json")) { User exUser = new User { username = "******", name = "name", canEdit = false }; List <User> exUserList = new List <User>() { exUser }; File.WriteAllText("users.json", JsonConvert.SerializeObject(exUserList, Formatting.Indented)); } String usersString = File.ReadAllText("users.json"); try { users = JsonConvert.DeserializeObject <List <User> >(usersString); } catch { MessageBox.Show("!אירעה שגיאה בעת טעינת רשימת המשתמשים\r\n.משתמש בקובץ ברירת המחדל", "!שגיאה"); User exUser = new User { username = "******", name = "name", canEdit = false }; List <User> exUserList = new List <User>() { exUser }; File.WriteAllText("users.json", JsonConvert.SerializeObject(exUserList, Formatting.Indented)); users = exUserList; } username.Items.AddRange(users.ToArray()); foreach (User u in username.Items) { if (u.username.Equals(Environment.UserName)) { username.SelectedItem = u; break; } } string name = null; if (users == null) { users = new List <User>(); } User user = null; foreach (User u in users) { if (u.Equals(username.SelectedItem)) { name = u.name; user = u; } } if (string.IsNullOrEmpty(name)) { MessageBox.Show(this, new string("!אתה לא רשום במערכת\r\n.פנה לאחראי כדי להשתמש במערכת".ToCharArray()), "!שגיאה", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); Application.Exit(); return; } if (System.DateTime.Now.Hour > 10 && !user.canEdit) { MessageBox.Show(this, new string("!אין אפשרות לבצע הזמנה אחרי השעה 10:00".ToCharArray()), "!שגיאה", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, MessageBoxOptions.RightAlign); Application.Exit(); return; } if (user.canEdit) { username.Enabled = true; //username.BackColor = System.Drawing.SystemColors.ControlLightLight; //label4.BackColor = System.Drawing.SystemColors.ControlLightLight; generateText.Visible = true; } if (!File.Exists("locations.json")) { Location exLocation = new Location { name = "name", address = "address" }; List <Location> exLocationList = new List <Location>() { exLocation }; File.WriteAllText("locations.json", JsonConvert.SerializeObject(exLocationList, Formatting.Indented)); } String locationsString = File.ReadAllText("locations.json"); try { locations = JsonConvert.DeserializeObject <List <Location> >(locationsString); } catch { MessageBox.Show("!אירעה שגיאה בעת טעינת רשימת המקומות\r\n.משתמש בקובץ ברירת המחדל", "!שגיאה"); Location exLocation = new Location { name = "name", address = "address" }; List <Location> exLocationList = new List <Location>() { exLocation }; File.WriteAllText("locations.json", JsonConvert.SerializeObject(exLocationList, Formatting.Indented)); locations = exLocationList; } location.Items.AddRange(locations.ToArray()); location.SelectedIndex = 0; if (!Directory.Exists("restaurants")) { Directory.CreateDirectory("restaurants"); } if (!Directory.Exists("restaurants/morning")) { Directory.CreateDirectory("restaurants/morning"); } if (!Directory.Exists("restaurants/noon")) { Directory.CreateDirectory("restaurants/noon"); } if (!Directory.Exists("recipments")) { Directory.CreateDirectory("recipments"); } if (!Directory.Exists("recipments/" + DateTime.Now.Year)) { Directory.CreateDirectory("recipments/" + DateTime.Now.Year); } if (!Directory.Exists("recipments/" + DateTime.Now.Year + "/" + DateTime.Now.Month)) { Directory.CreateDirectory("recipments/" + DateTime.Now.Year + "/" + DateTime.Now.Month); } List <String> morningRestaurants = new List <string>(Directory.GetFiles("restaurants/morning")); if (morningRestaurants.ToArray().Length == 0) { MorningFoodSource exFoodSource = MorningFoodSource.Example(); File.WriteAllText("restaurants/morning/foodsource1.json", JsonConvert.SerializeObject(exFoodSource, Formatting.Indented)); } morningRestaurants = new List <string>(Directory.GetFiles("restaurants/morning")); morningFoodSources = new List <MorningFoodSource>(); morningFoodSource.SelectedIndex = 0; //foodSources.Add(new FoodSource { name = "בחר ספק" }); foreach (string file in morningRestaurants) { String foodsourceString = File.ReadAllText(file); morningFoodSources.Add(JsonConvert.DeserializeObject <MorningFoodSource>(foodsourceString)); } foreach (MorningFoodSource fs in morningFoodSources) { morningFoodSource.Items.Add(fs); } List <String> noonRestaurants = new List <string>(Directory.GetFiles("restaurants/noon")); if (noonRestaurants.ToArray().Length == 0) { NoonFoodSource exFoodSource = NoonFoodSource.Example(); File.WriteAllText("restaurants/noon/foodsource1.json", JsonConvert.SerializeObject(exFoodSource, Formatting.Indented)); } noonRestaurants = new List <string>(Directory.GetFiles("restaurants/noon")); noonFoodSources = new List <NoonFoodSource>(); noonFoodSource.SelectedIndex = 0; //foodSources.Add(new FoodSource { name = "בחר ספק" }); foreach (string file in noonRestaurants) { String foodsourceString = File.ReadAllText(file); noonFoodSources.Add(JsonConvert.DeserializeObject <NoonFoodSource>(foodsourceString)); } foreach (NoonFoodSource fs in noonFoodSources) { noonFoodSource.Items.Add(fs); } hour.SelectedIndex = 0; }