Пример #1
0
 /// <summary>
 ///   Determina si se puede editar la informacion del grid de fechas de temporadas
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 /// <history>
 ///   [vku] 28/Jul/2016 Created
 /// </history>
 private void dgrDates_BeginningEdit(object sender, DataGridBeginningEditEventArgs e)
 {
     if (!GridHelper.IsInEditMode(sender as DataGrid))
     {
         if (e.Column.SortMemberPath.ToString() == "sdEndD")
         {
             SeasonDate sd = (SeasonDate)dgrDates.SelectedItem;
             if (sd.sdStartD == DateTime.MinValue.Date)
             {
                 e.Cancel = true;
                 UIHelper.ShowMessage("Enter the 'From' date first.", MessageBoxImage.Exclamation, "IM.Administrator");
             }
         }
         if (!e.Row.IsNewItem)
         {
             isEdit = true;
         }
         else
         {
             isEdit = false;
         }
     }
     else
     {
         e.Cancel = true;
     }
 }
Пример #2
0
        /// <summary>
        ///   Obtiene los registros de las fechas de temporada
        /// </summary>
        /// <param name="seasonD">Objeto con filtros adicionales</param>
        /// <returns>Lista de fechas de una temporada</returns>
        /// <history>
        ///   [vku] 27/Jul/2016 Created
        /// </history>
        public static async Task <List <SeasonDate> > GetSeasonDates(SeasonDate seasonD = null)
        {
            return(await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    var query = from sd in dbContext.SeasonsDates
                                select sd;

                    if (seasonD != null)
                    {
                        if (!string.IsNullOrWhiteSpace(seasonD.sdss))//Filtro por ID de season
                        {
                            query = query.Where(sd => sd.sdss == seasonD.sdss);
                        }
                    }
                    return query.OrderBy(ssd => ssd.sdStartD).ToList();
                }
            }));
        }
Пример #3
0
        /// <summary>
        ///   Guarda las fechas de temporadas
        /// </summary>
        /// <returns></returns>
        /// <history>
        ///   [vku] 03/Ago/2016 Created
        /// </history>
        public async static Task <int> SaveSeason(Season season, bool blnUpdate, List <SeasonDate> lstAdd, List <SeasonDate> lstDel, List <SeasonDate> lstChange)
        {
            return(await Task.Run(() =>
            {
                using (var dbContext = new IMEntities(ConnectionHelper.ConnectionString()))
                {
                    using (var transaction = dbContext.Database.BeginTransaction(System.Data.IsolationLevel.Serializable))
                    {
                        try
                        {
                            #region Update
                            if (blnUpdate)
                            {
                                dbContext.Entry(season).State = EntityState.Modified;
                            }
                            #endregion

                            #region Add
                            else
                            {
                                Season seasonVal = dbContext.Seasons.Where(ss => ss.ssID == season.ssID).FirstOrDefault();
                                if (seasonVal != null)
                                {
                                    return -1;
                                }
                                else
                                {
                                    dbContext.Seasons.Add(season);
                                }
                            }
                            #endregion

                            #region dellRangeDates
                            if (lstDel.Count > 0)
                            {
                                lstDel.ForEach(item =>
                                {
                                    dbContext.Entry(item).State = EntityState.Deleted;
                                });
                            }
                            #endregion

                            #region addRangeDates
                            if (lstAdd.Count > 0)
                            {
                                lstAdd.ForEach(item =>
                                {
                                    SeasonDate seasonD = dbContext.SeasonsDates.Where(dbSD => dbSD.sdss == season.ssID && dbSD.sdStartD == item.sdStartD && dbSD.sdEndD == item.sdEndD).FirstOrDefault();
                                    if (seasonD == null)
                                    {
                                        item.sdss = season.ssID;
                                        dbContext.Entry(item).State = EntityState.Added;
                                    }
                                });
                            }
                            #endregion

                            #region ChangeRange
                            if (lstChange.Count > 0)
                            {
                                lstChange.ForEach(item =>
                                {
                                    SeasonDate seasonD = dbContext.SeasonsDates.Where(dbSD => dbSD.sdss == item.sdss && dbSD.sdStartD == item.sdStartD && dbSD.sdEndD == item.sdEndD).FirstOrDefault();
                                    if (seasonD == null)
                                    {
                                        dbContext.Entry(item).State = EntityState.Added;
                                    }
                                });
                            }
                            #endregion

                            int nRes = dbContext.SaveChanges();
                            transaction.Commit();
                            return nRes;
                        }
                        catch
                        {
                            transaction.Rollback();
                            return 0;
                        }
                    }
                }
            }));
        }
