Skip to content
This repository was archived by the owner on Feb 10, 2022. It is now read-only.

Commit 17fdd31

Browse files
Upgrade to Data binding (#3)
* upgrade course to bindable * upgrade course_table to bindable * upgrade department to bindable * format some code * add missing bindable inheritance * remove unneeded readonly * make SupportedDataSourceInfo used only by index * Add course list to ListBox * make CourseManagementForm to modeless * add CourseDayTime model * fix time model error * get data from management vm * make course selection form be resizable * add some comments * enable more fields * use databinding to connect vm and form * extract some values to vm to shrink form code size * bind course weektime checkbox gridview to form * ensure checkbox is using correct state values * connect course hours to combobox * add form validation process * the gridview can check now * add course time validation * add enable status binding * use 2d list to store the check states * add optional notify property and add update function * use column to transmit time instead of row * add course class change features * implements add new course feature * change selected index when listbox item changed * add internet lost handler * add notify in usecases * fix check state handle error in selection form * fix course management form adding method error * enable data stream update process * disconnect changed event when form close * fix selection form initial loading error * disable selection form cache * make selection result form modeless * fix select course not update result form error * add language restrictions * release/1.3.0.3 * fix result form open many times problem * release/1.3.0.4
1 parent 3e480bf commit 17fdd31

35 files changed

+1890
-678
lines changed

CourseCrawler.csproj

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
<UpdatePeriodically>false</UpdatePeriodically>
2525
<UpdateRequired>false</UpdateRequired>
2626
<MapFileExtensions>true</MapFileExtensions>
27-
<ApplicationRevision>3</ApplicationRevision>
28-
<ApplicationVersion>1.2.0.%2a</ApplicationVersion>
27+
<ApplicationRevision>5</ApplicationRevision>
28+
<ApplicationVersion>1.3.0.%2a</ApplicationVersion>
2929
<UseApplicationTrust>false</UseApplicationTrust>
3030
<CreateDesktopShortcut>true</CreateDesktopShortcut>
3131
<PublishWizardCompleted>true</PublishWizardCompleted>
@@ -44,7 +44,7 @@
4444
</PropertyGroup>
4545
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
4646
<PlatformTarget>AnyCPU</PlatformTarget>
47-
<DebugType>pdbonly</DebugType>
47+
<DebugType>none</DebugType>
4848
<Optimize>true</Optimize>
4949
<OutputPath>bin\Release\</OutputPath>
5050
<DefineConstants>TRACE</DefineConstants>
@@ -87,12 +87,14 @@
8787
<Reference Include="System.Xml" />
8888
</ItemGroup>
8989
<ItemGroup>
90-
<Compile Include="src\Constants.cs" />
90+
<Compile Include="src\Consts.cs" />
9191
<Compile Include="src\Domain\Course.cs" />
92+
<Compile Include="src\Domain\CourseDayTime.cs" />
9293
<Compile Include="src\Domain\CourseTable.cs" />
9394
<Compile Include="src\Domain\Department.cs" />
9495
<Compile Include="src\Dto\CourseDto.cs" />
9596
<Compile Include="src\Dto\CourseTableDto.cs" />
97+
<Compile Include="src\Dto\CourseDayTimeDto.cs" />
9698
<Compile Include="src\Form\CourseManagementForm.cs">
9799
<SubType>Form</SubType>
98100
</Compile>
@@ -120,20 +122,23 @@
120122
<Compile Include="src\Program.cs" />
121123
<Compile Include="Properties\AssemblyInfo.cs" />
122124
<Compile Include="src\Store\Store.cs" />
123-
<Compile Include="src\SupportedRange.cs" />
125+
<Compile Include="src\SupportedDataSourceInfo.cs" />
124126
<Compile Include="src\Type\Enums.cs" />
125127
<Compile Include="src\Type\Interfaces\Courses.cs" />
126128
<Compile Include="src\Type\Interfaces\ObserverableDictionary.cs" />
127129
<Compile Include="src\Type\Interfaces\Result.cs" />
128130
<Compile Include="src\Type\Interfaces\UseCases.cs" />
129131
<Compile Include="src\Type\Interfaces\Bindable.cs" />
132+
<Compile Include="src\UseCase\AddCourseUseCase.cs" />
130133
<Compile Include="src\UseCase\CrawlerUseCase.cs" />
131134
<Compile Include="src\UseCase\FetchDepartmentCourseTableUseCase.cs" />
132135
<Compile Include="src\UseCase\GetAllCourseUseCase.cs" />
133136
<Compile Include="src\UseCase\GetAllDepartmentsUseCase.cs" />
134137
<Compile Include="src\UseCase\GetCourseTableUseCase.cs" />
135138
<Compile Include="src\UseCase\GetDepartmentUseCase.cs" />
139+
<Compile Include="src\UseCase\RemoveCourseUseCase.cs" />
136140
<Compile Include="src\UseCase\SelectedCourseUseCase.cs" />
141+
<Compile Include="src\UseCase\UpdateCourseUseCase.cs" />
137142
<Compile Include="src\Util\Utils.cs" />
138143
<Compile Include="src\ViewModel\CourseManagementFormViewModel.cs" />
139144
<Compile Include="src\ViewModel\CourseSelectionResultFormViewModel.cs" />
@@ -160,6 +165,7 @@
160165
<EmbeddedResource Include="src\Form\StartUpForm.resx">
161166
<DependentUpon>StartUpForm.cs</DependentUpon>
162167
</EmbeddedResource>
168+
<None Include="ClassDiagram1.cd" />
163169
<None Include="LICENSE" />
164170
<None Include="packages.config" />
165171
<None Include="Properties\DataSources\Store.datasource" />

src/Constants.cs renamed to src/Consts.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace CourseCrawler
55
{
6-
internal static class Constants
6+
internal static class Consts
77
{
88
public static readonly string CoursePagePath = "https://aps.ntut.edu.tw/course/tw/Subj.jsp?format=-4&year=110&sem=1&code=";
99
public static readonly string[] StringSplitSeperators = new[] { "\r\n", "\r", "\n", " ", "\n\r" };
@@ -27,11 +27,21 @@ internal static class Constants
2727
public static readonly string NameConflictErrMsgHead = "課程名稱相同:";
2828
public static readonly string TimeConflictErrMsgHead = "衝堂:";
2929
public static readonly string SuccessfullySelectCourse = "加選成功";
30+
public static readonly string SuccessfullySaveCourse = "儲存成功";
3031
public static readonly string FailToSelectCourse = "加選失敗";
3132
public static readonly string UnselectCourse = "退選";
3233
public static readonly string SelectedCourse = "SelectedCourse";
3334
public static readonly string TabPageNameTitle = "tabPage";
3435
public static readonly string AllCourses = "AllCourses";
3536
public static readonly string AllDepartments = "AllDepartments";
37+
public static readonly int Big5EncodingCodePage = 950;
38+
public static readonly int CourseAmountPerDay = 14;
39+
public static readonly string MsgCourseDayTimeStringArraySizeNotAllowed = "Time string array has invalid length.";
40+
public static readonly string MsgArrayLengthMustBeNonnegative = "Array length must be nonnegative";
41+
public static readonly string CourseTimePeriodNameChars = "1234N56789ABCD";
42+
public static readonly string MsgElementNotFound = "Member Not Found!";
43+
public static readonly string MsgElementShouldNotBeFound = "Member Should Not Be Found!";
44+
public static readonly string MsgDeadArea = "This area should not be proccessed!";
45+
public static readonly string MsgFailToFetchResources = "Fail to fetch resources. Is the Internet works normally??";
3646
}
3747
}

src/Domain/Course.cs

Lines changed: 154 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace CourseCrawler
44
{
5-
internal class Course : ICourse
5+
internal class Course : Bindable, ICourse
66
{
77
public Course(
88
string serial,
@@ -12,13 +12,13 @@ public Course(
1212
string hour,
1313
CourseType type,
1414
string[] teachers = null,
15-
string[] mondayTimes = null,
16-
string[] tuesdayTimes = null,
17-
string[] wednesdayTimes = null,
18-
string[] thursdayTimes = null,
19-
string[] fridayTimes = null,
20-
string[] saturdayTimes = null,
21-
string[] sundayTimes = null,
15+
CourseDayTime sundayTimes = null,
16+
CourseDayTime mondayTimes = null,
17+
CourseDayTime tuesdayTimes = null,
18+
CourseDayTime wednesdayTimes = null,
19+
CourseDayTime thursdayTimes = null,
20+
CourseDayTime fridayTimes = null,
21+
CourseDayTime saturdayTimes = null,
2222
string[] classrooms = null,
2323
string studentAmount = "0",
2424
string givenUpStudentAmount = "0",
@@ -28,10 +28,12 @@ public Course(
2828
string remark = "",
2929
string attachedStudentAmount = "0",
3030
bool isExperiment = false,
31-
bool isSelected = false
31+
bool isSelected = false,
32+
bool isChecked = false
3233
)
3334
{
3435
_isSelected = isSelected;
36+
_isChecked = isChecked;
3537
_serial = serial;
3638
_name = name;
3739
_level = level;
@@ -58,20 +60,21 @@ public Course(
5860
}
5961

6062
private bool _isSelected = false;
63+
private bool _isChecked = false;
6164
private string _serial;
6265
private string _name;
6366
private string _level;
6467
private string _credit;
6568
private string _hour;
6669
private CourseType _type;
6770
private string[] _teachers;
68-
private string[] _mondayTimes;
69-
private string[] _tuesdayTimes;
70-
private string[] _wednesdayTimes;
71-
private string[] _thursdayTimes;
72-
private string[] _fridayTimes;
73-
private string[] _saturdayTimes;
74-
private string[] _sundayTimes;
71+
private CourseDayTime _mondayTimes;
72+
private CourseDayTime _tuesdayTimes;
73+
private CourseDayTime _wednesdayTimes;
74+
private CourseDayTime _thursdayTimes;
75+
private CourseDayTime _fridayTimes;
76+
private CourseDayTime _saturdayTimes;
77+
private CourseDayTime _sundayTimes;
7578
private string[] _classrooms;
7679
private string _studentAmount;
7780
private string _givenUpStudentAmount;
@@ -83,68 +86,170 @@ public Course(
8386
private bool _isExperiment;
8487

8588
// MakeSelected
86-
public void MakeSelected() => _isSelected = true;
89+
public void MakeSelected() => IsSelected = true;
8790

8891
// MakeUnselected
89-
public void MakeUnselected() => _isSelected = false;
92+
public void MakeUnselected() => IsSelected = false;
9093

91-
public bool IsSelected => _isSelected;
94+
public bool IsSelected
95+
{
96+
get => _isSelected;
97+
set => SetField(ref _isSelected, value);
98+
}
9299

93-
public string Serial => _serial;
100+
public bool IsChecked
101+
{
102+
get => _isChecked;
103+
set => SetField(ref _isChecked, value);
104+
}
94105

95-
public string Name => _name;
106+
public string Serial
107+
{
108+
get => _serial;
109+
set => SetField(ref _serial, value);
110+
}
96111

97-
public string Level => _level;
112+
public string Name
113+
{
114+
get => _name;
115+
set => SetField(ref _name, value);
116+
}
117+
118+
public string Level
119+
{
120+
get => _level;
121+
set => SetField(ref _level, value);
122+
}
98123

99-
public string Credit => _credit;
124+
public string Credit
125+
{
126+
get => _credit;
127+
set => SetField(ref _credit, value);
128+
}
100129

101-
public string Hour => _hour;
130+
public string Hour
131+
{
132+
get => _hour;
133+
set => SetField(ref _hour, value);
134+
}
102135

103-
public CourseType Type => _type;
136+
public CourseType Type
137+
{
138+
get => _type;
139+
set => SetField(ref _type, value);
140+
}
104141

105-
public string[] Teachers => _teachers;
142+
public string[] Teachers
143+
{
144+
get => _teachers;
145+
set => SetField(ref _teachers, value);
146+
}
106147

107148
public List<WeekTime> WeekTimes => new()
108149
{
109-
new WeekTime(Constants.Monday, MondayTimes),
110-
new WeekTime(Constants.Tuesday, TuesdayTimes),
111-
new WeekTime(Constants.Wednesday, WednesdayTimes),
112-
new WeekTime(Constants.Thursday, ThursdayTimes),
113-
new WeekTime(Constants.Friday, FridayTimes),
114-
new WeekTime(Constants.Saturday, SaturdayTimes),
115-
new WeekTime(Constants.Sunday, SundayTimes),
150+
new(Consts.Sunday, CourseDayTimeDto.ToStringArray(SundayTimes)),
151+
new(Consts.Monday, CourseDayTimeDto.ToStringArray(MondayTimes)),
152+
new(Consts.Tuesday, CourseDayTimeDto.ToStringArray(TuesdayTimes)),
153+
new(Consts.Wednesday, CourseDayTimeDto.ToStringArray(WednesdayTimes)),
154+
new(Consts.Thursday, CourseDayTimeDto.ToStringArray(ThursdayTimes)),
155+
new(Consts.Friday, CourseDayTimeDto.ToStringArray(FridayTimes)),
156+
new(Consts.Saturday, CourseDayTimeDto.ToStringArray(SaturdayTimes)),
116157
};
117158

118-
public string[] MondayTimes => _mondayTimes;
159+
public CourseDayTime MondayTimes
160+
{
161+
get => _mondayTimes;
162+
set => SetField(ref _mondayTimes, value);
163+
}
119164

120-
public string[] TuesdayTimes => _tuesdayTimes;
165+
public CourseDayTime TuesdayTimes
166+
{
167+
get => _tuesdayTimes;
168+
set => SetField(ref _tuesdayTimes, value);
169+
}
121170

122-
public string[] WednesdayTimes => _wednesdayTimes;
171+
public CourseDayTime WednesdayTimes
172+
{
173+
get => _wednesdayTimes;
174+
set => SetField(ref _wednesdayTimes, value);
175+
}
123176

124-
public string[] ThursdayTimes => _thursdayTimes;
177+
public CourseDayTime ThursdayTimes
178+
{
179+
get => _thursdayTimes;
180+
set => SetField(ref _thursdayTimes, value);
181+
}
125182

126-
public string[] FridayTimes => _fridayTimes;
183+
public CourseDayTime FridayTimes
184+
{
185+
get => _fridayTimes;
186+
set => SetField(ref _fridayTimes, value);
187+
}
127188

128-
public string[] SaturdayTimes => _saturdayTimes;
189+
public CourseDayTime SaturdayTimes
190+
{
191+
get => _saturdayTimes;
192+
set => SetField(ref _saturdayTimes, value);
193+
}
129194

130-
public string[] SundayTimes => _sundayTimes;
195+
public CourseDayTime SundayTimes
196+
{
197+
get => _sundayTimes;
198+
set => SetField(ref _sundayTimes, value);
199+
}
131200

132-
public string[] Classrooms => _classrooms;
201+
public string[] Classrooms
202+
{
203+
get => _classrooms;
204+
set => SetField(ref _classrooms, value);
205+
}
133206

134-
public string StudentAmount => _studentAmount;
207+
public string StudentAmount
208+
{
209+
get => _studentAmount;
210+
set => SetField(ref _studentAmount, value);
211+
}
135212

136-
public string GivenUpStudentAmount => _givenUpStudentAmount;
213+
public string GivenUpStudentAmount
214+
{
215+
get => _givenUpStudentAmount;
216+
set => SetField(ref _givenUpStudentAmount, value);
217+
}
137218

138-
public string[] TAs => _tas;
219+
public string[] TAs
220+
{
221+
get => _tas;
222+
set => SetField(ref _tas, value);
223+
}
139224

140-
public CourseLanguage Language => _language;
225+
public CourseLanguage Language
226+
{
227+
get => _language;
228+
set => SetField(ref _language, value);
229+
}
141230

142-
public string[] OutlineAndProgressUrl => _outlineAndProgressUrl;
231+
public string[] OutlineAndProgressUrl
232+
{
233+
get => _outlineAndProgressUrl;
234+
set => SetField(ref _outlineAndProgressUrl, value);
235+
}
143236

144-
public string Remark => _remark;
237+
public string Remark
238+
{
239+
get => _remark;
240+
set => SetField(ref _remark, value);
241+
}
145242

146-
public string AttachedStudentAmount => _attachedStudentAmount;
243+
public string AttachedStudentAmount
244+
{
245+
get => _attachedStudentAmount;
246+
set => SetField(ref _attachedStudentAmount, value);
247+
}
147248

148-
public bool IsExperiment => _isExperiment;
249+
public bool IsExperiment
250+
{
251+
get => _isExperiment;
252+
set => SetField(ref _isExperiment, value);
253+
}
149254
}
150255
}

0 commit comments

Comments
 (0)