/// <summary>
        /// Valida que el objeto cumpla con los filtros establecidos
        /// </summary>
        /// <param name="showProgramCategory"></param>
        /// <returns>True. Si cumple | False. no cumple</returns>
        /// <history>
        /// [emoguel] created 04/06/2016
        /// </history>
        private bool ValidateFilter(ShowProgramCategory showProgramCategory)
        {
            if (_nStatus != -1)//Filtro por estatus
            {
                if (showProgramCategory.sgA != Convert.ToBoolean(_nStatus))
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_showProgramCategoryFilter.sgID))//Filtro por ID
            {
                if (_showProgramCategoryFilter.sgID != showProgramCategory.sgID)
                {
                    return(false);
                }
            }

            if (!string.IsNullOrWhiteSpace(_showProgramCategoryFilter.sgN))
            {
                if (!showProgramCategory.sgN.Contains(_showProgramCategoryFilter.sgN, StringComparison.OrdinalIgnoreCase))
                {
                    return(false);
                }
            }

            return(true);
        }
        /// <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 03/06/2016
        /// </history>
        private void Cell_DoubleClick(object sender, RoutedEventArgs e)
        {
            ShowProgramCategory          showProgramCategory       = (ShowProgramCategory)dgrShowProgramscategories.SelectedItem;
            frmShowProgramCategoryDetail frmShowProgramCategoryDet = new frmShowProgramCategoryDetail();

            frmShowProgramCategoryDet.Owner    = this;
            frmShowProgramCategoryDet.enumMode = EnumMode.Edit;
            frmShowProgramCategoryDet.oldShowProgramCategory = showProgramCategory;
            if (frmShowProgramCategoryDet.ShowDialog() == true)
            {
                int nIndex = 0;
                List <ShowProgramCategory> lstShowProgramcategories = (List <ShowProgramCategory>)dgrShowProgramscategories.ItemsSource;
                if (ValidateFilter(frmShowProgramCategoryDet.showProgramCategory))                                   //Verificamos que cumpla con los filtros
                {
                    ObjectHelper.CopyProperties(showProgramCategory, frmShowProgramCategoryDet.showProgramCategory); //Actualizamos los datos
                    lstShowProgramcategories.Sort((x, y) => string.Compare(x.sgN, y.sgN));                           //Ordenamos la lista
                    nIndex = lstShowProgramcategories.IndexOf(showProgramCategory);                                  //Obtenemos la posición del registro
                }
                else
                {
                    lstShowProgramcategories.Remove(showProgramCategory);                            //Quitamos el registro
                }
                dgrShowProgramscategories.Items.Refresh();                                           //Actualizamos la vista
                GridHelper.SelectRow(dgrShowProgramscategories, nIndex);                             //Seleccionamos el registro
                StatusBarReg.Content = lstShowProgramcategories.Count + " Show Program Categories."; //Actualizamos el contador
            }
        }
