C# ve sql server ile STOK TAKİP PROGRAMI

Öncelikle Bütün kodları tarafıma ait olup sorunsuz çalışmaktadır. Program ile satı yapıp, ürün bilgileri kayıt altında tutarak ayrıca günlük ve aylık satış toplamlarını görüntüleyebilecek siniz. genellikle stored-procedure ağırlıklıdır.


Programın videosu :https://www.youtube.com/watch?v=Nqk_7JHi8T8

Programın ana görüntüsü bu şekildedir.


visual stdio kısmında yer alan bütün kodlar aşağıda verilmiştir sonrasında is stored procedureler yer almaktadır.

Parça Satış butonunun altında yer alan kodlar şu şekildedir:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class Parca_Satis : Form
    {
        public Parca_Satis()
        {
            InitializeComponent();
        }

        private void Parca_Satis_Load(object sender, EventArgs e)
        {





            SqlConnection baglantı = new SqlConnection();
            SqlCommand komut = new SqlCommand();
            baglantı.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantı.Open();
            komut.Connection = baglantı;
            komut.CommandText = ("delete from satis_stok");
            komut.ExecuteNonQuery();
            baglantı.Close();


            SqlConnection baglantı3 = new SqlConnection();
            SqlCommand komut3 = new SqlCommand();
            baglantı3.ConnectionString = (@"Data Source=.\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=stok_program;Integrated Security=True;");
            baglantı3.Open();
            komut3.Connection = baglantı3;
            komut3.CommandText = ("delete from satok_guncelle");
            komut3.ExecuteNonQuery();
            baglantı3.Close();

        }



        private void ekle_Click(object sender, EventArgs e)
        {






        }



        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {


            if (e.KeyCode == Keys.Enter)
            {
                SqlConnection baglantım = new SqlConnection();
                SqlCommand komutm = new SqlCommand();
                baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
                baglantım.Open();
                komutm.Connection = baglantım;
                komutm.CommandText = ("select Stok_Adet from Parca where Parca_no='" + textBox4.Text.ToString() + "'");

                string str = Convert.ToString(komutm.ExecuteScalar());

                int a;
                a = Int32.Parse(str);

                komutm.ExecuteNonQuery();
                baglantım.Close();
                if (a <= 0)
                {
                    MessageBox.Show("Ürün Stokta Kalmadı");
                    textBox4.ResetText();

                }

                else
                {


                    SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
                    SqlCommand sorgu = new SqlCommand();

                    baglan.Open();
                    sorgu.Connection = baglan;
                    sorgu.CommandType = CommandType.StoredProcedure;

                    sorgu.CommandText = "Parca_getir";


                    sorgu.Parameters.AddWithValue("@Parca_no", textBox4.Text.ToString());

                    sorgu.Parameters.Add("@Parca_adi", SqlDbType.NVarChar, 255);
                    sorgu.Parameters["@Parca_adi"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Raf_no", SqlDbType.NVarChar, 255);
                    sorgu.Parameters["@Raf_no"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Fiyat", SqlDbType.Decimal);
                    sorgu.Parameters["@Fiyat"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Stok_Adet", SqlDbType.Int);
                    sorgu.Parameters["@Stok_Adet"].Direction = ParameterDirection.Output;
                    sorgu.ExecuteNonQuery();

                    baglan.Close();

                    textBox5.Text = sorgu.Parameters["@Parca_adi"].Value.ToString();
                    textBox9.Text = sorgu.Parameters["@Raf_no"].Value.ToString();
                    textBox7.Text = sorgu.Parameters["@Fiyat"].Value.ToString();
                    textBox1.Text = sorgu.Parameters["@Stok_Adet"].Value.ToString();


                    if (textBox7.Text.Length > 0)
                    {
                        listBox1.Items.Add(textBox7.Text);
                        listBox2.Items.Add(textBox4.Text);



                        try
                        {
                            SqlConnection baglantı = new SqlConnection();
                            SqlCommand komut = new SqlCommand();

                            for (int i = 0; i < listBox2.Items.Count; i++)
                            {
                                baglantı.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
                                baglantı.Open();
                                komut.Connection = baglantı;
                                komut.CommandText = ("insert into satis_stok(Parca_no) values ('" + listBox2.Items[i].ToString() + "')");
                                komut.ExecuteNonQuery();
                                baglantı.Close();

                            }

                        }
                        catch (Exception hata)
                        {

                            MessageBox.Show(hata.Message);
                        }

                        listBox2.Items.Clear();

                        int sonuc = 0;
                        for (int i = 0; i < listBox1.Items.Count; i++)
                        {
                            sonuc += Convert.ToInt32(listBox1.Items[i]);
                        }
                        textBox2.Text = sonuc.ToString();
                    }
                    else
                    {
                        MessageBox.Show("ürün bulunamadı");


                    }

                    textBox4.ResetText();
                }


            }





        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {





            SqlConnection baglantı = new SqlConnection();
            SqlCommand komut = new SqlCommand();
            baglantı.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantı.Open();
            komut.Connection = baglantı;
            komut.CommandText = ("UPDATE satis_stok SET satis_stok.Parca_id = Parca.Parca_id FROM satis_stok, Parca WHERE satis_stok.Parca_no = Parca.Parca_no");
            komut.ExecuteNonQuery();
            baglantı.Close();



            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();

            baglan.Open();
            sorgu.Connection = baglan;
            sorgu.CommandType = CommandType.StoredProcedure;

            sorgu.CommandText = "stok_guncelle";

            sorgu.ExecuteNonQuery();

            //baglan.Close();

            SqlConnection baglan3 = new SqlConnection(@"Data Source=.\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu3 = new SqlCommand();

            baglan3.Open();
            sorgu3.Connection = baglan3;
            sorgu3.CommandType = CommandType.StoredProcedure;

            sorgu3.CommandText = "rapor_guncelle";

            sorgu3.ExecuteNonQuery();

            baglan3.Close();



            SqlConnection baglan2 = new SqlConnection(@"Data Source=.\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu2 = new SqlCommand();

            baglan2.Open();
            sorgu2.Connection = baglan2;
            sorgu2.CommandType = CommandType.StoredProcedure;

            sorgu2.CommandText = "stok_guncelle2";

            sorgu2.ExecuteNonQuery();

            baglan2.Close();

            if (checkBox1.Checked == true)
            {
                SqlConnection bgln = new SqlConnection(@"Data Source=.\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=stok_program;Integrated Security=True");
                SqlCommand srg = new SqlCommand();

                bgln.Open();
                srg.Connection = bgln;
                srg.CommandType = CommandType.StoredProcedure;
                srg.CommandText = "Borc_doldur";

                srg.Parameters.AddWithValue("@Adi", textBox3.Text);
                srg.Parameters.AddWithValue("@Soyadi", textBox6.Text);
                srg.Parameters.AddWithValue("@Telefon", textBox8.Text);

                srg.ExecuteNonQuery();
                bgln.Close();
            }




            SqlConnection baglantı2 = new SqlConnection();
            SqlCommand komut2 = new SqlCommand();
            baglantı2.ConnectionString = (@"Data Source=.\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=stok_program;Integrated Security=True;");
            baglantı2.Open();
            komut2.Connection = baglantı2;
            komut2.CommandText = ("delete from satis_stok");
            komut2.ExecuteNonQuery();
            //baglantı2.Close();

            SqlConnection baglantı3 = new SqlConnection();
            SqlCommand komut3 = new SqlCommand();
            baglantı3.ConnectionString = (@"Data Source=.\SQLEXPRESS;Trusted_Connection=yes;Initial Catalog=stok_program;Integrated Security=True;");
            baglantı3.Open();
            komut3.Connection = baglantı3;
            komut3.CommandText = ("delete from satok_guncelle");
            komut3.ExecuteNonQuery();
            baglantı3.Close();



            this.Hide();


        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void checkBox1_Click(object sender, EventArgs e)
        {






        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked == false)
            {

                label10.Visible = false;
                label11.Visible = false;
                label12.Visible = false;
                textBox3.Visible = false;
                textBox6.Visible = false;
                textBox8.Visible = false;

            }

            if (checkBox1.Checked == true)
            {
                label10.Visible = true;
                label11.Visible = true;
                label12.Visible = true;
                textBox3.Visible = true;
                textBox6.Visible = true;
                textBox8.Visible = true;
            }
        }

        private void Parca_Satis_Load_1(object sender, EventArgs e)
        {

        }

        private void Parca_Satis_Load_2(object sender, EventArgs e)
        {

        }
    }
}




Parça Güncelle butonunun altında yer alan kodlar şu şekildedir:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class Parca_Guncelle : Form
    {
        public Parca_Guncelle()
        {
            InitializeComponent();
        }

        private void textBox4_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SqlConnection baglantım = new SqlConnection();
                SqlCommand komutm = new SqlCommand();
                baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
                baglantım.Open();
                komutm.Connection = baglantım;
                komutm.CommandText = ("select Stok_Adet from Parca where Parca_no='" + textBox4.Text.ToString() + "'");

                string str = Convert.ToString(komutm.ExecuteScalar());

                int a;
                a = Int32.Parse(str);

                komutm.ExecuteNonQuery();
                baglantım.Close();
                if (a <= 0)
                {
                    MessageBox.Show("Ürün Stokta Kalmadı");
                    textBox4.ResetText();

                }

                else
                {


                    SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
                    SqlCommand sorgu = new SqlCommand();

                    baglan.Open();
                    sorgu.Connection = baglan;
                    sorgu.CommandType = CommandType.StoredProcedure;

                    sorgu.CommandText = "Parca_Guncelle_getir";


                    sorgu.Parameters.AddWithValue("@Parca_no", textBox4.Text.ToString());

                    sorgu.Parameters.Add("@Parca_adi", SqlDbType.NVarChar, 255);
                    sorgu.Parameters["@Parca_adi"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Parca_aciklama", SqlDbType.NVarChar, 255);
                    sorgu.Parameters["@Parca_aciklama"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Fiyat", SqlDbType.Decimal);
                    sorgu.Parameters["@Fiyat"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Stok_Adet", SqlDbType.Int);
                    sorgu.Parameters["@Stok_Adet"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@alis_fiyat", SqlDbType.Int);
                    sorgu.Parameters["@alis_fiyat"].Direction = ParameterDirection.Output;
                    sorgu.Parameters.Add("@Raf_No", SqlDbType.NVarChar, 255);
                    sorgu.Parameters["@Raf_No"].Direction = ParameterDirection.Output;
                    sorgu.ExecuteNonQuery();

                    baglan.Close();

                    textBox5.Text = sorgu.Parameters["@Parca_adi"].Value.ToString();
                    richTextBox1.Text = sorgu.Parameters["@Parca_aciklama"].Value.ToString();
                    textBox7.Text = sorgu.Parameters["@Fiyat"].Value.ToString();
                    textBox1.Text = sorgu.Parameters["@Stok_Adet"].Value.ToString();
                    textBox2.Text = sorgu.Parameters["@alis_fiyat"].Value.ToString();
                    textBox3.Text = sorgu.Parameters["@Raf_no"].Value.ToString();



                }


            }
        }

        private void ekle_Click(object sender, EventArgs e)
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();
            baglan.Open();
            sorgu.Connection = baglan;
            sorgu.CommandType = CommandType.StoredProcedure;

            sorgu.CommandText = "Guncelleme";


            sorgu.Parameters.AddWithValue("@Parca_no", textBox4.Text);
            sorgu.Parameters.AddWithValue("@Parca_adi", textBox5.Text);
            sorgu.Parameters.AddWithValue("@Parca_aciklama", richTextBox1.Text);
            sorgu.Parameters.AddWithValue("@Stok_Adet", textBox1.Text);
            sorgu.Parameters.AddWithValue("@Fiyat", Convert.ToDecimal(textBox7.Text));
            sorgu.Parameters.AddWithValue("@alis_fiyat", Convert.ToDecimal(textBox2.Text));
            sorgu.Parameters.AddWithValue("@Raf_no", textBox3.Text);
            sorgu.ExecuteNonQuery();
            MessageBox.Show("Güncellendi");
            baglan.Close();
            textBox4.Clear(); textBox7.Clear(); richTextBox1.Clear(); textBox1.Clear(); textBox5.Clear(); textBox2.Clear(); textBox3.Clear();
        }

        private void Parca_Guncelle_Load(object sender, EventArgs e)
        {

        }


    }
}



Parça Sil Butonunu altında yer alan kodlar şu şekildedir:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class Parca_Sil : Form
    {
        public Parca_Sil()
        {
            InitializeComponent();
        }

        private void ekle_Click(object sender, EventArgs e)
        {
            SqlConnection baglantım = new SqlConnection();
            SqlCommand komutm = new SqlCommand();
            baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantım.Open();
            komutm.Connection = baglantım;
            komutm.CommandText = ("select count(*) from Parca where Parca_no='" + textBox4.Text.ToString() + "'");

            string str = Convert.ToString(komutm.ExecuteScalar());

            int a;
            a = Int32.Parse(str);

            komutm.ExecuteNonQuery();
            baglantım.Close();
            if (a <= 0)
            {
                MessageBox.Show("Böyle Bir ürün yok");


            }

            else
            {



                SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
                SqlCommand sorgu = new SqlCommand();
                if (textBox4.Text == "")
                {
                    MessageBox.Show("Lütfen bos birakmayiniz.");
                }

                else
                {
                    baglan.Open();
                    sorgu.Connection = baglan;
                    sorgu.CommandType = CommandType.StoredProcedure;

                    sorgu.CommandText = "Parca_sil";


                    sorgu.Parameters.AddWithValue("@Parca_no", textBox4.Text);


                    sorgu.ExecuteNonQuery();

                    MessageBox.Show("silindi");

                    baglan.Close();

                    textBox4.Clear();
                }
            }
        }

        private void Parca_Sil_Load(object sender, EventArgs e)
        {

        }

        private void Parca_Sil_Load_1(object sender, EventArgs e)
        {

        }

        private void Parca_Sil_Load_2(object sender, EventArgs e)
        {

        }

    }
}


Parça Görüntüle Butonunun altında yer alan kodlar şu şekildedir:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class Parca_Goruntule : Form
    {
        public Parca_Goruntule()
        {
            InitializeComponent();
        }





        private void Parca_Goruntule_Load(object sender, EventArgs e)
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();

            baglan.Open();
            sorgu.Connection = baglan;
            sorgu.CommandType = CommandType.StoredProcedure;

            sorgu.CommandText = "borc_getir";
            SqlDataAdapter da = new SqlDataAdapter(sorgu);
            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            baglan.Close();
        }

        private void ekle_Click(object sender, EventArgs e)
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();

            baglan.Open();
            sorgu.Connection = baglan;
            sorgu.CommandType = CommandType.StoredProcedure;

            sorgu.CommandText = "ara";
            sorgu.Parameters.AddWithValue("@Parca_adi", textBox4.Text);
            SqlDataAdapter da = new SqlDataAdapter(sorgu);
            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            baglan.Close();
        }
    }
}



Parça_Kaydet Butonunun altında yer alan kodlar şu şekildedir:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class Parca_Kaydet : Form
    {
        public Parca_Kaydet()
        {
            InitializeComponent();
        }

        private void ekle_Click(object sender, EventArgs e)
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();
            if (textBox4.Text == "" || textBox5.Text == "" || textBox7.Text == "")
            {
                MessageBox.Show("Lütfen bos birakmayiniz.");
            }

            else
            {
                baglan.Open();
                sorgu.Connection = baglan;
                sorgu.CommandType = CommandType.StoredProcedure;

                sorgu.CommandText = "Parca_ekleme";


                sorgu.Parameters.AddWithValue("@Parca_no", textBox4.Text);
                sorgu.Parameters.AddWithValue("@Parca_adi", textBox5.Text);
                sorgu.Parameters.AddWithValue("@Parca_aciklama", richTextBox1.Text);
                sorgu.Parameters.AddWithValue("@Stok_Adet", textBox1.Text);
                sorgu.Parameters.AddWithValue("@Fiyat", textBox7.Text);
                sorgu.Parameters.AddWithValue("@alis_fiyat", textBox2.Text);
                sorgu.Parameters.AddWithValue("@Raf_no", textBox3.Text);
                sorgu.ExecuteNonQuery();

                MessageBox.Show("Kaydedildi");

                baglan.Close();

                textBox4.Clear(); textBox7.Clear(); richTextBox1.Clear(); textBox1.Clear(); textBox5.Clear();
                textBox2.Clear(); textBox3.Clear();

            }
        }

        private void textBox7_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox7_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }

        private void Parca_Kaydet_Load(object sender, EventArgs e)
        {

        }

        private void Parca_Kaydet_Load_1(object sender, EventArgs e)
        {

        }

        private void Parca_Kaydet_Load_2(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar);
        }
    }
}



