|
namespace HiyerarsiTestx
{
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
public partial class FrmKayit : Form
{
SqlCommand scommx = new SqlCommand();
DataTable dtx = new DataTable();
public FrmKayit()
{
InitializeComponent();
scommx.Connection = FrmMain.sconnx;
}
private void FrmKayit_Shown(object sender, EventArgs e)
{
this.KategorileriGetir();
}
private void KategorileriGetir()
{
scommx.CommandText = "select * from Kategoriler";
dtx.Clear();
dtx.Load(scommx.ExecuteReader());
cmbCategoryName.Items.Clear();
cmbdegerler.Items.Clear();
cmbCategoryName.Items.Add("AnaKategori");
cmbdegerler.Items.Add("0");
foreach (DataRow rowItemx in dtx.Rows)
{
string KategoriAd = rowItemx["KategoriAd"].ToString();
string KategoriNo = rowItemx["KategoriNo"].ToString();
cmbCategoryName.Items.Add(KategoriAd);
cmbdegerler.Items.Add(KategoriNo);
}
}
private void btnKaydet_Click(object sender, EventArgs e)
{
scommx.CommandText = "insert into Kategoriler(KategoriAd,UstKategoriNo) values (@KategoriAd,@UstKategoriNo)";
scommx.Parameters.AddWithValue("@KategoriAd", textBox1.Text.Trim());
scommx.Parameters.AddWithValue("@UstKategoriNo", int.Parse(cmbdegerler.Text.Trim()));
scommx.ExecuteNonQuery();
scommx.Parameters.Clear();
textBox1.Text = string.Empty;
cmbCategoryName.SelectedIndex = 0;
MessageBox.Show("Kaydedildi", "bilgi", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.Close();
}
private void cmbCategoryName_SelectedIndexChanged(object sender, EventArgs e)
{
cmbdegerler.SelectedIndex = cmbCategoryName.SelectedIndex;
}
private void btnCansel_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
|