-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buku_lihat.cs
125 lines (109 loc) · 4.02 KB
/
Buku_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
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;
using static System.Windows.Forms.AxHost;
namespace Aplikasi_Perpustakaan
{
public partial class Buku_lihat : Form
{
public Buku_lihat()
{
InitializeComponent();
}
public void nav(object sender, EventArgs e)
{
Page page = new Page();
this.Hide();
page.Move(sender, e);
}
private void Buku_lihat_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void Buku_lihat_Load(object sender, EventArgs e)
{
lbl_nama.Text = Login.nama;
btn_user.Visible = Login.permission;
panel4.Visible = Login.permission;
panel_admin.Visible = !Login.permission;
Fill();
}
void Fill()
{
Viewer.DataSource = null;
string sql = "SELECT * FROM [dbo].[Buku]";
SqlCommand cmd = new SqlCommand(sql, Navigasi.cnn);
DataTable dt = new DataTable();
Page.READ(cmd, dt);
Viewer.DataSource = dt;
}
void filtering()
{
Viewer.DataSource = null;
string sql = "";
string search = txt_search.Text.ToString();
SqlCommand cmd = new SqlCommand(sql, Navigasi.cnn);
if (search != "" || !string.IsNullOrEmpty(search))
{
sql = "SELECT * FROM [dbo].[Buku] WHERE Nama=@search OR Jenis=@search";
cmd.Parameters.AddWithValue("@search", search);
}
else
{
sql = "SELECT * FROM [dbo].[Buku]";
}
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].[buku] 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].[buku] WHERE ID=@ID SET Nama=@Nama, Jenis=@Jenis";
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("@Jenis", Viewer.Rows[e.RowIndex].Cells[4].Value.ToString());
Page.EXECUTE(cmd);
Fill();
MessageBox.Show(rows + " Berhasil");
}
else
{
MessageBox.Show(rows + " Dibatalkan");
}
}
}
private void btn_filter_Click(object sender, EventArgs e)
{
filtering();
}
}
}