示例#1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                if (this.ValidateChildren())
                {
                    GatherData();
                    model.FK_PartyID = this.PartyID;
                    if (this.ContactID == 0)
                    {
                        model.IsActive = true;
                        this.ContactID = _contactService.AddNewContact(model);
                    }
                    else
                    {
                        _contactService.UpdateContact(model);
                    }

                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                string errMessage = ex.Message;
                if (ex.InnerException != null)
                {
                    errMessage += string.Format("\n{0}", ex.InnerException.Message);
                }
                MessageBox.Show(errMessage, "frmContact::btnSave_Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
        }
        private void GeneratePartiesForSalesLead()
        {
            ServiceSalesLead _leadService    = new ServiceSalesLead();
            ServiceParties   _partyService   = new ServiceParties();
            ServiceContacts  _contactService = new ServiceContacts();

            List <TBL_MP_CRM_SM_SalesLead> dbLeads = _leadService.GetAllSalesLeadDBItems();

            if (dbLeads == null)
            {
                return;
            }
            progressBar1.Value   = 0;
            progressBar1.Minimum = 0; progressBar1.Maximum = dbLeads.Count;

            int progressVAl = 0;

            foreach (TBL_MP_CRM_SM_SalesLead lead in dbLeads)
            {
                lblTitle.Text = string.Format("{0} of {1}\n\n{2} {3}\n{4}", progressVAl + 1, progressBar1.Maximum, lead.LeadNo, lead.LeadDate.ToString("dd MMM yyyy"), lead.LeadName);

                Tbl_MP_Master_Party party = _partyService.GetPartyByPartyName(lead.LeadName);
                if (party != null)
                {
                    lead.FK_PartyID = party.PK_PartyId;
                    _leadService.UpdateSalesLeadMasterInfo(lead);
                    lblTitle.Text += string.Format("\nExisting Party found. Customer update in SalesLead PartyID:{0}", lead.FK_PartyID);
                }
                else
                {
                    party = new Tbl_MP_Master_Party()
                    {
                        PartyType       = "C",
                        FK_PartyType    = 2,
                        PartyName       = lead.LeadName,
                        FK_IndustryType = 8003,
                        EmailID         = lead.LeadEmailID,
                        Website         = lead.LeadWebsite,
                        IsActive        = true
                    };

                    int partyID = _partyService.AddNewParty(party);
                    Tbl_MP_Master_PartyContact_Detail contact = new Tbl_MP_Master_PartyContact_Detail()
                    {
                        FK_PartyID         = partyID,
                        ContactPersoneName = lead.ContactPersone,
                        Address            = lead.LeadAddress,
                        EmailID            = lead.LeadEmailID,
                        TelephoneNo        = lead.LeadPhoneNo,
                        MobileNo           = lead.LeadMobileNo,
                        FaxNo    = lead.LeadFAXNo,
                        IsActive = true,
                    };
                    _contactService.AddNewContact(contact);
                    lblTitle.Text += "\n\nNew Party & Contact created.";
                }
                progressVAl++;
                progressBar1.Value = progressVAl;
                Application.DoEvents();
            }
        }