ZhiYeJianKang_PeiXun/Song.Site/Json/QuesRandomForEmp.aspx.cs

114 lines
4.4 KiB
C#
Raw Permalink Normal View History

2025-02-20 15:41:53 +08:00
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WeiSha.Common;
using Song.ServiceInterfaces;
using Song.Entities;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
namespace Song.Site.Json
{
public partial class QuesRandomForEmp : System.Web.UI.Page
{
//<2F>Ծ<EFBFBD>id<69><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>id,Ա<><D4B1>id
private int sbjid = WeiSha.Common.Request.Form["sbjid"].Int32 ?? 0;
private int diff = WeiSha.Common.Request.Form["diff"].Int32 ?? 0;
private int type = WeiSha.Common.Request.Form["type"].Int32 ?? 0;
//<2F><>ȡ<EFBFBD><C8A1>ǰѧ<C7B0><D1A7><EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ծ<EFBFBD>
protected void Page_Load(object sender, EventArgs e)
{
Song.Entities.Organization org = Business.Do<IOrganization>().OrganCurrent();
EmpAccount currentUser = Extend.LoginState.Admin.CurrentUser;
if (currentUser == null)
{
Response.Write("");
Response.End();
return;
}
//<2F><>ǰԱ<C7B0><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7>
Song.Entities.Team team = Business.Do<ITeam>().TeamSingle((int)currentUser.Team_ID);
if (team != null) sbjid = (int)team.Sbj_ID;
//Ա<><D4B1>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>ѧ<EFBFBD>Ʒ<EFBFBD>Χ
string sel = Business.Do<ISystemPara>()["SubjectForAccout_" + currentUser.Acc_Id].String;
string[] arr = sel.Split(',');
if (arr.Length > 0) arr[arr.Length - 1] = sbjid.ToString();
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡѧ<C8A1><D1A7>
if (arr.Length > 1)
{
Random rand = new Random();
int index = rand.Next(0, arr.Length - 1);
sbjid = Convert.ToInt32(arr[index]);
}
Song.Entities.Questions[] ques = Business.Do<IQuestions>().QuesRandom(org.Org_ID, sbjid, -1, -1, type, diff, diff, true, 1);
string tm = "";
if (ques.Length > 0)
{
Song.Entities.Questions q = ques[0];
q = replaceText(q);
tm = q.ToJson();
//<2F><><EFBFBD><EFBFBD><EFBFBD>ǵ<EFBFBD>ѡ<EFBFBD><EFBFBD><E2A3AC><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>
if (q.Qus_Type == 1 || q.Qus_Type == 2 || q.Qus_Type == 5)
tm = getAnserJson(q, tm);
}
Response.Write(tm);
Response.End();
}
private string getAnserJson(Song.Entities.Questions q, string json)
{
//<2F><>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
Song.Entities.QuesAnswer[] ans = Business.Do<IQuestions>().QuestionsAnswer(q, null);
string ansStr = "[";
for (int i = 0; i < ans.Length; i++)
{
ansStr += ans[i].ToJson();
if (i < ans.Length - 1) ansStr += ",";
}
ansStr += "]";
json = json.Replace("}", ",\"Answer\":" + ansStr + "}");
return json;
}
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD><D0B5>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
/// </summary>
/// <param name="qs"></param>
/// <returns></returns>
private Song.Entities.Questions replaceText(Song.Entities.Questions qs)
{
qs.Qus_Title = qs.Qus_Title == null ? "" : qs.Qus_Title;
qs.Qus_Title = qs.Qus_Title.Replace("\r","");
qs.Qus_Title = qs.Qus_Title.Replace("\n", "");
qs.Qus_Title = qs.Qus_Title.Replace("\"", "<22><>");
qs.Qus_Title = qs.Qus_Title.Replace("\t", "");
//
qs.Qus_Explain = qs.Qus_Explain == null ? "" : qs.Qus_Explain;
if (qs.Qus_Explain != string.Empty)
{
qs.Qus_Explain = qs.Qus_Explain.Replace("\r", "");
qs.Qus_Explain = qs.Qus_Explain.Replace("\n", "");
qs.Qus_Explain = qs.Qus_Explain.Replace("\"", "<22><>");
qs.Qus_Explain = qs.Qus_Title.Replace("\t", "");
}
//
if (qs.Qus_Answer != string.Empty)
{
qs.Qus_Answer = qs.Qus_Answer == null ? "" : qs.Qus_Answer;
qs.Qus_Answer = qs.Qus_Answer.Replace("\r", "");
qs.Qus_Answer = qs.Qus_Answer.Replace("\n", "");
qs.Qus_Answer = qs.Qus_Answer.Replace("\"", "<22><>");
qs.Qus_Answer = qs.Qus_Title.Replace("\t", "");
}
return qs;
}
}
}