Exemplo n.º 1
0
        private void Save()
        {
            if (vgridCompanyInfo.GetRecordObject(0) == null)
                return;

            account accnt = vgridCompanyInfo.GetRecordObject(0) as account;
            if (accnt == null)
                return;

            //if (CompanyRemarks != null)
            //    accnt.remarks = CompanyRemarks;

            /**
             * [@jeff 06.20.2012]: https://brightvision.jira.com/browse/PLATFORM-1460
             * add event logging for edited accounts.
             */
            accnt.last_modified_machine = UserSession.CurrentUser.ComputerName;
            accnt.last_modified_source = BrightVision.EventLog.Business.FacadeEventLog.Source_Bright_Sales_Company_Information;
            accnt.modified_by = UserSession.CurrentUser.UserId;
            accnt.modified_date = DateTime.Now;
            m_objDatabaseModel.accounts.FirstOrDefault(i => i.id == accnt.id);
            m_objDatabaseModel.accounts.ApplyCurrentValues(accnt);

            int SubCampaignId = m_objDatabaseModel.final_lists.FirstOrDefault(i => i.id == m_FinalListId).sub_campaign_id;
            sub_campaign_account_remarks _efeCompanyRemarks = m_objDatabaseModel.sub_campaign_account_remarks.FirstOrDefault(i => i.sub_campaign_id == SubCampaignId && i.account_id == m_AccountId);
            if (_efeCompanyRemarks == null) {
                m_objDatabaseModel.sub_campaign_account_remarks.AddObject(
                    new sub_campaign_account_remarks() {
                        sub_campaign_id = SubCampaignId,
                        account_id = m_AccountId,
                        remarks = tbxAccountSubCampaignRemark.Text
                    }
                );
            }
            else {
                _efeCompanyRemarks.remarks = tbxAccountSubCampaignRemark.Text;
                m_objDatabaseModel.sub_campaign_account_remarks.ApplyCurrentValues(_efeCompanyRemarks);
            }

            m_objDatabaseModel.SaveChanges();
            CompanyPhone = accnt.telephone;
            CompanyWebsite = accnt.www;

            //if (OnCompanyInformationSaved != null) {
            //    CompanyInformationArgs cargs = new CompanyInformationArgs(accnt);
            //    OnCompanyInformationSaved(this, cargs);
            //}

            /**
             * save company geo code information
             */
            #region Code Logic
            StringBuilder _address = new StringBuilder();
            if (!string.IsNullOrEmpty(accnt.box_address))
                _address.Append(accnt.box_address);
            if (!string.IsNullOrEmpty(accnt.street_address))
                _address.Append(_address.Length > 0 ? "," + accnt.street_address : accnt.street_address);
            if (!string.IsNullOrEmpty(accnt.zipcode))
                _address.Append(_address.Length > 0 ? "," + accnt.zipcode : accnt.zipcode);
            if (!string.IsNullOrEmpty(accnt.city))
                _address.Append(_address.Length > 0 ? "," + accnt.city : accnt.city);
            if (!string.IsNullOrEmpty(accnt.country))
                _address.Append(_address.Length > 0 ? "," + accnt.country : accnt.country);

            GoogleMapUtility _oMapUtility = new GoogleMapUtility();
            if (!string.IsNullOrEmpty(_address.ToString()) || !GoogleMapUtility.IsValidGeoAddress(_address.ToString()))
            {
                string[] _oGeoData = _oMapUtility.GetGeographicalData(_address.ToString()).Split(',');
                double _Latitude = 0;
                double _Longitude = 0;

                // save only if returned success code
                if (_oGeoData[0].ToString().Equals("200"))
                {
                    if (_oGeoData[2] != null)
                        if (ValidationUtility.IsCurrency(_oGeoData[2]))
                            _Latitude = Convert.ToDouble(_oGeoData[2], CultureInfo.InvariantCulture);

                    if (_oGeoData[3] != null)
                        if (ValidationUtility.IsCurrency(_oGeoData[3]))
                            _Longitude = Convert.ToDouble(_oGeoData[3], CultureInfo.InvariantCulture);

                    if (_Latitude != 0 || _Longitude != 0)
                    {
                        BrightPlatformEntities _efDbModel = new BrightPlatformEntities(UserSession.EntityConnection);
                        _efDbModel.FISaveGeographicalData(0, accnt.id, (decimal)_Latitude, (decimal)_Longitude, UserSession.CurrentUser.UserId);
                    }
                }
            }
            #endregion
        }
