-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLoc.cs
More file actions
176 lines (152 loc) · 12.3 KB
/
Loc.cs
File metadata and controls
176 lines (152 loc) · 12.3 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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Asset_Mng
{
public partial class Loc : Form
{
public Loc()
{
InitializeComponent();
}
public static string node;
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
node = treeView1.SelectedNode.Text;
listBox1.Items.Clear();
SqlConnection connection = Main.connection;
// string find1="select [شناسه]"
string find = "SELECT [اتاق].[نام] from اتاق inner join واحد on [اتاق].[واحد]=[واحد].[نام] where [واحد].[نام]='" + treeView1.SelectedNode.Text + "';";
connection.Close();
connection.Open();
SqlCommand command = new SqlCommand(find, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
listBox1.Items.Add(reader["نام"].ToString());
}
connection.Close();
}
private void Location_Load(object sender, EventArgs e)
{
SqlConnection connection = Main.connection;
string find = "Select * from واحد";
connection.Open();
SqlCommand command = new SqlCommand(find, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string temp = reader["نام"].ToString();
treeView1.Nodes.Add(temp);
}
connection.Close();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = Main.connection;
connection.Open();
string insert = "Insert into واحد ([نام]) values (@name)";
SqlCommand command = new SqlCommand(insert, connection);
command.Parameters.Add("@name", textBox1.Text);
treeView1.Nodes.Add(textBox1.Text);
textBox1.Clear();
command.ExecuteNonQuery();
connection.Close();
}
public static string list;//////
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
list = listBox1.SelectedItem.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection connection = Main.connection;
string insert = "Insert into اتاق ([واحد],[نام]) values (@unit,@name);";
connection.Open();
SqlCommand command = new SqlCommand(insert, connection);
command.Parameters.Add("@unit", node);
command.Parameters.Add("@name", textBox2.Text);
listBox1.Items.Add(textBox2.Text);
textBox2.Clear();
command.ExecuteNonQuery();
connection.Close();
}
public static string nodname;
private void treeView1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point p = new Point(e.X, e.Y);
TreeNode node = treeView1.GetNodeAt(p);
if (node != null)
{
nodname = node.Text;
treeView1.SelectedNode = node;
contextMenuStrip1.Show(treeView1, p);
}
}
}
private void listBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
Point p = new Point(e.X, e.Y);
listBox1.SelectedIndex = listBox1.IndexFromPoint(p);
if (listBox1.SelectedIndex != -1)
{
contextMenuStrip2.Show(listBox1, p);
}
}
}
private void ویرایشToolStripMenuItem_Click(object sender, EventArgs e)
{
Editunit frm = new Editunit();
frm.ShowDialog();
}
private void حدفToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = new DialogResult();
result = MessageBox.Show("آیا میخواهید این نوع را حذف کنید؟", "هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
SqlConnection connection = Main.connection;
connection.Open();
SqlCommand command = new SqlCommand();
command.Connection = connection;
string delete = "DELETE from واحد where نام='" + Loc.node + "';";
command.CommandText = delete;
command.ExecuteNonQuery();
treeView1.SelectedNode.Remove();
MessageBox.Show("حذف شد");
connection.Close();
}
}
private void ویرایشToolStripMenuItem1_Click(object sender, EventArgs e)
{
Editroom frm = new Editroom();
frm.ShowDialog();
}
private void حذفToolStripMenuItem_Click(object sender, EventArgs e)
{
DialogResult result = new DialogResult();
result = MessageBox.Show("آیا میخواهید این نوع را حذف کنید؟", "هشدار", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (result == DialogResult.Yes)
{
SqlConnection connection = Main.connection;
connection.Open();
SqlCommand command = new SqlCommand();
command.Connection = connection;
string delete1 = "DELETE from اتاق where [نام]='" + Loc.list + "' and واحد='"+Loc.node+"';";
command.CommandText = delete1;
command.ExecuteNonQuery();
MessageBox.Show("حذف شد");
connection.Close();
}
}
}
}