Exemplo n.º 1
0
        private void hoursDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int newHoursTotal = int.Parse(hoursDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString());

            int editedClassIndex = classResponse.contents.FindIndex(x => x.className == hoursDataGridView.Rows[e.RowIndex].Cells[0].Value.ToString());

            if (hoursControl.classesToEdit.Exists(x => x.classID == classResponse.contents[editedClassIndex].classID)) // check if this class is on the "to edit" list
            {
                hoursControl.classesToEdit[hoursControl.classesToEdit.FindIndex(x => x.classID == classResponse.contents[editedClassIndex].classID)].totalHours = newHoursTotal;
            }
            else
            {
                // if it is not on the "to edit" list, then check if it is on the "to add" list
                if (hoursControl.classesToAdd.Exists(x => x.classID == classResponse.contents[editedClassIndex].classID))
                {
                    hoursControl.classesToAdd[hoursControl.classesToAdd.FindIndex(x => x.classID == classResponse.contents[editedClassIndex].classID)].totalHours = newHoursTotal;
                }
                else
                {
                    // if it is in neither one of them, create a new entry on the "to edit" list
                    classesToEdit toEdit = new classesToEdit();
                    toEdit.classID    = classResponse.contents[editedClassIndex].classID;
                    toEdit.totalHours = newHoursTotal;
                    hoursControl.classesToEdit.Add(toEdit);
                }
            }
        }
Exemplo n.º 2
0
        private void addClassBTN_Click(object sender, EventArgs e)
        {
            if (classesCB.Items.Count > 0 && classesCB.SelectedItem != null)
            {
                int classIndex = classResponse.contents.FindIndex(x => x.className == classesCB.SelectedItem.ToString());
                classesCB.Items.RemoveAt(classesCB.SelectedIndex);
                if (classesCB.Items.Count > 0)
                {
                    classesCB.SelectedIndex = 0;
                }

                DataGridViewRow         row    = new DataGridViewRow();
                DataGridViewTextBoxCell TBcell = new DataGridViewTextBoxCell();
                TBcell.Value = classResponse.contents[classIndex].className;
                NumericUpDownCell NumUpDownCell = new NumericUpDownCell();
                NumUpDownCell.Value = 300;
                DataGridViewButtonCell BTNCell = new DataGridViewButtonCell();
                BTNCell.Tag   = classIndex;
                BTNCell.Value = WorkspaceConfigFormStrings.RemoveBTN;

                row.Cells.Add(TBcell);
                row.Cells.Add(NumUpDownCell);
                row.Cells.Add(BTNCell);

                if (sentWorkspaceID != 0)                                                                                                                         // checks if we're editing a workspace
                {
                    if (!hoursControl.classesToAdd.Exists(x => x.classID == classResponse.contents[classIndex].classID))                                          // checks if this class is not on the "to add" list
                    {
                        if (hoursControl.classesToRemove.Exists(x => x.classID == classResponse.contents[classIndex].classID))                                    // checks if this class if on the "to remove" list
                        {
                            hoursControl.classesToRemove.Remove(hoursControl.classesToRemove.Find(x => x.classID == classResponse.contents[classIndex].classID)); // removes the class from the "to remove" list
                        }

                        if (hoursControl.classesToEdit.Exists(x => x.classID == classResponse.contents[classIndex].classID)) // checks if this class is on the "to edit" list
                        {
                            hoursControl.classesToEdit[hoursControl.classesToEdit.FindIndex(x => x.classID == classResponse.contents[classIndex].classID)].totalHours = 300;
                        }
                        else
                        {
                            if (workspaceResponse.contents[0].hours != null)
                            {
                                if (workspaceResponse.contents[0].hours.Exists(x => x.classID == classResponse.contents[classIndex].classID)) // checks if this class was already registered on the server
                                {
                                    // if the class was alread redistered on the server, this will add to the "to edit" list instead of the "to add". This way, it will not create multiple instances of the same class on the same workspace
                                    if (workspaceResponse.contents[0].hours[workspaceResponse.contents[0].hours.FindIndex(x => x.classID == classResponse.contents[classIndex].classID)].totalHours != 300) // checks if the hours total on server is different than the default 300
                                    {
                                        classesToEdit toEdit = new classesToEdit();
                                        toEdit.classID    = classResponse.contents[classIndex].classID;
                                        toEdit.totalHours = 300;
                                    }
                                }
                                else
                                {
                                    // add the class to the "to add" list
                                    classesToAdd toAdd = new classesToAdd();
                                    toAdd.classID    = classResponse.contents[classIndex].classID;
                                    toAdd.totalHours = 300;
                                    hoursControl.classesToAdd.Add(toAdd);
                                }
                            }
                            else
                            {
                                // add the class to the "to add" list
                                classesToAdd toAdd = new classesToAdd();
                                toAdd.classID    = classResponse.contents[classIndex].classID;
                                toAdd.totalHours = 300;
                                hoursControl.classesToAdd.Add(toAdd);
                            }
                        }
                    }
                }
                else
                {
                    // new workspace
                    classesToAdd toAdd = new classesToAdd();
                    toAdd.classID    = classResponse.contents[classIndex].classID;
                    toAdd.totalHours = 300;
                    hoursControl.classesToAdd.Add(toAdd);
                }
                hoursDataGridView.Rows.Add(row);
            }
        }