public void updateCampaignDetailsTab()
        {
            try
            {
                CampaignMasterPrimaryKey objCampaignMasterPrimaryKey = new CampaignMasterPrimaryKey(Convert.ToInt64(hiddenCampaignID.Value));
                objCampaignMaster = CampaignMaster.SelectOne(objCampaignMasterPrimaryKey, ConnectionString);
                DataTable campMaster = CampaignMasterBase.SelectByName("CampaignName", txtCampaignName.Text.ToString(), ConnectionString);
                if (campMaster.Rows.Count == 0)
                {
                    objCampaignMaster.CampaignName = txtCampaignName.Text;
                }
                else
                {
                    txtCampaignName.Text = objCampaignMaster.CampaignName;
                }
                objCampaignMaster.FromAddress = ddlFromAddress.SelectedItem.Text;
                objCampaignMaster.FromName = txtFromName.Text.ToString().Trim();
                objCampaignMaster.CampaignDescription = txtCampaignDescription.Text;
                objCampaignMaster.ReplytoAddress = txtReplytoAddress.Text;
                objCampaignMaster.ReplaytoName = txtReplaytoName.Text;
                objCampaignMaster.Subject = txtSubject.Text;
                objCampaignMaster.TrackReads = chkTrackReads.Checked;
                if (RadEditor1.Content.ToString().Trim().Length != 0)
                    objCampaignMaster.htmlHasUnsubLink = chkAddress.Checked;
                else
                    objCampaignMaster.htmlHasUnsubLink = false;
                if (textRadEditor.Content.ToString().Trim().Length != 0)
                    objCampaignMaster.txtHasUnsubLink = chkTxtAddress.Checked;
                else
                    objCampaignMaster.txtHasUnsubLink = false;


                objCampaignMaster.ModifiedDate = DateTime.Now;
                if (txtUnsubscribe.Text != string.Empty)
                {
                    hdUnsubscribeText.Value = lblunsubinfo.Text;
                    hdUnsubscribeLinkText.Value = lblunsublinktext.Text;
                    objCampaignMaster.UnsubscribeText = txtUnsubscribe.Text;
                    objCampaignMaster.UnsubscribeLinkText = DDLinktext.SelectedItem.Text;
                    lblunsubinfo.Text = txtUnsubscribe.Text;
                    lblunsublinktext.Text = DDLinktext.SelectedItem.Text;
                    DivUnsubtext.InnerHtml = lblunsubinfo.Text + " \n" + lblunsublinktext.Text;
                }
                //Bellow code is used to insert or Update assigned Campaign details in to CampaignMailing Table
                bool mailingInstStatus = false;
                if (hdCampMailingFlag.Value == "1")
                {
                    CampaignMailingBase objCampaignMailingBase = new CampaignMailingBase(ConnectionString);
                    if (AssCampIdDb.Value.ToString().Length != 0 && AssCampIdDb.Value != null)
                    {
                        if (objCampaignMailingBase.checkAssignedCampaignId(Convert.ToInt64(hiddenCampaignID.Value), Convert.ToInt64(AssCampIdDb.Value.ToString()), ConnectionString))
                        {
                            mailingInstStatus = objCampaignMailingBase.UpdateAssignedCampaignId(Convert.ToInt64(hiddenCampaignID.Value), (ddlCampsNames.SelectedItem.Text != defaultListItem) ? Convert.ToInt64(ddlCampsNames.SelectedItem.Value) : 0, ConnectionString);
                        }
                        else if (ddlCampsNames.SelectedItem.Text != defaultListItem)
                        {
                            CampaignMailing objCampaignMailing = new CampaignMailing(ConnectionString);
                            objCampaignMailing.CampaignId = Convert.ToInt64(hiddenCampaignID.Value);
                            objCampaignMailing.CampaignsID = Convert.ToInt64(ddlCampsNames.SelectedItem.Value);//Mailing Id
                            objCampaignMailing.CreatedDate = DateTime.Now;
                            objCampaignMailing.ModifiedDate = DateTime.Now;
                            objCampaignMailing.IsActive = true;
                            mailingInstStatus = objCampaignMailing.Insert();
                        }
                    }
                }

                if (hdCampMailingFlag.Value == "1" && mailingInstStatus == true)
                {
                    if (ddlCampsNames.Text != defaultListItem)
                        objCampaignMaster.AssignedCampaignID = Convert.ToInt64(ddlCampsNames.SelectedItem.Value);
                    else
                        objCampaignMaster.AssignedCampaignID = 0;
                    objCampaignMaster.UpdateCampaignDetails();
                }
                else
                {
                    objCampaignMaster.UpdateCampaignDetails();
                }

                checkCampaignStatus();
                hdCampDetailsTab1.Value = "0";
                lblCampName.Text = txtCampaignName.Text.Trim();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        public bool saveCampaignDetailsTab(bool Rflag)
        {
            if (txtCampaignName.Text == string.Empty)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Please enter Mailing name in Mailing Details Tab.')", true);
                Rflag = false;
            }
            else if (ddlFromAddress.SelectedItem.Text == string.Empty)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Please enter FromAddress.')", true);
                Rflag = false;
            }
            else if (txtFromName.Text == string.Empty)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Please enter FromName.')", true);
                Rflag = false;
            }
            else if (txtSubject.Text == string.Empty)
            {
                ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Please enter subject from Mailing Details tab.')", true);
                Rflag = false;
            }
            else
            {
                if (hiddenCampaignID.Value == string.Empty)
                {
                    objCampaignMaster = new CampaignMaster(ConnectionString);
                    DataTable campMaster = CampaignMasterBase.SelectByName("CampaignName", txtCampaignName.Text.ToString(), ConnectionString);
                    if (campMaster.Rows.Count != 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "Success", "alert('Mailing already Exists with this Name.')", true);
                        Rflag = false;
                    }
                    else
                    {
                        objCampaignMaster.CampaignName = txtCampaignName.Text;
                        objCampaignMaster.CampaignDescription = txtCampaignDescription.Text;
                        objCampaignMaster.FromAddress = ddlFromAddress.SelectedItem.Text;
                        objCampaignMaster.FromName = txtFromName.Text;
                        objCampaignMaster.ReplytoAddress = txtReplytoAddress.Text;
                        objCampaignMaster.ReplaytoName = txtReplaytoName.Text;
                        objCampaignMaster.Subject = txtSubject.Text;
                        objCampaignMaster.TrackReads = chkTrackReads.Checked;

                        if (RadEditor1.Content.ToString().Trim().Length != 0)
                            objCampaignMaster.htmlHasUnsubLink = chkAddress.Checked;
                        else
                            objCampaignMaster.htmlHasUnsubLink = false;
                        if (textRadEditor.Content.ToString().Trim().Length != 0)
                            objCampaignMaster.txtHasUnsubLink = chkTxtAddress.Checked;
                        else
                            objCampaignMaster.txtHasUnsubLink = false;

                        objCampaignMaster.UnsubscribeText = txtUnsubscribe.Text;
                        objCampaignMaster.UnsubscribeLinkText = DDLinktext.SelectedItem.Text;
                        if (ddlCampsNames.Text != defaultListItem)
                            objCampaignMaster.AssignedCampaignID = Convert.ToInt64(ddlCampsNames.SelectedItem.Value);
                        else
                            objCampaignMaster.AssignedCampaignID = 0;
                        lblunsubinfo.Text = txtUnsubscribe.Text;
                        lblunsublinktext.Text = DDLinktext.SelectedItem.Text;
                        DivUnsubtext.InnerHtml = lblunsubinfo.Text + " \n" + lblunsublinktext.Text;

                        objCampaignMaster.TemplateId = 0;
                        objCampaignMaster.HTMLContent = string.Empty;
                        objCampaignMaster.TextContent = string.Empty;
                        objCampaignMaster.SelectCondition = string.Empty;
                        objCampaignMaster.SuppressDomain = string.Empty;
                        objCampaignMaster.SuppressSelection = string.Empty;

                        Int64 campaignMasterID = objCampaignMaster.insertMailing(objCampaignMaster);
                        if (campaignMasterID > 0)
                        {
                            //Insert In CampaignJob Table
                            CampaignJob objCampaignJob = new CampaignJob(ConnectionString);
                            objCampaignJob.CampaignMasterID = campaignMasterID;
                            objCampaignJob.CreatedDatetime = DateTime.Now;
                            objCampaignJob.ScheduledDatetime = DateTime.Now; //Convert.ToDateTime(scheduledTime);
                            objCampaignJob.SendType = sendType;
                            objCampaignJob.Status = 5;
                            objCampaignJob.Insert();

                            //Insert in CampaignMailing Table
                            if (ddlCampsNames.Text != defaultListItem)
                            {
                                CampaignMailing objCampaignMailing = new CampaignMailing(ConnectionString);
                                objCampaignMailing.CampaignId = campaignMasterID;
                                objCampaignMailing.CampaignsID = Convert.ToInt64(ddlCampsNames.SelectedItem.Value);//Mailing Id
                                objCampaignMailing.CreatedDate = DateTime.Now;
                                objCampaignMailing.ModifiedDate = DateTime.Now;
                                objCampaignMailing.IsActive = true;
                                objCampaignMailing.Insert();
                            }
                            status = true;
                            insert = true;
                        }
                        hiddenCampaignID.Value = campaignMasterID.ToString();
                        lblCampName.Text = objCampaignMaster.CampaignName.ToString().Trim();
                        Rflag = true;
                        statusType = "Inserted";
                        //statusType = "Updated";
                        ViewState["statusType"] = "Inserted";
                        hdCampDetailsTab1.Value = "0"; //After Save CampaignDetails Iam Change the Value of Hidden Variable value to Zero.
                    }
                }
                else
                {
                    updateCampaignDetailsTab();
                    Rflag = true;
                }
            }
            return Rflag;
        }
