This repository was archived by the owner on Dec 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFormOpenFileDialog.cs
More file actions
298 lines (266 loc) · 11.4 KB
/
FormOpenFileDialog.cs
File metadata and controls
298 lines (266 loc) · 11.4 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
using CodeForger.CodeForgerDBDataSetTableAdapters;
using extensions;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CodeForger
{
public partial class FormOpenFileDialog : Form
{
public static string titleGlobal, pathGlobal, contentsGlobal, isexternalGlobal;
public FormOpenFileDialog()
{
InitializeComponent();
}
private void FormOpenFileDialog_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default.AccountLogin != -1)
{
displayDBData();
}
else
{
radioButtonLoadDBFile.Enabled = false;
radioButtonLoadDBFile.Checked = false;
radioButtonOpenExtFile.Checked = true;
}
this.Location = new Point(
(Screen.PrimaryScreen.WorkingArea.Width - this.Width) / 2,
(Screen.PrimaryScreen.WorkingArea.Height - this.Height) / 2);
//MessageBox.Show(this.Owner.Name);
}
string parseFileExtension(string extension)
{
switch (extension)
{
case ".txt":
return "Text";
case ".c":
return "C";
case ".bf":
return "Brainfuck";
case ".cpp":
return "C++";
case ".lsp":
return "LISP";
case ".psc":
return "Pseudocode";
}
return null;
}
string parseFileTypeName(string fileTypeName)
{
switch (fileTypeName)
{
case "Text":
return ".txt";
case "C":
return ".c";
case "Brainfuck":
return ".bf";
case "C++":
return ".cpp";
case "LISP":
return ".lsp";
case "Pseudocode":
return ".psc";
}
return null;
}
private void buttonOpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Text files (*.txt)|*.txt|Pseudocode files (*.psc)|*.psc|Brainfuck files (*.bf)|*.bf|LISP files (*.lsp)|*.lsp|C files (*.c)|*.c|C++ files (*.cpp)|*.cpp|All files (*.*)|*.*";
if (ofd.ShowDialog() == DialogResult.OK)
{
string title = Path.GetFileName(ofd.FileName);
string path = ofd.FileName;
StreamReader sr = new StreamReader(path);
string content = sr.ReadToEnd();
sr.Close();
//MessageBox.Show(title);
titleGlobal = title;
pathGlobal = path;
contentsGlobal = content;
isexternalGlobal = "1";
Properties.Settings.Default.OpenFileTitle = titleGlobal;
Properties.Settings.Default.OpenFilePath = pathGlobal;
Properties.Settings.Default.OpenFileContents = contentsGlobal;
Properties.Settings.Default.OpenFileIsExternal = isexternalGlobal;
Properties.Settings.Default.OpenFileType = parseFileExtension(Path.GetExtension(path));
//MessageBox.Show(Path.GetExtension(path));
if (string.Equals(this.Owner.Name, "Form1"))
{
var form = new FormMain(title, path, content, "1", parseFileExtension(Path.GetExtension(path)));
form.Show();
this.Hide();
//this.Close();
//this.Dispose();
form.FormClosed += (s, args) =>
{
this.Close();
foreach (Form f in Application.OpenForms)
if (f.Name == "Form1")
f.Close();
};
foreach (Form f in Application.OpenForms)
{
if (f.Name == "Form1")
f.Hide();
}
}
else
{
this.Close();
this.Dispose();
}
}
}
/*private void showDBData()
{
LinkLabel[] files = new LinkLabel[100];
int counter = 0;
CodeTableTableAdapter codeTableTA = new CodeTableTableAdapter();
var data = codeTableTA.GetData();
foreach (var row in data)
{
//MessageBox.Show(Convert.ToDateTime(row[3]).Day.ToString());
files[counter] = new LinkLabel();
files[counter].Size = new Size(300, 25);
files[counter].Font = new Font("Microsoft Sans Serif", 10);
files[counter].Text = row[5].ToString() + " | " + Convert.ToDateTime(row[3]).Day.ToString() + "." + Convert.ToDateTime(row[3]).Month.ToString() + "." + Convert.ToDateTime(row[3]).Year.ToString() + " at " + Convert.ToDateTime(row[3]).Hour + ":" + Convert.ToDateTime(row[3]).Minute;
files[counter].Location = new Point(10, counter * 30);
files[counter].Click += new EventHandler(linkLabelFiles_Click);
panelOptions.Controls.Add(files[counter]);
counter++;
}
}*/
private void dataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
//MessageBox.Show(e.RowIndex.ToString());
DataGridView dataGridView = (DataGridView)panelOptions.Controls[0];
if (e.RowIndex == dataGridView.Rows.Count - 1 || e.RowIndex < 0)
{
return;
}
DataGridViewRow dataGridViewRow = dataGridView.Rows[e.RowIndex];
DataGridViewCell dataGridViewCell = dataGridViewRow.Cells[0];
CodeTableTableAdapter codeTableTA = new CodeTableTableAdapter();
var data = codeTableTA.GetData();
string codeName = dataGridViewCell.Value.ToString();
int counter = 0;
foreach (var row in data)
{
if (string.Equals(row[5].ToString(), codeName))
{
titleGlobal = row[5].ToString();
pathGlobal = null;
contentsGlobal = row[1].ToString();
isexternalGlobal = "0";
Properties.Settings.Default.OpenFileTitle = titleGlobal;
Properties.Settings.Default.OpenFilePath = pathGlobal;
Properties.Settings.Default.OpenFileContents = contentsGlobal;
Properties.Settings.Default.OpenFileIsExternal = isexternalGlobal;
string extension = parseFileTypeName(row[2].ToString());
//Create a temporary file to allow compiling
string newPath = Path.GetFullPath(Path.Combine(Application.StartupPath, @"..\..\tmp\" + titleGlobal + extension));
if (!File.Exists(newPath))
{
File.Create(newPath).Close();
}
StreamWriter sr = new StreamWriter(newPath);
sr.Write(row[1].ToString());
sr.Close();
if (this.Owner.Name == "Form1")
{
var form = new FormMain(row[5].ToString(), counter.ToString(), row[1].ToString(), "0", row[2].ToString());
form.Show();
this.Hide();
//this.Close();
form.FormClosed += (s, args) =>
{
this.Close();
foreach (Form f in Application.OpenForms)
if (f.Name == "Form1")
f.Close();
};
foreach (Form f in Application.OpenForms)
{
if (f.Name == "Form1")
f.Hide();
}
}
else
{
//MessageBox.Show("lol");
this.Close();
}
}
counter++;
}
}
private void displayDBData()
{
DataGridView dataGridView = new DataGridView();
dataGridView.Size = new Size(this.Width - 20, panelOptions.Height - 5);
dataGridView.Location = new Point(0, 0);
dataGridView.BackgroundColor = Color.White;
dataGridView.BorderStyle = BorderStyle.None;
dataGridView.GridColor = Color.White;
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
dataGridView.RowHeadersVisible = false;
dataGridView.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None;
dataGridView.DefaultCellStyle.SelectionBackColor = Color.WhiteSmoke;
dataGridView.DefaultCellStyle.SelectionForeColor = Color.Black;
dataGridView.ColumnHeadersDefaultCellStyle.SelectionBackColor = Color.White;
//dataGridView.CurrentCell = null;
//dataGridView.ClearSelection();
dataGridView.ReadOnly = true;
//dataGridView.SelectedRows.Clear();
//dataGridView.Column
dataGridView.CellDoubleClick += dataGridView_CellDoubleClick;
dataGridView.ColumnCount = 3;
dataGridView.Columns[0].Name = "Name";
dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns[1].Name = "Date Modified";
dataGridView.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns[2].Name = "Type";
dataGridView.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
panelOptions.Controls.Add(dataGridView);
CodeTableTableAdapter codeTableTA = new CodeTableTableAdapter();
var data = codeTableTA.GetData();
foreach (var row in data)
{
if (int.Parse(row[4].ToString()) == Properties.Settings.Default.AccountLogin)
dataGridView.Rows.Add(row[5].ToString(), row[3].ToString(), row[2].ToString());
}
}
private void radioButtonLoadDBFile_CheckedChanged(object sender, EventArgs e)
{
if (radioButtonLoadDBFile.Checked == true)
{
panelOptions.Controls.Clear();
//MessageBox.Show(nr.ToString());
displayDBData();
}
else
{
panelOptions.Controls.Clear();
Button buttonOpenFile = new Button();
buttonOpenFile.Text = "Choose file";
buttonOpenFile.Location = new Point(5, 5);
buttonOpenFile.Size = new Size(120, 30);
buttonOpenFile.Click += new EventHandler(buttonOpenFile_Click);
panelOptions.Controls.Add(buttonOpenFile);
}
}
}
}