-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBconnection.cs
146 lines (100 loc) · 3.52 KB
/
DBconnection.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
144
145
146
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace Nazam_pos
{
public class DBconnection
{
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
SqlDataReader dr;
private double dailysales;
private string con;
private int productline;
private int stockonhand;
private int criticalitem;
public string Myconnection()
{
//string con= @"Data Source = DESKTOP - O9L6C35; Initial Catalog = Inventory 1; Integrated Security = True";
con= "Data Source=DESKTOP-O9L6C35;Initial Catalog=Inventory 1;Integrated Security=True";
//con = @"Data Source=DESKTOP-T4AVUIO;Initial Catalog=Inventory 1;Integrated Security=True ";
return con;
}
public double DailySales()
{
string sdate = DateTime.Now.ToShortDateString();
cn = new SqlConnection();
cn.ConnectionString = con;
cn.Open();
cm = new SqlCommand("select isnull(sum(total),0) as total from tblcart where sdate between '" + sdate + "'and'" + sdate + "'and status like 'Sold'", cn);
dailysales = double.Parse(cm.ExecuteScalar().ToString());
cn.Close();
return dailysales;
}
public double ProductLine()
{
cn = new SqlConnection();
cn.ConnectionString = con;
cn.Open();
cm = new SqlCommand("select count (*) from tblProducts", cn);
productline = int.Parse(cm.ExecuteScalar().ToString());
cn.Close();
return productline;
}
public double StockOnHand()
{
cn = new SqlConnection();
cn.ConnectionString = con;
cn.Open();
cm = new SqlCommand("select isnull (sum(qty),0) as qty from tblProducts", cn);
stockonhand = int.Parse(cm.ExecuteScalar().ToString());
cn.Close();
return stockonhand;
}
public double CriticalItem()
{
cn = new SqlConnection();
cn.ConnectionString = con;
cn.Open();
cm = new SqlCommand("select count(*) from vwCriticalItems", cn);
criticalitem = int.Parse(cm.ExecuteScalar().ToString());
cn.Close();
return criticalitem;
}
public double GetVal()
{
double vat = 0;
cn.ConnectionString = Myconnection();
cn.Open();
cm = new SqlCommand(" select * from tblVat ", cn);
dr = cm.ExecuteReader();
while (dr.Read())
{
vat = Double.Parse(dr["vat"].ToString());
}
dr.Close();
cn.Close();
return vat;
}
public string GetPassword(string user)
{
string password="";
cn.ConnectionString = Myconnection();
cn.Open();
cm = new SqlCommand(" select * from tblUser where username =@username", cn);
cm.Parameters.AddWithValue("@username", user);
dr = cm.ExecuteReader();
dr.Read();
if(dr.HasRows)
{
password = dr["password"].ToString();
}
dr.Close();
cn.Close();
return password;
}
}
}