private void button4_Click(object sender, EventArgs e) { UrunTanimlari utanim = new UrunTanimlari(); utanim.Show(); this.Hide(); }
private void pictureBox2_Click(object sender, EventArgs e) { UrunTanimlari urn = new UrunTanimlari(); kullaniciid = KullaniciIdLabel.Text; urn.Show(); this.Hide(); }
private void button3_Click(object sender, EventArgs e) { if (UrunAditxt.Text == "") { MessageBox.Show("Ürün Adı Boş Bırakmayın."); } else if (UrunBirimCb.SelectedIndex == 0) { MessageBox.Show("Ürün Birimi Boş Bırakmayın."); } else if (BirimFiyattxt.Text == "") { MessageBox.Show("Birim Fiyatı Boş Bırakmayın."); } else if (MinimumAdetTxt.Text == "") { MessageBox.Show("Minumum Adet Boş Bırakmayın."); } else { string kontrol = "Select * from Urunler where UrunAdi='" + UrunAditxt.Text + "'"; if (DataBase.select(kontrol).Rows.Count > 0) { MessageBox.Show("Ürün Adı Mevcut."); return; } string sql = "Insert Into Urunler(UrunAdi,UrunKodu,MinimumStok,UrunBirimi,BirimFiyat) VALUES('" + UrunAditxt.Text + "','" + UrunKodutxt.Text + "','" + MinimumAdetTxt.Text + "','" + UrunBirimCb.SelectedItem.ToString() + "','" + BirimFiyattxt.Text + "')SELECT SCOPE_IDENTITY();"; string id = DataBase.execScalar(sql); if (ResimTxt.Text != "") { dosyaAdi = Path.GetFileName(dosyaYolu); //Dosya adını alma string kaynak = dosyaYolu; string hedef = Application.StartupPath + @"\resimler\"; string yeniad = UrunAditxt.Text.Trim().Replace(" ", string.Empty) + ".jpg"; //Benzersiz isim verme string resimekle = "Insert Into UrunResim(UrunId,ResimUrl) VALUES('" + id + "','" + yeniad + "')"; DataBase.ExecSql(resimekle); File.Copy(kaynak, hedef + yeniad); } if (Resim2Txt.Text != "") { dosyaAdi2 = Path.GetFileName(dosyaYolu2); //Dosya adını alma string kaynak = dosyaYolu2; string hedef = Application.StartupPath + @"\resimler\"; string yeniad = "2" + UrunAditxt.Text.Trim().Replace(" ", string.Empty) + ".jpg"; string resimekle = "Insert Into UrunResim(UrunId,ResimUrl) VALUES('" + id + "','" + yeniad + "')"; DataBase.ExecSql(resimekle); File.Copy(kaynak, hedef + yeniad); } MessageBox.Show("Kaydedildi."); UrunTanimlari utanim = new UrunTanimlari(); utanim.Show(); this.Hide(); } }
private void button5_Click(object sender, EventArgs e) { if (UrunAditxt.Text == "") { MessageBox.Show("Ürün Adı Boş Bırakmayın."); } else if (UrunBirimCb.SelectedIndex == 0) { MessageBox.Show("Ürün Birimi Boş Bırakmayın."); } else if (BirimFiyattxt.Text == "") { MessageBox.Show("Birim Fiyatı Boş Bırakmayın."); } else if (MinimumAdetTxt.Text == "") { MessageBox.Show("Minumum Adet Boş Bırakmayın."); } else { try { string kontrol = "Select * from Urunler where UrunAdi='" + UrunAditxt.Text + "'"; string komut = @"UPDATE Urunler SET UrunAdi='" + UrunAditxt.Text + "',UrunKodu='" + UrunKodutxt.Text + "',MinimumStok='" + MinimumAdetTxt.Text + "',UrunBirimi='" + UrunBirimCb.SelectedItem.ToString() + "',BirimFiyat='" + BirimFiyattxt.Text + "' WHERE UrunRef=" + urun_id; DataBase.ExecSql(komut); if (ResimTxt.Text != "") { dosyaAdi = Path.GetFileName(dosyaYolu); //Dosya adını alma string kaynak = dosyaYolu; string hedef = Application.StartupPath + @"\resimler\"; string yeniad = UrunAditxt.Text.Trim().Replace(" ", string.Empty) + ".jpg"; //Benzersiz isim verme string resimsorgu = "Select * from UrunResim Where ResimUrl='" + yeniad + "'"; //Resim Varsa yapılacaklar if (DataBase.select(resimsorgu).Rows.Count > 0) { DataTable tblresimupdate = DataBase.select(resimsorgu); string path = hedef; DirectoryInfo di = new DirectoryInfo(path); FileInfo[] rgFiles = di.GetFiles(); foreach (FileInfo fi in rgFiles) { //fi.Name bize dosyanın adını dönüyor. //fi.FullName ise bize dosyasının dizin bilgisini döner. if (fi.Name == yeniad) { File.Delete(hedef + yeniad); } } string resimguncelle = "Update UrunResim set UrunId='" + urun_id + "',ResimUrl='" + yeniad + "' where ResimId=" + tblresimupdate.Rows[0]["ResimId"].ToString(); DataBase.ExecSql(resimguncelle); File.Copy(kaynak, hedef + yeniad); } //Resim Yoksa Insert edilecek else { string resimeklee = "Insert Into UrunResim(UrunId,ResimUrl) VALUES('" + urun_id + "','" + yeniad + "')"; DataBase.ExecSql(resimeklee); File.Copy(kaynak, hedef + yeniad); } } if (Resim2Txt.Text != "") { dosyaAdi2 = Path.GetFileName(dosyaYolu2); //Dosya adını alma string kaynak = dosyaYolu2; string hedef = Application.StartupPath + @"\resimler\"; string yeniad = "2" + UrunAditxt.Text.Trim().Replace(" ", string.Empty) + ".jpg"; //Benzersiz isim verme string resimsorgu = "Select * from UrunResim Where ResimUrl='" + yeniad + "'"; DataTable tbl = DataBase.select(resimsorgu); if (DataBase.select(resimsorgu).Rows.Count > 0) { string path = hedef; DirectoryInfo di = new DirectoryInfo(path); FileInfo[] rgFiles = di.GetFiles(); foreach (FileInfo fi in rgFiles) { if (fi.Name == yeniad) { File.Delete(hedef + yeniad); } } string resimekle = "Update UrunResim set UrunId='" + urun_id + "',ResimUrl='" + yeniad + "' where ResimId=" + tbl.Rows[1]["ResimId"].ToString(); DataBase.ExecSql(resimekle); File.Copy(kaynak, hedef + yeniad); } else { string resimeklee = "Insert Into UrunResim(UrunId,ResimUrl) VALUES('" + urun_id + "','" + yeniad + "')"; DataBase.ExecSql(resimeklee); File.Copy(kaynak, hedef + yeniad); } } MessageBox.Show("Güncellendi."); UrunTanimlari utanim = new UrunTanimlari(); utanim.Show(); this.Hide(); } catch (Exception hata) { MessageBox.Show(hata.Message); } } }