-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreditRequest.cs
143 lines (134 loc) · 5.6 KB
/
CreditRequest.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
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Text.RegularExpressions;
namespace VBS
{
public partial class CreditRequest : Form
{
Home home;
private string BankID { get; set; }
SQLiteConnection connection;
public CreditRequest(Home home, string BankID)
{
InitializeComponent();
this.home = home;
this.BankID = BankID;
string connectionPath = @"Data Source=C:\Users\Nathnael\Desktop\My Stuff\School Stuff\Projects\C#\FinalProject\database\bankclients.db; version=3;";
connection = new SQLiteConnection(connectionPath);
}
private void CreditRequest_Load(object sender, EventArgs e)
{
}
private void submitBtn_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(employment.Texts) && !string.IsNullOrEmpty(GMI.Texts) && !string.IsNullOrEmpty(reason.Texts) && !string.IsNullOrEmpty(amount.Texts) && !string.IsNullOrEmpty(employment.Texts) && !string.IsNullOrEmpty(empTime.Texts))
{
int num;
if (!Regex.IsMatch(amount.Texts, @"[0-9]+"))
{
customeMessageBox message = new customeMessageBox("Please Type in a number");
message.Show();
}
else
{
if (!Regex.IsMatch(GMI.Texts, @"[0-9]+"))
{
customeMessageBox message = new customeMessageBox("Please Type in a number");
message.Show();
}
else
{
if (!Regex.IsMatch(empTime.Texts, @"[0-9]+"))
{
customeMessageBox message = new customeMessageBox("Please Type in a number");
message.Show();
}
else
{
string creditQuery = "INSERT INTO CreditRequests (RequestID,BankID,Reason,Amount,AnythingElse,Salary,Employment,JobYear) VALUES(@RId,@ID,@reason,@amount,@aElse,@salary,@job,@year);";
try
{
connection.Open();
using (SQLiteCommand command = new SQLiteCommand(creditQuery, connection))
{
command.Parameters.AddWithValue("@RId", rID());
command.Parameters.AddWithValue("ID", BankID);
command.Parameters.AddWithValue("@reason", reason.Texts);
command.Parameters.AddWithValue("@amount", amount.Texts);
command.Parameters.AddWithValue("@aElse", any.Texts);
command.Parameters.AddWithValue("@salary", GMI.Texts);
command.Parameters.AddWithValue("@job", employment.Texts);
command.Parameters.AddWithValue("@year", empTime.Texts);
command.ExecuteNonQuery();
customeMessageBox success = new customeMessageBox("Request has been submitted. Response will be submitted once the decision has been made.");
success.Show();
}
}
catch (Exception ex)
{
customeMessageBox error = new customeMessageBox(ex.Message);
error.Show();
}
finally
{
connection.Close();
}
}
}
}
}
else
{
if (string.IsNullOrEmpty(amount.Texts))
{
amountLab.Visible = true;
}
else
{
amountLab.Visible = false;
}
if (string.IsNullOrEmpty(reason.Texts))
{
reasonLab.Visible = true;
}
else
{
reasonLab.Visible = false;
}
if (string.IsNullOrEmpty(GMI.Texts))
{
GMILab.Visible = true;
}
else
{
GMILab.Visible = false;
}
if (string.IsNullOrEmpty(employment.Texts))
{
employmentLab.Visible = true;
}
else
{
employmentLab.Visible = false;
}
}
}
private string rID()
{
string query = "SELECT * FROM CreditRequests; ";
using (SQLiteDataAdapter reader = new SQLiteDataAdapter(query, connection))
{
DataTable t = new DataTable();
reader.Fill(t);
return (t.Rows.Count + 1).ToString();
}
}
}
}