-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKitapListe.cs
87 lines (80 loc) · 2.88 KB
/
KitapListe.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using Excel = Microsoft.Office.Interop.Excel;
namespace KütüphaneTakipProgramı
{
public partial class KitapListe : Form
{
public KitapListe()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection("Server=.;Database=KUTUPHANE;Trusted_Connection=True;");
DataTable tbl = new DataTable();
private void KitapListe_Load(object sender, EventArgs e)
{
SqlDataAdapter adp = new SqlDataAdapter("spKitapListe", con);
adp.Fill(tbl);
dGridListe.DataSource = tbl;
}
private void btnGeri_Click(object sender, EventArgs e)
{
AnaEkran ana = new AnaEkran();
ana.Show();
this.Hide();
}
private void txtAra_TextChanged(object sender, EventArgs e)
{
try
{
DataTable tbl = new DataTable("Kitaplar");
SqlDataAdapter adp = new SqlDataAdapter("Select * from Kitaplar where Adi like @Adi", con);
adp.SelectCommand.Parameters.AddWithValue("@Adi", txtAra.Text + "%");
con.Open();
adp.Fill(tbl);
dGridListe.DataSource = tbl.DefaultView;
con.Close();
}
catch (Exception)
{
MessageBox.Show("Hata");
}
}
Excel.Application uyg;
Excel.Workbook ktp;
Excel.Worksheet syf;
private void btnExcel_Click(object sender, EventArgs e)
{
DataTable dt=new DataTable("Kitaplar");
DataRow dr;
SqlConnection con=new SqlConnection("Server=.;Database=KUTUPHANE;Trusted_Connection=True;");
SqlDataAdapter adp;
uyg=new Excel.Application();
ktp=uyg.Workbooks.Add();
syf = (Excel.Worksheet)ktp.Worksheets.get_Item(1);
string aktar = "select * from Kitaplar";
adp = new SqlDataAdapter(aktar, con);
adp.Fill(dt);
for (int i = 1; i < dt.Columns.Count+1; i++)
{
for (int a = 1; a < dt.Rows.Count+1; a++)
{
dr = dt.Rows[a - 1];
syf.Cells[a, i] = dr[i - 1].ToString();
}
}
ktp.SaveAs(Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH") + "\\Desktop\\KitapListe.xls");
ktp.Close();
uyg.Quit();
MessageBox.Show("Başarıyla Masaüstüne Kaydedildi");
}
}
}