Ejemplo n.º 1
0
        private void BindListOfProspects(int id)
        {
            var dbContext = new ProspectDataContext();
            gvComments.DataSource = dbContext.ProspectConversations.Where(p => p.ProspectId.Equals(id)).ToList();
            gvComments.DataBind();

            spanProspectId.InnerText = id.ToString();
            if (gvComments.Rows.Count == 0)
            {
                gvComments.DataSource = ReturnEmptyDataTableComments();
                gvComments.DataBind();
            }

            PopulateDropdownsProspectConversations();
            divComments.Style.Add(HtmlTextWriterStyle.Display, "block");
        }
Ejemplo n.º 2
0
        private void PopulateDropdownsProspectConversations()
        {
            var dbContext = new ProspectDataContext();

            var ddlProspectCommentTypeAdd = (DropDownList)gvComments.FooterRow.FindControl("ddlProspectCommentTypeAdd");
            ddlProspectCommentTypeAdd.DataSource = dbContext.ProspectCommentTypes.ToList();
            ddlProspectCommentTypeAdd.DataTextField = "ProspectComment";
            ddlProspectCommentTypeAdd.DataValueField = "ProspectCommentTypeID";
            ddlProspectCommentTypeAdd.DataBind();

            ddlProspectCommentTypeAdd.Items.Insert(0, "Select");

            var ddlProspectStageIdAdd = (DropDownList)gvComments.FooterRow.FindControl("ddlProspectStageIDAdd");
            ddlProspectStageIdAdd.DataSource = dbContext.ProspectProspectStages.ToList();
            ddlProspectStageIdAdd.DataTextField = "ProspectStage";
            ddlProspectStageIdAdd.DataValueField = "ProspectStageID";
            ddlProspectStageIdAdd.DataBind();

            ddlProspectStageIdAdd.Items.Insert(0, "Select");

            var ddlCommentSourcesAdd = (DropDownList)gvComments.FooterRow.FindControl("ddlCommentSourcesAdd");
            ddlCommentSourcesAdd.DataSource = dbContext.ProspectCommentSources.ToList();
            ddlCommentSourcesAdd.DataTextField = "ProspectCommentSource1";
            ddlCommentSourcesAdd.DataValueField = "ProspectCommentSourceID";
            ddlCommentSourcesAdd.DataBind();

            ddlCommentSourcesAdd.Items.Insert(0, "Select");
        }
Ejemplo n.º 3
0
        protected void gvProspects_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                var lblCreatedBy = (Label)e.Row.FindControl("lblCreatedBy");

                if (lblCreatedBy != null )
                {
                    if (!string.IsNullOrEmpty(lblCreatedBy.Text))
                    {
                        var dbContext = new ProspectDataContext();
                        var userId = Guid.Parse(lblCreatedBy.Text);

                        var query = from c in dbContext.UserInfos
                            where c.UserId.Equals(userId)
                            select c.FirstName + " " + c.LastName;

                        lblCreatedBy.Text = query.First();
                    }
                }
            }

            if (e.Row.RowType == DataControlRowType.Footer)
            {
                var txtLastActivityDateAdd = (TextBox) e.Row.FindControl("txtLastActivityDateAdd");
                txtLastActivityDateAdd.Attributes.Add("datepicker", "datepicker();");
            }
        }
Ejemplo n.º 4
0
        private void BindGrid(SearchOn searchOn,string searchTerm=null,int startRowIndex=0, int maximumRows=0)
        {
            var dbContext = new ProspectDataContext();

            var listProspects = dbContext.Prospects.OrderBy(x => x.LastActivityDate).ToList();

            if (!string.IsNullOrEmpty(searchTerm))
            {
                switch (searchOn)
                {
                   case SearchOn.Company:
                        listProspects = listProspects.Where(p => p.Company.ToLower().Contains(searchTerm)).ToList();
                        break;
                   case SearchOn.ContactEmail:
                        listProspects = listProspects.Where(p => p.ContactEmail.ToLower().Contains(searchTerm)).ToList();
                        break;
                   case SearchOn.ContactName:
                        listProspects = listProspects.Where(p => p.ContactName.ToLower().Contains(searchTerm)).ToList();
                        break;
                   case SearchOn.ContactPhone:
                        listProspects = listProspects.Where(p => p.ContactPhone.ToLower().Contains(searchTerm)).ToList();
                        break;
                   case SearchOn.ContactCity:
                        listProspects = listProspects.Where(p => p.ContactCity.ToLower().Contains(searchTerm)).ToList();
                        break;
                   case SearchOn.ContactState:
                        listProspects = listProspects.Where(p => p.ContactState.ToLower().Contains(searchTerm)).ToList();
                        break;
                }

            }

            gvProspects.DataSource = listProspects;
            gvProspects.DataBind();

            if (gvProspects.Rows.Count == 0)
            {
                gvProspects.DataSource = ReturnEmptyDataTable();
                gvProspects.DataBind();
                lblMsg.Text = "No records found";
            }
            else
            {
                lblMsg.Text = listProspects.Count + " records found.";
            }

            gvProspects.SelectedIndex = -1;
            divComments.Style.Add(HtmlTextWriterStyle.Display, "none");
        }
