예제 #1
0
        /// <summary>
        /// Saves the current selection
        /// </summary>
        private bool PerformSave()
        {
            errProv.Clear();

            bool savedSuccessfully = false;

            List <ValidatableIntStringPair> exceptionItems = new List <ValidatableIntStringPair>();

            TimeEntry savedItem = null;

            //validate
            List <ValidationMessage> errors = OperationsReadWrite.SaveTimeEntry(
                new ValidatableParameter <Guid> {
                Value = m_lastTimeEntry == null ? Guid.Empty : m_lastTimeEntry.TimeEntryId, Source = null
            },
                new ValidatableParameter <Guid> {
                Value = m_currUser.UserId, Source = null
            },
                new ValidatableParameter <Guid> {
                Value = cbxProjects.SelectedItem == null ? Guid.Empty : ((Project)cbxProjects.SelectedItem).Id, Source = cbxProjects
            },
                new ValidatableParameter <Guid> {
                Value = cbxTasks.SelectedItem == null ? Guid.Empty : ((Task)cbxTasks.SelectedItem).Id, Source = cbxTasks
            },
                new ValidatableParameter <string> {
                Value = txtDetails.Text, Source = txtDetails
            },
                new ValidatableParameter <DateTime?> {
                Value = dtpStart.Value, Source = dtpStart
            },
                new ValidatableParameter <DateTime?> {
                Value = dtpEnd.Value, Source = dtpEnd
            },
                new ValidatableParameter <int> {
                Value = Convert.ToInt32(nudExc1.Value), Source = nudExc1
            },
                new ValidatableParameter <string> {
                Value = txtExc1.Text, Source = txtExc1
            },
                out savedItem);

            if (savedItem != null)
            {
                m_lastTimeEntry = savedItem;
            }

            if (errors.Count > 0)
            {
                //set up the list of controls that may have errors associated
                List <Control> validatableControls = new List <Control>();
                validatableControls.Add(cbxProjects);
                validatableControls.Add(cbxTasks);
                validatableControls.Add(dtpStart);
                validatableControls.Add(dtpEnd);
                validatableControls.Add(nudExc1);
                validatableControls.Add(txtExc1);

                //hook up errors to controls
                foreach (ValidationMessage currError in errors)
                {
                    if (currError.Source != null)
                    {
                        bool found     = false;
                        int  currIndex = 0;
                        while (!found && currIndex < validatableControls.Count)
                        {
                            if (validatableControls[currIndex] == currError.Source)
                            {
                                found = true;
                                errProv.SetError(validatableControls[currIndex], currError.MessageText);
                            }
                            currIndex++;
                        }

                        if (!found)
                        {
                            errProv.SetError(cbxProjects, currError.MessageText);
                        }
                    }
                    else
                    {
                        errProv.SetError(cbxProjects, currError.MessageText);
                    }
                }
            }
            else
            {
                //indicate that save was clicked
                SaveClicked = true;
                SetupGrid();

                //indicate it saved OK
                savedSuccessfully = true;
            }

            return(savedSuccessfully);
        }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            errProv.Clear();

            List <ValidatableIntStringPair> exceptionItems = new List <ValidatableIntStringPair>();

            TimeEntry savedItem = null;

            //validate
            List <ValidationMessage> errors = OperationsReadWrite.SaveTimeEntry(
                new ValidatableParameter <Guid> {
                Value = m_lastTimeEntry == null ? Guid.Empty : m_lastTimeEntry.TimeEntryId, Source = null
            },
                new ValidatableParameter <Guid> {
                Value = m_currUser.UserId, Source = null
            },
                new ValidatableParameter <Guid> {
                Value = m_lastTimeEntry.ProjectId, Source = lblProjectVal
            },
                new ValidatableParameter <Guid> {
                Value = m_lastTimeEntry.TaskId, Source = lblTaskVal
            },
                new ValidatableParameter <string> {
                Value = txtDetails.Text, Source = txtDetails
            },
                new ValidatableParameter <DateTime?> {
                Value = dtpStart.Value, Source = dtpStart
            },
                new ValidatableParameter <DateTime?> {
                Value = dtpEnd.Value, Source = dtpEnd
            },
                new ValidatableParameter <int> {
                Value = Convert.ToInt32(nudExc1.Value), Source = nudExc1
            },
                new ValidatableParameter <string> {
                Value = txtExc1.Text, Source = txtExc1
            },
                out savedItem);

            if (errors.Count > 0)
            {
                //set up the list of controls that may have errors associated
                List <Control> validatableControls = new List <Control>();
                validatableControls.Add(lblProjectVal);
                validatableControls.Add(lblTaskVal);
                validatableControls.Add(dtpStart);
                validatableControls.Add(dtpEnd);
                validatableControls.Add(nudExc1);
                validatableControls.Add(txtExc1);

                //hook up errors to controls
                foreach (ValidationMessage currError in errors)
                {
                    if (currError.Source != null)
                    {
                        bool found     = false;
                        int  currIndex = 0;
                        while (!found && currIndex < validatableControls.Count)
                        {
                            if (validatableControls[currIndex] == currError.Source)
                            {
                                found = true;
                                errProv.SetError(validatableControls[currIndex], currError.MessageText);
                            }
                            currIndex++;
                        }

                        if (!found)
                        {
                            errProv.SetError(btnSave, currError.MessageText);
                        }
                    }
                    else
                    {
                        errProv.SetError(btnSave, currError.MessageText);
                    }
                }
            }
            else
            {
                SavedEntry   = savedItem;
                WasConfirmed = true;
                this.Close();
            }
        }