Exemplo n.º 1
0
        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BackEndObjects.Contacts contactObj = new BackEndObjects.Contacts();
            Panel_Create_Contact.Enabled = false;
            Label_Disable.Visible        = true;

            contactObj.setContactEntityId(((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Contact_Ent_Id")).Text);
            //contactObj.setContactName(((Label)GridView1.SelectedRow.Cells[1].FindControl("Label_Name")).Text);
            //contactObj.setEmailID(((Label)GridView1.SelectedRow.Cells[1].FindControl("Label_Email")).Text);
            contactObj.setContactName(((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Name")).Text);
            contactObj.setEmailID(((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Email_Id")).Text);
            contactObj.setEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
            contactObj.setFromSite("Y");

            //if (Session[SessionFactory.CREATE_CONTACT_LOCALITY_ID]!=null)
            if (((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Local_Id")).Text != null)
            {
                contactObj.setLocalityId(((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Local_Id")).Text);
            }

            contactObj.setMobNo(((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Contact_No")).Text);

            if (((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Street_Name")).Text != null)
            {
                contactObj.setStreetName(((Label)GridView1.SelectedRow.Cells[0].FindControl("Label_Street_Name")).Text);
            }

            String prodList = "";
            //Get the product/service details
            Dictionary <String, ProductCategory> prodDict = MainBusinessEntity.getProductDetailsforMainEntitybyIdDB(contactObj.getContactEntityId());

            foreach (KeyValuePair <String, ProductCategory> kvp in prodDict)
            {
                prodList += kvp.Value.getCategoryId() + ",";
            }

            if (prodList.Length > 0)
            {
                prodList = prodList.TrimEnd(',');
            }

            contactObj.setProdList(prodList);

            Session[SessionFactory.CREATE_CONTACT_CONTACT_OBJ] = contactObj;
        }
Exemplo n.º 2
0
        protected void Buttin_Submit_Click(object sender, EventArgs e)
        {
            BackEndObjects.Contacts contactObj = (Contacts)Session[SessionFactory.CREATE_CONTACT_CONTACT_OBJ];
            if (contactObj == null && TextBox_Contact_Name.Text.Equals(""))
            {
                Label_Status.Text      = "Please select contact from the site or enter the details";
                Label_Status.ForeColor = System.Drawing.Color.Red;
                Label_Status.Visible   = true;
                Buttin_Submit.Focus();
            }
            else
            {
                if (contactObj == null)
                {
                    contactObj = new BackEndObjects.Contacts();
                    BackEndObjects.Id IdGen = new Id();

                    int[]  prodServ = ListBoxProdServc.GetSelectedIndices();
                    String prodList = "";

                    for (int i = 0; i < prodServ.Length; i++)
                    {
                        if (i < (prodServ.Length - 1))
                        {
                            prodList += ListBoxProdServc.Items[prodServ[i]].Value + ",";
                        }
                        else
                        {
                            prodList += ListBoxProdServc.Items[prodServ[i]].Value;
                        }
                    }

                    contactObj.setContactEntityId(IdGen.getNewId(BackEndObjects.Id.ID_TYPE_CMP_USR_STRING));
                    contactObj.setContactName(TextBox_Contact_Name.Text);
                    contactObj.setContactShortName(TextBox_Contact_ShortName.Text);
                    contactObj.setEmailID(TextBox_EmailId.Text);
                    contactObj.setEntityId(Session[SessionFactory.MAIN_BUSINESS_ENTITY_ID_STRING].ToString());
                    contactObj.setFromSite("N");
                    String localId = (!DropDownList_Locality.SelectedValue.Equals("_") && !DropDownList_Locality.SelectedValue.Equals("") ?
                                      DropDownList_Locality.SelectedValue : (!DropDownList_City.SelectedValue.Equals("_") && !DropDownList_City.SelectedValue.Equals("") ?
                                                                             DropDownList_City.SelectedValue : (!DropDownList_State.SelectedValue.Equals("_") && !DropDownList_State.SelectedValue.Equals("") ?
                                                                                                                DropDownList_State.SelectedValue : (!DropDownList_Country.SelectedValue.Equals("_") && !DropDownList_Country.SelectedValue.Equals("") ?
                                                                                                                                                    DropDownList_Country.SelectedValue : ""))));

                    contactObj.setLocalityId(localId);
                    contactObj.setMobNo(TextBox_Contact_No.Text);
                    contactObj.setStreetName(TextBox_Street_Name.Text);
                    contactObj.setProdList(prodList);
                }
                else
                {
                    contactObj = (BackEndObjects.Contacts)Session[SessionFactory.CREATE_CONTACT_CONTACT_OBJ];
                    contactObj.setContactShortName(TextBox_Contact_ShortName.Text);
                    Session.Remove(SessionFactory.CREATE_CONTACT_ADDRESS_LINE1);
                    Session.Remove(SessionFactory.CREATE_CONTACT_CONTACT_OBJ);
                    Session.Remove(SessionFactory.CREATE_CONTACT_LOCALITY_ID);
                }

                try
                {
                    bool found = false;

                    Dictionary <String, Dictionary <String, String> > existingContactDict = (Dictionary <String, Dictionary <String, String> >)Session[SessionFactory.ALL_CONTACT_EXISTING_CONTACT_LIST];
                    if (existingContactDict != null && existingContactDict.Count > 0)
                    {
                        Dictionary <String, String> existingContactNames      = existingContactDict["names"];
                        Dictionary <String, String> existingContactShortNames = existingContactDict["shortnames"];
                        Dictionary <String, String> existingContactEmailIds   = existingContactDict["emailids"];
                        Dictionary <String, String> existingContactPhNos      = existingContactDict["phonenos"];

                        if (existingContactShortNames != null && existingContactShortNames.ContainsKey(contactObj.getContactShortName()))
                        {
                            found = true;
                        }
                        else if (existingContactNames != null && existingContactNames.ContainsKey(contactObj.getContactName()))
                        {
                            found = true;
                        }
                        else if (existingContactEmailIds != null && existingContactEmailIds.ContainsKey(contactObj.getEmailId()))
                        {
                            found = true;
                        }
                        else if (existingContactPhNos != null && existingContactPhNos.ContainsKey(contactObj.getMobNo()))
                        {
                            found = true;
                        }
                    }

                    if (found)
                    {
                        Label_Status.Text      = "Contact Exists with similar details. Please recheck";
                        Label_Status.ForeColor = System.Drawing.Color.Red;
                        Label_Status.Visible   = true;
                        Buttin_Submit.Focus();
                    }
                    else
                    {
                        BackEndObjects.Contacts.insertContactDetailsDB(contactObj);
                        Label_Status.Text      = "Contact created successfully";
                        Label_Status.ForeColor = System.Drawing.Color.Green;
                        Label_Status.Visible   = true;
                        Buttin_Submit.Focus();
                        Dictionary <String, String> allExistingContacts = (Dictionary <String, String>)Session[SessionFactory.EXISTING_CONTACT_DICTIONARY];
                        if (!allExistingContacts.ContainsKey(contactObj.getContactName()))
                        {
                            allExistingContacts.Add(contactObj.getContactName(), contactObj.getContactEntityId());
                        }
                        Session[SessionFactory.EXISTING_CONTACT_DICTIONARY] = allExistingContacts;

                        if (existingContactDict != null && existingContactDict.Count > 0)
                        {
                            Dictionary <String, String> existingContactNames      = existingContactDict["names"];
                            Dictionary <String, String> existingContactShortNames = existingContactDict["shortnames"];
                            Dictionary <String, String> existingContactEmailIds   = existingContactDict["emailids"];
                            Dictionary <String, String> existingContactPhNos      = existingContactDict["phonenos"];

                            if (existingContactShortNames != null && !existingContactShortNames.ContainsKey(contactObj.getContactShortName()) && !contactObj.getContactShortName().Equals(""))
                            {
                                existingContactShortNames.Add(contactObj.getContactShortName(), "");
                            }
                            if (existingContactNames != null && !existingContactNames.ContainsKey(contactObj.getContactName()) && !contactObj.getContactName().Equals(""))
                            {
                                existingContactNames.Add(contactObj.getContactName(), "");
                            }
                            if (existingContactEmailIds != null && !existingContactEmailIds.ContainsKey(contactObj.getEmailId()) && !contactObj.getEmailId().Equals(""))
                            {
                                existingContactEmailIds.Add(contactObj.getEmailId(), "");
                            }
                            if (existingContactPhNos != null && !existingContactPhNos.ContainsKey(contactObj.getMobNo()) && !contactObj.getMobNo().Equals(""))
                            {
                                existingContactPhNos.Add(contactObj.getMobNo(), "");
                            }

                            existingContactDict.Clear();
                            existingContactDict.Add("names", existingContactNames);
                            existingContactDict.Add("shortnames", existingContactShortNames);
                            existingContactDict.Add("emailids", existingContactEmailIds);
                            existingContactDict.Add("phonenos", existingContactPhNos);
                            Session[SessionFactory.ALL_CONTACT_EXISTING_CONTACT_LIST] = existingContactDict;
                        }


                        if (Request.QueryString.GetValues("parentContext") != null)
                        {
                            String parentContext = Request.QueryString.GetValues("parentContext")[0];
                            if (parentContext.Equals("lead") || parentContext.Equals("potn") || parentContext.Equals("rfq") || parentContext.Equals("broadcast") || parentContext.Equals("defect") || parentContext.Equals("sr"))
                            {
                                ScriptManager.RegisterStartupScript(this, typeof(string), "DispContactLead", "RefreshParent();", true);
                            }
                        }
                        else
                        {
                            DataTable dt = (DataTable)Session[SessionFactory.ALL_CONTACT_DATA_GRID];
                            dt.Rows.Add();

                            int i = dt.Rows.Count - 1;

                            dt.Rows[i]["ContactEntId"] = contactObj.getContactEntityId();
                            dt.Rows[i]["ContactName"]  = contactObj.getContactName();
                            dt.Rows[i]["ShortName"]    = contactObj.getContactShortName();
                            dt.Rows[i]["PhNo"]         = contactObj.getMobNo();
                            dt.Rows[i]["EmailId"]      = contactObj.getEmailId();
                            dt.Rows[i]["FromSite"]     = contactObj.getFromSite();

                            dt.DefaultView.Sort = "ContactName" + " " + "ASC";
                            Session[SessionFactory.ALL_CONTACT_DATA_GRID] = dt.DefaultView.ToTable();

                            ScriptManager.RegisterStartupScript(this, typeof(string), "updateContactGrid", "RefreshParentPostCreation();", true);
                        }
                    }

                    /*ListItem lt = new ListItem();
                     * lt.Text = (contactObj.getContactShortName() != null && !contactObj.getContactShortName().Equals("") ? contactObj.getContactShortName() :
                     *  contactObj.getContactName());
                     * lt.Value = contactObj.getContactEntityId();
                     *
                     * DropDownList prevDropList = PreviousPage.FindControl("DropDownList_Contacts") as DropDownList;
                     * ((DropDownList)Page.PreviousPage.FindControl("DropDownList_Contacts")).Items.Add(lt);*/
                }
                catch (Exception ex)
                {
                    Label_Status.Text      = "Contact creation failed";
                    Label_Status.ForeColor = System.Drawing.Color.Red;
                    Label_Status.Visible   = true;
                    Buttin_Submit.Focus();
                }
            }
        }