Borç_Görüntüle Butonunun arkasında yer alan kodlar şu şekildedir:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;
namespace Stok_Program
{
    public partial class Borc_Goruntule : Form
    {
        public Borc_Goruntule()
        {
            InitializeComponent();
        }

        private void Borc_Goruntule_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'stok_programDataSet3.Borclu' table. You can move, or remove it, as needed.
            // TODO: This line of code loads data into the 'stok_programDataSet2.Borclu' table. You can move, or remove it, as needed.

            grid_doldur();

            dataGridView1.Columns[8].Visible = false;
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1)
            {
                MessageBox.Show("Başlıklara Değil Verilerin üzerine Tıklayınız");

            }
            else
            {

                textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
                textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
                textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
                textBox6.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
                textBox7.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
                textBox8.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
                textBox13.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();
            }
        }

        private void ekle_Click(object sender, EventArgs e)
        {
            
        }

        public void grid_doldur()
        {

            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();

            baglan.Open();
            sorgu.Connection = baglan;
            sorgu.CommandType = CommandType.StoredProcedure;

            sorgu.CommandText = "borc_goruntule";
            SqlDataAdapter da = new SqlDataAdapter(sorgu);
            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            baglan.Close();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void button2_Click(object sender, EventArgs e)
        {



            


        }

        private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {








            //int deger = Convert.ToInt32(dataGridView1.CurrentRow.Cells["borc_tutar"].Value);
            //   textBox12.Text = deger.ToString();


        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            //int Topla = 0;

            //Topla += Convert.ToInt32(dataGridView1.CurrentRow.Cells["borc_tutar"].Value);

            //textBox12.Text = Convert.ToString(Topla);//çalıştır

        }

        private void ekle_Click_1(object sender, EventArgs e)
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();


            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || dataGridView1.Columns[8].ToString() == "")
            {

                MessageBox.Show("satır seçiniz ve değerin textlerde yazılı olduğundan emin olunuz");


            }
            else
            {

                baglan.Open();
                sorgu.Connection = baglan;
                sorgu.CommandType = CommandType.StoredProcedure;

                sorgu.CommandText = "Borc_guncelleme";

                sorgu.Parameters.AddWithValue("@Adi", textBox1.Text);
                sorgu.Parameters.AddWithValue("@Soyadi", textBox2.Text);
                sorgu.Parameters.AddWithValue("@Telefon", textBox3.Text);
                sorgu.Parameters.AddWithValue("@Parca_no", textBox4.Text);
                sorgu.Parameters.AddWithValue("@adet", textBox5.Text);
                sorgu.Parameters.AddWithValue("@Parca_adi", textBox6.Text);
                sorgu.Parameters.AddWithValue("@borc_tutar", Convert.ToDecimal(textBox7.Text));
                sorgu.Parameters.AddWithValue("@ID", textBox8.Text);
                sorgu.Parameters.AddWithValue("@Raf_no", textBox13.Text);

                sorgu.ExecuteNonQuery();

                MessageBox.Show("Güncellendi");

                baglan.Close();

                textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear();
                textBox5.Clear(); textBox6.Clear(); textBox7.Clear(); textBox8.Clear();
                textBox13.Clear();

            }



            dataGridView1.Columns[8].Visible = false;
            grid_doldur();
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            SqlConnection baglantım = new SqlConnection();
            SqlCommand komutm = new SqlCommand();
            baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantım.Open();
            komutm.Connection = baglantım;

            if (textBox9.Text != "" && textBox10.Text != "" && textBox11.Text != "")
            {
                komutm.CommandText = ("select * from Borclu where Adi='" + textBox9.Text.ToString() + "' and Soyadi= '" + textBox10.Text.ToString() + "' and Telefon= '" + textBox11.Text.ToString() + "'");
            }
            else if (textBox9.Text != "" && textBox10.Text == "" && textBox11.Text == "")
            {
                komutm.CommandText = ("select * from Borclu where Adi='" + textBox9.Text.ToString() + "'and Soyadi= '" + textBox10.Text.ToString() + "'");

            }
            else if (textBox9.Text != "" && textBox10.Text != "" && textBox11.Text == "")
            {
                komutm.CommandText = ("select * from Borclu where Adi='" + textBox9.Text.ToString() + "'");

            }

            else if (textBox11.Text != "" && textBox10.Text != "" && textBox9.Text == "")
            {
                komutm.CommandText = ("select * from Borclu where Adi='" + textBox9.Text.ToString() + "' and Soyadi= '" + textBox10.Text.ToString() + "'");
            }

            else if (textBox9.Text == "" && textBox10.Text != "" && textBox11.Text == "")
            {
                komutm.CommandText = ("select * from Borclu where Soyadi='" + textBox10.Text.ToString() + "'");
            }
            else if (textBox9.Text == "" && textBox10.Text == "" && textBox11.Text != "")
            {
                komutm.CommandText = ("select * from Borclu where Telefon='" + textBox11.Text.ToString() + "'");
            }

            else if (textBox9.Text == "" && textBox10.Text != "" && textBox11.Text != "")
            {
                komutm.CommandText = ("select * from Borclu where Soyadi='" + textBox10.Text.ToString() + "'and Telefon= '" + textBox11.Text.ToString() + "'");
            }

            else if (textBox9.Text != "" && textBox10.Text == "" && textBox11.Text != "")
            {
                komutm.CommandText = ("select * from Borclu where Adi='" + textBox9.Text.ToString() + "'and Telefon= '" + textBox11.Text.ToString() + "'");
            }

            else if (textBox9.Text == "" && textBox10.Text == "" && textBox11.Text == "")
            {
                komutm.CommandText = ("select * from Borclu");
            }

            SqlDataAdapter da = new SqlDataAdapter(komutm);
            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            baglantım.Close();

            double sum = 0;
            for (int i = 0; i < dataGridView1.Rows.Count; ++i)
            {
                sum += Convert.ToDouble(dataGridView1.Rows[i].Cells[6].Value);
            }
            textBox12.Text = sum.ToString();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();


            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || dataGridView1.Columns[8].ToString() == "")
            {

                MessageBox.Show("satır seçiniz ve değerin textlerde yazılı olduğundan emin olunuz");


            }
            else
            {

                baglan.Open();
                sorgu.Connection = baglan;
                sorgu.CommandType = CommandType.StoredProcedure;

                sorgu.CommandText = "Borc_silme";


                sorgu.Parameters.AddWithValue("@ID", textBox8.Text);

                sorgu.ExecuteNonQuery();

                MessageBox.Show("Silindi");

                baglan.Close();

                textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear();
                textBox5.Clear(); textBox6.Clear(); textBox7.Clear(); textBox8.Clear();


            }



            dataGridView1.Columns[8].Visible = false;
            grid_doldur();
        }




    }
}


