public DisplaySignupSheet(Control parent, string filePath, SignupSheet newSheet)
        {
            this.dataLoaded = false;

            InitializeComponent();

            // Reassign its parent.
            this.Parent = parent;

            // Generate the new file path.
            string startTimeString = newSheet.StartTime.ToString("yyyy-MM-dd-HH-mm-ss");
            string endTimeString = newSheet.EndTime.ToString("yyyy-MM-dd-HH-mm-ss");
            filePath += '\\' + newSheet.SessionName + '_' + startTimeString + '_' + endTimeString + ".json";
            Console.WriteLine("New signup sheet location: " + filePath);

            // Store the file path, which is the basis of a document.
            this.filePath = filePath;

            // Use the assigned sheet instead of dump it from the file.
            this.sheet = newSheet;
            // Bind the data source after instantiate the BindingList.
            this.dataViewer.DataSource = new BindingSource(this.sheet.Entries, null);
            this.dataLoaded = true;

            // Save immediately, since this file is newly created.
            SaveToFile();
        }
        public void LoadFromFile()
        {
            // If the file doesn't exist, the table IS dirty upon opening.
            if(File.Exists(this.filePath))
            {
                this.isDirty = false;
                using(StreamReader reader = new StreamReader(this.filePath))
                {
                    string content = reader.ReadToEnd();
                    sheet = JsonConvert.DeserializeObject<SignupSheet>(content);
                }
            }
            else
            {
                this.isDirty = true;
            }

            // Bind the data source after instantiate the BindingList.
            this.dataViewer.DataSource = new BindingSource(this.sheet.Entries, null);

            this.dataLoaded = true;
        }
Ejemplo n.º 3
0
        private void newSignupSheet_Click(object sender, EventArgs e)
        {
            DialogResult status;

            string filePath = ChooseFolder();
            if(filePath.Length == 0)
            {
                return;
            }

            using(SignupSheetDetail details = new SignupSheetDetail())
            {
                status = details.ShowDialog();

                if(status == DialogResult.OK)
                {
                    bool showNewSignupSheet = true;

                    if(!IsUserListLoaded())
                    {
                        status = MessageBox.Show("Please load a user list to continue.",
                                                 "No user list loaded.",
                                                 MessageBoxButtons.OKCancel,
                                                 MessageBoxIcon.Question);
                        if(status == DialogResult.OK)
                        {
                            this.openUserList.PerformClick();
                        }
                        else
                        {
                            showNewSignupSheet = false;
                        }
                    }

                    // Force save the user list.
                    DisplayUserList userList = this.displayRegion.Panel2.Controls["display"] as DisplayUserList;
                   userList.ForceSave();

                    if(showNewSignupSheet)
                    {
                        // Create a dummy signup sheet object.
                        SignupSheet newSheet = new SignupSheet();
                        newSheet.SessionName = details.SessionName;
                        newSheet.StartTime = details.StartTime;
                        newSheet.EndTime = details.EndTime;

                        // Import the users from the user list.
                        BindingList<Entry> templateEntries = new BindingList<Entry>();
                        foreach(UserInfo user in userList.GetUsers())
                        {
                            Entry newEntry = new Entry();
                            newEntry.Name = user.FirstName + ' ' + user.LastName;
                            newEntry.Signed = false;
                            templateEntries.Add(newEntry);
                        }
                        newSheet.Entries = templateEntries;

                        // Create the object and add to panel.
                        DisplaySignupSheet display = new DisplaySignupSheet(this, filePath, newSheet);
                        AddDisplayToPanel(this.displayRegion.Panel1, display);

                        // Write hint on the status bar.
                        this.applicationStatus.Text = "Right click on the list to close it.";

                        this.serverToolStripMenuItem.Enabled = true;
                    }
                    else
                    {
                        this.applicationStatus.Text = "Abort create new signup sheet.";
                        this.applicationStatus.ForeColor = Color.Red;
                    }
                }
                else
                {
                    this.applicationStatus.Text = "Abort creation.";
                }
            }
        }