Example #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    

        }
        private void SendNow(MasterReport mrd)
        {

            if (mrd.ValidateMaster())
            {
                mrd.Dto.MasterQ = MasterReport.GetMasterQuestions(mrd.Dto.MasterRptId);
                Session["IsMasterReport"] = true;
                this.Response.Redirect("process_response_email.aspx");
            }
            else
            {
                Session.Remove("MasterSch");
                sndMsg.Text = string.Format("there is a configuration error for the below master report you should receive. Due to this error a report can not be generated.<br><span class=head>Please get in touch with {0} in order to fix the configuration error.", mrd.Dto.Creator);
            }
        
        }
Example #3
0
        private void SendNow(MasterReport mrd)
        {

            mrd.Dto.MasterQ = MasterReport.GetMasterQuestions(mrd.Dto.MasterRptId);
            if (!mrd.ValidateMaster())
            {
                List<MasterQuestionnaireDto> lst = new List<MasterQuestionnaireDto>();
                lst = FormRegistry.MasterReportDao.GetMasterQuestionnaires(mrd.Dto.MasterRptId);
                string Questionnaire_ID="";
                for (int i = 0; i < lst.Count; i++)
                {
                    Questionnaire_ID = Questionnaire_ID + lst[i].QId.ToString() + ",";
                }
                _qid = Questionnaire_ID.Substring(0, (Questionnaire_ID.Length - 1));
                DateTime from = Convert.ToDateTime(mFrom.Text);
                DateTime until = Convert.ToDateTime(mUntil.Text);
                //TODO Susann change to also recognize responses received after (milliseconds) 23:59:59,000
                //until = until.AddHours(23).AddMinutes(59).AddSeconds(59);
                until = until.AddDays(1d);
                mrd.Dto.From = from;
                mrd.Dto.To = until;

                //Fill the updated headings from Master Report
                string mstRptHeadings = FormRegistry.MasterReportDao.GetMasterElementHeadings(mrd.Dto.MasterRptId);
                if (!string.IsNullOrEmpty(mstRptHeadings))
                    mrd.SetHeadings(mstRptHeadings);

                Server.Transfer("process_response_email.aspx");
            }
            else
            {
                #region create and send email

                MailMessage msg = new MailMessage();

                //.NET 1.1: msg.BodyFormat = MailFormat.Html;
                msg.IsBodyHtml = true;

                //.NET 1.1: msg.From = email_from;
                msg.From = new MailAddress(utility.getParameter("email_sender"));

                //.NET 1.1: msg.To = report_params.permss_user;
                //MailAddressCollection to = msg.To;
                utility.set_Mail_address(ref msg, "to", mrd.Dto.Creator);
                //to.Add(report_params.permss_user);
                msg.Subject = String.Format("RFG - FAILURE - combined response file report for master report {0}", mrd.Dto.MasterName);


                #region building emails content (information about the responsefiles)

                string mail_text = @"
                                <style>
									body {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;} 
        							table {font-family:""Arial"";font-weight:normal;font-size:10pt;color:black;}
                                    p {font-family:""Arial"";font-weight:normal;color:black;margin-top: -5px}
        							b {font-family:""Arial"";font-weight:bold;color:black;margin-top: -5px}
        							H1 { font-family:""Arial"";font-weight:normal;font-size:14pt;color:black }
        							H2 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:maroon }
									H3 { font-family:""Arial"";font-weight:normal;font-size:10pt;color:darkgreen }
        							pre {font-family:""Arial Console"";font-size: .9em}
                                    .head{ font-family:""Arial"";font-weight:bold;font-size:10pt;color:red }
        							.marker {font-weight: bold; color: black;text-decoration: none;}
        							.version {color: gray;}
        							.error {margin-bottom: 10px;}
        							.expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
								</style>";



                mail_text = String.Format("{0}<span><p>Hello {1},<br><br>", mail_text, mrd.Dto.Creator);
                string txt = "there is a configuration error for the below master report you should receive. Due to this error a report can not be generated.<br><span class=head>Please get in touch with {1} in order to fix the configuration error.</span><br><br><table border=1>";
                mail_text = String.Format("{0}" + txt, mail_text, mrd.Dto.Creator.ToString());

                if (mrd.Dto.MasterRptId > 1)
                    mail_text = String.Format("{0}<tr><td width=100>Master Report Name:</td><td><b>{1}(mid = {2})</b> &nbsp;</td></tr>", mail_text, mrd.Dto.MasterName, mrd.Dto.MasterRptId.ToString());
                else
                    mail_text = String.Format("{0}<tr><td width=100>Master Report Name:</td><td><b>{1}{2}</b> &nbsp;</td></tr>", mail_text, mrd.Dto.MasterName, "");
                //}
                mail_text = String.Format("{0}<tr><td>from: </td><td><b>{1}</b></td></tr>", mail_text, mrd.Dto.From.ToString());
                mail_text = String.Format("{0}<tr><td>until: </td><td><b>{1}</b></td></tr>", mail_text, mrd.Dto.To.HasValue ? mrd.Dto.To.Value.AddDays(-1d).ToString() : mrd.Dto.To.ToString());
                mail_text = String.Format("{0}<tr><td>number of records<br>in response file: </td><td><b>{1}</b></td></tr><br>", mail_text, 0);

                string str = "";
                mrd.Dto.MasterQ.ForEach(delegate(MasterQuestionnaireDto mq)
                {
                    str = string.Format("{4}{0}-{1}({2}={3})<br>", mq.CName, mq.QName, "qid", mq.QId.ToString(), str);
                });
                mail_text = String.Format("{0}<tr><td>list of questionnaires/<br>processors contained<br>in this master report: </td><td><b>{1}</b></td></tr></table><br>", mail_text, str);

                mail_text = String.Format("{0}<br>Regards,<br>Your RFG-team</p></span>", mail_text);
                #endregion

                msg.Body = mail_text;

                //.NET 1.1: SmtpMail.Send(msg);
                SmtpClient smtp = new SmtpClient(utility.getParameter("smtp"));
                smtp.Send(msg);

                msg.Dispose();

                #endregion

            }
        }
        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";
            }
        }