protected void btnLogin_Click(object sender, EventArgs e) { userName = txtUsername.Text.ToString(); userPassword = txtUserPassword.Text.ToString(); DataRow drGiris = con.GetDataRow("select ug.userGroupID,ug.userGroupName,u.userID,u.userName,p.userPasword from [userGroup] ug inner join [user] u on ug.userGroupID=u.userGroupID inner join [password] p on u.userID=p.userID where u.userName='******' and p.userPasword='" + userPassword + "'"); if (drGiris != null) { if (drGiris["userGroupID"].ToString() == "2") { Session["userID"] = drGiris["userID"].ToString(); Response.Redirect("~/page/TeacherIndex.aspx"); } else if (drGiris["userGroupID"].ToString() == "3") { Session["userID"] = drGiris["userID"].ToString(); Response.Redirect("~/page/StudentIndex.aspx"); } } else { lblError.Text = "Hatalı Kullanıcı Adı veya Şifre"; } }
protected void btnInsert_Click(object sender, EventArgs e) { if (txtAddQuestion.Text.Length < 5) { lblError1.Text = "Lütfen İçerik Doldurunuz."; } else { } if (rbA.Checked) { reply = 1; } else if (rbB.Checked) { reply = 2; } else if (rbC.Checked) { reply = 3; } else if (rbD.Checked) { reply = 4; } if (reply != 0) { if (rbText.Checked) { SqlConnection connect = con.baglan(); SqlCommand cmd = new SqlCommand("insert into question (userID,subjectID,questionName,isText) values (@USERID,@SUBJECTID,@QUESTIONSNAME,@ISTEXT)", connect); cmd.Parameters.Add("@USERID", Session["userID"]); cmd.Parameters.Add("@SUBJECTID", drpSubject.SelectedItem.Value); cmd.Parameters.Add("@QUESTIONSNAME", txtAddQuestion.Text); cmd.Parameters.Add("@ISTEXT", "0"); if (cmd.ExecuteNonQuery() == 0) { connect.Close(); connect.Dispose(); } else { DataRow drQuestions = con.GetDataRow("select * from [question] where CONVERT(NVARCHAR(MAX), questionName)='" + txtAddQuestion.Text + "'"); if (drQuestions["questionID"] != null) { SqlCommand replyCmd = new SqlCommand("insert into reply (questionID,a,b,c,d,trueReplyID) values(@QUESTIONSID,@A,@B,@C,@D,@TRUEREPLY)", connect); replyCmd.Parameters.Add("@QUESTIONSID", drQuestions["questionID"]); replyCmd.Parameters.Add("@A", A.Text); replyCmd.Parameters.Add("@B", B.Text); replyCmd.Parameters.Add("@C", C.Text); replyCmd.Parameters.Add("@D", D.Text); replyCmd.Parameters.Add("@TRUEREPLY", reply); replyCmd.ExecuteNonQuery(); Response.Redirect("RemoveQuestions.aspx"); } else { connect.Close(); connect.Dispose(); } } } else if (rbImages.Checked) { if (fuA.PostedFile.ContentType == "image/png" && fuB.PostedFile.ContentType == "image/png" && fuC.PostedFile.ContentType == "image/png" && fuD.PostedFile.ContentType == "image/png") { if (fuA.PostedFile.ContentLength < 5000000 && fuD.PostedFile.ContentLength < 5000000 && fuC.PostedFile.ContentLength < 5000000 && fuD.PostedFile.ContentLength < 5000000) { if (fuA.HasFile && fuB.HasFile && fuC.HasFile && fuD.HasFile && fuQuestion.HasFile) { SqlConnection connect = con.baglan(); Random rnd = new Random(); fuQuestion.PostedFile.SaveAs(Server.MapPath("~/upload/") + Session["userID"].ToString() + fuQuestion.FileName.ToString()); SqlCommand cmd = new SqlCommand("insert into question (userID,subjectID,questionName,isText) values (@USERID,@SUBJECTID,@QUESTIONSNAME,@ISTEXT)", connect); cmd.Parameters.Add("@USERID", Session["userID"]); cmd.Parameters.Add("@SUBJECTID", drpSubject.SelectedItem.Value); cmd.Parameters.Add("@QUESTIONSNAME", Session["userID"].ToString() + fuQuestion.FileName.ToString()); cmd.Parameters.Add("@ISTEXT", "1"); if (cmd.ExecuteNonQuery() == 0) { connect.Close(); connect.Dispose(); } else { DataRow drQuestions = con.GetDataRow("select * from [question] where CONVERT(NVARCHAR(MAX), questionName)='" + Session["userID"].ToString() + fuQuestion.FileName.ToString() + "'"); if (drQuestions["questionID"] != null) { fuA.PostedFile.SaveAs(Server.MapPath("~/upload/") + drQuestions["questionID"].ToString() + fuA.FileName.ToString()); fuB.PostedFile.SaveAs(Server.MapPath("~/upload/") + drQuestions["questionID"].ToString() + fuB.FileName.ToString()); fuC.PostedFile.SaveAs(Server.MapPath("~/upload/") + drQuestions["questionID"].ToString() + fuC.FileName.ToString()); fuD.PostedFile.SaveAs(Server.MapPath("~/upload/") + drQuestions["questionID"].ToString() + fuD.FileName.ToString()); SqlCommand replyCmd = new SqlCommand("insert into reply (questionID,a,b,c,d,trueReply) values(@QUESTIONSID,@A,@B,@C,@D,@TRUEREPLY)", connect); replyCmd.Parameters.Add("@QUESTIONSID", drQuestions["questionID"]); replyCmd.Parameters.Add("@A", drQuestions["questionID"].ToString() + fuA.FileName.ToString()); replyCmd.Parameters.Add("@B", drQuestions["questionID"].ToString() + fuB.FileName.ToString()); replyCmd.Parameters.Add("@C", drQuestions["questionID"].ToString() + fuC.FileName.ToString()); replyCmd.Parameters.Add("@D", drQuestions["questionID"].ToString() + fuD.FileName.ToString()); replyCmd.Parameters.Add("@TRUEREPLY", reply); replyCmd.ExecuteNonQuery(); Response.Redirect("RemoveQuestions.aspx"); } else { connect.Close(); connect.Dispose(); } } } else { lblError.Visible = true; lblError.Text = "Dosya Yüklenemedi."; } } else { lblError.Visible = true; lblError.Text = "Dosya boyutu uygun değil."; } } else { lblError.Visible = true; lblError.Text = "Dosya uzantısı uygun değil."; } } } else { lblError1.Visible = true; lblError1.Text = "Hatalı İşlem"; } }
void score() { DataRow drScore = con.GetDataRow("select count(s.subjectName)*2 as count from test t inner join userReply ur on t.testID = ur.testID inner join question q on ur.questionID = q.questionID inner join[subject] s on q.subjectID = s.subjectID inner join reply r on q.questionID = r.questionID where t.testID =" + testID + " and r.trueReplyID IN(ur.trueReplyID)"); lblScore.Text = drScore["count"].ToString(); }