-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm26.cs
131 lines (115 loc) · 5.23 KB
/
Form26.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data;
using MySql.Data.MySqlClient;
namespace ECAMS
{
public partial class Form26 : Form
{
int i,check_in,id,soc_id;
String donate, by;
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if( txt_donate.ReadOnly == true)
{
txt_donate.ReadOnly = false;
}
else
{
txt_donate.ReadOnly =true;
}
}
MySqlConnection connectionstring = new MySqlConnection("server = localhost;" + "user id = root;" +
"database=ecams_database;" + "password=facebook2018;");
public Form26(int society_id)
{
InitializeComponent();
for(int i = 1; i < 25; i++)
{
comboBox1.Items.Add(i.ToString());
}
soc_id = society_id;
}
private void btn_reset_Click(object sender, EventArgs e)
{
txt_item.Text = txt_value.Text = txt_donate.Text = comboBox1.Text = "";
radioButton1.Checked = radioButton2.Checked = false;
}
private void btn_add_Click(object sender, EventArgs e)
{
try
{
if (connectionstring.State != ConnectionState.Open)
{
connectionstring.Open();
}
if (txt_item.Text == "" || txt_value.Text == "" || comboBox1.Text == "" || (radioButton1.Checked == false && radioButton2.Checked == false)
|| int.TryParse(txt_item.Text, out check_in) || !int.TryParse(txt_value.Text, out check_in) ||
!int.TryParse(comboBox1.Text, out check_in))
{
MessageBox.Show("Invalid inputs entered!","Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
}
else
{
MySqlCommand cmd = connectionstring.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from society where society_id='" + soc_id + "'";
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
cmd.ExecuteNonQuery();
id = Convert.ToInt32(dt.Rows[0]["inventory_inventory_id"]);
dt.Rows.Clear();
cmd.CommandText = "select * from part where inventory_inventory_id='" + id + "' and part_name='" + txt_item.Text + "'";
da.Fill(dt);
cmd.ExecuteNonQuery();
i = Convert.ToInt32(dt.Rows.Count);
if (i == 1)
{
MessageBox.Show("This Item is already exist!", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
connectionstring.Close();
}
else
{
if (radioButton1.Checked == true)
{
donate = "true";
by = txt_donate.Text;
dt.Rows.Clear();
cmd.CommandText = "select * from `old_boy` where `old_boy_name`='"+ by+"'";
da.Fill(dt);
cmd.ExecuteNonQuery();
i = Convert.ToInt32(dt.Rows.Count);
if (i == 1)
{
cmd.CommandText = "insert into old_boy_donation(old_boy_old_boy_id,donation) values('"+ Convert.ToInt32(dt.Rows[0]["old_boy_id"].ToString())+"','"+ txt_item.Text+"')";
cmd.ExecuteNonQuery();
MessageBox.Show("This item is recognize as donate from an oldboy!", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
}
else if (radioButton2.Checked == true)
{
donate = "false";
by = "bought";
}
dt.Rows.Clear();
cmd.CommandText = "insert into part (part_name,quantity,inventory_inventory_id,donate,donated_by,value) values('" + txt_item.Text + "','" + comboBox1.SelectedItem + "','" + id + "','" + donate + "','" + by + "','" + txt_value.Text + "')";
cmd.ExecuteNonQuery();
MessageBox.Show("Item Added Successfully!", "Information", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}