public LoginForm() { InitializeComponent(); // init directory paths base_dir = ConfigurationSettings.AppSettings["BaseDirectory"]; //db_dir = base_dir + "PCRL_phizer_study.db"; config_path = base_dir + "config.json"; // load config on opening string json = ""; try { using (StreamReader sr = new StreamReader(config_path)) { json = sr.ReadToEnd(); } } catch (Exception exp) { Console.WriteLine("The file could not be read:"); Console.WriteLine(exp.Message); } config = JsonConvert.DeserializeObject<Config>(json); }
public LogBox(string name, string station, string labroom, Config config) { //general properties data = new LogData(name, station, labroom); config_ = config; Name = name + "Logbox"; Text = station + "-" + name; BackColor = SystemColors.Control; Width = 340; Height = 320; Margin = new Padding(8); //checkboxes with labels and lists behavior.Text = "Behavior:"; behavior.Height = label_ht; behavior.Width = label_width; behavior.Location = new Point(label_x, label_y); behaviorCheck.Location = new Point(check_x, check_y); behaviorCheck.Width = 20; behaviorCheck.CheckedChanged += new System.EventHandler(behaviorCheck_Checked); behaviorList.Location = new Point(list_x, check_y); behaviorList.Width = 190; behaviorList.Items.AddRange(config.behavior_list); stool.Text = "Stool:"; stool.Height = label_ht; stool.Location = new Point(label_x, label_y + label_dy); stoolCheck.Location = new Point(check_x, check_y + label_dy); stoolCheck.Width = 20; stoolCheck.CheckedChanged += new System.EventHandler(stoolCheck_Checked); stoolList.Location = new Point(list_x, check_y + label_dy); stoolList.Width = 190; stoolList.Items.AddRange(config.stool_list); suppFeed.Text = "Supplemental Feed:"; suppFeed.Height = label_ht; suppFeed.Width = 130; suppFeed.Location = new Point(label_x, label_y + 2 * label_dy); suppFeedList.Location = new Point(list_x, check_y + 2 * label_dy); suppFeedList.Height = 66; suppFeedList.Width = 190; suppFeedList.Items.AddRange(config.supp_feed_templates.Keys.ToArray<string>()); //foreach (SuppFood sfObj in supp_foods) { // suppFeedObjs.Add(sfObj); //} // init supplemental food data table /*suppFeedTable.AutoGenerateColumns = false; suppFeedTable.Location = new Point(list_x, check_y + 2 * label_dy); suppFeedTable.Size = new Size(180, 70); suppFeedTable.ScrollBars = ScrollBars.Both; suppFeedTable.DataSource = suppFeedObjs; // add columns DataGridViewColumn column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Name"; column.Name = "Name"; column.Width = 60; suppFeedTable.Columns.Add(column); column = new DataGridViewTextBoxColumn(); column.DataPropertyName = "Amount"; column.Name = "Amt (g)"; column.Width = 60; suppFeedTable.Columns.Add(column);*/ equipment.Text = "Equipment:"; equipment.Height = label_ht; equipment.Width = label_width; equipment.Location = new Point(label_x, label_y + 5*label_dy); equipmentCheck.Location = new Point(check_x, check_y + 5*label_dy); equipmentCheck.Width = 20; equipmentCheck.CheckedChanged += new System.EventHandler(equipmentCheck_Checked); equipCheckList.Location = new Point(list_x, check_y + 5*label_dy); equipCheckList.Height = 66; equipCheckList.Width = 190; equipCheckList.ScrollAlwaysVisible = true; equipCheckList.CheckOnClick = true; equipCheckList.Items.AddRange(config.equipment_list); training.Text = "Training:"; training.Height = label_ht; training.Width = label_width; training.Location = new Point(label_x, label_y + 7*label_dy + 16); trainingCheck.Width = 20; trainingCheck.Location = new Point(check_x, check_y + 7*label_dy + 16); trainingCheck.CheckedChanged += new System.EventHandler(trainingCheck_Checked); trainingList.Width = 190; trainingList.Location = new Point(list_x - 5, check_y + 7*label_y + 30); trainingList.Items.AddRange(config.training_list); comment.Text = "Comments:"; comment.Location = new Point(label_x, label_y + 8*label_dy + 16); comment.Height = label_ht; comment.Width = label_width; comment.FlatStyle = FlatStyle.Standard; commentText.Location = new Point(check_x, label_y + 8*label_dy + 16); commentText.Width = 220; commentText.Height = 50; //report button /*report.Text = "Latest Report"; report.Location = new Point(110, label_y + (int)(9.5 * label_dy) + 5); report.Height = button_ht; report.Width = button_width; report.FlatStyle = FlatStyle.Standard; report.Click += new System.EventHandler(report_Click);*/ Controls.Add(behavior); Controls.Add(behaviorCheck); Controls.Add(stool); Controls.Add(stoolCheck); Controls.Add(suppFeed); Controls.Add(suppFeedList); Controls.Add(equipment); Controls.Add(equipmentCheck); Controls.Add(training); Controls.Add(trainingCheck); Controls.Add(comment); Controls.Add(commentText); //Controls.Add(report); }
private void loginButton_Click(object sender, EventArgs e) { // reload config upon login, so to update any changes string json = ""; try { using (StreamReader sr = new StreamReader(config_path)) { json = sr.ReadToEnd(); } } catch (Exception exp) { Console.WriteLine("The file could not be read:"); Console.WriteLine(exp.Message); } config = JsonConvert.DeserializeObject<Config>(json); //check login if (usernameTextbox.Text.Equals(string.Empty)) { MessageBox.Show("Please fill in username and password fields."); return; } //set db directory db_dir = config.db_file; username = usernameTextbox.Text; password = passwordTextbox.Text; Dictionary<string, Dictionary<string, string>> labmembers = config.labmember_data; var user = from labmember in labmembers where labmember.Key.Equals(username) && labmember.Value["password"].Equals(password) select labmember; if (!user.Any()) MessageBox.Show("Invalid username or password.\nPlease proceed to create an account."); else { name[0] = user.First().Value["first"]; name[1] = user.First().Value["last"]; LabroomForm labroomForm = new LabroomForm(this); labroomForm.Show(); Hide(); } }