public void TestMasterRecordCRUD() { MasterReportDto dto = new MasterReportDto(MasterReportDto.TransientId, new List<MasterQuestionnaireDto>(), "", DateTime.Now, new List<Pair<PageElementType, string>>(), ""); MasterReportDto persDto = FormRegistry.MasterReportDao.Create(dto); Assert.AreNotEqual(0, persDto.MasterRptId); _createdMasterReports.Add(persDto.MasterRptId); List<MasterReportDto> list = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad"); Assert.IsNotNull(list); Assert.Less(0, list.Count); MasterReportDto persDto2 = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto.MasterRptId; }); Assert.IsNotNull(persDto2); Assert.IsFalse(dto.Equals(persDto2, false)); MasterReport mr = new MasterReport(persDto); MasterQuestionnaireDto mq = new MasterQuestionnaireDto(_currentQuestionnaire.QuestionnaireId, _currentQuestionnaire.QidTitle, _currentCampaign.CampaignCode, DateTime.Today, DateTime.Today, "*****@*****.**"); mr.AddSchQuestionnaire(mq); mr.Save(); MasterReport mr2 = new MasterReport(persDto2); //Assert.IsTrue(mr2.ValidateMaster()); List<MasterQuestionnaireDto> mqs = MasterReport.GetMasterQuestions(mr2.Dto.MasterRptId); if(mqs.Count > 0) Assert.Less(0 , mqs.Count); else Assert.IsEmpty(mqs); if(mqs.Count > 0) Assert.IsTrue(mqs.Exists(delegate(MasterQuestionnaireDto cur) { return cur.QId == mq.QId; })); else Assert.IsFalse(mqs.Exists(delegate(MasterQuestionnaireDto cur) { return cur.QId == mq.QId; })); FormRegistry.QuestionnaireDao.Delete(mq.QId, TestUser); _createdQuestionnaires.Remove(mq.QId); mqs = MasterReport.GetMasterQuestions(mr2.Dto.MasterRptId); Assert.IsNotNull(mqs); Assert.AreEqual(0, mqs.Count); FormRegistry.MasterReportDao.DeleteMasterReport(persDto.MasterRptId); _createdMasterReports.Remove(persDto.MasterRptId); list = FormRegistry.MasterReportDao.GetMasterReports(null, null, null, null, "ad"); Assert.IsNotNull(list); persDto = list.Find(delegate(MasterReportDto cur) { return cur.MasterRptId == persDto2.MasterRptId; }); Assert.IsNull(persDto); }
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 }
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 void saveMasterNow() { mrd = mrd_local; bool isValid = true; lbl1.Text = string.Empty; lbl2.Text = string.Empty; lbl0.Text = string.Empty; lbl4.Text = string.Empty; if ((!savemasterreport.Checked) && (!extractnow.Checked)) { isValid = false; lbl0.ForeColor = Color.Red; lbl0.Text = "Either Save Master Report or Extact Report Now should be selected !"; } #region master name cnt be null if (isValid) if ((savemasterreport.Checked) && (mName.Text.Trim() == string.Empty)) { isValid = false; lbl0.ForeColor = Color.Red; string msg = string.IsNullOrEmpty(mName.Text.Trim()) ? "Master Name" : ""; lbl0.Text = string.Format("<b>{0} cannot be empty</b>", msg.TrimStart(',')); } else if ((savemasterreport.Checked) && (mName.Text.Trim() != string.Empty) && content == "new") { #region Validation for Same Master report name Hashtable h_params = new Hashtable(); h_params.Add("MasterName", mName.Text.Trim()); DataTable MasterReportNames = DB.execProc("select_masterreportname", h_params); if (MasterReportNames.Rows.Count != 0) { isValid = false; lbl0.ForeColor = Color.Red; lbl0.Text = string.Format("<b>Master Report Name already Exists</b>"); } #endregion } #endregion if (isValid) if (dg1.Items.Count < 1) { isValid = false; lbl1.ForeColor = Color.Red; lbl1.Text = "Please add a Questionnaire. "; } if (isValid) { foreach (DataGridItem dgm in dtl1.Items) { string updVal = ((TextBox)dgm.Cells[2].Controls[1]).Text.Trim(); if (updVal == "") { isValid = false; break; } } if (!isValid) { lbl2.ForeColor = Color.Red; lbl2.Text = "Captions cannot be Empty !"; } } if (isValid) if ((extractnow.Checked) && ((mFrom.Text == "") || (mUntil.Text == ""))) { isValid = false; lbl4.ForeColor = Color.Red; string msg = string.IsNullOrEmpty(mFrom.Text.Trim()) ? "From Date" : ""; msg = string.IsNullOrEmpty(mUntil.Text.Trim()) ? msg + ",Until Date" : msg; lbl4.Text = string.Format("<b>{0} cannot be empty</b>", msg.TrimStart(',')); } if ((isValid) && (extractnow.Checked)) isValid = validateDate(mFrom.Text, mUntil.Text); if (isValid) { if (savemasterreport.Checked) { List<Pair<PageElementType, string>> headings = new List<Pair<PageElementType, string>>(); foreach (DataGridItem dgm in dtl1.Items) { string updVal = ((TextBox)dgm.Cells[2].Controls[1]).Text.Trim(); if (updVal == "") updVal = dgm.Cells[1].Text; //val = string.Format("{1}:{2}|{0}", val, dgm.Cells[0].Text, updVal); string PageElement = Migration.ConvertElement(dgm.Cells[1].Text); headings.Add(new Pair<PageElementType, string>(Migration.Convert(PageElement), updVal)); } if (mrd != null) { Hashtable h_params = new Hashtable(); DateTime frm, to; bool frmParseSuccess = DateTime.TryParse(mFrom.Text, out frm); bool untilParseSuccess = DateTime.TryParse(mUntil.Text, out to); //TODO Susann change to also recognize responses received after (milliseconds) 23:59:59,000 //to = to.AddHours(23).AddMinutes(59).AddSeconds(59); to = to.AddDays(1d); mrd.Dto.MasterName = mName.Text.TrimStart(' ').TrimEnd(' ').ToString(); //mrd.Dto.ScheduleMode = ScheduleMode.None;// h_params.Add("schedule_mode", ""); //if (DateTime.TryParse(mFrom.Text, out frm)) if (frmParseSuccess) mrd.Dto.From = frm;//h_params.Add("from", frm); else mrd.Dto.From = null; //checked for duplicate code because to was overwritten here again //if (DateTime.TryParse(mUntil.Text, out to)) if (untilParseSuccess) //TODO Susann to change to also recognize responses received after (milliseconds) 23:59:59,000 //TODO Susann check if overwriting ever worked or did result in wrong date anyway mrd.Dto.To = to;// h_params.Add("to", to); else mrd.Dto.To = null; //h_params.Add("schedule_day", 7); mrd.Dto.MElementHeading = headings;// SetHeadings(val); mrd.Save(); for (int i = 0; i < dg1.Items.Count; i++) { FormRegistry.MasterReportDao.AddQuestionnaireToReport(mrd.Dto.MasterRptId, Convert.ToInt32(dg1.Items[i].Cells[1].Text)); } } } if (extractnow.Checked) { if (!mrd.ValidateMaster()) { #region convert dates DateTime from = Convert.ToDateTime(mFrom.Text); DateTime until = Convert.ToDateTime(mUntil.Text); //TODO Susann to change to also recognize responses received after (milliseconds) 23:59:59,000 //until = until.AddHours(23).AddMinutes(59).AddSeconds(59); until = until.AddDays(1d); #endregion List<Pair<PageElementType, string>> headings = new List<Pair<PageElementType, string>>(); foreach (DataGridItem dgm in dtl1.Items) { string updVal = ((TextBox)dgm.Cells[2].Controls[1]).Text; if (updVal == "") updVal = dgm.Cells[1].Text; //val = string.Format("{1}:{2}|{0}", val, dgm.Cells[0].Text, updVal); string PageElement = Migration.ConvertElement(dgm.Cells[1].Text); headings.Add(new Pair<PageElementType, string>(Migration.Convert(PageElement), updVal)); } mrd.Dto.MElementHeading = headings;// SetHeadings(val); mrd.Dto.From = from; mrd.Dto.To = until; string QuestionnaireID = ""; for (int i = 0; i < dg1.Items.Count; i++) { QuestionnaireID = QuestionnaireID + dg1.Items[i].Cells[1].Text + ","; } _qid = QuestionnaireID.Substring(0, (QuestionnaireID.Length - 1)); Server.Transfer("process_response_email.aspx"); // } } else SendFailuremail(); } Response.Redirect("index_MasterReport.aspx"); //else //{ // Response.Redirect("index_MasterReport.aspx"); //} } else { //isValid = false; //lbl1.ForeColor = Color.Red; //lbl1.Text = "unable to find master report"; } }
private void saveMasterSch() { mrd = mrd_local; #region custom validate bool isValid = true; bool isweekly = false; #region master name cnt be null if (mName.Text == "") { isValid = false; lbl0.ForeColor = Color.Red; lbl0.Text = "<b>Master Name cannot be empty</b>"; } #endregion #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 schedule_recipient = ""; 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 //string schedule_id = ""; if (isValid) { if (schedule_recipient.Length == 0) { schedule_recipient = permss.EmailAddress; } Hashtable h_params = new Hashtable(); if (mrd != null) { //h_params.Add("master_id", ).Dto.MasterRptId); mrd.Dto.MasterName = mName.Text.TrimStart(' ').TrimEnd(' ').ToString(); //update of recipient is only allowed for admins if (permss.UserType == UserType.Admin) { mrd.Dto.RecipientEmail = schedule_recipient; } //} mrd.Dto.ScheduleMode = Migration.ConvertToScheduleMode(schedule_mode.SelectedItem.Value); if (isweekly) { int scheduleDay = 0; if (int.TryParse(schedule_day.SelectedItem.Value, out scheduleDay)) { mrd.Dto.ScheduleDay = scheduleDay; } } mrd.Save(); Response.Redirect("index_scheduled_Masterexports.aspx"); } } }