コード例 #1
0
        /// <summary>
        /// Valida que un Segement cumpla con los filtros actuales
        /// </summary>
        /// <param name="segmentByLS"></param>
        /// <returns>True. Si cumple | False. No cumple</returns>
        /// <history>
        /// [emoguel] created 02/06/2016
        /// </history>
        private bool ValidateFilter(SegmentByLeadSource segmentByLS)
        {
            if (_nStatus != -1)//Filtro por estatus
            {
                if (segmentByLS.soA != Convert.ToBoolean(_nStatus))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_segmentByLSFilter.soID))//Filtro por ID
            {
                if (segmentByLS.soID != _segmentByLSFilter.soID)
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_segmentByLSFilter.soN))//Filtro por descripcion
            {
                if (!segmentByLS.soN.Contains(_segmentByLSFilter.soN, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Abre la ventana detalle en modo "detalle" o "edición" dependiendo de sus permisos
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 02/06/2016
        /// </history>
        private void Cell_DoubleClick(object sender, RoutedEventArgs e)
        {
            SegmentByLeadSource          segmentByLS    = (SegmentByLeadSource)dgrSegments.SelectedItem;
            frmSegmentByLeadSourceDetail frmSegmentByLS = new frmSegmentByLeadSourceDetail();

            frmSegmentByLS.Owner = this;
            frmSegmentByLS.oldSegmentByLeadSource = segmentByLS;
            frmSegmentByLS.enumMode = (_blnEdit) ? EnumMode.Edit : EnumMode.ReadOnly;
            if (frmSegmentByLS.ShowDialog() == true)
            {
                int nIndex = 0;
                List <SegmentByLeadSource> lstSegmentByLS = (List <SegmentByLeadSource>)dgrSegments.ItemsSource;
                if (ValidateFilter(frmSegmentByLS.segmentByLeadSource))                           //Validar que cumpla con los filtros
                {
                    ObjectHelper.CopyProperties(segmentByLS, frmSegmentByLS.segmentByLeadSource); //Actualizamos los datos
                    lstSegmentByLS.Sort((x, y) => string.Compare(x.soN, y.soN));                  //Ordenamos la lista
                    nIndex = lstSegmentByLS.IndexOf(segmentByLS);                                 //Obtenemos la posición del registro
                }
                else
                {
                    lstSegmentByLS.Remove(segmentByLS);                     //Quitamos el registro
                }
                dgrSegments.Items.Refresh();                                //Actualizamos la vista
                GridHelper.SelectRow(dgrSegments, nIndex);                  //Seleccionamos el registro
                StatusBarReg.Content = lstSegmentByLS.Count + " Segments."; //Actualizamos el contador
            }
        }
コード例 #3
0
        /// <summary>
        /// Llena el grid de segments By Lead Source
        /// </summary>
        /// <param name="leadSource">Objeto a seleccionar</param>
        /// <history>
        /// [emoguel] created 02/06/2016
        /// </history>
        private async void LoadSegmentsByLeadSource(SegmentByLeadSource segmentByLS = null)
        {
            try
            {
                status.Visibility = Visibility.Visible;
                int nIndex = 0;
                List <SegmentByLeadSource> lstSegmentsByLS = await BRSegmentsByLeadSource.GetSegmentsByLeadSource(_nStatus, _segmentByLSFilter);

                dgrSegments.ItemsSource = lstSegmentsByLS;
                if (lstSegmentsByLS.Count > 0 && segmentByLS != null)
                {
                    segmentByLS = lstSegmentsByLS.Where(so => so.soID == segmentByLS.soID).FirstOrDefault();
                    nIndex      = lstSegmentsByLS.IndexOf(segmentByLS);
                }
                GridHelper.SelectRow(dgrSegments, nIndex);
                StatusBarReg.Content = lstSegmentsByLS.Count + " Segments.";
                status.Visibility    = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }
コード例 #4
0
        /// <summary>
        /// Guarda un registro en el catalogo Segments By Agency
        /// Desasigna|Asigna Agencias a un segment
        /// </summary>
        /// <param name="segmentByLeadSource">OBjeto a guardar</param>
        /// <param name="lstAdd">Lista a asignar</param>
        /// <param name="lstDel">Lista a desasignar</param>
        /// <param name="blnUpdate">True. Actualiza | False. Inserta</param>
        /// <returns>-1. Existe un registro con el mismo ID | 0. No se guardó | 1. Se guardó</returns>
        /// <history>
        /// [emoguel] created 02/06/2016
        /// </history>
        public async static Task <int> SaveSegmentByLeadSource(SegmentByLeadSource segmentByLeadSource, List <LeadSource> lstAdd, List <LeadSource> lstDel, bool blnUpdate)
        {
            int nRes = await Task.Run(() => {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    using (var transacction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                    {
                        try
                        {
                            #region Update
                            if (blnUpdate)
                            {
                                dbContext.Entry(segmentByLeadSource).State = System.Data.Entity.EntityState.Modified;
                            }
                            #endregion
                            #region Add
                            else
                            {
                                if (dbContext.SegmentsByLeadSources.Where(so => so.soID == segmentByLeadSource.soID).FirstOrDefault() != null)//Existe un registro
                                {
                                    return(-1);
                                }
                                else//Agregar
                                {
                                    #region GetPosition
                                    var items = (from sa in dbContext.SegmentsByAgencies
                                                 select new Item
                                    {
                                        Id = sa.seO.ToString(),
                                        UserId = sa.seID,
                                        Name = sa.seN,
                                        By = "Agency"
                                    }).Union(from sl in dbContext.SegmentsByLeadSources
                                             select new Item
                                    {
                                        Id     = sl.soO.ToString(),
                                        UserId = sl.soID,
                                        Name   = sl.soN,
                                        By     = "Lead Source"
                                    }).ToList().OrderBy(it => int.Parse(it.Id)).ToList();
                                    var item = items.LastOrDefault();
                                    segmentByLeadSource.soO = Convert.ToInt32(item.Id) + 1;
                                    #endregion
                                    dbContext.SegmentsByLeadSources.Add(segmentByLeadSource);
                                }
                            }
                            #endregion

                            #region Agencies
                            //Asignar
                            dbContext.LeadSources.AsEnumerable().Where(ls => lstAdd.Any(lss => lss.lsID == ls.lsID)).ToList().ForEach(ls =>
                            {
                                ls.lsso = segmentByLeadSource.soID;
                            });

                            //Desasignar
                            dbContext.LeadSources.AsEnumerable().Where(ls => lstDel.Any(lss => lss.lsID == ls.lsID)).ToList().ForEach(ls =>
                            {
                                ls.lsso = null;
                            });
                            #endregion

                            int nSave = dbContext.SaveChanges();
                            transacction.Commit();
                            return(nSave);
                        }
                        catch
                        {
                            transacction.Rollback();
                            return(0);
                        }
                    }
                }
            });

            return(nRes);
        }
コード例 #5
0
        /// <summary>
        /// Obtiene registros del catalogo SegmentByLeadSource
        /// </summary>
        /// <param name="nStatus">-1. Todos | 0. Inactivos | 1. Activos</param>
        /// <param name="segment">Objeto con filtros adicionales</param>
        /// <returns>Lista de tipo SegmentByLeadSource</returns>
        /// <history>
        /// [emoguel] created 16/05/2016
        /// </history>
        public async static Task <List <SegmentByLeadSource> > GetSegmentsByLeadSource(int nStatus = -1, SegmentByLeadSource segment = null)
        {
            List <SegmentByLeadSource> lstSegments = await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from so in dbContext.SegmentsByLeadSources
                                select so;

                    if (nStatus != -1)//Filtro por Estatus
                    {
                        bool blnStatus = Convert.ToBoolean(nStatus);
                        query          = query.Where(so => so.soA == blnStatus);
                    }

                    if (segment != null)
                    {
                        if (!string.IsNullOrWhiteSpace(segment.soID))//Filtro por ID
                        {
                            query = query.Where(so => so.soID == segment.soID);
                        }

                        if (!string.IsNullOrWhiteSpace(segment.soN))//Filtro por descripción
                        {
                            query = query.Where(so => so.soN.Contains(segment.soN));
                        }
                    }

                    return(query.OrderBy(so => so.soN).ToList());
                }
            });

            return(lstSegments);
        }
コード例 #6
0
        /// <summary>
        /// Recarga los datos de la lista
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 02/06/2016
        /// </history>
        private void btnRef_Click(object sender, RoutedEventArgs e)
        {
            SegmentByLeadSource segmentByLS = (SegmentByLeadSource)dgrSegments.SelectedItem;

            LoadSegmentsByLeadSource(segmentByLS);
        }