예제 #3
0
        /// <summary>
        /// Guarda un registro en el catalogo ShowProgramcategories
        /// Asigan y Desasigna showprograms a su category
        /// </summary>
        /// <param name="showProgramcategory">Objeto a guardar</param>
        /// <param name="lstAdd">Lista para asignar</param>
        /// <param name="lstDel">Lista para 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 04/06/2016
        /// </history>
        public static async Task <int> SaveShowProgramCategory(ShowProgramCategory showProgramcategory, List <ShowProgram> lstAdd, List <ShowProgram> 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 Actualizar
                            if (blnUpdate)
                            {
                                dbContext.Entry(showProgramcategory).State = System.Data.Entity.EntityState.Modified;
                            }
                            #endregion
                            #region Agregar
                            else
                            {
                                if (dbContext.ShowProgramsCategories.Where(sg => sg.sgID == showProgramcategory.sgID).FirstOrDefault() != null)
                                {
                                    return(-1);
                                }
                                else
                                {
                                    dbContext.ShowProgramsCategories.Add(showProgramcategory);
                                }
                            }
                            #endregion

                            #region AddShowProgram
                            dbContext.ShowPrograms.AsEnumerable().Where(sk => lstAdd.Any(skk => sk.skID == skk.skID)).ToList().ForEach(sk =>
                            {
                                sk.sksg = showProgramcategory.sgID;
                            });
                            #endregion

                            #region DelShowProgram
                            dbContext.ShowPrograms.AsEnumerable().Where(sk => lstDel.Any(skk => sk.skID == skk.skID)).ToList().ForEach(sk =>
                            {
                                sk.sksg = null;
                            });
                            #endregion

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

            return(nRes);
        }
        /// <summary>
        /// Llena el grid de show program categories
        /// </summary>
        /// <param name="showProgramCategory">Objeto a seleccionar</param>
        /// <history>
        /// [emoguel] created 03/06/2016
        /// </history>
        private async void LoadShowProgramsCategories(ShowProgramCategory showProgramCategory = null)
        {
            try
            {
                status.Visibility = Visibility.Visible;
                int nIndex = 0;
                List <ShowProgramCategory> lstShowPrograms = await BRShowProgramsCategories.GetShowProgramsCategories(_nStatus, _showProgramCategoryFilter);

                dgrShowProgramscategories.ItemsSource = lstShowPrograms;
                if (lstShowPrograms.Count > 0 && showProgramCategory != null)
                {
                    showProgramCategory = lstShowPrograms.Where(sg => sg.sgID == showProgramCategory.sgID).FirstOrDefault();
                    nIndex = lstShowPrograms.IndexOf(showProgramCategory);
                }
                GridHelper.SelectRow(dgrShowProgramscategories, nIndex);
                StatusBarReg.Content = lstShowPrograms.Count + " Show Programs Categories.";
                status.Visibility    = Visibility.Collapsed;
            }
            catch (Exception ex)
            {
                UIHelper.ShowMessage(ex);
            }
        }
        /// <summary>
        /// Recarga los datos del grid
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        /// [emoguel] created 03/06/2016
        /// </history>
        private void btnRef_Click(object sender, RoutedEventArgs e)
        {
            ShowProgramCategory showProgramcategory = (ShowProgramCategory)dgrShowProgramscategories.SelectedItem;

            LoadShowProgramsCategories(showProgramcategory);
        }
예제 #6
0
        /// <summary>
        /// Obtiene registros del catalogo ShowProgramsCategories
        /// </summary>
        /// <param name="nStatus">-1. Todos | 0.Inactivos | 1. todos</param>
        /// <param name="showProgramCategory">Objeto con filtros adicionales</param>
        /// <returns>Lista de tipo ShowProgramCategory</returns>
        /// <history>
        /// [emoguel] created 25/04/2016
        /// </history>
        public async static Task <List <ShowProgramCategory> > GetShowProgramsCategories(int nStatus = -1, ShowProgramCategory showProgramCategory = null)
        {
            List <ShowProgramCategory> lstShowCategories =
                await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from sg in dbContext.ShowProgramsCategories
                                select sg;

                    if (nStatus != -1)//Filtro por estatus
                    {
                        bool blnStatus = Convert.ToBoolean(nStatus);
                        query          = query.Where(sk => sk.sgA == blnStatus);
                    }

                    if (showProgramCategory != null)//Filtro por ID
                    {
                        if (!string.IsNullOrWhiteSpace(showProgramCategory.sgID))
                        {
                            query = query.Where(sk => sk.sgID == showProgramCategory.sgID);
                        }

                        if (!string.IsNullOrWhiteSpace(showProgramCategory.sgN))//Filtro por descripción
                        {
                            query = query.Where(sk => sk.sgN.Contains(showProgramCategory.sgN));
                        }
                    }

                    return(query.OrderBy(sg => sg.sgN).ToList());
                }
            });

            return(lstShowCategories);
        }