Beispiel #3
0
        protected void lbtnAssigncampaigntomailing_Click(object sender, EventArgs e)
        {
            objCampaignMaster = new CampaignMaster(ConnectionString);
            if (RgrdSentCampaigns.MasterTableView.Items.Count > 0)
            {
                //Get contact Selection
                rememberContactSelectionForSent("SgrdaddchkSelectRecs", "lblSCampaignId", RgrdSentCampaigns, "Sgrdaddselectall");
                if (ViewState["SentSelectedContacts"] != null)
                {
                    StringBuilder strbEditContacts = new StringBuilder();
                    //adding selected contatIds to stringbuilder
                    for (int i = 0; i < contactsSelected.Count; i++)
                    {
                        strbEditContacts.Append(contactsSelected[i] + ", ");
                        //Bellow code is used to insert or Update assigned Campaign details in to CampaignMailing Table
                        bool mailingInstStatus = false;
                        CampaignMailingBase objCampaignMailingBase = new CampaignMailingBase(ConnectionString);
                        if (ddlCampaigns.SelectedItem.Text != defaultListItem)
                        {
                            if (objCampaignMailingBase.checkAssignedCampaignsId(Convert.ToInt64(contactsSelected[i]), ConnectionString))
                            {
                                mailingInstStatus = objCampaignMailingBase.UpdateAssignedCampaignId(Convert.ToInt64(contactsSelected[i]), (ddlCampaigns.SelectedItem.Text != defaultListItem) ? Convert.ToInt64(ddlCampaigns.SelectedItem.Value) : 0, ConnectionString);
                            }
                            else if (ddlCampaigns.SelectedItem.Text != defaultListItem)
                            {
                                CampaignMailing objCampaignMailing = new CampaignMailing(ConnectionString);
                                objCampaignMailing.CampaignId = Convert.ToInt64(contactsSelected[i]);
                                objCampaignMailing.CampaignsID = Convert.ToInt64(ddlCampaigns.SelectedItem.Value);//Mailing Id
                                objCampaignMailing.CreatedDate = DateTime.Now;
                                objCampaignMailing.ModifiedDate = DateTime.Now;
                                objCampaignMailing.IsActive = true;
                                mailingInstStatus = objCampaignMailing.Insert();
                            }
                        }
                        if (mailingInstStatus == true)
                        {
                            //get campaign details
                            CampaignMasterPrimaryKey pk = new CampaignMasterPrimaryKey(Convert.ToInt64(contactsSelected[i]));
                            objCampaignMaster = CampaignMaster.SelectOneWithCampaignJobUsingCampaignMasterID(pk, ConnectionString);

                            if (ddlCampaigns.Text != defaultListItem)
                                objCampaignMaster.AssignedCampaignID = Convert.ToInt64(ddlCampaigns.SelectedItem.Value);
                            else
                                objCampaignMaster.AssignedCampaignID = 0;

                            objCampaignMaster.UpdateCampaignDetails();
                        }

                    }
                    if (ddlCampaigns.SelectedItem.Text != defaultListItem)
                    {
                        strbEditContacts.Remove(strbEditContacts.Length - 2, 1);
                        ViewState["SentSelectedContacts"] = null;
                        hdrchkselected.Clear();
                        if (txtSentMailID.Text != string.Empty || txtSentmailSearch.Text != string.Empty)
                        {
                            SearchCriteria("", 0, 0);
                        }
                        else
                        {
                            bindGrid(string.Empty, 0);
                            bindCampNames();
                        }
                        lblMainMsg.ForeColor = System.Drawing.Color.Green;
                        lblMainMsg.Text = "Campaign to selected mailings(with ids: " + strbEditContacts.ToString() + ")assigned successfully!";
                    }
                }
            }
        }
        /// <summary>
        /// Populates the fields for multiple objects from the columns found in an open reader.
        /// </summary>
        ///
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <returns>Object of CampaignMailings</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			6/25/2012 02:05:58 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static CampaignMailings PopulateObjectsFromReaderWithCheckingReader(IDataReader rdr, DatabaseHelper oDatabaseHelper, string ConnectionString)
        {
            CampaignMailings list = new CampaignMailings();

            if (rdr.Read())
            {
                CampaignMailing obj = new CampaignMailing(ConnectionString);
                PopulateObjectFromReader(obj, rdr);
                list.Add(obj);
                while (rdr.Read())
                {
                    obj = new CampaignMailing(ConnectionString);
                    PopulateObjectFromReader(obj, rdr);
                    list.Add(obj);
                }
                oDatabaseHelper.Dispose();
                return list;
            }
            else
            {
                oDatabaseHelper.Dispose();
                return null;
            }
        }
        /// <summary>
        /// Populates the fields for multiple objects from the columns found in an open reader.
        /// </summary>
        ///
        /// <param name="rdr" type="IDataReader">An object that implements the IDataReader interface</param>
        ///
        /// <returns>Object of CampaignMailings</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			6/25/2012 02:05:58 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        internal static CampaignMailings PopulateObjectsFromReader(IDataReader rdr, string ConnectionString)
        {
            CampaignMailings list = new CampaignMailings();

            while (rdr.Read())
            {
                CampaignMailing obj = new CampaignMailing(ConnectionString);
                PopulateObjectFromReader(obj,rdr);
                list.Add(obj);
            }
            return list;
        }
        /// <summary>
        /// This method will return an object representing the record matching the primary key information specified.
        /// </summary>
        ///
        /// <param name="pk" type="CampaignMailingPrimaryKey">Primary Key information based on which data is to be fetched.</param>
        ///
        /// <returns>object of class CampaignMailing</returns>
        ///
        /// <remarks>
        ///
        /// <RevisionHistory>
        /// Author				Date			Description
        /// DLGenerator			6/25/2012 02:05:58 PM		Created function
        /// 
        /// </RevisionHistory>
        ///
        /// </remarks>
        ///
        public static CampaignMailing SelectOne(CampaignMailingPrimaryKey pk, string ConnectionString)
        {
            DatabaseHelper oDatabaseHelper = new DatabaseHelper(ConnectionString);
            bool ExecutionState = false;

            // Pass the values of all key parameters to the stored procedure.
            System.Collections.Specialized.NameValueCollection nvc = pk.GetKeysAndValues();
            foreach (string key in nvc.Keys)
            {
                oDatabaseHelper.AddParameter("@" + key,nvc[key] );
            }
            // The parameter '@ErrorCode' will contain the status after execution of the stored procedure.
            oDatabaseHelper.AddParameter("@ErrorCode", -1, System.Data.ParameterDirection.Output);

            IDataReader dr=oDatabaseHelper.ExecuteReader("sp_CampaignMailing_SelectbyPrimaryKey", ref ExecutionState);
            if (dr.Read())
            {
                CampaignMailing obj = new CampaignMailing(ConnectionString);
                PopulateObjectFromReader(obj,dr);
                dr.Close();
                oDatabaseHelper.Dispose();
                return obj;
            }
            else
            {
                dr.Close();
                oDatabaseHelper.Dispose();
                return null;
            }
        }