-
Notifications
You must be signed in to change notification settings - Fork 5
/
frmBatch.cs
executable file
·179 lines (155 loc) · 6.27 KB
/
frmBatch.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using MarkAble2.Properties;
namespace MarkAble2
{
public partial class frmBatch : Form
{
public frmBatch()
{
InitializeComponent();
}
private void frmBatch_Load(object sender, EventArgs e)
{
lstBooks.CheckOnClick = false;
chkSkipByDefault.Text = chkSkipByDefault.Text.Replace("{type}", Global.Options.Encoder.ToString());
FillList();
}
private void FillList()
{
if ((Global.CurrentBatch != null) && (Global.CurrentBatch.Lists.Count > 0))
{
labFileName.Text = Global.CurrentBatch.SourceFile;
chkSkipByDefault.Checked = Global.CurrentBatch.SkipConversion;
lstBooks.Items.Clear();
foreach(SeparateFileList fl in Global.CurrentBatch.Lists)
{
lstBooks.Items.Add(fl);
}
}
CheckAll(true);
}
private void CheckAll(bool truefalse)
{
for (int i = 0; i < lstBooks.Items.Count; i++)
{
lstBooks.SetItemChecked(i, truefalse);
}
}
private void butCheckAll_Click(object sender, EventArgs e)
{
CheckAll(true);
}
private void butCheckNone_Click(object sender, EventArgs e)
{
CheckAll(false);
}
private void butDelete_Click(object sender, EventArgs e)
{
if (lstBooks.SelectedItem != null)
{
var fl = (SeparateFileList) lstBooks.SelectedItem;
if (MessageBox.Show(Resources.Are_you_sure_you_want_to_remove_this_project_permanently_from_the_batch_file, Resources.Sure_query, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
{
Global.CurrentBatch.Lists.Remove(fl);
try
{
//save changed file
Global.ToXmlFile(Global.CurrentBatch.SourceFile, Global.CurrentBatch, false);
if (Global.CurrentBatch.Lists.Count == 0)
{
if (
MessageBox.Show(Resources.The_batch_file_is_now_empty_Delete_it_query, Resources.Empty_exclaim,
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
try
{
File.Delete(Global.CurrentBatch.SourceFile);
DialogResult = DialogResult.Cancel;
}
catch (Exception ex)
{
MessageBox.Show(Resources.Unable_to_delete_batch_file + "\r\n\r\n" + ex.Message, Resources.Error_exclaim);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(Resources.Unable_to_alter_batch_file + "\r\n\r\n" + ex.Message, Resources.Error_exclaim);
}
FillList();
}
}
}
private void butNext_Click(object sender, EventArgs e)
{
for (int i = lstBooks.Items.Count - 1; i >= 0; i--)
{
if (lstBooks.GetItemChecked(i))
{
var fl = (SeparateFileList) lstBooks.Items[i];
if (!fl.AllFilesExist())
{
if (
MessageBox.Show(
Resources.Could_not_find_some_of_the_files_in_project_booktitle.Replace("<booktitle>",fl.BookTitle) +
"\r\r\r\n" +
Resources.Remove_the_project_from_the_batch_query,
Resources.Missing_files, MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
lstBooks.Items.Remove(lstBooks.Items[i]);
Global.CurrentBatch.Lists.Remove(fl);
}
else
{
lstBooks.SetItemChecked(i,false);
}
}
}
}
//For simplicity, we temporarily remove (ie, don't save to file) the unwanted projects
//from the current batch before going on. If no projects left, we cancel.
for (int i = 0; i < lstBooks.Items.Count; i++)
{
if (lstBooks.GetItemChecked(i) == false)
{
var project = (SeparateFileList) lstBooks.Items[i];
Global.CurrentBatch.Lists.Remove(project);
}
}
if (Global.CurrentBatch.Lists.Count == 0)
{
MessageBox.Show(Resources.Nothing_to_do_exclaim, Resources.Cancelled);
}
DialogResult = Global.CurrentBatch.Lists.Count > 0 ? DialogResult.OK : DialogResult.Cancel;
}
private void chkSkipByDefault_CheckedChanged(object sender, EventArgs e)
{
Global.CurrentBatch.SkipConversion = chkSkipByDefault.Checked;
try
{
Global.ToXmlFile(Global.CurrentBatch.SourceFile, Global.CurrentBatch, false);
}
catch (Exception ex)
{
MessageBox.Show(Resources.Unable_to_alter_batch_file + "\r\n\r\n" + ex.Message, Resources.Error_exclaim);
}
}
private bool DoneIt;
private void frmBatch_Activated(object sender, EventArgs e)
{
if(!DoneIt)
{
DoneIt = true;
}
}
}
}