Esempio n. 1
0
        private void btnDegisiklikKaydet_Click(object sender, EventArgs e)
        {
            int stokAdet     = 0;
            int eksilenDeger = 0;
            int Num;

            if (baglanti.State == ConnectionState.Closed)
            {
                baglanti.Open();
            }

            komut = new OleDbCommand("Select * From Depo Where UrunId=" + urunID, baglanti);
            OleDbDataReader oku = komut.ExecuteReader();

            while (oku.Read())
            {
                tbUrunAd.Text   = oku["UrunAd"].ToString();
                tbUrunAdet.Text = oku["UrunAdet"].ToString();
            }

            bool isNum = int.TryParse(tbDusulecekDeger.Text.ToString(), out Num);

            if (isNum)
            {
                stokAdet     = int.Parse(tbUrunAdet.Text.ToString());
                eksilenDeger = int.Parse(tbDusulecekDeger.Text.ToString());


                if (tbUrunAdet.Text != "" && Convert.ToInt32(tbUrunAdet.Text.ToString()) > 0)
                {
                    if (stokAdet >= eksilenDeger)
                    {
                        stokAdet = stokAdet - eksilenDeger;

                        komut = new OleDbCommand("UPDATE Depo SET UrunAdet='" + stokAdet.ToString() + "' WHERE UrunID =" + urunID, baglanti);
                        komut.ExecuteNonQuery();
                        baglanti.Close();

                        MessageBox.Show("Değişiklikleriniz kaydedildi.", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();

                        Form1 anaForm = (Form1)Application.OpenForms["Form1"];
                        anaForm.dataGridDoldur("Select * From Depo ORDER BY UrunId");
                    }
                    else if (stokAdet < eksilenDeger)
                    {
                        MessageBox.Show("Stoktaki ürün adedinden fazla ürün girdiniz.", "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Hatalı Giriş Yaptınız.", "Hata!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Hata", "Hata!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Lütfen Sayısal Bir Değer Girin", "Hata!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.Close();
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                kategorileriGetir();
                if (durum == 1)
                {
                    if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text))
                    {
                        if (baglanti.State == ConnectionState.Closed)
                        {
                            baglanti.Open();
                        }

                        komut = new OleDbCommand("UPDATE Depo SET UrunAd='" + textBox1.Text + "',UrunAdet=" + textBox3.Text + ",UrunBirim='" + textBox4.Text + "',UrunKonum='" + textBox2.Text + "' WHERE UrunId=" + urunID, baglanti);
                        komut.ExecuteNonQuery();
                        baglanti.Close();

                        MessageBox.Show("Değişiklikleriniz kaydedildi.", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();

                        Form1 anaForm = (Form1)Application.OpenForms["Form1"];
                        anaForm.dataGridDoldur("Select * From Depo ORDER BY UrunId");
                    }
                    else
                    {
                        MessageBox.Show("Alanlar Boş Bırakılamaz", "Hata!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
                else
                {
                    if (baglanti.State == ConnectionState.Closed)
                    {
                        baglanti.Open();
                    }

                    if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text) && !string.IsNullOrEmpty(textBox3.Text) && !string.IsNullOrEmpty(textBox4.Text))
                    {
                        String urunKontrol = "SELECT UrunAd FROM Depo WHERE UrunAd='" + textBox1.Text.ToString() + "' and UrunBirim='" + textBox4.Text.ToString() + "'";

                        if (!kayitvarmi(urunKontrol))
                        {
                            if (baglanti.State == ConnectionState.Closed)
                            {
                                baglanti.Open();
                            }

                            komut = new OleDbCommand("INSERT INTO Depo(UrunAd,KategoriAd,UrunAdet,UrunBirim,UrunKonum) VALUES ('" + textBox1.Text +
                                                     "','" + comboBox2.Text +
                                                     "','" + textBox3.Text +
                                                     "','" + textBox4.Text +
                                                     "','" + textBox2.Text + "')", baglanti);
                            komut.ExecuteNonQuery();
                            baglanti.Close();
                            MessageBox.Show("Ürününüz kaydedildi.", "Başarılı", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            Form1 anaForm = (Form1)Application.OpenForms["Form1"];
                            anaForm.dataGridDoldur("Select * From Depo ORDER BY UrunId");
                        }
                        else
                        {
                            MessageBox.Show("Aynı isimde ürün ekleyemezsiniz.", "Hata!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            this.Close();
                        }

                        textBox1.Text  = "";
                        comboBox2.Text = "";
                        textBox2.Text  = "";
                        textBox3.Text  = "";
                        textBox4.Text  = "";
                    }
                    else
                    {
                        MessageBox.Show("Alanlar Boş Bırakılamaz", "Hata!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                    }
                }
            }
            catch
            {
            }
        }