Satis_Rapor butonunu arkasında yer alan kodlar şu şekildedir:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class Satis_Rapor : Form
    {
        public Satis_Rapor()
        {
            InitializeComponent();
        }

        private void Satis_Rapor_Load(object sender, EventArgs e)
        {
            doldur();

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection baglantım = new SqlConnection();
            SqlCommand komutm = new SqlCommand();
            baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantım.Open();
            komutm.Connection = baglantım;
            komutm.CommandText = ("delete from satis_rapor");

            

            komutm.ExecuteNonQuery();
            baglantım.Close();

            doldur();
        }


        private void doldur()
        {
            SqlConnection baglan = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True");
            SqlCommand sorgu = new SqlCommand();

            baglan.Open();
            sorgu.Connection = baglan;
            sorgu.CommandType = CommandType.StoredProcedure;

            sorgu.CommandText = "satis_rapor_doldur";
            SqlDataAdapter da = new SqlDataAdapter(sorgu);
            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            baglan.Close();
        
        
        }
    }
}



Günlük_Ciro butonunun arkasında yer alan kodlar şu şekildedir:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Data.Sql;

namespace Stok_Program
{
    public partial class ciro : Form
    {
        public ciro()
        {
            InitializeComponent();
        }

        private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
        {

        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            string tarih = monthCalendar1.SelectionRange.Start.ToString();
            tarih = tarih.Substring(0, 10);


            SqlConnection baglantım = new SqlConnection();
            SqlCommand komutm = new SqlCommand();
            baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantım.Open();
            komutm.Connection = baglantım;
            komutm.CommandText = ("select sum(satis_tutar) from satis_rapor where CONVERT(VARCHAR(10),satis_tarih,104)='" + tarih.ToString() + "'");

            string str = Convert.ToString(komutm.ExecuteScalar());


            textBox1.Text = str;

            komutm.ExecuteNonQuery();
            baglantım.Close();


            string tarih2 = monthCalendar1.SelectionRange.Start.ToString();
            tarih2 = tarih2.Substring(6, 4) + "." + tarih2.Substring(3, 2);
            SqlConnection baglantım2 = new SqlConnection();
            SqlCommand komutm2 = new SqlCommand();
            baglantım2.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantım2.Open();
            komutm2.Connection = baglantım2;
            komutm2.CommandText = ("select sum(satis_tutar) from satis_rapor where CONVERT(VARCHAR(7),satis_tarih,102)='" + tarih2.ToString() + "'");

            string str2 = Convert.ToString(komutm2.ExecuteScalar());


            textBox2.Text = str2;

            komutm2.ExecuteNonQuery();
            baglantım2.Close();



        }

