public static Yazar getAuthor(int id) { Yazar Value = null; SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); SqlCommand cmd = new SqlCommand("select * from dbo.Yazar where ID=" + id.ToString(), con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { id = reader.GetInt32(0); string adi = reader.GetString(1); string soyadi = reader.GetString(2); Yazar Current = new Yazar(id, adi, soyadi); string ozgecmis; try { ozgecmis = reader.GetString(3); } catch (SqlNullValueException snve) { ozgecmis = ""; } Current.Ozgecmis = ozgecmis; Value = Current; } reader.Close(); con.Close(); return Value; }
public static List<Yazar> getAuthors() { List<Yazar> Value = new List<Yazar>(); SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); SqlCommand cmd = new SqlCommand("select * from dbo.Yazar", con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); string adi = reader.GetString(1); string soyadi = reader.GetString(2); Yazar Current = new Yazar(id, adi, soyadi); string ozgecmis; try { ozgecmis = reader.GetString(3); } catch(SqlNullValueException snve) { ozgecmis = ""; } Current.Ozgecmis = ozgecmis; Value.Add(Current); } reader.Close(); con.Close(); return Value; }
public Kitap(int id, string adi, int basimYili, Yazar[] yazar, Yayinevi yayinevi, Kategori kategori, int sayfa, bool kiralama, bool hasar, Decimal fiyat) : base(id, adi) { this.BasimYili = basimYili; this.Author = yazar; this.Publisher = yayinevi; this.Category = kategori; this.SayfaSayisi = sayfa; this.KiralamaDurumu = kiralama; this.HasarDurumu = hasar; this.Fiyat = fiyat; }
public static int record(Yazar Value) { int rvalue = 0; SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); String CommandString = ""; if (Value.ID == 0) { CommandString += "insert into dbo.Yazar"; if (String.IsNullOrEmpty(Value.Ozgecmis)) { CommandString += " (Adi,Soyadi) values('" + Value.Adi + "','" + Value.Soyadi + "')"; } else { CommandString += " values('" + Value.Adi + "','" + Value.Soyadi + "','" + Value.Ozgecmis + "')"; } SqlCommand cmd = new SqlCommand(CommandString, con); con.Open(); try { int rows = cmd.ExecuteNonQuery(); if (rows == 1) { con.Close(); cmd = new SqlCommand("select ID from dbo.Yazar order by ID desc",con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); reader.Read(); rvalue = reader.GetInt32(0); reader.Close(); } else { rvalue = 0; } } catch(Exception ex) { rvalue = 0; } con.Close(); } else { CommandString += "update dbo.Yazar set"; if (String.IsNullOrEmpty(Value.Ozgecmis)) { CommandString += " Adi='" + Value.Adi + "',Soyadi='" + Value.Soyadi + "'"; } else { CommandString += " Adi='" + Value.Adi + "',Soyadi='" + Value.Soyadi + "',Ozgecmis='" + Value.Ozgecmis + "'"; } CommandString += " where ID=" + Value.ID.ToString(); SqlCommand cmd = new SqlCommand(CommandString, con); con.Open(); try { int rows = cmd.ExecuteNonQuery(); if (rows == 1) { rvalue = Value.ID; } else { rvalue = 0; } } catch (Exception ex) { rvalue = 0; } con.Close(); } return rvalue; }
private void YazarEkle_Click(object sender, EventArgs e) { bool check = false; String[] AdSoyad = YazarIslemleri.seperateName(YazarCB.Text); String Ad = AdSoyad[0]; String Soyad = AdSoyad[1]; foreach (Yazar item in YazarCB.Items) { if (item.Adi.Equals(Ad) && item.Soyadi.Equals(Soyad) && !YazarList.Items.Contains(item)) { YazarList.Items.Add(item); check = true; break; } } if (!check) { Yazar Current = new Yazar(Ad, Soyad); if (!YazarList.Items.Contains(Current)) { YazarList.Items.Add(Current); } } }
private void Finish_Click(object sender, EventArgs e) { try { Decimal Fiyat = Decimal.Parse(FiyatTB.Text); bool check = true; if (String.IsNullOrEmpty(KitapTB.Text)) { check = false; MessageBox.Show("Lütfen kitap adını girin"); } if (check && String.IsNullOrEmpty(YayineviCB.Text)) { check = false; MessageBox.Show("Lütfen yayınevi girin"); } if (check && String.IsNullOrEmpty(KategoriCB.Text)) { check = false; MessageBox.Show("Lütfen kategori girin"); } if (check) { Current.Adi = KitapTB.Text; Current.BasimYili = (int)BasimYiliNUD.Value; if (YazarList.Items.Count > 0) { Yazar[] Yazarlar = new Yazar[YazarList.Items.Count]; YazarList.Items.CopyTo(Yazarlar, 0); Current.Author = Yazarlar; } if (YayineviCB.SelectedIndex != -1) { Current.Publisher = (Yayinevi)YayineviCB.SelectedItem; } else { String Isim = YayineviCB.Text; bool added = false; foreach (Yayinevi item in YayineviCB.Items) { if (item.Adi.Equals(Isim)) { Current.Publisher = item; added = true; break; } } if (!added) { Current.Publisher = new Yayinevi(Isim); } } if (KategoriCB.SelectedIndex != -1) { Current.Category = (Kategori)KategoriCB.SelectedItem; } else { String Isim = KategoriCB.Text; bool added = false; foreach (Kategori item in KategoriCB.Items) { if (item.Adi.Equals(Isim)) { Current.Category = item; added = true; break; } } if (!added) { Current.Category = new Kategori(Isim); } } Current.SayfaSayisi = (int)SayfaSayisiNUD.Value; Current.HasarDurumu = Hasar.Checked; Current.Fiyat = Fiyat; Current.Ozet = OzetRTB.Text; Current.Kapak = KapakTB.Text; if (KitapIslemleri.record(Current)) { MessageBox.Show("Başarıyla kaydedildi"); } else { MessageBox.Show("Kayıt sırasında bir hata oluştu"); } this.Close(); } } catch (ArgumentNullException ane) { MessageBox.Show("Fiyat kaydedilirken hata oluştu\n" + ane.Message); } catch (FormatException nfe) { MessageBox.Show("Fiyat kaydedilirken hata oluştu\n" + nfe.Message); } catch (OverflowException oe) { MessageBox.Show("Fiyat kaydedilirken hata oluştu\n" + oe.Message); } }
public static List<Kitap> mostRentedBook(DateTime First, DateTime Last) { List<Kitap> Value = new List<Kitap>(); SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); String CommandString = "select KitapID,COUNT(KitapID) as KiralamaSayisi from dbo.Kiralama" + " join dbo.KiralamaDetay on Kiralama.ID = KiralamaDetay.ID" + " where KiralamaDetay.KiralamaTarihi between"; CommandString += " '" + convertToSqlDate(First.ToShortDateString()) + "' and"; CommandString += " '" + convertToSqlDate(Last.ToShortDateString()) + "' group by KitapID"; CommandString += " order by KiralamaSayisi desc"; SqlCommand cmd = new SqlCommand(CommandString, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); int max = 0; List<int> Kitaplar = new List<int>(); if (reader.Read()) { max = reader.GetInt32(1); Kitaplar.Add(reader.GetInt32(0)); } while (reader.Read()) { int currentCount = reader.GetInt32(1); if (currentCount == max) { Kitaplar.Add(reader.GetInt32(0)); } else if (currentCount < max) { break; } } reader.Close(); con.Close(); if (Kitaplar.Count > 0) { CommandString = "select * from dbo.Kitap where "; foreach (int item in Kitaplar) { CommandString += "ID=" + item.ToString() + " or "; } CommandString = CommandString.Remove(CommandString.Length - 4); cmd = new SqlCommand(CommandString, con); con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); SqlConnection AuthorCon = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); SqlCommand AuthorCmd = new SqlCommand("select YazarID from dbo.KitapYazar where KitapID = " + id.ToString(), AuthorCon); AuthorCon.Open(); SqlDataReader AuthorReader = AuthorCmd.ExecuteReader(); List<Yazar> YazarList = new List<Yazar>(); while (AuthorReader.Read()) { YazarList.Add(YazarIslemleri.getAuthor(AuthorReader.GetInt32(0))); } AuthorReader.Close(); AuthorCon.Close(); Yazar[] Yazarlar = null; if (YazarList.Count > 0) { Yazarlar = new Yazar[YazarList.Count]; YazarList.CopyTo(Yazarlar); } Yayinevi Publisher = YayineviIslemleri.getPublisher(reader.GetInt32(3)); Kategori Category = KategoriIslemleri.getCategory(reader.GetInt32(4)); Kitap Current = new Kitap(id, reader.GetString(1), int.Parse(reader.GetString(2)), Yazarlar, Publisher, Category, reader.GetInt32(5), reader.GetBoolean(7), reader.GetBoolean(6), reader.GetDecimal(8)); try { Current.Ozet = reader.GetString(9); } catch (SqlNullValueException snve) { Current.Ozet = ""; } try { Current.Kapak = reader.GetString(10); } catch (SqlNullValueException snve) { Current.Kapak = ""; } if (!Value.Contains(Current)) { Value.Add(Current); } } reader.Close(); con.Close(); } return Value; }
public static List<Yazar> mostPopularAuthor(DateTime First, DateTime Last) { List<Yazar> Value = new List<Yazar>(); SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); String CommandString = "select YazarID,COUNT(YazarID) as TercihSayisi from dbo.Kiralama "; CommandString += "join dbo.KiralamaDetay on Kiralama.ID = KiralamaDetay.ID "; CommandString += "join dbo.Kitap on Kitap.ID = Kiralama.KitapID "; CommandString += "join dbo.KitapYazar on Kitap.ID = KitapYazar.KitapID "; CommandString += "where KiralamaDetay.KiralamaTarihi between "; CommandString += "'" + convertToSqlDate(First.ToShortDateString()) + "' and "; CommandString += "'" + convertToSqlDate(Last.ToShortDateString()) + "'"; CommandString += " group by YazarID order by TercihSayisi desc"; SqlCommand cmd = new SqlCommand(CommandString, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); int max = 0; List<int> Authors = new List<int>(); if (reader.Read()) { max = reader.GetInt32(1); Authors.Add(reader.GetInt32(0)); } while (reader.Read()) { int currentCount = reader.GetInt32(1); if (currentCount == max) { Authors.Add(reader.GetInt32(0)); } else if (currentCount < max) { break; } } reader.Close(); con.Close(); if (Authors.Count > 0) { CommandString = "select * from dbo.Yazar where "; foreach (int item in Authors) { CommandString += "ID=" + item.ToString() + " or "; } CommandString = CommandString.Remove(CommandString.Length - 4); cmd = new SqlCommand(CommandString, con); con.Open(); reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); string adi = reader.GetString(1); string soyadi = reader.GetString(2); Yazar Current = new Yazar(id, adi, soyadi); string ozgecmis; try { ozgecmis = reader.GetString(3); } catch (SqlNullValueException snve) { ozgecmis = ""; } Current.Ozgecmis = ozgecmis; Value.Add(Current); } reader.Close(); con.Close(); } return Value; }
public static List<Kitap> search(string kitapAdi, Yazar[] yazarlar, int[] yillar) { List<Kitap> Value = new List<Kitap>(); SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); String CommandString = "select ID,Adi,BasimYili,YayineviID,KategoriID,SayfaSayisi,HasarDurumu,KiralamaDurumu,Ucret,Ozet,Kapak "; CommandString += "from dbo.Kitap join dbo.KitapYazar on dbo.Kitap.ID = dbo.KitapYazar.KitapID where "; CommandString += "(Adi like '%" + kitapAdi + "%') and ("; int counter = 0; foreach (Yazar item in yazarlar) { if (item.ID != 0) { CommandString += "dbo.KitapYazar.YazarID=" + item.ID.ToString() + " or "; counter++; } } if (counter > 0) { CommandString = CommandString.Remove(CommandString.Length - 4); CommandString += ") and ("; } foreach (int item in yillar) { CommandString += "dbo.Kitap.BasimYili='" + item.ToString() + "' or "; } CommandString = CommandString.Remove(CommandString.Length - 4); CommandString += ")"; SqlCommand cmd = new SqlCommand(CommandString, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); SqlConnection AuthorCon = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); SqlCommand AuthorCmd = new SqlCommand("select YazarID from dbo.KitapYazar where KitapID = " + id.ToString(), AuthorCon); AuthorCon.Open(); SqlDataReader AuthorReader = AuthorCmd.ExecuteReader(); List<Yazar> YazarList = new List<Yazar>(); while (AuthorReader.Read()) { YazarList.Add(YazarIslemleri.getAuthor(AuthorReader.GetInt32(0))); } AuthorReader.Close(); AuthorCon.Close(); Yazar[] Yazarlar = null; if (YazarList.Count > 0) { Yazarlar = new Yazar[YazarList.Count]; YazarList.CopyTo(Yazarlar); } Yayinevi Publisher = YayineviIslemleri.getPublisher(reader.GetInt32(3)); Kategori Category = KategoriIslemleri.getCategory(reader.GetInt32(4)); Kitap Current = new Kitap(id, reader.GetString(1), int.Parse(reader.GetString(2)), Yazarlar, Publisher, Category, reader.GetInt32(5), reader.GetBoolean(7), reader.GetBoolean(6), reader.GetDecimal(8)); try { Current.Ozet = reader.GetString(9); } catch (SqlNullValueException snve) { Current.Ozet = ""; } try { Current.Kapak = reader.GetString(10); } catch (SqlNullValueException snve) { Current.Kapak = ""; } if (!Value.Contains(Current)) { Value.Add(Current); } } reader.Close(); con.Close(); return Value; }
public static List<Kitap> search(string kitapAdi) { List<Kitap> Value = new List<Kitap>(); SqlConnection con = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); String CommandString = "select * from dbo.Kitap where Adi like '%" + kitapAdi + "%'"; SqlCommand cmd = new SqlCommand(CommandString, con); con.Open(); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { int id = reader.GetInt32(0); SqlConnection AuthorCon = new SqlConnection("Server=.;Database=KutuphaneOtomasyon;Trusted_Connection=true"); SqlCommand AuthorCmd = new SqlCommand("select YazarID from dbo.KitapYazar where KitapID = " + id.ToString(), AuthorCon); AuthorCon.Open(); SqlDataReader AuthorReader = AuthorCmd.ExecuteReader(); List<Yazar> YazarList = new List<Yazar>(); while (AuthorReader.Read()) { YazarList.Add(YazarIslemleri.getAuthor(AuthorReader.GetInt32(0))); } AuthorReader.Close(); AuthorCon.Close(); Yazar[] Yazarlar = null; if (YazarList.Count > 0) { Yazarlar = new Yazar[YazarList.Count]; YazarList.CopyTo(Yazarlar); } Yayinevi Publisher = YayineviIslemleri.getPublisher(reader.GetInt32(3)); Kategori Category = KategoriIslemleri.getCategory(reader.GetInt32(4)); Kitap Current = new Kitap(id, reader.GetString(1), int.Parse(reader.GetString(2)), Yazarlar, Publisher, Category, reader.GetInt32(5), reader.GetBoolean(7), reader.GetBoolean(6), reader.GetDecimal(8)); try { Current.Ozet = reader.GetString(9); } catch (SqlNullValueException snve) { Current.Ozet = ""; } try { Current.Kapak = reader.GetString(10); } catch (SqlNullValueException snve) { Current.Kapak = ""; } Value.Add(Current); } reader.Close(); con.Close(); return Value; }
private void KitapEkle_Click(object sender, EventArgs e) { Kitap Yeni = new Kitap(null, (int)BasimYiliNUD.Value, null, null, null, 0, false, false, 0); if (!String.IsNullOrEmpty(KitapTB.Text)) { Yeni.Adi = KitapTB.Text; } if (BasimYiliList.Items.Count == 1) { Yeni.BasimYili = (int)BasimYiliList.Items[0]; } if (!String.IsNullOrEmpty(YazarCB.Text)) { String[] AdSoyad = YazarIslemleri.seperateName(YazarCB.Text); String Ad = AdSoyad[0]; String Soyad = AdSoyad[1]; bool check = false; foreach (Yazar item in YazarCB.Items) { if (item.Adi.Equals(Ad) && item.Soyadi.Equals(Soyad)) { check = true; break; } } Yazar[] Yazarlar; if (check) { Yazarlar = new Yazar[YazarList.Items.Count]; YazarList.Items.CopyTo(Yazarlar, 0); } else { Yazarlar = new Yazar[YazarList.Items.Count + 1]; YazarList.Items.CopyTo(Yazarlar, 0); Yazarlar[YazarList.Items.Count] = new Yazar(Ad, Soyad); } Yeni.Author = Yazarlar; } else if (YazarList.Items.Count > 0) { Yazar[] Yazarlar = new Yazar[YazarList.Items.Count]; YazarList.Items.CopyTo(Yazarlar, 0); Yeni.Author = Yazarlar; } Form2 EkleForm = new Form2("Yeni Kitap Ekle", Yeni); EkleForm.ShowDialog(); refreshAuthors(); setList(); }
private void setList() { String KitapAdi = KitapTB.Text.Replace("'",""); int yazar = YazarList.Items.Count; int basimyili = BasimYiliList.Items.Count; if (!String.IsNullOrEmpty(KitapAdi)) { KitapAdi = KitapAdi.Trim().Replace(' ', '%'); if (yazar > 0) { Yazar[] Yazarlar = new Yazar[yazar]; YazarList.Items.CopyTo(Yazarlar, 0); if (basimyili > 0) { int[] Yillar = new int[basimyili]; for (int i = 0; i < basimyili; i++)// CopyTo çalışmadı { Yillar[i] = (int)(BasimYiliList.Items[i]); } KitapList.DataSource = KitapIslemleri.search(KitapAdi, Yazarlar, Yillar); } else { KitapList.DataSource = KitapIslemleri.search(KitapAdi, Yazarlar); } } else { if (basimyili > 0) { int[] Yillar = new int[basimyili]; for (int i = 0; i < basimyili; i++) { Yillar[i] = (int)(BasimYiliList.Items[i]); } KitapList.DataSource = KitapIslemleri.search(KitapAdi, Yillar); } else { KitapList.DataSource = KitapIslemleri.search(KitapAdi); } } } else { if (yazar > 0) { Yazar[] Yazarlar = new Yazar[yazar]; YazarList.Items.CopyTo(Yazarlar, 0); if (basimyili > 0) { int[] Yillar = new int[basimyili]; for (int i = 0; i < basimyili; i++) { Yillar[i] = (int)(BasimYiliList.Items[i]); } KitapList.DataSource = KitapIslemleri.search(Yazarlar, Yillar); } else { KitapList.DataSource = KitapIslemleri.search(Yazarlar); } } else { if (basimyili > 0) { int[] Yillar = new int[basimyili]; for (int i = 0; i < basimyili; i++) { Yillar[i] = (int)(BasimYiliList.Items[i]); } KitapList.DataSource = KitapIslemleri.search(Yillar); } else { KitapList.DataSource = new List<Kitap>(); } } } }
public Form3(String Title, Object Edition, int type) { InitializeComponent(); this.Text = Title; KurulusYiliNUD.Maximum = DateTime.Now.Year; this.Type = type; switch (Type) { case 0: label5.Text = "Yazar :"; comboBox1.DataSource = YazarIslemleri.getAuthors(); label2.Text = "Özgeçmiş :"; label4.Hide(); KurulusYiliNUD.Hide(); KurulusYiliCB.Hide(); CurrentYaz = (Yazar)Edition; if (comboBox1.Items.Contains(CurrentYaz)) { comboBox1.SelectedItem = CurrentYaz; } else { comboBox1.SelectedIndex = -1; AdiTB.Text = CurrentYaz.Adi; SoyadiTB.Text = CurrentYaz.Soyadi; richTextBox1.Text = CurrentYaz.Ozgecmis; } break; case 1: label5.Text = "Yayınevi :"; comboBox1.DataSource = YayineviIslemleri.getPublishers(); label2.Text = "Adres :"; label3.Hide(); SoyadiTB.Hide(); KurulusYiliNUD.Enabled = false; KurulusYiliCB.Checked = false; CurrentYay = (Yayinevi)Edition; if (comboBox1.Items.Contains(CurrentYay)) { comboBox1.SelectedItem = CurrentYay; } else { comboBox1.SelectedIndex = -1; AdiTB.Text = CurrentYay.Adi; richTextBox1.Text = CurrentYay.Adres; if (CurrentYay.KurulusYili != 0) { KurulusYiliNUD.Value = CurrentYay.KurulusYili; KurulusYiliCB.Checked = true; } } break; case 2: comboBox1.DataSource = KategoriIslemleri.getCategories(); label3.Hide(); SoyadiTB.Hide(); label4.Hide(); KurulusYiliNUD.Hide(); KurulusYiliCB.Hide(); CurrentKat = (Kategori)Edition; if (comboBox1.Items.Contains(CurrentKat)) { comboBox1.SelectedItem = CurrentKat; } else { comboBox1.SelectedIndex = -1; AdiTB.Text = CurrentKat.Adi; richTextBox1.Text = CurrentKat.Aciklama; } break; } }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex != -1) { switch (Type) { case 0: CurrentYaz = (Yazar)comboBox1.SelectedItem; AdiTB.Text = CurrentYaz.Adi; SoyadiTB.Text = CurrentYaz.Soyadi; richTextBox1.Text = CurrentYaz.Ozgecmis; break; case 1: CurrentYay = (Yayinevi)comboBox1.SelectedItem; AdiTB.Text = CurrentYay.Adi; richTextBox1.Text = CurrentYay.Adres; if (CurrentYay.KurulusYili != 0) { KurulusYiliNUD.Value = CurrentYay.KurulusYili; KurulusYiliCB.Checked = true; } break; case 2: CurrentKat = (Kategori)comboBox1.SelectedItem; AdiTB.Text = CurrentKat.Adi; richTextBox1.Text = CurrentKat.Aciklama; break; } } }