Ejemplo n.º 1
0
        public void TestAdd3QuesitonnairesAndGetBack()
        {

                QuestionnaireDto q1 = SetupQuestionnaireForMasterReport(Q1Elements);
                QuestionnaireDto q2 = SetupQuestionnaireForMasterReport(Q1Elements);
                QuestionnaireDto q3 = SetupQuestionnaireForMasterReport(Q1Elements);
                MasterReport mrp = new MasterReport(TestUser);

                //create report
                mrp.CreateMasterReport("master name", TestUser, Migration.Convert(ScheduleMode.Daily), 0, DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1), true, q1.QuestionnaireId);


                FormRegistry.MasterReportDao.AddQuestionnaireToReport(mrp.Dto.MasterRptId, q1.QuestionnaireId);

                Assert.IsFalse(mrp.ValidateMaster());
                mrp.Save();
                Assert.Less(0, mrp.Dto.MasterRptId);
                _createdMasterReports.Add(mrp.Dto.MasterRptId);

                //check read
                List<MasterReportDto> list = FormRegistry.MasterReportDao.GetMasterReports(true, 0, null, null, "ad");
                Assert.IsNotNull(list);
                MasterReportDto mine = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == mrp.Dto.MasterRptId; });
                Assert.IsNotNull(mine);
                MasterReport mrpSel = new MasterReport(mine);
                mrpSel.Dto.MasterQ = MasterReport.GetMasterQuestions(mrpSel.Dto.MasterRptId);
                Assert.IsNotNull(mrpSel.Dto.MasterQ);
                if (mrpSel.Dto.MasterQ.Count > 0)
                    Assert.AreEqual(1, mrpSel.Dto.MasterQ.Count);
                else
                    Assert.AreEqual(0, mrpSel.Dto.MasterQ.Count);


                if (mrpSel.Dto.MasterQ.Count > 0)
                    Assert.AreEqual(q1.QuestionnaireId, mrpSel.Dto.MasterQ[0].QId);
                else
                    Assert.AreNotEqual(q1.QuestionnaireId, mrpSel.Dto.MasterQ[0].QId);

                //add others
                //mrpSel.AddSchQuestionaire    

        }