        private void ciro_Load(object sender, EventArgs e)
        {

        }
    }
}



Uyarı butonunun arkasında yer alan kodlar şu şekildedir.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.OleDb;
using System.Data.SqlClient;

namespace Stok_Program
{
    public partial class uyari : Form
    {
        public uyari()
        {
            InitializeComponent();
        }

        private void uyari_Load(object sender, EventArgs e)
        {

            SqlConnection baglantım = new SqlConnection();
            SqlCommand komutm = new SqlCommand();
            baglantım.ConnectionString = (@"Data Source=.\SQLEXPRESS;Initial Catalog=stok_program;Integrated Security=True;");
            baglantım.Open();
            komutm.Connection = baglantım;


            komutm.CommandText = ("select * from Parca where Stok_Adet <5 ");


            SqlDataAdapter da = new SqlDataAdapter(komutm);
            System.Data.DataTable dt = new System.Data.DataTable();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            baglantım.Close();









        }
    }
}




Tablolar:
USE [stok_program]
GO
/****** Object:  Table [dbo].[satok_guncelle]    Script Date: 09/14/2017 11:41:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[satok_guncelle](
[Parca_no] [varchar](255) COLLATE Turkish_CI_AS NULL,
[stok] [int] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


USE [stok_program]
GO
/****** Object:  Table [dbo].[satis_stok]    Script Date: 09/14/2017 11:40:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING OFF
GO
CREATE TABLE [dbo].[satis_stok](
[Parca_no] [varchar](255) COLLATE Turkish_CI_AS NULL,
[Parca_id] [int] NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


USE [stok_program]
GO
/****** Object:  Table [dbo].[satis_rapor]    Script Date: 09/14/2017 11:40:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[satis_rapor](
[Parca_no] [varchar](255) COLLATE Turkish_CI_AS NULL,
[satis_adet] [int] NULL,
[Parca_adi] [varchar](255) COLLATE Turkish_CI_AS NULL,
[satis_tutar] [money] NULL,
[satis_tarih] [datetime] NULL,
[Raf_no] [varchar](255) COLLATE Turkish_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


USE [stok_program]
GO
/****** Object:  Table [dbo].[Parca]    Script Date: 09/14/2017 11:40:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Parca](
[Parca_no] [varchar](255) COLLATE Turkish_CI_AS NULL,
[Parca_adi] [varchar](255) COLLATE Turkish_CI_AS NULL,
[Parca_aciklama] [varchar](max) COLLATE Turkish_CI_AS NULL,
[Fiyat] [money] NULL,
[Stok_Adet] [int] NULL,
[Parca_id] [int] IDENTITY(1,1) NOT NULL,
[alis_fiyat] [money] NULL,
[Raf_no] [varchar](255) COLLATE Turkish_CI_AS NULL
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF


Stored_Procedureler yalnızca kullanıcı girişi yoktur onu zaten siz yapabilirsiniz..


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[stok_guncelle2]    Script Date: 09/14/2017 11:43:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[stok_guncelle2]
as
begin
update Parca   set Parca.Stok_Adet=Parca.Stok_Adet-satok_guncelle.stok from satok_guncelle where Parca.Parca_no=satok_guncelle.Parca_no
end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[stok_guncelle]    Script Date: 09/14/2017 11:43:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[stok_guncelle]
as
begin
insert into satok_guncelle Select Parca_no,Count(Parca_no) From satis_stok Group By Parca_no
end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[satis_rapor_doldur]    Script Date: 09/14/2017 11:43:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[satis_rapor_doldur]
as
begin
select * from satis_rapor
end

USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[rapor_guncelle]    Script Date: 09/14/2017 11:43:01 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[rapor_guncelle]
as
begin
insert into satis_rapor(Parca_no,satis_adet) select Parca_no,stok from satok_guncelle
update satis_rapor
set satis_rapor.Parca_adi=Parca.Parca_adi,satis_rapor.Raf_no=Parca.Raf_no, satis_rapor.satis_tutar=satis_rapor.satis_adet*Parca.Fiyat  from Parca
where satis_rapor.Parca_no=Parca.Parca_no and satis_rapor.satis_tutar is null
update satis_rapor
set satis_tarih=getdate() where satis_tarih is null

end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Parca_sil]    Script Date: 09/14/2017 11:42:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[Parca_sil](@Parca_no varchar(255))
as
begin
delete from Parca where Parca_no=@Parca_no
end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Parca_guncelle_getir]    Script Date: 09/14/2017 11:42:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Parca_guncelle_getir]
(@Parca_no varchar(255),@Parca_adi varchar(255)out,@Parca_aciklama varchar(max)out,@fiyat money out,@alis_fiyat money out,@Stok_Adet int out,@Raf_no varchar(255) out)
as
begin
select @Parca_adi=Parca_adi,@Parca_aciklama=Parca_aciklama,@fiyat=fiyat,@Stok_Adet=Stok_Adet,@alis_fiyat=alis_fiyat,@Raf_no=Raf_no from Parca where Parca_no=@Parca_no


end

USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Parca_getir]    Script Date: 09/14/2017 11:42:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Parca_getir]
(@Parca_no varchar(255),@Parca_adi varchar(255)out,@fiyat money out,@Stok_Adet int out,@Raf_no varchar(255) out)
as
begin
select @Parca_adi=Parca_adi,@fiyat=fiyat,@Stok_Adet=Stok_Adet,@Raf_no=Raf_no from Parca where Parca_no=@Parca_no
end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Parca_ekleme]    Script Date: 09/14/2017 11:42:46 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Parca_ekleme](@Parca_no varchar(255),
@Parca_adi varchar(255),@Parca_aciklama varchar(max),@Stok_Adet int,
@Fiyat money,@alis_fiyat money,@Raf_no varchar(255)
)
AS  
BEGIN  
insert into Parca(Parca_no, 
Parca_adi,Parca_aciklama,Stok_Adet, 
Fiyat,alis_fiyat,Raf_no
values(@Parca_no, 
@Parca_adi,@Parca_aciklama,@Stok_Adet, 
@Fiyat,@alis_fiyat,@Raf_no
)  
END 

USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Guncelleme]    Script Date: 09/14/2017 11:42:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Guncelleme]
(@Parca_no varchar(255),@Parca_adi varchar(255),@Parca_aciklama varchar(max),@fiyat money ,@Stok_Adet int,@alis_fiyat money,@Raf_no varchar(255))
as
begin
update Parca set Parca_adi=@Parca_adi,Parca_aciklama=@Parca_aciklama,fiyat=@fiyat,Stok_Adet=@Stok_Adet,alis_fiyat=@alis_fiyat,Raf_no=@Raf_no
where Parca_no=@Parca_no
end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Borc_silme]    Script Date: 09/14/2017 11:42:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Borc_silme]
(@ID int)
as
begin
delete from Borclu where ID=@ID
end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Borc_guncelleme]    Script Date: 09/14/2017 11:42:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Borc_guncelleme]
(@Adi varchar(255),@Soyadi varchar(255),@Telefon varchar(255),@Parca_no varchar(255),@adet int,@Parca_adi varchar(255),@borc_tutar money,@ID int,@Raf_no varchar(255))
as
begin
update Borclu set Adi=@Adi,Soyadi=@Soyadi,Telefon=@Telefon,Parca_no=@Parca_no,adet=@adet,Parca_adi=@Parca_adi,borc_tutar=@borc_tutar,Raf_no=@Raf_no
where ID=@ID
end

USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[borc_goruntule]    Script Date: 09/14/2017 11:42:27 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[borc_goruntule]
as
begin
select * from borclu
end

USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[borc_getir]    Script Date: 09/14/2017 11:42:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[borc_getir]
as
begin
select Parca_no,Parca_adi,Parca_aciklama,Fiyat,Stok_Adet,alis_fiyat,Raf_no from Parca
end



USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[Borc_doldur]    Script Date: 09/14/2017 11:42:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[Borc_doldur](@Adi varchar(255),@Soyadi varchar(255),@Telefon varchar(255))
as
begin
insert into Borclu (Parca_no,adet) select Parca_no,stok from satok_guncelle
update Borclu
set Borclu.Parca_adi=Parca.Parca_adi, Borclu.borc_tutar=Borclu.adet*Parca.Fiyat,Borclu.Raf_no=Parca.Raf_no  from Parca
where Borclu.Parca_no=Parca.Parca_no and Borclu.borc_tutar is null
update Borclu set Adi=@Adi,Soyadi=@Soyadi,Telefon=@Telefon where satis_tarih is null

update Borclu
set satis_tarih=getdate() where satis_tarih is null

end


USE [stok_program]
GO
/****** Object:  StoredProcedure [dbo].[ara]    Script Date: 09/14/2017 11:42:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[ara](@Parca_adi varchar(255))
as
begin
select Parca_no,Parca_adi,Parca_aciklama,Fiyat,Stok_Adet,alis_fiyat,Raf_no from Parca where Parca_adi LIKE '%'+@Parca_adi+'%'
end






Yorumlar