Forum
rsayi = new Random();
ArrayList arryCk = new ArrayList();
ArrayList arryk = new ArrayList();
ArrayList arryo = new ArrayList();
ArrayList arryCz = new ArrayList();
ArrayList arryz = new ArrayList();
ArrayList ArrySorular = new ArrayList();
int s=1;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add("Seçiniz.");
DropDownList2.Items.Clear();
DropDownList2.Items.Add("Seçiniz.");
SqlConnection conUnite;
string strsorgu;
SqlCommand cmddselectUnite;
SqlDataReader dtrUnite;
strsorgu = "Select * From DersTablosu";
conUnite = new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");
conUnite.Open();
cmddselectUnite = new SqlCommand(strsorgu, conUnite);
dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
DropDownList1.Items.Add(dtrUnite["Ders"].ToString());
}
dtrUnite.Close();
conUnite.Close();
strsorgu = "Select * From SinifSubeTablosu Order By Sinif";
conUnite = new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");
conUnite.Open();
cmddselectUnite = new SqlCommand(strsorgu, conUnite);
dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
DropDownList3.Items.Add(dtrUnite["Sinif"].ToString());
}
dtrUnite.Close();
conUnite.Close();
strsorgu = "Select * From SubeTablosu";
conUnite = new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");
conUnite.Open();
cmddselectUnite = new SqlCommand(strsorgu, conUnite);
dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
CheckBoxList1.Items.Add(dtrUnite["Sube"].ToString()); ;
}
dtrUnite.Close();
conUnite.Close();
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add("Seçiniz.");
string uniteID = DropDownList1.SelectedIndex.ToString();
SqlConnection conUnite;
string strsorgu;
SqlCommand cmddselectUnite;
SqlDataReader dtrUnite;
strsorgu = "Select Unite From UniteTablosu Where DersID=@DersID";
conUnite = new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");
conUnite.Open();
cmddselectUnite = new SqlCommand(strsorgu, conUnite);
cmddselectUnite.Parameters.AddWithValue("@DersID",uniteID);
dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
DropDownList2.Items.Add(dtrUnite["Unite"].ToString());
}
dtrUnite.Close();
conUnite.Close();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void DropDownList2_SelectedIndexChanged1(object sender, EventArgs e)
{
CokKolayTxt.Text = "";
CokKolayTxt.Focus();
KolayTxt.Text = "";
OrtaTxt.Text = "";
ZorTxt.Text = "";
CokZorTxt.Text = "";
Panel1.Visible=true;
}
protected void TablolamaBtn_Click(object sender, EventArgs e)
{
ArrySorular.Clear();
SqlConnection conUnite;
string strsorgu;
SqlCommand cmddselectUnite;
SqlDataReader dtrUnite;
int ik, ick, io, iz, icz;
ik = Int32.Parse(KolayTxt.Text);
ick = int.Parse(CokKolayTxt.Text);
io = int.Parse(OrtaTxt.Text);
iz = int.Parse(ZorTxt.Text);
icz = int.Parse(CokZorTxt.Text);
int id;
int ck = 0, k = 0, o = 0, z = 0, cz = 0,toplam=0;
// Hangi soru tipinden ve zorluk derecesinden ne kadar soru var saydırma.
if (RadioButtonList1.SelectedIndex == 0)
{
strsorgu =
"Select * From TestTablosu Where UniteAdi=@Unit";conUnite =
new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");conUnite.Open();
cmddselectUnite =
new SqlCommand(strsorgu, conUnite);cmddselectUnite.Parameters.AddWithValue(
"@Unit", DropDownList2.SelectedItem.Value);dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
if (dtrUnite["Zorluk"].ToString() == "Çok Zor")
{
cz++;
arryCz.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Zor")
{
z++;
arryz.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Orta")
{
o++;
arryo.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Kolay")
{
k++;
arryk.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Çok Kolay")
{
ck++;
arryCk.Add(dtrUnite[
"ID"]);}
}
toplam = ick + icz + io + ik + iz;
dtrUnite.Close();
conUnite.Close();
conUnite =
new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");conUnite.Open();
cmddselectUnite =
new SqlCommand();cmddselectUnite.Connection = conUnite;
string sqlWhere = "";
for (int l = 0; l < ick; l++)
{
id = rsayi.Next(arryCk.Count);
id =
int.Parse(arryCk[id].ToString());sqlWhere +=
"ID=@id" + l.ToString();cmddselectUnite.Parameters.AddWithValue(
"@id" + l.ToString(), id);if (l < ick)
{
if (l==ick-1)
{
if (ik != 0 || io != 0 || iz != 0 || icz != 0)
{
sqlWhere +=
" OR ";}
}
else
{
sqlWhere +=
" OR ";}
}
}
for (int j = 10; j < 10+ik; j++)
{
id = rsayi.Next(arryk.Count);
id =
int.Parse(arryk[id].ToString());sqlWhere +=
"ID=@id" + j.ToString();cmddselectUnite.Parameters.AddWithValue(
"@id" + j.ToString(), id);if (j < 10 + ik)
{
if (j == 10 + ik - 1)
{
if (io != 0 || iz != 0 || icz != 0)
{
sqlWhere +=
" OR ";}
}
else
{
sqlWhere +=
" OR ";}
}
}
for (int m = 20; m < 20+io; m++)
{
id = rsayi.Next(arryo.Count);
id =
int.Parse(arryo[id].ToString());sqlWhere +=
"ID=@id" + m.ToString();cmddselectUnite.Parameters.AddWithValue(
"@id" + m.ToString(), id);if (m < 20 + io)
{
if (m == 20 + io - 1)
{
if (iz != 0 || icz != 0)
{
sqlWhere +=
" OR ";}
}
else
{
sqlWhere +=
" OR ";}
}
}
for (int n = 30; n < 30+iz; n++)
{
id = rsayi.Next(arryz.Count);
id =
int.Parse(arryz[id].ToString());sqlWhere +=
"ID=@id" + n.ToString();cmddselectUnite.Parameters.AddWithValue(
"@id" + n.ToString(), id);if (n < iz + 30)
{
if (n == iz + 30 - 1)
{
if (icz != 0)
{
sqlWhere +=
" OR ";}
}
else
{
sqlWhere +=
" OR ";}
}
}
for (int p = 40; p < icz + 40; p++)
{
id = rsayi.Next(arryCz.Count);
id =
int.Parse(arryCz[id].ToString());sqlWhere +=
"ID=@id" + p.ToString();cmddselectUnite.Parameters.AddWithValue(
"@id" + p.ToString(), id);if (p < icz + 40 - 1)
sqlWhere +=
" OR ";}
string sqlSelect = "'Zorluk: ' + Zorluk + '[br]' + CAST(Soru AS nvarchar(max)) + '[br]' + 'A) ' + A + '[br]B) ' + B + '[br]C) ' + C + '[br]D) ' + D + '[br]E) ' + E AS 'Sorular'";
strsorgu =
string.Format("Select {0} FROM TestTablosu WHERE {1}", sqlSelect, sqlWhere);cmddselectUnite.CommandText = strsorgu;
dtrUnite = cmddselectUnite.ExecuteReader();
GridView1.DataSource = dtrUnite;
GridView1.DataBind();
dtrUnite.Close();
conUnite.Close();
}
if (RadioButtonList1.SelectedIndex == 1)
{
strsorgu =
"Select * From KlasikSoruTablosu Where UniteAdi=@Unit";conUnite =
new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");conUnite.Open();
cmddselectUnite =
new SqlCommand(strsorgu, conUnite);cmddselectUnite.Parameters.AddWithValue(
"@Unit", DropDownList2.SelectedItem.Value);dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
if (dtrUnite["Zorluk"].ToString() == "Çok Zor")
{
cz++;
arryCz.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Zor")
{
z++;
arryz.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Orta")
{
o++;
arryo.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Kolay")
{
k++;
arryk.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Çok Kolay")
{
ck++;
arryCk.Add(dtrUnite[
"ID"]);}
}
dtrUnite.Close();
conUnite.Close();
for (int i = 0; i < ick; i++)
{
id = rsayi.Next(arryCk.Count);
id =
int.Parse(arryCk[id].ToString());strsorgu =
"Select * From KlasikSoruTablosu Where ID=@id";conUnite =
new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");conUnite.Open();
cmddselectUnite =
new SqlCommand(strsorgu, conUnite);cmddselectUnite.Parameters.AddWithValue(
"@id", id);dtrUnite = cmddselectUnite.ExecuteReader();
GridView1.DataSource = dtrUnite;
GridView1.DataBind();
dtrUnite.Close();
conUnite.Close();
}
}
else if (RadioButtonList1.SelectedIndex == 2)
{
strsorgu =
"Select * From BoslukDoldurmaTablosu Where UniteAdi=@Unit";conUnite =
new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");conUnite.Open();
cmddselectUnite =
new SqlCommand(strsorgu, conUnite);cmddselectUnite.Parameters.AddWithValue(
"@Unit", DropDownList2.SelectedItem.Value);dtrUnite = cmddselectUnite.ExecuteReader();
while (dtrUnite.Read())
{
if (dtrUnite["Zorluk"].ToString() == "Çok Zor")
{
cz++;
arryCz.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Zor")
{
z++;
arryz.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Orta")
{
o++;
arryo.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Kolay")
{
k++;
arryk.Add(dtrUnite[
"ID"]);}
if (dtrUnite["Zorluk"].ToString() == "Çok Kolay")
{
ck++;
arryCk.Add(dtrUnite[
"ID"]);}
}
dtrUnite.Close();
conUnite.Close();
for (int i = 0; i < ick; i++)
{
id = rsayi.Next(arryCk.Count);
id =
int.Parse(arryCk[id].ToString());strsorgu =
"Select * From BoslukDoldurmaTablosu Where ID=@id";conUnite =
new SqlConnection(@"Server=localhost;Data Source=.\SQLExpress;Integrated Security=True;AttachDbfileName=|DataDirectory|Database.mdf;User Instance=True");conUnite.Open();
cmddselectUnite =
new SqlCommand(strsorgu, conUnite);cmddselectUnite.Parameters.AddWithValue(
"@id", id);dtrUnite = cmddselectUnite.ExecuteReader();
GridView1.DataSource = dtrUnite;
GridView1.DataBind();
dtrUnite.Close();
conUnite.Close();
}
}
Yardımcı olursanız çok sevinitim. Şimdiden teşekkürler.
Veri tabanımdaki soruları rastgele alıp bir sınav oluşturacağım. Yazdığım kodla bunu yapmaya çalıştım ama olmadı.