Пример #4
0
        /// <summary>
        ///   Valida las fechas ingresadas
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///   [vku] 28/Jul/2016 Created
        /// </history>
        private void dgrDates_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            if (e.EditAction == DataGridEditAction.Cancel)
            {
                isCancel = true;
            }
            else
            {
                isCancel       = false;
                changedTextBox = e.EditingElement as TextBox;
                if (changedTextBox.Text.ToString() != "")
                {
                    if (ValidateHelper.IsDate(changedTextBox.Text.ToString()))
                    {
                        string   ssd    = changedTextBox.Text.ToString();
                        DateTime ssDate = Convert.ToDateTime(ssd);
                        if (ssDate.Year == _year.Year)
                        {
                            ValidateRangeDates(ssDate, e.Column.SortMemberPath.ToString(), e.Row.IsNewItem, Convert.ToInt32(e.Row.GetIndex().ToString()));
                            if (!isCancel)
                            {
                                List <RangeDatesTraslape> lstRangeDates     = new List <RangeDatesTraslape>();
                                RangeDatesTraslape        lstRangeTranslape = new RangeDatesTraslape();
                                if (isEdit)
                                {
                                    lstRangeDates     = BRSeasons.GetRangeDatesForValidateTraslapeIsEdit(ssDate, season.ssID);
                                    lstRangeTranslape = lstRangeDates.Cast <RangeDatesTraslape>().FirstOrDefault();
                                }
                                else
                                {
                                    lstRangeDates     = BRSeasons.GetRangeDatesForValidateTraslape(ssDate);
                                    lstRangeTranslape = lstRangeDates.Cast <RangeDatesTraslape>().FirstOrDefault();
                                }
                                if (lstRangeDates.Count > 0)
                                {
                                    isCancel = true;

                                    UIHelper.ShowMessage("The date is in the range of dates " + "(" + lstRangeTranslape.sdStartD.ToShortDateString() + " to " + lstRangeTranslape.sdEndD.ToShortDateString() + ")" + " of season " + "'" + lstRangeTranslape.ssN + "'" + ". " + "Specify another date.");
                                    SeasonDate data = e.Row.DataContext as SeasonDate;
                                    if (isEdit)
                                    {
                                        string strColumn = e.Column.SortMemberPath.ToString();
                                        switch (strColumn)
                                        {
                                        case "sdStartD":
                                            changedTextBox.Text = data.sdStartD.ToShortDateString();
                                            break;

                                        case "sdEndD":
                                            changedTextBox.Text = data.sdEndD.ToShortDateString();
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        changedTextBox.Text = string.Empty;
                                    }
                                }
                                else
                                {
                                    GridHelper.UpdateSourceFromARow(sender as DataGrid);
                                }
                            }
                        }
                        else
                        {
                            isCancel = true;
                            UIHelper.ShowMessage("The date does not belong to the year being edited " + _year.Year, MessageBoxImage.Exclamation, "IM.Administrator");
                            changedTextBox.Text = string.Empty;
                        }
                    }
                    else
                    {
                        isCancel = true;
                        UIHelper.ShowMessage("Invalid Date", MessageBoxImage.Error, "IM.Administrator");
                        changedTextBox.Text = string.Empty;
                    }
                }
                else
                {
                    if (e.Column.SortMemberPath == "sdEndD")
                    {
                        UIHelper.ShowMessage("Specify a Date", MessageBoxImage.Error, "IM.Administrator");
                        e.Cancel = true;
                    }
                    else
                    {
                        isCancel = true;
                    }
                }
            }
        }