-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
CalendarPickerForm.cs
69 lines (54 loc) · 1.69 KB
/
CalendarPickerForm.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Threading.Tasks;
using TelegramBotBase.Args;
using TelegramBotBase.Base;
using TelegramBotBase.Controls.Inline;
using TelegramBotBase.Enums;
using TelegramBotBase.Form;
namespace TelegramBotBase.Example.Tests.Controls;
public class CalendarPickerForm : AutoCleanForm
{
public CalendarPickerForm()
{
DeleteMode = EDeleteMode.OnLeavingForm;
Init += CalendarPickerForm_Init;
}
public CalendarPicker Picker { get; set; }
private int? SelectedDateMessage { get; set; }
private Task CalendarPickerForm_Init(object sender, InitEventArgs e)
{
Picker = new CalendarPicker
{
Title = "Datum auswählen / Pick date"
};
AddControl(Picker);
return Task.CompletedTask;
}
public override async Task Action(MessageResult message)
{
switch (message.RawData)
{
case "back":
var s = new Menu();
await NavigateTo(s);
break;
}
}
public override async Task Render(MessageResult message)
{
var s = "";
s = "Selected date is " + Picker.SelectedDate.ToShortDateString() + "\r\n";
s += "Selected month is " + Picker.Culture.DateTimeFormat.MonthNames[Picker.VisibleMonth.Month - 1] + "\r\n";
s += "Selected year is " + Picker.VisibleMonth.Year;
var bf = new ButtonForm();
bf.AddButtonRow(new ButtonBase("Back", "back"));
if (SelectedDateMessage != null)
{
await Device.Edit(SelectedDateMessage.Value, s, bf);
}
else
{
var m = await Device.Send(s, bf);
SelectedDateMessage = m.MessageId;
}
}
}