private void MovePrevious(ManageCampaignBookingEvents.OnLoadPreviousCompany.CampaignList e) { m_BrightSalesProperty.CampaignBooking.LoadPreviousCompanySuccess = false; if (gvCampaignList.RowCount < 1) return; /** * check current company if being released by the the user before loading the next company. */ sub_campaign_account_lists _item = null; int _AcctId = ValidationUtility.TryParseInt(gvCampaignList.GetRowCellValue(m_CampaignListSelectedRow, "account_id").ToString()); int _FinalListId = ValidationUtility.TryParseInt(gvCampaignList.GetRowCellValue(m_CampaignListSelectedRow, "final_list_id").ToString()); using (BrightPlatformEntities _efDbContext = new BrightPlatformEntities(UserSession.EntityConnection)) { _item = _efDbContext.sub_campaign_account_lists.FirstOrDefault(i => i.account_id == _AcctId && i.final_list_id == _FinalListId ); if (_item != null) _efDbContext.Detach(_item); if ((_item.locked && _item.locked_by == UserSession.CurrentUser.UserId) || !_item.locked) { gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked", false); this.GetCurrentCampaignListAccount(); this.ReleaseCurrentCompanyLock(); } /** * [@jeff 10.18.2013]: https://brightvision.jira.com/browse/PLATFORM-2638 * added logic to go to the next company if campaign list is on companies and contacts mode. */ int _Row = 0; if (gvCampaignList.FocusedRowHandle > 0) _Row = gvCampaignList.FocusedRowHandle - 1; for (; _Row < gvCampaignList.RowCount; _Row--) { int _PrevAcctId = ValidationUtility.TryParseInt(ValidationUtility.IFNullString(gvCampaignList.GetRowCellValue(_Row, "account_id"),"0")); if (_AcctId != _PrevAcctId) break; } /** * now, we will load the next company and re-check if this is currently worked by other consultants. */ m_BrightSalesProperty.CommonProperty.CompanyLocked = false; gvCampaignList.FocusedRowHandle = _Row; _AcctId = ValidationUtility.TryParseInt(gvCampaignList.GetRowCellValue(m_CampaignListSelectedRow, "account_id").ToString()); _FinalListId = ValidationUtility.TryParseInt(gvCampaignList.GetRowCellValue(m_CampaignListSelectedRow, "final_list_id").ToString()); _item = _efDbContext.sub_campaign_account_lists.FirstOrDefault(i => i.account_id == _AcctId && i.final_list_id == _FinalListId ); if (_item.locked && _item.locked_by > 0 && _item.locked_by != UserSession.CurrentUser.UserId) { user _user = _efDbContext.users.FirstOrDefault(i => i.id == _item.locked_by); if (_user != null) _efDbContext.Detach(_user); m_BrightSalesProperty.CommonProperty.CompanyLocked = true; NotificationDialog.Warning("Bright Sales", string.Format("{0}This company is currently worked by{0}{1}", Environment.NewLine, _user.fullname)); } this.SetCampaignListAppointmentParams(); if (!m_BrightSalesProperty.CommonProperty.CompanyLocked) { bool islocked = m_CurrentCampaignListAccount.locked; int? lockedBy = m_CurrentCampaignListAccount.locked_by; bool _State = islocked && lockedBy != UserSession.CurrentUser.UserId ? false : true; btnWorkOnCompany.Enabled = _State; btnRemoveCompany.Enabled = _State; if ((islocked && lockedBy == UserSession.CurrentUser.UserId) || !islocked) { //var BPContext = new BrightPlatformEntities(UserSession.EntityConnection); m_CurrentCampaignListAccount.locked = true; m_CurrentCampaignListAccount.locked_by = UserSession.CurrentUser.UserId; m_CurrentCampaignListAccount.locked_timestamp = _efDbContext.FIUpdateUserLock( m_FinalListId, m_AccountId, m_CurrentCampaignListAccount.locked, m_CurrentCampaignListAccount.locked_by ).FirstOrDefault(); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked", m_CurrentCampaignListAccount.locked); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_by", m_CurrentCampaignListAccount.locked_by); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "Locked_By_User", UserSession.CurrentUser.UserFullName); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_timestamp", m_CurrentCampaignListAccount.locked_timestamp); } gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked", true); } } m_CampaignListSelectedRow = gvCampaignList.FocusedRowHandle < 0 ? 0 : gvCampaignList.FocusedRowHandle; m_BrightSalesProperty.CampaignBooking.LoadPreviousCompanySuccess = true; return; }
/** / private void GetFindFilterString(string pFilterText) { m_CampaignListFindFilter = string.Empty; if (string.IsNullOrEmpty(pFilterText)) return; List<string> _FilterString = new List<string>(); for (int i = 0; i < gvCampaignList.VisibleColumns.Count; i++) { if (CampaignListMode == eCampaignListMode.CompaniesOnly) { if (gvCampaignList.VisibleColumns[i].FieldName.Equals("id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_status") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("locked") || gvCampaignList.VisibleColumns[i].FieldName.Equals("locked_by") || gvCampaignList.VisibleColumns[i].FieldName.Equals("locked_timestamp") || gvCampaignList.VisibleColumns[i].FieldName.Equals("final_list_id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_latitude") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_longitude") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_address")) continue; //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Employees_Total_1") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Employees_Total_2") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Employees_Total_3") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Turnover_1") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Turnover_2") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Turnover_3") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Export_1") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Export_2") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Export_3") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Result_1") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Result_2") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Result_3") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Sales_Aborad_1") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Sales_Aborad_2") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Sales_Aborad_3") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Created") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Modified") || //gvCampaignList.VisibleColumns[i].FieldName.Equals("Company_Validated")) } else if (CampaignListMode == eCampaignListMode.CompaniesAndContacts) { if (gvCampaignList.VisibleColumns[i].FieldName.Equals("id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_status") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("locked") || gvCampaignList.VisibleColumns[i].FieldName.Equals("locked_by") || gvCampaignList.VisibleColumns[i].FieldName.Equals("locked_timestamp") || gvCampaignList.VisibleColumns[i].FieldName.Equals("final_list_id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_latitude") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_longitude") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_latitude") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_longitude") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_address") || gvCampaignList.VisibleColumns[i].FieldName.Equals("contact_id") || gvCampaignList.VisibleColumns[i].FieldName.Equals("account_address")) continue; } _FilterString.Add(string.Format("Contains(Lower({0}),'{1}')", gvCampaignList.VisibleColumns[i].FieldName, pFilterText.ToLowerInvariant() )); } if (_FilterString.Count > 0) m_CampaignListFindFilter = string.Join(" Or ", _FilterString.ToArray()); } private void GetCheckedFilters() { m_CampaignListCheckedFilter = string.Empty; List<string> _FilterString = new List<string>(); if (cbxFilterMeLastUser.Checked) _FilterString.Add(string.Format("Contains(Lower([Company_Last_User]),Lower('{0}'))", UserSession.CurrentUser.UserFullName )); if (cbxShowOnlyNonFinished.Checked) _FilterString.Add("[Company_Status] != 'Finished'"); if (_FilterString.Count > 0) m_CampaignListCheckedFilter = string.Join(" And ", _FilterString.ToArray()); } private void GetSpecificColumnFilters() { m_CampaignListSpecificColumnFilter = string.Empty; if (string.IsNullOrEmpty(m_OperatorArgs.Value.ToString())) return; try { DevExpress.Data.Filtering.GroupOperator _Operators = (DevExpress.Data.Filtering.GroupOperator)m_OperatorArgs.Value; for (int i = 0; i < _Operators.Operands.Count; i++) { string _Operator = _Operators.Operands[i].ToString(); if (_Operator.Contains("=") || _Operator.Contains(">") || _Operator.Contains(">=") || _Operator.Contains("<") || _Operator.Contains("<=") || _Operator.Contains("<>") || _Operator.Contains("Between") || _Operator.Contains("Is Null") || _Operator.Contains("Is Not Null")) { string _operand_value = ((DevExpress.Data.Filtering.BinaryOperator)(_Operators.Operands[i])).RightOperand.ToString(); //if (ValidationUtility.IsCurrency(_Operators.Operands[i].ToString())) if (ValidationUtility.IsCurrency(_operand_value.Replace("'", ""))) continue; } string _value = _Operators.Operands[i].ToString().Replace("'", """); _Operators.Operands[i] = _value.Replace("[", "Lower(").Replace("]", ")"); } m_CampaignListSpecificColumnFilter = _Operators.ToString().Replace("'L", "L").Replace(";'", ";"); m_CampaignListSpecificColumnFilter = m_CampaignListSpecificColumnFilter.Replace("'", "").Replace(""", "'"); } catch { string _Val = m_OperatorArgs.Value.ToString(); if (_Val.Contains("=") || _Val.Contains(">") || _Val.Contains(">=") || _Val.Contains("<") || _Val.Contains("<=") || _Val.Contains("<>") || _Val.Contains("Between") || _Val.Contains("Is Null") || _Val.Contains("Is Not Null")) { string _operand_value = ((DevExpress.Data.Filtering.BinaryOperator)(m_OperatorArgs.Value)).RightOperand.ToString(); if (!ValidationUtility.IsCurrency(_operand_value.Replace("'", ""))) { string _temp = _Val.Replace("'", """); _Val = _temp.Replace("[", "Lower(").Replace("]", ")"); } else m_CampaignListSpecificColumnFilter = _Val; } else { DevExpress.Data.Filtering.CriteriaOperatorCollection _operators = ((DevExpress.Data.Filtering.FunctionOperator)(((DevExpress.Data.Filtering.CriteriaOperator)(m_OperatorArgs.Value)))).Operands; string _operand_value = _operators[1].ToString(); if (!ValidationUtility.IsCurrency(_operand_value.Replace("'", ""))) { string _temp = _Val.Replace("'", """); _Val = _temp.Replace("[", "Lower(").Replace("]", ")"); } m_CampaignListSpecificColumnFilter = _Val; //.Replace("[", "Lower(").Replace("]", ")"); } m_CampaignListSpecificColumnFilter = _Val.Replace("'", "").Replace(""", "'"); } //if (string.IsNullOrEmpty(gvCampaignList.FilterPanelText)) { // m_CampaignListSpecificColumnFilter = string.Empty; // return; //} //string[] _ColumnFilter = Regex.Split(gvCampaignList.FilterPanelText, " And "); //for (int i = 0; i < _ColumnFilter.Count(); i++) { // if (_ColumnFilter[i].Contains(">") || // _ColumnFilter[i].Contains(">=") || // _ColumnFilter[i].Contains("<") || // _ColumnFilter[i].Contains("<=") || // _ColumnFilter[i].Contains("Between") || // _ColumnFilter[i].Contains("Is Null") || // _ColumnFilter[i].Contains("Is Not Null") || // _ColumnFilter[i].Contains("In")) // continue; //} //m_CampaignListSpecificColumnFilter = string.Join(" A ", _ColumnFilter.ToArray()); //if (!string.IsNullOrEmpty(m_CampaignListSpecificColumnFilter)) // m_CampaignListSpecificColumnFilter = m_CampaignListSpecificColumnFilter.Replace("[", "Lower(").Replace("]", ")"); } /**/ private void WorkOnSelectedAccount() { if (gvCampaignList.RowCount < 1) return; try { this.ReleaseCurrentCompanyLock(); bool islocked = m_CurrentCampaignListAccount.locked; int? lockedBy = m_CurrentCampaignListAccount.locked_by; bool _State = islocked && lockedBy != UserSession.CurrentUser.UserId ? false : true; btnWorkOnCompany.Enabled = _State; btnRemoveCompany.Enabled = _State; if ((islocked && lockedBy == UserSession.CurrentUser.UserId) || !islocked) { using (BrightPlatformEntities _efDbContext = new BrightPlatformEntities(UserSession.EntityConnection)) { m_CurrentCampaignListAccount.locked = true; m_CurrentCampaignListAccount.locked_by = UserSession.CurrentUser.UserId; m_CurrentCampaignListAccount.locked_timestamp =_efDbContext.FIUpdateUserLock( m_FinalListId, m_AccountId, m_CurrentCampaignListAccount.locked, m_CurrentCampaignListAccount.locked_by ).FirstOrDefault(); } gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked", m_CurrentCampaignListAccount.locked); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_by", m_CurrentCampaignListAccount.locked_by); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "Locked_By_User", UserSession.CurrentUser.UserFullName); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_timestamp", m_CurrentCampaignListAccount.locked_timestamp); this.LoadCampaignBooking(ObjectEventSender.btnWorkOnCompany_Click); } else { gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked", true); NotificationDialog.Warning("Bright Sales", "The selected company is currently edited by another user. Please try again later."); m_CurrentCampaignListAccount = null; } } catch (Exception e) { m_EventBus.Notify(new FrmSalesConsultantEvents.Tracer() { ErrorMessage = e.Message }); } }
public bool CanWorkCompany() { if (gvCampaignList.RowCount < 1) return false; this.GetCurrentCampaignListAccount(); this.ReleaseCurrentCompanyLock(); //this.GetCurrentCampaignListAccount(); if (m_CurrentCampaignListAccount == null) return false; bool islocked = m_CurrentCampaignListAccount.locked; int? lockedBy = m_CurrentCampaignListAccount.locked_by; if ((islocked && lockedBy == UserSession.CurrentUser.UserId) || !islocked) { var BPContext = new BrightPlatformEntities(UserSession.EntityConnection); m_CurrentCampaignListAccount.locked = true; m_CurrentCampaignListAccount.locked_by = UserSession.CurrentUser.UserId; m_CurrentCampaignListAccount.locked_timestamp = BPContext.FIUpdateUserLock( m_CurrentCampaignListAccount.final_list_id, m_CurrentCampaignListAccount.account_id, m_CurrentCampaignListAccount.locked, m_CurrentCampaignListAccount.locked_by).FirstOrDefault(); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked", m_CurrentCampaignListAccount.locked); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_by", m_CurrentCampaignListAccount.locked_by); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_user", UserSession.CurrentUser.UserFullName); gvCampaignList.SetRowCellValue(gvCampaignList.FocusedRowHandle, "locked_timestamp", m_CurrentCampaignListAccount.locked_timestamp); return true; } else { NotificationDialog.Warning("Bright Sales", "The selected company is currently edited by another user. Please try again later."); m_CurrentCampaignListAccount = null; return false; } }