public void Test_SetCellTemplate()
        {
            //---------------Set up test pack-------------------
            DataGridViewNumericUpDownColumn dtColumn = new DataGridViewNumericUpDownColumn();
            NumericUpDownCell NumericUpDownCell      = new NumericUpDownCell();

            //---------------Assert Precondition----------------
            Assert.AreNotSame(NumericUpDownCell, dtColumn.CellTemplate);
            //---------------Execute Test ----------------------
            dtColumn.CellTemplate = NumericUpDownCell;

            //---------------Test Result -----------------------
            Assert.AreSame(NumericUpDownCell, dtColumn.CellTemplate);
        }
        public void TestNumericUpDownCell_HasCorrectSettings()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            NumericUpDownCell numericUpDownCell = new NumericUpDownCell();

            //---------------Test Result -----------------------
            Assert.AreEqual("0.00", numericUpDownCell.Style.Format);
            Assert.AreEqual(typeof(NumericUpDownEditingControl), numericUpDownCell.EditType);
            Assert.AreEqual(typeof(Decimal), numericUpDownCell.ValueType);
            Assert.IsInstanceOf(typeof(Decimal), numericUpDownCell.DefaultNewRowValue);

            Decimal newRowValue = (Decimal)numericUpDownCell.DefaultNewRowValue;

            Assert.AreEqual(0D, newRowValue);
        }
Example #3
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);
            }
        }
Example #4
0
        private void WorkspaceConfigForm_Load(object sender, EventArgs e)
        {
            DataGridViewTextBoxColumn className = new DataGridViewTextBoxColumn();

            className.Name       = "className";
            className.HeaderText = AdministrationMenuStrings.ClassName;
            className.ReadOnly   = true;
            hoursDataGridView.Columns.Add(className);

            NumericUpDownColumn column = new NumericUpDownColumn();

            column.Name       = "totalHours";
            column.HeaderText = WorkspaceConfigFormStrings.TotalHours;
            column.ReadOnly   = false;
            hoursDataGridView.Columns.Add(column);

            DataGridViewButtonColumn removeBTN = new DataGridViewButtonColumn();

            removeBTN.HeaderText = "";
            removeBTN.Name       = "removeBTN";
            hoursDataGridView.Columns.Add(removeBTN);

            using (loadingForm loading = new loadingForm(RequestAllData))
            {
                loading.ShowDialog();
            }

            try
            {
                classResponse     = JsonConvert.DeserializeObject <classServerResponse>(classRequest);
                allWorkspacesList = JsonConvert.DeserializeObject <workspacesServerResponse>(allWorkspacesRequest);

                if (classResponse.status)
                {
                    if (classResponse.contents.Count < 1)
                    {
                        MessageBox.Show(WorkspaceConfigFormStrings.ClassesNotFound, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                    }
                    else
                    {
                        if (allWorkspacesList.status)
                        {
                            foreach (classContent Class in classResponse.contents)
                            {
                                classesCB.Items.Add(Class.className);
                            }
                        }
                        else
                        {
                            MessageBox.Show(GlobalStrings.Error + ": " + allWorkspacesList.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Close();
                        }
                    }
                }
                else
                {
                    MessageBox.Show(GlobalStrings.Error + ": " + classResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Response: " + classResponse + "\n" +
                                "Request:" + classRequest + "\n" +
                                "Error: " + ex.Message + "\n" +
                                "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
            }

            if (sentWorkspaceID != 0)
            {
                using (loadingForm loading = new loadingForm(RequestWorkspaceData))
                {
                    loading.ShowDialog();
                }

                try
                {
                    workspaceResponse = JsonConvert.DeserializeObject <workspacesServerResponse>(workspaceRequest);

                    if (workspaceResponse.status)
                    {
                        if (workspaceResponse.contents.Count != 1)
                        {
                            MessageBox.Show(GlobalStrings.GotMoreThanOneEntry, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            Close();
                        }
                        else
                        {
                            this.Text = String.Format(WorkspaceConfigFormStrings.FormTitle, workspaceResponse.contents[0].workspaceName);
                            WorkspaceNameTOPBox.Text = workspaceResponse.contents[0].workspaceName;
                            workspaceNameTB.Text     = workspaceResponse.contents[0].workspaceName;

                            readCheck.Checked  = workspaceResponse.contents[0].read;
                            writeCheck.Checked = workspaceResponse.contents[0].write;


                            if (workspaceResponse.contents[0].hours != null)
                            {
                                foreach (hoursContent item in workspaceResponse.contents[0].hours)
                                {
                                    DataGridViewRow         row    = new DataGridViewRow();
                                    DataGridViewTextBoxCell TBcell = new DataGridViewTextBoxCell();
                                    TBcell.Value = classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className;
                                    classesCB.Items.Remove(classResponse.contents[classResponse.contents.FindIndex(x => x.classID == item.classID)].className);
                                    NumericUpDownCell NumUpDownCell = new NumericUpDownCell();
                                    NumUpDownCell.Value = item.totalHours;
                                    DataGridViewButtonCell BTNCell = new DataGridViewButtonCell();
                                    BTNCell.Tag   = classResponse.contents.FindIndex(x => x.classID == item.classID);
                                    BTNCell.Value = WorkspaceConfigFormStrings.RemoveBTN;

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

                                    hoursDataGridView.Rows.Add(row);
                                }
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(GlobalStrings.Error + ": " + workspaceResponse.errors, GlobalStrings.Error, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Workspace Response: " + workspaceResponse + "\n" +
                                    "Workspace Request:" + workspaceRequest + "\n" +
                                    "Error: " + ex.Message + "\n" +
                                    "Stack: " + ex.StackTrace, "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Close();
                }
            }
            else
            {
                this.Text = WorkspaceConfigFormStrings.NewWorkspaceTitle;
                WorkspaceNameTOPBox.Text = WorkspaceConfigFormStrings.NewWorkspace;
            }
        }