using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Mvc;
using VRH.Log4Pro.MultiLanguageManager;
using Vrh.Web.Common.Lib;
using Vrh.iScheduler;
namespace Vrh.Web.iScheduler
{
///
/// A Manager és Editor cshtml-ek számára szükséges model.
///
public class SchedulerModel : CommonModel
{
#region Properties
///
/// A már kielemzett iScheduler XML.
///
public SchedulerXmlParser Scheduler { get; set; }
///
/// A Schedules tábla egyedi azonosítója, mely egy ütemezést azonosít.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.Id))]
public int Id { get; set; } = 0;
///
/// Kiválasztot objektum azonosítója.
///
public string ObjectIdValue { get; set; }
///
/// Kiválasztot objektum megnevezése.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.ObjectId))]
[LocaleRequired]
public string ObjectIdText { get; set; }
///
/// Kiválasztot művelet azonosítója.
///
public string OperationIdValue { get; set; }
///
/// Kiválasztot művelet megnevezése.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.OperationId))]
[LocaleRequired]
public string OperationIdText { get; set; }
///
/// Az ütemezés időpontja, amikor a műveletet végre kell hajtani.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.OperationTime))]
[LocaleRequired]
public DateTime OperationTime { get; set; }
///
/// Az objektum típusa. ReadOnly
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.ObjectTpye))]
[LocaleRequired]
public string ObjectType { get; set; }
///
/// Az ütemezés időpontja, amikor a műveletet végre kell hajtani.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.ObjectGroupId))]
[LocaleRequired]
public string ObjectGroupId { get; set; }
///
/// Az ütemezés állapota
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.State))]
public ScheduleStates State { get; set; }
///
/// Az állapot megadott nyelvre fordítva.
///
public string StateTranslate { get; set; }
///
/// Állapotok szűréséhez a választó lista.
///
public List StateFilterList { get; set; }
///
/// Ha már létezik az ütemezéshez visszatérő üzenet, akkor annak megjelenítése.
/// Értékét az Editor GET részében kell beállítani.
///
public bool IsExistReturnMessage { get; set; } = false;
///
/// Ha az ütemezés egy sorozat tagja, akkor annak azonosítója.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Manager.Label.SeriesId))]
public int? SeriesId { get; set; } = null;
///
/// Ütemezése típusa.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.ScheduleType))]
public string ScheduleType { get; set; }
///
/// Ha ütemezés típusának átváltása történik, azt fel kell ismerni valahogy.
/// Ez szolgál arra, hogy a POST-ban észre lehessen venni, ha megváltoztatták az ütemezés típusát.
///
public string PreviousScheduleType { get; set; }
#region Standard properties for the series
///
/// Hetek vagy hónapok száma, minimum 1.
///
public int NumberOf { get; set; } = 1;
///
/// Ha az ütemezés egy sorozat tagja, akkor annak típusa.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.SeriesName))]
public string SeriesName { get; set; } = null;
///
/// Ha az ütemezés egy sorozat tagja, akkor annak színe.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.SeriesColor))]
public string SeriesColor { get; set; } = null;
#endregion Standard properties for the series
#region Days of the week
///
/// A kiválasztott napokat tartalmazó tömb.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Days))]
public int[] SelectedWeekDays { get; set; } = new[] { 1, 2, 3, 4, 5 };
///
/// Igaz, ha hétfő is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Monday))]
public bool IsMonday { get; set; } = true;
///
/// Igaz, ha Kedd is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Tuesday))]
public bool IsTuesday { get; set; } = true;
///
/// Igaz, ha Szerda is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Wednesday))]
public bool IsWednesday { get; set; } = true;
///
/// Igaz, ha Csütörtök is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Thursday))]
public bool IsThursday { get; set; } = true;
///
/// Igaz, ha Péntek is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Friday))]
public bool IsFriday { get; set; } = true;
///
/// Igaz, ha Szombat is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Saturday))]
public bool IsSaturday { get; set; } = false;
///
/// Igaz, ha Vasárnap is kiválasztott.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Sunday))]
public bool IsSunday { get; set; } = false;
#endregion Days of the week
///
/// Annak a jelzése, hogy az Editor mentése után legyen-e végrehajtás.
///
[DisplayNameWithTrueWordCodes(typeof(SchedulerWordCodes.iScheduler.Editor.Label.ScheduleExecute))]
public bool IsScheduleExecute { get; set; } = false;
///
/// A dátumformátum megőrzése céljából.
///
public string DateTimeFormat { get; set; } = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
///
/// A kapcsolati sztringet is meg kell őrizni.
///
public string ConnectionString { get; set; }
///
/// Az ObjectId lekérdezéséhez szükséges URL.
///
public string ObjectIdUrl { get; set; }
///
/// Az OperationId lekérdezéséhez szükséges URL.
///
public string OperationIdUrl { get; set; }
///
/// Az ObjectEditor indításához szükséges URL.
///
public string ObjectEditorUrl { get; set; }
///
/// A CheckObjects indításához szükséges URL.
///
public string CheckObjectsUrl { get; set; }
///
/// Annak jelzése, hogy milyen nézetből hívták az editor.
/// Null érték azt jelenti, hogy nem a list és nem is a calendar nézetből hívták.
///
public string CallingViewMode { get; set; } = null;
///
/// Az éppen érvényes nézet.
///
public string CurrentViewMode { get; set; } = DisplayMode.List.ToString();
///
/// Konzisztencia ellenőrzés alatt a táblázat fölé kiírandó üzenet.
///
public string ConsistencyHeader { get; set; } = "";
///
/// A konzisztencia ellenőrzés gombjának stílusa, amely a bekapcsolt állapotot jelenti.
///
public string ConsistencyStyle { get; set; } = "";
///
/// Konzisztencia ellenőrzéshez használt akció iScheduler controller-be hívó Url.
///
public string ConsistencyUrl { get; set; } = "";
///
/// Meg kell őrizni a POST számára, mert ott fog kelleni.
///
public string XmlParserConnectionString { get; set; }
#endregion Properties
#region Constructor
///
/// A view-hoz használt model konstruktora.
///
public SchedulerModel()
{
this.SelectedWeekDays = new[] { 1, 2, 3, 4, 5 };
}
///
/// A view-hoz használt model konstruktora, de itt meg kell adni a már feldolgozott xml struktúrát.
///
/// A már feldolgozott xml struktúra.
/// Aktuális megjelenítési mód.
public SchedulerModel(SchedulerXmlParser isxp, string displayMode = null) : this()
{
this.Scheduler = isxp ?? throw new ArgumentNullException("_scheduler");
this.CurrentViewMode = isxp.Manager.DefaultDisplayMode.ToString();
#region Értékek a post részére (hidden)
this.CallingViewMode = string.IsNullOrWhiteSpace(displayMode) ? null : displayMode;
this.ConnectionString = isxp.ConnectionString;
this.XmlParserConnectionString = isxp.XmlParserConnectionString;
this.ObjectType = isxp.ObjectType;
this.ObjectGroupId = isxp.ObjectGroupId == SchConst.Groups.All ? null : isxp.ObjectGroupId;
this.ObjectIdUrl = isxp.UrlVars.Substitution(isxp.ListObjects.GetUrl(true));
this.OperationIdUrl = isxp.UrlVars.Substitution(isxp.ListOperations.GetUrl(true));
this.CheckObjectsUrl = isxp.UrlVars.Substitution(isxp.CheckObjects.GetUrl(true), SchConst.UrlVars.GROUPID);
//itt most csak az objecttype-ot helyettesítjük, mert a GroupId-t majd ha megadta az Editor ablakban
this.ObjectEditorUrl = isxp.UrlVars.Substitution(isxp.ObjectEditor.GetUrl(true), SchConst.UrlVars.OBJECTTYPE);
#endregion Értékek a post részére (hidden)
#region Konzisztencia ellenőrzéshez inicializálások
if (isxp.Manager.Buttons != null && isxp.Manager.Buttons.Any())
{
ButtonElement bttn = isxp.Manager.Buttons.FirstOrDefault(x => x.Name == ButtonElement.SysButtonNames.ConsistencyCheck);
if (bttn != null)
{
this.ConsistencyHeader = base.Trans(typeof(SchedulerWordCodes.iScheduler.Manager.ConsistencyTitle));
string stl = bttn.Style ?? ""; // a toggle button stílusánál fontos, hogy legyen ";" jel a végén
this.ConsistencyStyle = stl == "" ? "" : (stl + (stl.EndsWith(";") ? "" : ";"));
this.ConsistencyUrl = bttn.Url.GetUrl(true); //ebben nem lehet változó
}
}
#endregion Konzisztencia ellenőrzéshez inicializálások
}
#endregion Constructor
#region Public methods
///
/// Kötelező kitöltésre figyelmeztető üzenetet ad vissza.
///
///
///
public string RequiredMessage(string fieldLabel)
{
return base.TransFormat(typeof(GeneralWordCodes.MLM.General.Messages.RequiredWithName), fieldLabel);
}
///
/// A hét napjainak listája. Vasárnapnál 0 a value, Hétfőnél 1.
///
///
public IEnumerable GetDaysOfWeek()
{
var result = new List
{
new SelectListItem() { Value = "1", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Monday)) },
new SelectListItem() { Value = "2", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Tuesday)) },
new SelectListItem() { Value = "3", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Wednesday)) },
new SelectListItem() { Value = "4", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Thursday)) },
new SelectListItem() { Value = "5", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Friday)) },
new SelectListItem() { Value = "6", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Saturday)) },
new SelectListItem() { Value = "0", Text = base.Trans(typeof(SchedulerWordCodes.iScheduler.Editor.Label.Sunday)) }
};
return result;
}
///
/// .NET dátumformátum konvertálása Bootstrap datetimepicker formátumra
///
/// .NET DateTime formátum
/// Bootstrap DatetimePicker Formátum
/// DataTables-ből átemelve és átnevezve. WA.
public string DateTimeToBootstrapDTPF(string dateTimeFormat)
{
// dátum formátumok:
// http://msdn.microsoft.com/en-us/library/8kb3ddd4%28v=vs.110%29.aspx
// http://www.malot.fr/bootstrap-datetimepicker/
string result = dateTimeFormat;
result = result.Replace('m', 'i'); // perc
result = result.Replace('h', 'x').Replace('H', 'h').Replace('x', 'H'); // óra
result = result.Replace("MMMM", "XX").Replace("MMM", "X").Replace("MM", "xx").Replace('M', 'x'); // hónap ideiglenes csere
result = result.Replace("XX", "MM").Replace('X', 'M').Replace("xx", "mm").Replace('x', 'm'); // hónap
return result;
}
#endregion Public methods
}
}