-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAdd-User.aspx.cs
109 lines (103 loc) · 3.62 KB
/
Add-User.aspx.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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Add_User : System.Web.UI.Page
{
databaseaccesslayer dataobj = new databaseaccesslayer();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
string sql1 = @"select * from Application_Setting where User_Id=" + Session["Id"] + " and Appl_Id=1 and IsVaild=1";
DataTable dt1 = dataobj.Selectdatatable(sql1);
if (dt1.Rows.Count != 1)
{
Response.Redirect("MainPage.aspx");
}
addValidationGroup();
BindgrdTrades();
}
catch (Exception)
{
Response.Redirect("MainPage.aspx");
}
}
}
private void addValidationGroup()
{
foreach (Control ctrl in UpdatePanel1.Controls[0].Controls)
{
TextBox txtbx = ctrl as TextBox;
if (txtbx != null)
{
txtbx.Attributes["ValidationGroup"] = txtbx.ValidationGroup;
}
DropDownList drp = ctrl as DropDownList;
if (drp != null)
{
drp.Attributes["ValidationGroup"] = drp.ValidationGroup;
}
}
}
private void BindgrdTrades()
{
try
{
string sql = @"select Id as الكود,FormName as الاسم from Application";
gridSelect.DataSource = dataobj.Selectdatatable(sql);
gridSelect.DataBind();
}
catch (Exception ex)
{
dataobj.Alert(ex.Message, this);
}
}
protected void btnAdd_Click(object sender, EventArgs e)
{
try
{
string sql = @"INSERT INTO [dbo].[Ta_Users] ([Name],[UserName],[UsePassword],[Mobil],[Address],[Email]) VALUES(@1,@2,@3,@4,@5,@6)";
dataobj.Execute(sql, TxtName.Text, txtUserName.Text, txtPassword.Text, txtMobil.Text, txtAddress.Text,txtMail.Text);
string sql1 = @"select Id from [dbo].[Ta_Users] where [UserName]='" + txtUserName.Text + "' and [UsePassword]='" + txtPassword.Text + "'";
DataTable dt = dataobj.Selectdatatable(sql1);
for (int i = 0; i < gridSelect.Rows.Count; i++)
{
CheckBox c = (gridSelect.Rows[i].Cells[0].FindControl("btnCheckAll") as CheckBox);
if (c.Checked == true)
{
string sql2 = @"INSERT INTO [dbo].[Application_Setting] ([User_Id],[Appl_Id],[IsVaild]) VALUES(@1,@2,@3)";
dataobj.Execute(sql2, dt.Rows[0]["Id"].ToString(), gridSelect.Rows[i].Cells[1].Text, true);
}
}
helper.cleartxt(UpdatePanel1);
BindgrdTrades();
dataobj.Alert("Success", this);
}
catch (Exception ex)
{
dataobj.Alert(ex.Message, this);
}
}
protected void chkActive_CheckedChanged(object sender, EventArgs e)
{
try
{
bool x = chkActive.Checked;
for (int i = 0; i < gridSelect.Rows.Count; i++)
{
CheckBox c = (gridSelect.Rows[i].Cells[0].FindControl("btnCheckAll") as CheckBox);
c.Checked = x;
}
}
catch (Exception ex)
{
dataobj.Alert(ex.Message, this);
}
}
}