-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddNewUserFromAdmin.xaml.cs
112 lines (106 loc) · 4.25 KB
/
AddNewUserFromAdmin.xaml.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.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Informix.Net.Core;
namespace ISL
{
/// <summary>
/// Interaction logic for AddNewUserFromAdmin.xaml
/// </summary>
public partial class AddNewUserFromAdmin : Window
{
IfxConnection con;
//Connection String
string cs = "DataBase=logindb;Server=ol_informix1410_9;User ID = informix; Password=Rinvoke1;";
public string[] userType { get; set; }
public AddNewUserFromAdmin()
{
InitializeComponent();
userType = new string[] { "Admin", "User" };
DataContext = this;
}
private void Submit_Click(object sender, RoutedEventArgs e)
{
if (textBoxEmail.Text.Length == 0)
{
errormessage.Text = "Enter an email.";
textBoxEmail.Focus();
}
else if (!Regex.IsMatch(textBoxEmail.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"))
{
errormessage.Text = "Enter a valid email.";
textBoxEmail.Select(0, textBoxEmail.Text.Length);
textBoxEmail.Focus();
}
else
{
string firstname = textBoxFirstName.Text;
string lastname = textBoxLastName.Text;
string email = textBoxEmail.Text;
string username = textBoxUserName.Text;
string usertype = comboBoxUserType.Text;
string password = passwordBox1.Password;
if (username.Length == 0)
{
errormessage.Text = "Enter username.";
textBoxUserName.Focus();
}
else
{
if (passwordBox1.Password.Length == 0)
{
errormessage.Text = "Enter password.";
passwordBox1.Focus();
}
else if (passwordBoxConfirm.Password.Length == 0)
{
errormessage.Text = "Enter Confirm password.";
passwordBoxConfirm.Focus();
}
else if (passwordBox1.Password != passwordBoxConfirm.Password)
{
errormessage.Text = "Confirm password must be same as password.";
passwordBoxConfirm.Focus();
}
else
{
if (usertype.Length == 0)
{
errormessage.Text = "Select user type.";
comboBoxUserType.Focus();
}
errormessage.Text = "";
string address = textBoxAddress.Text;
con = new IfxConnection(cs);
con.Open();
IfxCommand cmd = new IfxCommand("Insert into User (firstname,lastname,email,username,usertype,password,address) values('" + firstname + "','" + lastname + "','" + email + "','" + username + "','" + usertype + "','" + password + "','" + address + "')", con);
cmd.CommandType = CommandType.Text;
int rows = cmd.ExecuteNonQuery();
con.Close();
if (rows > 0)
{
if (usertype.Equals("Admin"))
errormessage.Text = "Admin registered successfully.";
else
errormessage.Text = "User registered successfully.";
}
else
{
errormessage.Text = "Registeration Failed";
}
}
}
}
}
}
}