-
Notifications
You must be signed in to change notification settings - Fork 0
/
Peminjaman_lihat.cs
154 lines (135 loc) · 5.39 KB
/
Peminjaman_lihat.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
147
148
149
150
151
152
153
154
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Aplikasi_Perpustakaan
{
public partial class Peminjaman_lihat : Form
{
public Peminjaman_lihat()
{
InitializeComponent();
Page move = new Page();
}
public void nav(object sender, EventArgs e)
{
Page page = new Page();
this.Hide();
page.Move(sender, e);
}
private void Peminjaman_lihat_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
void Fill()
{
string sql = "SELECT * FROM [dbo].[Peminjaman]";
SqlCommand cmd = new SqlCommand(sql, Navigasi.cnn);
DataTable dt = new DataTable();
Page.READ(cmd, dt);
Viewer.DataSource = dt;
}
private void Peminjaman_lihat_Load(object sender, EventArgs e)
{
Fill();
lbl_nama.Text = Login.nama;
btn_user.Visible = Login.permission;
panel4.Visible = Login.permission;
panel_admin.Visible = !Login.permission;
}
private void btn_filter_Click(object sender, EventArgs e)
{
fitering();
}
public void fitering()
{
Viewer.DataSource = null;
string tanggal = "";
if (btn_tanggal.Checked != true)
{
tanggal = "";
}
else
{
tanggal = datepick_search.Value.ToString("yyyy/MM/dd");
}
string sql;
if (!string.IsNullOrEmpty(txt_search.Text.ToString()) || txt_search.Text != "")
{
if (tanggal != "")
{
sql = "SELECT * FROM [dbo].[Peminjaman] WHERE [Tanggal]=@tanggal AND [Nama]=@search OR [Kelas]=@search OR [Buku]=@search OR [Pengawas]=@search OR [Status]=@search";
}
else
{
sql = "SELECT * FROM [dbo].[Peminjaman] WHERE [Nama]=@search OR [Kelas]=@search OR [Buku]=@search OR [Pengawas]=@search OR [Status]=@search";
}
}
else
{
if (tanggal != "")
{
sql = "SELECT * FROM [dbo].[Peminjaman] WHERE [Tanggal] =@tanggal";
}
else
{
sql = "SELECT * FROM [dbo].[Peminjaman]";
}
}
SqlCommand cmd = new SqlCommand(sql, Navigasi.cnn);
cmd.Parameters.AddWithValue("@tanggal", tanggal);
cmd.Parameters.AddWithValue("@search", txt_search.Text);
DataTable dt = new DataTable();
Page.READ(cmd, dt);
Viewer.DataSource = dt;
}
private void Viewer_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var rows = Viewer.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (rows == "Delete")
{
if (MessageBox.Show("Yakin ingin melakuan " + rows, rows, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.Cancel)
{
string sql = "DELETE FROM [dbo].[Peminjaman] WHERE ID=@ID";
SqlCommand cmd = new SqlCommand(sql, Navigasi.cnn);
cmd.Parameters.AddWithValue("@ID", Viewer.Rows[e.RowIndex].Cells[2].Value.ToString());
Page.EXECUTE(cmd);
Fill();
MessageBox.Show(rows + " Berhasil");
}
else
{
MessageBox.Show(rows + " Dibatalkan");
}
}
else if (rows == "Update")
{
if (MessageBox.Show("Yakin ingin melakuan " + rows, rows, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != DialogResult.Cancel)
{
string sql = "UPDATE [dbo].[Peminjaman] SET Nama=@Nama, Kelas=@Kelas, Buku=@Buku, Pengawas=@Pengawas, Denda=@Denda, Status=@Status WHERE ID=@ID";
SqlCommand cmd = new SqlCommand(sql, Navigasi.cnn);
cmd.Parameters.AddWithValue("@ID", Viewer.Rows[e.RowIndex].Cells[2].Value.ToString());
cmd.Parameters.AddWithValue("@Nama", Viewer.Rows[e.RowIndex].Cells[3].Value.ToString());
cmd.Parameters.AddWithValue("@Kelas", Viewer.Rows[e.RowIndex].Cells[4].Value.ToString());
cmd.Parameters.AddWithValue("@Buku", Viewer.Rows[e.RowIndex].Cells[5].Value.ToString());
cmd.Parameters.AddWithValue("@Pengawas", Viewer.Rows[e.RowIndex].Cells[6].Value.ToString());
cmd.Parameters.AddWithValue("@Denda", Viewer.Rows[e.RowIndex].Cells[8].Value.ToString());
cmd.Parameters.AddWithValue("@Status", Viewer.Rows[e.RowIndex].Cells[9].Value.ToString());
Page.EXECUTE(cmd);
Fill();
MessageBox.Show(rows + " Berhasil");
}
else
{
MessageBox.Show(rows + " Dibatalkan");
}
}
}
}
}