Ejemplo n.º 1
0
        private void SavePage()
        {
            DataAccess oDataAccess = new DataAccess();
            FQDNN_Form oForm = oDataAccess.GetFullForm(FormID);

            FQDNN_FormPage oCurrentPage = null;

            foreach (FQDNN_FormPage oFormPage in oForm.FQDNN_FormPage)
            {
                if (oFormPage.PageNumber == PageNumber)
                {
                    oCurrentPage = oFormPage;
                    break;
                }
            }

            if (oCurrentPage != null)
            {
                FQDNN_FormFiling oFormFiling = GetCurrentFormFilingFromViewState(oForm);
                if (oFormFiling == null)
                {
                    CommonLogic oCommonLogic = new CommonLogic();
                    oFormFiling = oDataAccess.InsertNewFiling(Request.Browser.Browser, oCommonLogic.GetUserIPAddress(), false, Request.Browser.Platform, UserId, oForm.FormID);
                }

                if (oFormFiling != null)
                {
                    //loop through each control on page and save the result.
                    List<FQDNN_FormFilingRecord> oNewFilingRecords = new List<FQDNN_FormFilingRecord>();
                    foreach (FQDNN_FormControl oFormControl in oCurrentPage.FQDNN_FormControl)
                    {
                        System.Web.UI.Control control = this.FindControl(oFormControl.GetControlID());
                        if (control != null)
                        {
                            Type type = control.GetType();

                            FQDNN_FormFilingRecord oNewFilingRecord = new FQDNN_FormFilingRecord();
                            oNewFilingRecord.FormControlID = oFormControl.FormControlID;
                            oNewFilingRecord.FormPageID = oCurrentPage.FormPageID;

                            PropertyInfo valuePropery = type.GetProperty(oFormControl.FQDNN_ControlDefinition.ValuePropertyName);
                            if (valuePropery != null)
                            {
                                oNewFilingRecord.Value = valuePropery.GetValue(control, null).ToString();
                            }
                            oNewFilingRecords.Add(oNewFilingRecord);
                        }
                    }
                    oDataAccess.InsertFilingRecords(oNewFilingRecords, oFormFiling.FormFilingID);
                }
            }
        }
        //check settings and return whether the current user is allowed to file the form
        public bool UserCanFileForm(UserInfo User, FQDNN_Form Form)
        {
            CommonLogic oCommonLogic = new CommonLogic();
            List<FQDNN_FormSetting> Settings = Form.FQDNN_FormSetting.ToList();
            FormSettings oFormSettings = new FormSettings();
            bool bFormAccessIsFiltered = oFormSettings.GetAccessIsFiltered(Settings);
            bool result = !bFormAccessIsFiltered;

            string listOfUsersAbleToFileForm = oFormSettings.GetListOfUsersAbleToFileForm(Settings);
            string listOfUserRolesAbleToFileForm = oFormSettings.GetListOfUserRolesAbleToFileForm(Settings);
            string listOfUsersNotAbleToFileForm = oFormSettings.GetListOfUsersNotAbleToFileForm(Settings);
            string listOfUserRolesNotAbleToFileForm = oFormSettings.GetListOfUserRolesNotAbleToFileForm(Settings);

            if (bFormAccessIsFiltered)
            {
                //if there are any allow rules then user is not allowed by default and then check if the user matches the rules.
                if (!String.IsNullOrEmpty(listOfUsersAbleToFileForm) || !String.IsNullOrEmpty(listOfUserRolesAbleToFileForm))
                {
                    result = false;
                    if (User != null)
                    {
                        if (!String.IsNullOrEmpty(listOfUsersAbleToFileForm))
                        {
                            if (oCommonLogic.IntIsInList(User.UserID, listOfUsersAbleToFileForm))
                            {
                                result = true;
                            }
                        }
                        if (!String.IsNullOrEmpty(listOfUserRolesAbleToFileForm))
                        {
                            if (oCommonLogic.UserIsInListOfRoles(User, listOfUserRolesAbleToFileForm))
                            {
                                result = true;
                            }
                        }
                    }
                }

                if (result == false)
                {
                    return false;
                }

                if (!String.IsNullOrEmpty(listOfUsersNotAbleToFileForm) || !String.IsNullOrEmpty(listOfUserRolesNotAbleToFileForm))
                {
                    if (User != null)
                    {
                        if (!String.IsNullOrEmpty(listOfUsersNotAbleToFileForm))
                        {
                            if (oCommonLogic.IntIsInList(User.UserID, listOfUsersNotAbleToFileForm))
                            {
                                result = false;
                            }
                        }
                        if (!String.IsNullOrEmpty(listOfUserRolesNotAbleToFileForm))
                        {
                            if (oCommonLogic.UserIsInListOfRoles(User, listOfUserRolesNotAbleToFileForm))
                            {
                                result = false;
                            }
                        }
                    }
                }
            }

            bool bUserCanFileMultipleTimes = oFormSettings.GetUserCanFileMultipleTimes(Settings);
            if (!bUserCanFileMultipleTimes)
            {
                DataAccess oDataAccess = new DataAccess();

                FQDNN_FormFiling oPreviousFormFiling = oDataAccess.GetLastFiling(User.UserID, oCommonLogic.GetUserIPAddress(), Form.FormID);

                if (oPreviousFormFiling != null)
                {
                    result = false;

                    bool bUserCanResumeFiling = oFormSettings.GetUserCanResumeFiling(Settings);
                    int iUserCanResumeInHours = oFormSettings.GetUserCanResumeInHours(Settings);

                    if (bUserCanResumeFiling)
                    {
                        DateTime Now = DateTime.Now;

                        if (Now > oPreviousFormFiling.DateCreated)
                        {
                            int hoursSincePreviousFiling = (Now - oPreviousFormFiling.DateCreated).Hours;
                            if (iUserCanResumeInHours > hoursSincePreviousFiling)
                            {
                                result = true;
                            }
                        }
                    }
                }
            }

            return result;
        }