-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddEditCharityForm.cs
112 lines (93 loc) · 4.12 KB
/
AddEditCharityForm.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
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 InteractiveMap
{
public partial class AddEditCharityForm : Form
{
private bool update;
private string fileName;
private DataRow charityToUpdate;
public AddEditCharityForm()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
Close();
ManageCharitiesForm form = new ManageCharitiesForm();
form.Show();
}
private void button4_Click(object sender, EventArgs e)
{
Close();
ManageCharitiesForm form = new ManageCharitiesForm();
form.Show();
}
private void button2_Click(object sender, EventArgs e)
{
Close();
ManageCharitiesForm form = new ManageCharitiesForm();
form.Show();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
throw new Exception("Не заполнено");
DataRow drCharity = update ? charityToUpdate : this.maraphonDataSet.Charity.NewRow();
drCharity["CharityName"] = textBox2.Text;
drCharity["CharityDescription"] = textBox3.Text;
drCharity["CharityLogo"] = fileName;
if (!update)
this.maraphonDataSet.Charity.Rows.Add(drCharity);
this.charityTableAdapter1.Update(this.maraphonDataSet.Charity);
Close();
ManageCharitiesForm form = new ManageCharitiesForm();
form.Show();
} catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Неверно заполненно");
this.charityTableAdapter1.Fill(this.maraphonDataSet.Charity);
}
}
private void AddEditCharityForm_Load(object sender, EventArgs e)
{
this.charityTableAdapter1.Fill(this.maraphonDataSet.Charity);
openFileDialog1.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
if (EditPDO.editedCharityName == "")
{
update = false;
} else
{
update = true;
charityToUpdate = this.maraphonDataSet.Charity.Select("CharityName = '" + EditPDO.editedCharityName + "'").Last();
pictureBox1.Image = Image.FromFile(@"D:\Download\desktopBackup\Колледж\удАЛЁНКА\Системное Программирование\InteractiveMap\charities\" + charityToUpdate["CharityLogo"].ToString());
textBox1.Text = @"D:\Download\desktopBackup\Колледж\удАЛЁНКА\Системное Программирование\InteractiveMap\charities\" + charityToUpdate["CharityLogo"].ToString();
fileName = charityToUpdate["CharityLogo"].ToString();
textBox2.Text = EditPDO.editedCharityName;
textBox3.Text = charityToUpdate["CharityDescription"].ToString();
}
}
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
textBox1.Text = openFileDialog1.FileName;
fileName = openFileDialog1.SafeFileName;
File.Copy(openFileDialog1.FileName, Path.Combine("D:\\Download\\desktopBackup\\Колледж\\удАЛЁНКА\\Системное Программирование\\InteractiveMap\\charities\\", fileName));
pictureBox1.Image = Image.FromFile(@"D:\Download\desktopBackup\Колледж\удАЛЁНКА\Системное Программирование\InteractiveMap\charities\" + fileName);
}
private void button5_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
}
}
}