Ejemplo n.º 5
0
        protected void gvProspects_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            var dbContext = new ProspectDataContext();
            var prospects = dbContext.Prospects.OrderBy(x => x.LastActivityDate).ToList();

            gvProspects.DataSource = prospects;
            gvProspects.PageIndex = e.NewPageIndex;
            gvProspects.DataBind();

            PopulateDropdowns();
            gvProspects.SelectedIndex = -1;
            spanProspectId.InnerText = string.Empty;
            gvComments.DataSource = ReturnEmptyDataTableComments();
            gvComments.DataBind();
            divComments.Style.Add(HtmlTextWriterStyle.Display, "none");
            lblMsg.Text = string.Empty;
        }
Ejemplo n.º 6
0
        protected void gvProspects_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = gvProspects.Rows[e.RowIndex];
            var prospectId =Convert.ToInt32(Convert.ToString(gvProspects.DataKeys[e.RowIndex].Values[0]));
            var company  = (row.FindControl("txtCompanyEdit") as TextBox).Text;
            var contactName  = (row.FindControl("txtContactNameEdit") as TextBox).Text;
            var contactEmail =(row.FindControl("txtContactEmailEdit") as TextBox).Text;
            var contactPhone  =(row.FindControl("txtContactPhoneEdit") as TextBox).Text;
            var contactCity  =(row.FindControl("txtContactCityEdit") as TextBox).Text;
            var contactState  =(row.FindControl("ddlStateEdit") as DropDownList).SelectedValue;
            var contactTimeZone =(row.FindControl("ddlTimeZoneEdit") as DropDownList).SelectedIndex==-1?"":(row.FindControl("ddlTimeZoneEdit") as DropDownList).SelectedValue;
            var createdByUserId = Guid.Parse("CF7C8C10-F16B-4746-9F05-3195682CA327");
            var lastActivityDate = (row.FindControl("txtLastActivityDateEdit") as TextBox).Text;

            using (var dataContext = new ProspectDataContext())
            {
                var prospect = dataContext.Prospects.FirstOrDefault(p => p.ProspectId.Equals(prospectId));

                if (prospect != null)
                {
                    prospect.Company = company;
                    prospect.ContactName = contactName;
                    prospect.ContactEmail = contactEmail;
                    prospect.ContactPhone = contactPhone;
                    prospect.ContactCity = contactCity;
                    prospect.ContactState = contactState;
                    prospect.ContactTimeZone = contactTimeZone;
                    prospect.CreatedByUserId = createdByUserId;
                    prospect.LastActivityDate = Convert.ToDateTime(lastActivityDate);

                    try
                    {

                        dataContext.SubmitChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var eve in ex.EntityValidationErrors)
                        {
                            Console.WriteLine(
                                "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                    ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                    }
                }

            }
            gvProspects.EditIndex = -1;
            BindGrid(SearchOn.None);
            PopulateDropdowns();
        }
Ejemplo n.º 7
0
        protected void gvComments_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                var lblConversationId = (Label) e.Row.FindControl("lblConversationId");

                if (lblConversationId != null)
                {

                    //Prospect Comment Div
                    var hidProspectComment = (HiddenField)e.Row.FindControl("hidProspectComment");

                    if (!string.IsNullOrEmpty(hidProspectComment.Value))
                    {
                        var hypProspectComment = (HyperLink)e.Row.FindControl("hypProspectComment");

                        if (hidProspectComment.Value.Length > 20)
                            hypProspectComment.Text = hidProspectComment.Value.Substring(0, 20);
                        else hypProspectComment.Text = hidProspectComment.Value;

                        var divProspectComment = (HtmlGenericControl)e.Row.FindControl("divProspectComment");
                        divProspectComment.InnerHtml = hidProspectComment.Value;

                        hypProspectComment.Attributes.Add("onclick",
                            "toggleDiv(" + divProspectComment.ClientID + "," + hypProspectComment.ClientID + ");");
                    }

                    //Key Phrase Div.
                    var hidKeyPhrase = (HiddenField)e.Row.FindControl("hidKeyPhrase");

                    if (!string.IsNullOrEmpty(hidKeyPhrase.Value))
                    {
                        var hypKeyPhrase = (HyperLink)e.Row.FindControl("hypKeyPhrase");

                        if (hidKeyPhrase.Value.Length > 20)
                            hypKeyPhrase.Text = hidKeyPhrase.Value.Substring(0, 20);
                        else hypKeyPhrase.Text = hidKeyPhrase.Value;

                        var divKeyPhrase = (HtmlGenericControl) e.Row.FindControl("divKeyPhrase");
                        divKeyPhrase.InnerHtml = hidKeyPhrase.Value;

                        hypKeyPhrase.Attributes.Add("onclick",
                            "toggleDiv(" + divKeyPhrase.ClientID + "," + hypKeyPhrase.ClientID + ");");
                    }

                }

                var dbContext = new ProspectDataContext();

                var lblCreatedBy = (Label)e.Row.FindControl("lblCreatedBy");

                if (lblCreatedBy != null && !string.IsNullOrEmpty(lblCreatedBy.Text))
                {
                    var userId = Guid.Parse(lblCreatedBy.Text);

                    var query = from c in dbContext.UserInfos
                                where c.UserId.Equals(userId)
                                select c.FirstName + " " + c.LastName;

                    lblCreatedBy.Text = query.First();
                }

                //CommentType
                var lblProspectCommentTypeId = (Label)e.Row.FindControl("lblProspectCommentTypeId");

                if (lblProspectCommentTypeId != null)
                {
                    var hidProspectCommentTypeId = (HiddenField) e.Row.FindControl("hidProspectCommentTypeId");
                    if (!string.IsNullOrEmpty(hidProspectCommentTypeId.Value))
                    {
                        var commentTypeid = Convert.ToInt32(hidProspectCommentTypeId.Value);

                        var prospectCommentType =
                            dbContext.ProspectCommentTypes.FirstOrDefault(
                                c => c.ProspectCommentTypeID.Equals(commentTypeid));

                        if (prospectCommentType != null)
                            lblProspectCommentTypeId.Text = prospectCommentType.ProspectComment;
                    }
                }

                //Prospect Stage
                var lblProspectStageId = (Label)e.Row.FindControl("lblProspectStageID");

                if (lblProspectStageId != null)
                {
                    var hidProspectStageId = (HiddenField) e.Row.FindControl("hidProspectStageID");
                    if (!string.IsNullOrEmpty(hidProspectStageId.Value))
                    {
                        var stageid = Convert.ToInt32(hidProspectStageId.Value);

                        var prospectStageType =
                            dbContext.ProspectProspectStages.FirstOrDefault(c => c.ProspectStageID.Equals(stageid));

                        if (prospectStageType != null)
                            lblProspectStageId.Text = prospectStageType.ProspectStage;
                    }
                }

                //Comment Source
                var lblCommentSources = (Label)e.Row.FindControl("lblCommentSources");

                if (lblCommentSources != null)
                {
                    var hidCommentSources = (HiddenField) e.Row.FindControl("hidCommentSources");
                    if (!string.IsNullOrEmpty(hidCommentSources.Value))
                    {
                        var commentSourceId = Convert.ToInt32(hidCommentSources.Value);

                        var commentSource =
                            dbContext.ProspectCommentSources.FirstOrDefault(
                                c => c.ProspectCommentSourceID.Equals(commentSourceId));

                        if (commentSource != null)
                            lblCommentSources.Text = commentSource.ProspectCommentSource1;
                    }
                }

            }
        }
