public void scheduledexports_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e) 
		{
			System.Web.UI.WebControls.DataList dl_scheduledexports = (DataList)this.FindControl("scheduledexports_list");
			string master_id = dl_scheduledexports.DataKeys[e.Item.ItemIndex].ToString();
			scheduledexports = (DataTable)Session["scheduledMasterexports"];
			DataRow scheduledexport = scheduledexports.Rows.Find(master_id);
			
			if ((bool)scheduledexport["enabled"])
			{
				//string questionnaire_name = String.Format("{0}/{1} ({2})", scheduledexport["country_name"].ToString(), scheduledexport["language_name"].ToString(), scheduledexport["qid_title"].ToString());
				string schedule_day = scheduledexport["schedule_day"].ToString();
				if (schedule_day == "")
				{
					schedule_day = "7";
				}

				string command = e.CommandName;
				switch(command)
				{				
					case "edit":
                        //Session["schedule_id"] = schedule_id;
                        //Session["campaign_name"] = scheduledexport["campaign_code_FK"].ToString();
                        //Session["questionnaire_name"] = questionnaire_name;
                        //Session["country_FK"] = scheduledexport["country_FK"].ToString();
                        //Session["mode"] = scheduledexport["schedule_mode"].ToString();
                        //Session["day"] = schedule_day;
                        Session["recipient"] = scheduledexport["recipient_email"].ToString();
                        MasterReport mrd = new MasterReport(permss.EmailAddress);
                        mrd.Dto.MasterRptId = int.Parse(master_id);
                        mrd.Dto.MasterName = scheduledexport["master_name"].ToString();
                        mrd.Dto.ScheduleMode = Migration.ConvertToScheduleMode(scheduledexport["schedule_mode"].ToString());
                        mrd.Dto.ScheduleDay = int.Parse(schedule_day);
                        mrd.Dto.RecipientEmail = scheduledexport["recipient_email"].ToString();
                        mrd.SetHeadings(scheduledexport["master_element_headings"].ToString());
                        mrd.Dto.MElementType = scheduledexport["master_element_types"].ToString();
                        Session["MasterSch"] = mrd;
                        Session["scheduled"] = true;
                        this.Response.Redirect("edit_scheduled_MasterReport.aspx?content=edit");
						break;
					case "delete":
						Session["master_id_name"] = String.Format("{0} ", scheduledexport["master_name"].ToString());
						Session["master_id"] = master_id;
                        this.Response.Redirect("delete_scheduled_Masterexport.aspx");
						break;
					default:
						break;
				}
			}
			else
			{
				error_table.Visible = true;
			}
		}
        private void Page_Load_edit()
        {
            // Put user code to initialize the page here
            string e_ttl = exp ? "Edit a scheduled export of master report" : "Edit an export of master report";
            page_utilities.Set_titles(this, e_ttl);


            //string mid = string.Empty;
            //if (Request.QueryString["mid"] != null)
            //{
            // mid = Request.QueryString["mid"].ToString();
            //}
            index_MasterReport MasterrptNow = null;

            if (!IsPostBack)
            {
                if (Context.Handler.GetType().Name.Equals("datamgmt_index_masterreport_aspx"))
                {
                    if ((index_MasterReport)Context.Handler != null)
                    {
                        MasterrptNow = (index_MasterReport)Context.Handler;
                        MaterRptId.Value = Convert.ToString(MasterrptNow.MstrId);
                    }
                }
            }

            Hashtable h_masterparams = new Hashtable();

            string countriesQ = null;
            string countriesP = null;
            if (permss.UserType != UserType.Admin)
            {
                countriesQ = String.Empty;
                countriesP = String.Empty;
                if (permss.ListOfPermitedCountriesQuestionnaire != null &&
                   permss.ListOfPermitedCountriesQuestionnaire.Count > 0)
                {                    
                    for (int i = 0; i < permss.ListOfPermitedCountriesQuestionnaire.Count; i++)
                    {
                        if (i != 0)
                        {
                            countriesQ += ",";
                        }
                        countriesQ += permss.ListOfPermitedCountriesQuestionnaire[i].Country;
                    }
                }
                if (permss.ListOfPermitedCountriesProcessor != null &&
                    permss.ListOfPermitedCountriesProcessor.Count > 0)
                {                    
                    for (int i = 0; i < permss.ListOfPermitedCountriesProcessor.Count; i++)
                    {
                        if (i != 0)
                        {
                            countriesP += ",";
                        }
                        countriesP += permss.ListOfPermitedCountriesProcessor[i].Country;
                    }
                }
            }            

            h_masterparams.Add("type", Migration.ConvertUserTypeToString(permss.UserType));
            h_masterparams.Add("countriesQ", countriesQ);
            h_masterparams.Add("countriesP", countriesP);

            DataTable MasterReportNames = DB.execProc("select_masterreports", h_masterparams);

            DataRow[] MasterName = null;
            Int32 Masterrpt_id = 0;

            if (MasterReportNames != null)
            {
                if (MasterReportNames.Rows.Count > 0)
                {                    
                    if (int.TryParse(MaterRptId.Value, out Masterrpt_id))
                        MasterName = MasterReportNames.Select("master_id = '" + Masterrpt_id + "'");

                }
            }

            if (MasterName.ToString().Trim().Length > 0)
            {
                mrd = new MasterReport(permss.EmailAddress);
                mrd.Dto.MasterRptId = int.Parse(MasterName[0]["master_id"].ToString());
                mrd.Dto.MasterName = MasterName[0]["master_name"].ToString();

                mrd.SetHeadings(MasterName[0]["master_element_headings"].ToString());
                mrd.Dto.MElementType = MasterName[0]["master_element_types"].ToString();

                mrd.Dto.Creator = MasterName[0]["creator"].ToString();
                mrd.Dto.RecipientEmail = MasterName[0]["recipient_email"].ToString();

                mrd.Dto.ScheduleMode = Migration.ConvertToScheduleMode(MasterName[0]["schedule_mode"].ToString());
                    
                int scheduleDay = 0;
                if (int.TryParse(MasterName[0]["schedule_day"].ToString(), out scheduleDay))
                {
                    mrd.Dto.ScheduleDay = scheduleDay;
                }
                else
                {
                    mrd.Dto.ScheduleDay = null;
                }

                mrd.Dto.IsScheduled = Convert.ToBoolean(MasterName[0]["isScheduled"].ToString());

                if (!IsPostBack)
                {
                    mName.Text = mrd.Dto.MasterName.Trim();
                    savemasterreport.Checked = true;
                }

                //attach questions
                mrd.Dto.MasterQ = MasterReport.GetMasterQuestions(mrd.Dto.MasterRptId);
                if (mrd.Dto.MasterQ.Count > 0)
                {
                    //bind heading
                    if (!IsPostBack)
                    {
                        if (mrd.Dto.MElementHeading.Count > 0)
                        {
                            dtl1.DataSource = mrd.Dto.MElementHeading;
                            dtl1.DataBind();
                        }
                        else { lbl2.Text = "No variable column exists for this Questionnaire/s."; }//btnUpdHd.Enabled = false; }
                    }
                    //bind ques
                    if (!IsPostBack)
                    {
                        dg1.DataSource = mrd.Dto.MasterQ;
                        dg1.DataBind();
                    }
                    pnlQuest.Visible = true;
                    pnlTimeFrame.Visible = true;
                }

                if (exp)
                {
                    schedule_mode.Items.FindByValue(mrd.Dto.ScheduleMode.ToString()).Selected = true;

                    if (schedule_mode.SelectedItem.Value == "w")
                    {
                        schedule_day.Enabled = true;
                        schedule_day.SelectedItem.Selected = false;
                        schedule_day.Items.FindByValue(mrd.Dto.ScheduleDay.ToString()).Selected = true;
                    }
                    #region load recepient
                    if (permss.UserType == UserType.Admin)
                    {
                        admin_behalf.Visible = true;

                        dd_possible_users.Enabled = true;

                        #region load dd_user and select if possible
                        Hashtable h_params = new Hashtable();
                        h_params.Add("masterID", Masterrpt_id);
                        DataTable DtFinalUsers = DB.execProc("select_users_permitted_for_masterreport", h_params);
                        dd_possible_users.DataSource = DtFinalUsers;
                        dd_possible_users.DataTextField = "useremail";

                        DataRow addingRow;
                        addingRow = DtFinalUsers.NewRow();
                        addingRow["useremail"] = "-- Please choose... --";
                        DtFinalUsers.Rows.InsertAt(addingRow, 0);

                        dd_possible_users.DataBind();

                        string recipient = string.Empty;
                        ListItem found_user = dd_possible_users.Items.FindByText(recipient);

                        if (found_user != null)
                        {
                            dd_possible_users.SelectedItem.Selected = false;
                            found_user.Selected = true;
                        }
                        else
                        {
                            tb_recipient.Text = recipient;
                        }
                        #endregion

                    }
                }
                    #endregion
                if (!IsPostBack)
                {
                    #region load campaigns                    
                    List<CampaignDto> listOfCampaigns = new List<CampaignDto>();
                    listOfCampaigns.Add(new CampaignDto() { CampaignCode = "-- Please choose... --" });
                    List<CampaignDto> tempCamp = CampaignFacade.SelectCampaignsByCodeCountriesTypeAndIndicatorIfEmpty(null, countriesQ, countriesP, 0);
                    if (tempCamp != null && tempCamp.Count > 0)
                        listOfCampaigns.AddRange(tempCamp);
				
                    campaign_list.DataSource = listOfCampaigns;
                    campaign_list.DataValueField = "CampaignCode";
                    campaign_list.DataBind();

                    campaign_list.Items[0].Selected = true;
                    #endregion
                }


            }
            if (!IsPostBack)
                mrd_local = mrd;
        }
