示例#1
0
        private void createSegemnt(string SegmentType)
        {
            try
            {
                lblMainMsg.Text = string.Empty;
                AdvanceListMasterBase listMaster = new AdvanceListMasterBase(ConnectionString);
                AdvanceSegmentMasterBase segmentMaster = new AdvanceSegmentMasterBase(ConnectionString);
                AdvanceListContactMaster objListContactMaster = new AdvanceListContactMaster(ConnectionString);
                DataTable dtListContactMaster = new DataTable();
                dtListContactMaster.Columns.Add(new DataColumn("ListMasterID", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("ContactId", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("CreatedDate", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("ModifiedDate", typeof(string)));
                dtListContactMaster.Columns.Add(new DataColumn("IsSegment", typeof(bool)));
                dtListContactMaster.Columns.Add(new DataColumn("IsActive", typeof(bool)));
                List<string> contactids = new List<string>();
                contactids = (List<string>)Session["ContactId"];
                if (hdfListId.Value != "")
                {
                    bool isDeleted = objListContactMaster.DeleteAllContactsFromList(Convert.ToInt64(hdfListId.Value));
                    if (isDeleted)
                    {

                        foreach (string contactID in contactids)
                        {
                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                            rowListContactMaster["ListMasterID"] = hdfListId.Value;
                            rowListContactMaster["ContactId"] = contactID;
                            //rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["IsActive"] = true;
                            dtListContactMaster.Rows.Add(rowListContactMaster);
                        }
                        string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        AdvanceListContactMaster.BulkCopy(dtListContactMaster, "AdvanceListContactMaster", SourceColumn, DestinationColumn, ConnectionString);

                        AdvanceListMasterPrimaryKey pk = new AdvanceListMasterPrimaryKey(Convert.ToInt64(hdfListId.Value));//hiddenEditID.Value));
                        AdvanceListMaster listMasterNew = AdvanceListMaster.SelectOne(pk, ConnectionString);

                        listMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                        listMaster.ListName = txtSegmentName.Text;
                        listMaster.ListDesc = txtDescription.Text;
                        listMaster.CreatedDate = listMasterNew.CreatedDate;
                        listMaster.ModifiedDate = System.DateTime.Now;
                        listMaster.IsSegment = true;
                        listMaster.Update();

                        segmentMaster.ListMasterID = Convert.ToInt64(hdfListId.Value);
                        segmentMaster.SegmentName = txtSegmentName.Text;
                        segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length);

                        if (rbSegCamRecOnly.Checked)
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='QueryBuild(this);'");
                        else
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='ListQueryBuild(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperator\" onChange='getSearchKeys(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorDefault\"", "\"ddlOperatorCommon\" onChange='displayDefaultValues(this);'");
                        segmentMaster.SegmentFilter = HtmlContent.Value;
                        segmentMaster.Type = SegmentType;
                        segmentMaster.Update();
                    }

                    Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=update");

                }
                else
                {

                    if (rgdContacts.MasterTableView.Items.Count > 0)
                    {
                        listMaster.ListName = txtSegmentName.Text;
                        listMaster.ListDesc = txtDescription.Text;
                        listMaster.CreatedDate = System.DateTime.Now;
                        listMaster.IsSegment = true;
                        listMaster.InsertWithDefaultValues(true);
                        Int64 listid = Convert.ToInt64(listMaster.ListMasterID);

                        segmentMaster.ListMasterID = listid;
                        segmentMaster.SegmentName = txtSegmentName.Text;
                        segmentMaster.SelectCondition = SelectedIds.Value.Substring(0, SelectedIds.Value.Length);
                        if (rbSegCamRecOnly.Checked)
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='QueryBuild(this);'");
                        else
                            HtmlContent.Value = HtmlContent.Value.Replace("\"ddlContactFieldName\"", "\"ddlContactField\" onChange='ListQueryBuild(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorName\"", "\"ddlOperator\" onChange='getSearchKeys(this);'");
                        HtmlContent.Value = HtmlContent.Value.Replace("\"ddlOperatorDefault\"", "\"ddlOperatorCommon\" onChange='displayDefaultValues(this);'");
                        segmentMaster.SegmentFilter = HtmlContent.Value;
                        segmentMaster.Type = SegmentType;
                        segmentMaster.Insert();

                        foreach (string contactID in contactids)
                        {
                            DataRow rowListContactMaster = dtListContactMaster.NewRow();
                            rowListContactMaster["ListMasterID"] = listid;
                            rowListContactMaster["ContactId"] = contactID;
                            rowListContactMaster["CreatedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["ModifiedDate"] = DateTime.Now.ToString();
                            rowListContactMaster["IsActive"] = true;
                            dtListContactMaster.Rows.Add(rowListContactMaster);
                        }
                        string[] SourceColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        string[] DestinationColumn = new[] { "ListMasterID", "ContactId", "CreatedDate", "ModifiedDate", "IsActive" };
                        AdvanceListContactMaster.BulkCopy(dtListContactMaster, "AdvanceListContactMaster", SourceColumn, DestinationColumn, ConnectionString);

                    }

                }
                Response.Redirect("~/pages/Segments.aspx?name=" + txtSegmentName.Text + "&mode=create");

            }
            catch (Exception ex)
            {

                lblMainMsg.Text = "Error: " + ex.Message;
                //lblMainMsg.Visible = true;
                rtsAddSegment.SelectedIndex = 0;
                rtsAddSegment.MultiPage.SelectedIndex = 0;

            }
        }