-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddForm.cs
63 lines (59 loc) · 2.14 KB
/
AddForm.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SpreadSheetConnector
{
public partial class AddForm : Form
{
private Form caller;
private string name;
private string folder;
private string googleUrl;
private UpdaterAction action;
private Tuple<int, int> removableRows;
public AddForm(Form caller)
{
InitializeComponent();
this.caller = caller;
}
private void AddButton_Click(object sender, EventArgs e)
{
Action<string> showMessage = (message) => { MessageBox.Show(message); };
name = NameTextBox.Text;
googleUrl = GoogleSheetPathTextBox.Text;
action = (string)ActionComboBox.SelectedItem == "Overwrite" ? UpdaterAction.Overwrite : UpdaterAction.Append;
int fromRange;
int toRange;
bool t1 = int.TryParse(FromRangeTextBox.Text, out fromRange);
bool t2 = int.TryParse(ToRangeTextBox.Text, out toRange);
if (name == "" || name == "Name") { showMessage("Enter name"); return; }
if (googleUrl == "" || googleUrl == "Google url") { showMessage("Enter google url"); return; }
if (folder == "") { showMessage("Pick folder"); return; }
if (!t1 | !t2) removableRows = null; else removableRows = new Tuple<int, int>(fromRange, toRange);
try
{
(caller as Form1).AppendNewUpdaterItem(new UpdaterItem(name, folder, googleUrl, action, removableRows));
}
catch(FileNotFoundException)
{
showMessage("Directory not found");
return;
}
Close();
}
private void PickFolderButton_Click(object sender, EventArgs e)
{
if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
{
folder = folderBrowserDialog.SelectedPath;
}
}
}
}