Ejemplo n.º 2
0
        public void TestSelectAllPermittedUsersForMasterreport()
        {             
            QuestionnaireDto q1 = SetupQuestionnaireForMasterReport(Q1Elements);
            QuestionnaireDto q2 = SetupQuestionnaireForMasterReport(Q1Elements);
            QuestionnaireDto q3 = SetupQuestionnaireForMasterReport(Q1Elements);
            MasterReport mrp = new MasterReport(TestUser);

            //create report
            mrp.CreateMasterReport("master name", TestUser, Migration.Convert(ScheduleMode.Daily), 0, DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1), true, q1.QuestionnaireId);
            FormRegistry.MasterReportDao.AddQuestionnaireToReport(mrp.Dto.MasterRptId, q1.QuestionnaireId);
            mrp.Save();
            _createdMasterReports.Add(mrp.Dto.MasterRptId);
            List<MasterReportDto> list = FormRegistry.MasterReportDao.GetMasterReports(true, 0, null, null, "ad");
            MasterReportDto mine = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == mrp.Dto.MasterRptId; });
            
            string email = "*****@*****.**" + GetNewStamp();
            string login = "******" + GetNewStamp();
            string password = "******";
            bool isAdmin = false;
            UserType type = UserType.CountryUserWithDataAccess;
            UserCompanyType companytype = UserCompanyType.HPI;
            List<CountryDto> listOfPermittedCountriesQuestionnaire = CommonFacade.GetListOfCountries("'uk'");
            int Company_Code = 0;
            UserDto user = new UserDto(email, isAdmin, password, login, type, listOfPermittedCountriesQuestionnaire, null, Company_Code, companytype);
            List<UserDto> listOfUsers = AdminRegistry.UserDao.SelectAllPermittedUsersPermittedForMasterreport(mine.MasterRptId);
            Assert.IsTrue(listOfUsers.Find(u => u.Login == login) == null);

            Assert.IsTrue(AdminRegistry.UserDao.CreateOrUpdate(user, "insert", null, null));
            foreach (CountryDto country in listOfPermittedCountriesQuestionnaire)
            {
                UserFacade.CreateOrUpdate(user, "country", "q", country.Country);
            }

            UserDto sel = AdminRegistry.UserDao.GetByLogin(login);
            Assert.IsTrue(listOfUsers.Find(u => u.Equals(sel)) != null);
            Assert.IsTrue(AdminRegistry.UserDao.Delete(user));            
            
        }
        private bool CrtMasterNow()
        {
            bool isValid = true;

            mrd = new MasterReport(permss.EmailAddress);
            int qid;
            int.TryParse(questionnaires_list.SelectedValue, out qid);

            mrd.CreateMasterReport("", permss.EmailAddress, "", 7, DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1), exp, qid);
            mrd_local = mrd;
            return isValid;
        }
        private bool CrtMasterSch()
        {
            bool isValid = true;
            if (mName.Text != String.Empty && 
                questionnaires_list.SelectedIndex > 0 && 
                (dd_possible_users.SelectedIndex > 0 || tb_recipient.Text != String.Empty))
            {
                #region custom validate

                bool isweekly = false;
                string schedule_recipient = String.Empty;



                #region check if a schedule mode is selected
                if (schedule_mode.SelectedIndex == 0)
                {
                    isValid = isValid & false;
                    error_mode.Visible = true;
                    error_day.Visible = false;
                }
                else
                {
                    error_mode.Visible = false;

                    if (schedule_mode.SelectedItem.Value == "w")
                    {
                        isweekly = true;
                        if (schedule_day.SelectedIndex == 0)
                        {
                            isValid = isValid & false;
                            error_day.Visible = true;
                        }
                        else
                        {
                            error_day.Visible = false;
                        }
                    }
                }
                #endregion

                #region check if schedule_recipient is correct if used

                string tb_recipient_input = tb_recipient.Text.Trim();

                if (permss.UserType == UserType.Admin)
                {
                    if (tb_recipient_input.Length != 0 && 
                        dd_possible_users.SelectedIndex != 0)
                    {
                        //which recipient has to be set??
                        isValid = isValid & false;
                        lb_email_error_tworecipients.Visible = true;
                    }
                    else
                    {
                        if (tb_recipient_input.Length != 0)
                        {
                            //validate that recipient(s) is/are HP/EDS-email_address(es)
                            if (!Check_email_entries(tb_recipient_input))
                            //if (!tb_recipient_input.EndsWith("@hp.com"))
                            {
                                //show error
                                isValid = isValid & false;
                                //lb_email_error_nonhp.Visible = true;
                            }
                            else
                            {
                                //check if user is already an RFG user, but doesn't have the permission...
                                ListItem found_user = dd_possible_users.Items.FindByText(tb_recipient_input);
                                if (found_user != null)
                                {
                                    //everything is almost fine but exchange the values...
                                    schedule_recipient = tb_recipient_input;
                                    tb_recipient.Text = "";
                                    dd_possible_users.SelectedItem.Selected = false;
                                    found_user.Selected = true;
                                }
                                else
                                {
                                    //ask database
                                    Hashtable h_params = new Hashtable();
                                    h_params.Add("useremail", tb_recipient_input);

                                    DataTable existing_user = DB.execProc("select_user", h_params);
                                    if (existing_user.Rows.Count != 0)
                                    {
                                        //user doesn't have the correct permissions for this questionnaire
                                        isValid = isValid & false;
                                        lb_email_error_nopermission.Visible = true;
                                    }
                                    else
                                    {
                                        //user doesn't exist
                                        schedule_recipient = tb_recipient_input;
                                    }
                                }
                            }
                        }
                        if (dd_possible_users.SelectedIndex != 0)
                        {
                            schedule_recipient = dd_possible_users.SelectedItem.Text;
                        }
                    }
                }
                #endregion

                #endregion

                if (isValid)
                {
                    MasterReport master = new MasterReport(permss.EmailAddress);
                    mName.Text = mName.Text.TrimStart(' ').TrimEnd(' ');
                    int scday = 7;
                    scday = isweekly ? int.Parse(schedule_day.SelectedItem.Value) : scday;
                    int qid;
                    int.TryParse(questionnaires_list.SelectedValue, out qid);
                    DateTime frm = new DateTime(), to = new DateTime();
                    if (!exp)
                    {
                        DateTime.TryParse(mFrom.Text, out frm);
                        DateTime.TryParse(mUntil.Text, out to);
                        //TODO Susann to change to also recognize responses received after (milliseconds) 23:59:59,000 
                        //to.AddHours(23).AddMinutes(59).AddSeconds(59);
                        to.AddDays(1d);
                    }
                    master.CreateMasterReport(mName.Text, schedule_recipient, schedule_mode.SelectedItem.Value, scday, DateTime.Today.AddDays(-1), DateTime.Today.AddDays(1), exp, qid);

                }


            }
            else
            {
                isValid = false;
                string errMsg = "Please enter ";
                errMsg = mName.Text != "" ? errMsg : errMsg + "Master Name ";
                errMsg = questionnaires_list.SelectedIndex > 0 ? errMsg : errMsg + "select a Questionnaire ";
                errMsg = (dd_possible_users.SelectedIndex > 0 || tb_recipient.Text != "") ? errMsg : errMsg + "enter recipient email";
                lbl1.ForeColor = Color.Red;
                lbl1.Text = "<b>" + errMsg + "</b>";
            }
            mrd_local = mrd;
            return isValid;
        }