C
Veritabanı Müşteri Bakiye ve Tahsilat İşlemleri
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.OleDb; namespace MusteriHesap { public partial class Form1 : Form { OleDbConnection con= new OleDbConnection("Provider=Microsoft.ACE.OleDb.12.0;Data Source=dbMusteri.accdb"); OleDbCommand cmd; OleDbDataReader dr; public Form1() { InitializeComponent(); } void Doldur() { listBox1.Items.Clear(); listBox1.Items.Add("Müşteri No\tBakiye"); listBox1.Items.Add("=========================="); cmd = new OleDbCommand(); con.Open(); cmd.Connection = con; cmd.CommandText = "Select *From Hesap"; dr = cmd.ExecuteReader(); while (dr.Read()) { listBox1.Items.Add(dr[0] + "\t\t" + dr[1]); } con.Close(); } public double BakiyeGetir(int mno) { con.Open(); double musteribakiye = 0; cmd.CommandText = "Select * From Hesap where musterino=" + mno + ""; dr = cmd.ExecuteReader(); while (dr.Read()) { musteribakiye = Convert.ToDouble(dr[1]); } con.Close(); return musteribakiye; } private void Form1_Load(object sender, EventArgs e) { Doldur(); } private void button1_Click(object sender, EventArgs e) { int mno=Convert.ToInt32(textBox1.Text); double cekilen=Convert.ToDouble(textBox2.Text); double mbakiye = BakiyeGetir(mno); if (mbakiye >= cekilen) { con.Open(); string sorgu = "Update Hesap Set bakiye=(bakiye-@cekilen) where musterino=@musterino"; cmd = new OleDbCommand(sorgu, con); cmd.Parameters.AddWithValue("@cekilen", cekilen); cmd.Parameters.AddWithValue("@musterino", Convert.ToInt32(textBox1.Text)); cmd.ExecuteNonQuery(); con.Close(); Doldur(); } else { MessageBox.Show("Yetersiz Bakiye. Şuanki Bakiyeniz: "+mbakiye.ToString("C2")); } } } }