Exemplo n.º 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!AllowSaving)
                return;

            if (m_IsEmpty)
                return;

            if (!CompliedRequiredFields()) {
                NotificationDialog.Error("Bright Sales", "Required fields firstname/lastname/email cannot be empty or has invalid data.");
                return;
            }

            if (BrightVision.Common.Utilities.ValidationUtility.IFNullString(editorRowLinkedInURL.Properties.Value, "") != "" &&
                !BrightVision.Common.Utilities.ValidationUtility.IFNullString(editorRowLinkedInURL.Properties.Value, "").Contains("/profile/view?id="))
            {
                NotificationDialog.Error("Bright Sales", "Invalid LinkedIn url.");
                editorRowLinkedInURL.Appearance.ForeColor = Color.FromArgb(255, 255, 255);
                editorRowLinkedInURL.Appearance.BackColor = Color.FromArgb(244, 102, 102);//red
                editorRowLinkedInURL.Appearance.BackColor2 = Color.FromArgb(244, 102, 102);//red
                return;
            }

            bool _editable = true;
            using (BrightPlatformEntities _efDbContext = new BrightPlatformEntities(UserSession.EntityConnection)) {
                sub_campaign_account_lists _eftCurrentCompany = _efDbContext.sub_campaign_account_lists.FirstOrDefault(i => i.final_list_id == m_FinalListId && i.account_id == m_AccountId);
                if (_eftCurrentCompany != null) {
                    if (_eftCurrentCompany.locked_by != null && _eftCurrentCompany.locked_by != UserSession.CurrentUser.UserId)
                        _editable = false;

                    _efDbContext.Detach(_eftCurrentCompany);
                }
            }

            if (!_editable) {
                NotificationDialog.Error("Bright Sales", "Currently worked by another user.");
                return;
            }

            //string _Message = string.Format("Are you sure to {0} this contact data?", (m_IsNewContact ? "save" : "update"));
            //DialogResult objResult = MessageBox.Show(_Message, "Bright Sales", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            //if (objResult == DialogResult.No)
            //    return;

            var contact = vgridContact.GetRecordObject(0) as CTContactDetails;
            if (contact.absence_start != null && contact.absence_end == null) {
                NotificationDialog.Error("Bright Sales", "Absence end required.");
                return;
            }

            WaitDialog.Show(ParentForm, "Saving contact data...");
            #region Save Contact Information
            if (contact.absence_start == null && contact.absence_end != null)
                contact.absence_start = DateTime.Now;

            int _Hours = Convert.ToDateTime(contact.absence_start).TimeOfDay.Hours;
            int _Minutes = Convert.ToDateTime(contact.absence_start).TimeOfDay.Minutes;
            if ((_Hours >= 0 && _Hours < 3) && _Minutes > 0) {
                DateTime _date = Convert.ToDateTime(contact.absence_start);
                TimeSpan _time = new TimeSpan(3, 0, 0);
                contact.absence_start = _date.Date + _time;
            }

            _Hours = Convert.ToDateTime(contact.absence_end).TimeOfDay.Hours;
            _Minutes = Convert.ToDateTime(contact.absence_end).TimeOfDay.Minutes;
            if ((_Hours >= 0 && _Hours < 3) && _Minutes > 0) {
                DateTime _date = Convert.ToDateTime(contact.absence_end);
                TimeSpan _time = new TimeSpan(3, 0, 0);
                contact.absence_end = _date.Date + _time;
            }

            if (contact.absence_start > contact.absence_end) {
                WaitDialog.Close();
                NotificationDialog.Error("Bright Sales", "Absence start must be less than absence end.");
                return;
            }

            int _AcctId = 0;
            if (m_CallingEnvironment == SelectionProperty.CallingEnvironment.CampaignList)
                _AcctId = m_BrightSalesProperty.CommonProperty.AccountId;
            else
                _AcctId = m_BrightSalesProperty.CommonProperty.CurrentWorkedAccountId;

            /**
             * set active = null, so the original active value stays as it is when saving contact.
             * activation/de-activation happens @ user level action (deactivate button & checkbox).
             */
            int _SubCampaignId = m_efDbModel.final_lists.FirstOrDefault(i => i.id == m_FinalListId).sub_campaign_id;

            if (!m_IsNewContact) {
                m_efDbModel.FIUpdateContactDetails(
                    contact.id, contact.first_name, contact.middle_name, contact.last_name, contact.direct_phone,
                    contact.mobile, contact.title_id, null, contact.role_tags, contact.address_1, contact.address_2, contact.city,
                    contact.zipcode, contact.country, contact.remarks, UserSession.CurrentUser.UserId,
                    contact.email, contact.linkedin_url, null, null, _AcctId, m_FinalListId,
                    UserSession.CurrentUser.ComputerName,
                    BrightVision.EventLog.Business.FacadeEventLog.Source_Bright_Sales_Contact_Information,
                    contact.absence_start,
                    contact.absence_end,
                    _SubCampaignId,
                    _AcctId
                );
            }
            else {
                int? contactId = m_efDbModel.FIUpdateContactDetails(
                    null, contact.first_name, contact.middle_name, contact.last_name, contact.direct_phone,
                    contact.mobile, contact.title_id, null, contact.role_tags, contact.address_1, contact.address_2, contact.city,
                    contact.zipcode, contact.country, contact.remarks, UserSession.CurrentUser.UserId,
                    contact.email, contact.linkedin_url, 0, true, _AcctId, m_FinalListId,
                    UserSession.CurrentUser.ComputerName,
                    BrightVision.EventLog.Business.FacadeEventLog.Source_Bright_Sales_Contact_Information,
                    contact.absence_start,
                    contact.absence_end,
                    _SubCampaignId,
                    _AcctId
                ).FirstOrDefault();

                contact.id = contactId == null ? 0 : (int)contactId;
            }
            //m_efDbModel.SaveChanges();
            this.SetParameters(contact.id);
            #endregion

            /**
             * save contact geo code information
             */
            #region Code Logic
            StringBuilder _address = new StringBuilder();
            if (!string.IsNullOrEmpty(contact.address_1))
                _address.Append(contact.address_1);
            if (!string.IsNullOrEmpty(contact.address_2))
                _address.Append(_address.Length > 0 ? "," + contact.address_2 : contact.address_2);
            if (!string.IsNullOrEmpty(contact.zipcode))
                _address.Append(_address.Length > 0 ? "," + contact.zipcode : contact.zipcode);
            if (!string.IsNullOrEmpty(contact.city))
                _address.Append(_address.Length > 0 ? "," + contact.city : contact.city);
            if (!string.IsNullOrEmpty(contact.country))
                _address.Append(_address.Length > 0 ? "," + contact.country : contact.country);

            GoogleMapUtility _oMapUtility = new GoogleMapUtility();
            if (!string.IsNullOrEmpty(_address.ToString()) || !GoogleMapUtility.IsValidGeoAddress(_address.ToString()))
            {
                string[] _oGeoData = _oMapUtility.GetGeographicalData(_address.ToString()).Split(',');
                double _Latitude = 0;
                double _Longitude = 0;

                // save only if returned success code
                if (_oGeoData[0].Equals("200")) {
                    if (_oGeoData[2] != null)
                        if (ValidationUtility.IsCurrency(_oGeoData[2]))
                            _Latitude = Convert.ToDouble(_oGeoData[2], CultureInfo.InvariantCulture);

                    if (_oGeoData[3] != null)
                        if (ValidationUtility.IsCurrency(_oGeoData[3]))
                            _Longitude = Convert.ToDouble(_oGeoData[3], CultureInfo.InvariantCulture);

                    if (_Latitude != 0 || _Longitude != 0)
                    {
                        BrightPlatformEntities _efDbModel = new BrightPlatformEntities(UserSession.EntityConnection);
                        _efDbModel.FISaveGeographicalData(1, contact.id, (decimal)_Latitude, (decimal)_Longitude, UserSession.CurrentUser.UserId);
                    }
                }
            }
            #endregion

            this.GetContactInformation();
            if (m_CallingEnvironment == SelectionProperty.CallingEnvironment.CampaignBooking) {
                m_EventBus.Notify(new ContactInformationEvents.OnSave.ManageCampaignBooking() {
                    OnSaveArgs = new ContactInformationEvents.ContactInformationArgs() {
                        ContactDetail = m_ContactDetail,
                        IsNewContact = m_IsNewContact,
                        NewContactId = m_ContactId
                    }
                });
            }
            else if (m_CallingEnvironment == SelectionProperty.CallingEnvironment.CampaignList) {
                m_EventBus.Notify(new ContactInformationEvents.OnSave.ManageCampaignList() {
                    OnSaveArgs = new ContactInformationEvents.ContactInformationArgs() {
                        ContactDetail = m_ContactDetail,
                        IsNewContact = m_IsNewContact,
                        NewContactId = m_ContactId
                    }
                });
            }

            //if (btnSave_OnClick != null)
            //    btnSave_OnClick(this, this.GetArguments());

            this.Show(contact.id, m_FinalListId, false, _AcctId);
            btnNew.Enabled = true;
            btnSave.Enabled = true;
            btnCancel.Enabled = false;
            //btnDelete.Enabled = true;
            if (m_IsActive)
                btnDelete.Enabled = true;
            else
                btnDelete.Enabled = false;
            m_IsNewContact = false;

            WaitDialog.Close();

            #region Original Code
            //if (m_objContactInformationForm.IsEmpty)
            //    return;

            //if (!m_objContactInformationForm.ValidateRequiredFields())
            //{
            //    MessageBox.Show("Required fields firstname/lastname cannot be empty.", "Bright Sales", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}

            //DialogResult objResult = MessageBox.Show("Are you sure to " +
            //    (m_objContactInformationForm.IsNewContact ? "save" : "update")
            //    + " this contact data?", "Bright Sales", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            //if (objResult == DialogResult.Yes)
            //{
            //
            //    WaitDialog.Show(ParentForm, "Saving contact data.");

            //    //m_objContactInformationForm.ContactRemarks = txtContactRemarks.Text;
            //    m_objContactInformationForm.AccountId = oAppointment.AccountId;
            //    m_objContactInformationForm.SaveContactInformation();
            //    m_oContactView.ContactId = m_objContactInformationForm.GetContactId();
            //    m_oContactView.PopulateContactView(oAppointment.SubCampaignId, oAppointment.AccountId, oAppointment.FinalListId);
            //    m_oContactView_gvContact_FocusedRowChanged(null, null);
            //    this.LoadContactInformation();
            //    var cont = m_oContactView.SelectedContact;

            //    if (cont == null)
            //        return;

            //    if (!string.IsNullOrEmpty(cont.direct_phone))
            //    {
            //        lcgCallDirect.Enabled = true;
            //        btnCallDirect.Enabled = true;
            //    }
            //    else
            //    {
            //        lcgCallDirect.Enabled = false;
            //        btnCallDirect.Enabled = false;
            //    }

            //    if (!string.IsNullOrEmpty(cont.mobile))
            //    {
            //        lcgCallMobile.Enabled = true;
            //        btnCallMobile.Enabled = true;
            //    }
            //    else
            //    {
            //        lcgCallMobile.Enabled = false;
            //        btnCallMobile.Enabled = false;
            //    }

            //    WaitDialog.Close();
            //}
            #endregion
        }