示例#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

            }
        }
		public void scheduledexports_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e) 
		{
			System.Web.UI.WebControls.DataList dl_scheduledexports = (DataList)this.FindControl("scheduledexports_list");
			string master_id = dl_scheduledexports.DataKeys[e.Item.ItemIndex].ToString();

			DataRow scheduledexport = scheduledexports.Rows.Find(master_id);
			
            //if ((bool)scheduledexport["enabled"])
            //{
				//string questionnaire_name = String.Format("{0}/{1} ({2})", scheduledexport["country_name"].ToString(), scheduledexport["language_name"].ToString(), scheduledexport["qid_title"].ToString());
            MasterReport mrd = new MasterReport(permss.EmailAddress);
            mrd.Dto.MasterRptId = int.Parse(master_id);
            _mstrId = int.Parse(master_id);
            _mstrName = scheduledexport["master_name"].ToString();
            mrd.Dto.MasterName = scheduledexport["master_name"].ToString();
            mrd.Dto.ScheduleMode = Migration.ConvertToScheduleMode(scheduledexport["schedule_mode"].ToString());
            //mrd.Schedule_Day = 7;
            mrd.Dto.RecipientEmail = scheduledexport["recipient_email"].ToString();
            //if (!string.IsNullOrEmpty(scheduledexport["from"].ToString()))
            //    mrd.Dto.From = (DateTime)scheduledexport["from"];
            //else
                mrd.Dto.From = null;
            //if (!string.IsNullOrEmpty(scheduledexport["to"].ToString()))
            //    mrd.Dto.To = (DateTime)scheduledexport["to"];
            //else
                mrd.Dto.To = null;

            mrd.SetHeadings(scheduledexport["master_element_headings"].ToString());
            mrd.Dto.MElementType = scheduledexport["master_element_types"].ToString();

				string command = e.CommandName;
				switch(command)
				{				
					case "edit":
                        Server.Transfer("edit_scheduled_MasterReport.aspx?content=edit");
						break;
					case "delete":
                        Server.Transfer("delete_scheduled_Masterexport.aspx");
						break;
                    case "send":
                        Server.Transfer("MasterReportNow.aspx");
                        break;
                    case "schedule":
                        Server.Transfer("MasterReportScheduled.aspx");
                        break;
                    default:
						break;
				}
            //}
            //else
            //{
            //    error_table.Visible = true;
            //}
		}