Ejemplo n.º 8
0
        protected void gvComments_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var row = gvComments.Rows[e.RowIndex];
            var conversationId = Convert.ToInt32(Convert.ToString(gvComments.DataKeys[e.RowIndex].Values[0]));
            var prospectId = Convert.ToInt32(spanProspectId.InnerText);

            var prospectComment = (row.FindControl("txtProspectCommentEdit") as TextBox).Text;
            var prospectCommentType =Convert.ToInt32((row.FindControl("ddlProspectCommentTypeEdit") as DropDownList).SelectedValue);
            var prospectStage = Convert.ToInt32((row.FindControl("ddlProspectStageIDEdit") as DropDownList).SelectedValue);
            var commentSource = Convert.ToInt32((row.FindControl("ddlCommentSourcesEdit") as DropDownList).SelectedValue);
            var lastActivityDate2Edit = Convert.ToDateTime((row.FindControl("txtLastActivityDate2Edit") as TextBox).Text);
            var keyPhrase = (row.FindControl("txtKeyPhraseEdit") as TextBox).Text;

            using (var dataContext = new ProspectDataContext())
            {
                var conversation = dataContext.ProspectConversations.FirstOrDefault(p => p.ConversationId.Equals(conversationId));

                if (conversation != null)
                {
                    conversation.ProspectComment = prospectComment;
                    conversation.ProspectCommentTypeID = prospectCommentType;
                    conversation.ProspectStageID = prospectStage;
                    conversation.ProspectCommentSourceID = commentSource;
                    conversation.KeyPhrase = keyPhrase;
                    conversation.LastActivityDate = lastActivityDate2Edit;
                    conversation.CreatedByUserId = UserId;

                    try
                    {
                        dataContext.SubmitChanges();
                    }
                    catch (DbEntityValidationException ex)
                    {
                        foreach (var eve in ex.EntityValidationErrors)
                        {
                            Console.WriteLine(
                                "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                    ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                    }
                }

            }
            gvComments.EditIndex = -1;
            BindListOfProspects(Convert.ToInt32(spanProspectId.InnerText));
            PopulateDropdownsProspectConversations();
        }
Ejemplo n.º 9
0
        protected void gvComments_OnRowEditing(object sender, GridViewEditEventArgs e)
        {
            var hidProspectCommentTypeId = (HiddenField)gvComments.Rows[e.NewEditIndex].FindControl("hidProspectCommentTypeId");
            var hidProspectStageId = (HiddenField)gvComments.Rows[e.NewEditIndex].FindControl("hidProspectStageID");
            var hidCommentSources = (HiddenField)gvComments.Rows[e.NewEditIndex].FindControl("hidCommentSources");

            gvComments.EditIndex = e.NewEditIndex;
            BindListOfProspects(Convert.ToInt32(spanProspectId.InnerText));

            var row = gvComments.Rows[e.NewEditIndex];

            var dbContext = new ProspectDataContext();

            #region  ProspectCommentType Dropdown...

            var ddlProspectCommentTypeEdit = (DropDownList)row.FindControl("ddlProspectCommentTypeEdit");

            ddlProspectCommentTypeEdit.DataSource = dbContext.ProspectCommentTypes.ToList();
            ddlProspectCommentTypeEdit.DataTextField = "ProspectComment";
            ddlProspectCommentTypeEdit.DataValueField = "ProspectCommentTypeID";
            ddlProspectCommentTypeEdit.DataBind();

            ddlProspectCommentTypeEdit.Items.Insert(0, "Select");

            ddlProspectCommentTypeEdit.Items.FindByValue(hidProspectCommentTypeId.Value).Selected = true;

            #endregion  ProspectCommentType Dropdown...

            #region ProspectStageType Dropdown...

            var ddlProspectStageIdEdit = (DropDownList)row.FindControl("ddlProspectStageIDEdit");

            ddlProspectStageIdEdit.DataSource = dbContext.ProspectProspectStages.ToList();
            ddlProspectStageIdEdit.DataTextField = "ProspectStage";
            ddlProspectStageIdEdit.DataValueField = "ProspectStageID";
            ddlProspectStageIdEdit.DataBind();

            ddlProspectStageIdEdit.Items.Insert(0, "Select");

            ddlProspectStageIdEdit.Items.FindByValue(hidProspectStageId.Value).Selected = true;

            #endregion ProspectStageType Dropdown...

            #region ProspectCommentSource Dropdown...

            var ddlCommentSourcesEdit = (DropDownList)row.FindControl("ddlCommentSourcesEdit");

            ddlCommentSourcesEdit.DataSource = dbContext.ProspectCommentSources.ToList();
            ddlCommentSourcesEdit.DataTextField = "ProspectCommentSource1";
            ddlCommentSourcesEdit.DataValueField = "ProspectCommentSourceID";
            ddlCommentSourcesEdit.DataBind();

            ddlCommentSourcesEdit.Items.Insert(0, "Select");

            ddlCommentSourcesEdit.Items.FindByValue(hidCommentSources.Value).Selected = true;

            #endregion ProspectCommentSource Dropdown...
        }
Ejemplo n.º 10
0
        protected void btnAddProspect_OnClick(object sender, EventArgs e)
        {
            var txtCompanyAdd = (TextBox)gvProspects.FooterRow.FindControl("txtCompanyAdd");
            var txtContactNameAdd = (TextBox)gvProspects.FooterRow.FindControl("txtContactNameAdd");
            var txtContactEmailAdd = (TextBox)gvProspects.FooterRow.FindControl("txtContactEmailAdd");
            var txtContactPhoneAdd = (TextBox)gvProspects.FooterRow.FindControl("txtContactPhoneAdd");
            var txtContactCityAdd = (TextBox)gvProspects.FooterRow.FindControl("txtContactCityAdd");
            var ddlState = (DropDownList)gvProspects.FooterRow.FindControl("ddlStateAdd");
            var ddlContactTimeZoneAdd = (DropDownList)gvProspects.FooterRow.FindControl("ddlTimeZoneAdd");
            var txtLastActivityDateAdd = (TextBox)gvProspects.FooterRow.FindControl("txtLastActivityDateAdd");

            var dbContext = new ProspectDataContext();

            var dbProspect = new Prospect
            {
                Company = txtCompanyAdd.Text,
                ContactName = txtContactNameAdd.Text,
                ContactEmail = txtContactEmailAdd.Text,
                ContactPhone = txtContactPhoneAdd.Text,
                ContactCity = txtContactCityAdd.Text,
                ContactState = ddlState.SelectedValue,
                ContactTimeZone = ddlContactTimeZoneAdd.SelectedValue,
                LastActivityDate =Convert.ToDateTime(txtLastActivityDateAdd.Text),
                CreatedByUserId = UserId
            };

            dbContext.Prospects.InsertOnSubmit(dbProspect);
            dbContext.SubmitChanges();
            lblMsg.Text = "Prospect for Company: " + txtCompanyAdd.Text + " added.";

            BindGrid(SearchOn.None);
            PopulateDropdowns();
        }
Ejemplo n.º 11
0
        protected void btnAddComments_OnClick(object sender, EventArgs e)
        {
            var txtProspectCommentAdd = (TextBox)gvComments.FooterRow.FindControl("txtProspectCommentAdd");
            var ddlProspectCommentTypeAdd = (DropDownList)gvComments.FooterRow.FindControl("ddlProspectCommentTypeAdd");
            var ddlProspectStageIdAdd = (DropDownList)gvComments.FooterRow.FindControl("ddlProspectStageIDAdd");
            var ddlCommentSourcesAdd = (DropDownList)gvComments.FooterRow.FindControl("ddlCommentSourcesAdd");
            var txtLastActivityDate2Add = (TextBox)gvComments.FooterRow.FindControl("txtLastActivityDate2Add");
            var txtKeyPhraseAdd = (TextBox)gvComments.FooterRow.FindControl("txtKeyPhraseAdd");

            var dbContext = new ProspectDataContext();

            var dbProspectConversation = new ProspectConversation
            {
                ProspectId = Convert.ToInt32(spanProspectId.InnerText) ,
                ProspectComment = txtProspectCommentAdd.Text,
                ProspectCommentTypeID = Convert.ToInt32(ddlProspectCommentTypeAdd.SelectedValue),
                ProspectStageID = Convert.ToInt32(ddlProspectStageIdAdd.SelectedValue),
                ProspectCommentSourceID = Convert.ToInt32(ddlCommentSourcesAdd.SelectedValue),
                KeyPhrase = txtKeyPhraseAdd.Text,
                LastActivityDate = Convert.ToDateTime(txtLastActivityDate2Add.Text),
                CreatedByUserId = UserId
            };

            dbContext.ProspectConversations.InsertOnSubmit(dbProspectConversation);
            dbContext.SubmitChanges();

            BindListOfProspects(Convert.ToInt32(spanProspectId.InnerText));
            PopulateDropdownsProspectConversations();
        }