public List <ShiTiEntity> GetShiTiByShiJuanId(int shiJuanId) { List <ShiTiEntity> listShiTi = new List <ShiTiEntity>(); string sql = string.Format(@"select * from shi_ti where is_deleted=0 and shi_juan_id={0}", shiJuanId); DataTable dtShiTi = MySqlHelper.ExecuteTable(sql); if (dtShiTi != null && dtShiTi.Rows.Count > 0) { foreach (DataRow dr in dtShiTi.Rows) { ShiTiEntity shiTiEntity = ConvertDataRowToShiTiEntity(dr); if (shiTiEntity != null) { listShiTi.Add(shiTiEntity); } } } else { listShiTi = null; } return(listShiTi); }
public ShiTiEntity GetPreShiTiByShiJuanIdAndCurrentIdOld(int shiJuanId, long currentShiTiId, int daTiType) { ShiTiEntity shiTiEntity = null; string sql = string.Empty; if (daTiType == 1) { sql = string.Format(@"select * from shi_ti where is_deleted=0 and shi_juan_id={0} and id>0 and id<{1} order by id desc limit 1 ", shiJuanId, currentShiTiId); } else if (daTiType == 2) { sql = string.Format(@" select * from shi_ti where is_deleted=0 and shi_juan_id={0} and id={1} limit 1 ", shiJuanId, currentShiTiId); } DataTable dtShiTi = MySqlHelper.ExecuteTable(sql); if (dtShiTi != null && dtShiTi.Rows.Count > 0) { DataRow dr = dtShiTi.Rows[0]; shiTiEntity = ConvertDataRowToShiTiEntity(dr); } return(shiTiEntity); }
public IActionResult ShiTiShunXuNext(int shiJuanId, string shiJuanName, long shiTiId, int daTiType) { IShiTi shiTi = new ShiTi(); ShiTiNumEntity shiTiNumEntity = shiTi.GetShiTiNum(shiJuanId); ShiTiEntity shiTiEntity = shiTi.GetNextShiTiByShiJuanIdAndCurrentIdOld(shiJuanId, shiTiId, daTiType); ViewBag.ShiTi = shiTiEntity; ViewBag.shiJuanId = shiJuanId; ViewBag.shiJuanName = shiJuanName; string myDaAn = string.Empty; if (this.ControllerContext.HttpContext.Request.Cookies.ContainsKey("DaTi")) { string strCookie = this.ControllerContext.HttpContext.Request.Cookies["DaTi"]; List <DaTiCookieEntity> listDaTiCookie = JsonHelper.DeserializeJsonToList <DaTiCookieEntity>(strCookie); List <DaTiCookieEntity> listDaTiCookieExist = listDaTiCookie.Where(i => i.daTiType == daTiType && i.shiJuanId == shiJuanId && i.shiTiId == shiTiEntity.id).ToList(); if (listDaTiCookieExist != null && listDaTiCookieExist.Count > 0) { myDaAn = listDaTiCookieExist[0].myDaAn; } } ViewBag.myDaAn = myDaAn; ViewBag.shiTiNumEntity = shiTiNumEntity; ViewBag.daTiType = daTiType; string viewName = "ShiTiShunXu"; if (shiTiEntity.tiXing == "单选题") { viewName = "ShiTiShunXu_DanXuan"; } else if (shiTiEntity.tiXing == "多选题") { viewName = "ShiTiShunXu_DuoXuan"; } else if (shiTiEntity.tiXing == "判断题") { viewName = "ShiTiShunXu_PanDuan"; } else if (shiTiEntity.tiXing == "简答题") { viewName = "ShiTiShunXu_JianDa"; } else { viewName = "ShiTiShunXu"; } //shiTiEntity.xuanXiang=shiTiEntity.xuanXiang.Replace(" b","<br/>b"); //shiTiEntity.xuanXiang = shiTiEntity.xuanXiang.Replace(" B", "<br/>B"); //shiTiEntity.xuanXiang = shiTiEntity.xuanXiang.Replace(" c", "<br/>c"); //shiTiEntity.xuanXiang = shiTiEntity.xuanXiang.Replace(" C", "<br/>C"); //shiTiEntity.xuanXiang = shiTiEntity.xuanXiang.Replace(" d", "<br/>d"); //shiTiEntity.xuanXiang = shiTiEntity.xuanXiang.Replace(" D", "<br/>D"); return(View(viewName)); }
public ShiTiEntity GetNextShiTiByByCondition(int shiJuanId, string tiXing, long currentShiTiId) { ShiTiEntity shiTiEntity = null; string sql = string.Format(@"select * from shi_ti where is_deleted=0 and shi_juan_id={0} and ti_xing='{1}' limit 1 ", shiJuanId, tiXing); DataTable dtShiTi = MySqlHelper.ExecuteTable(sql); if (dtShiTi != null && dtShiTi.Rows.Count > 0) { DataRow dr = dtShiTi.Rows[0]; shiTiEntity = ConvertDataRowToShiTiEntity(dr); } return(shiTiEntity); }
public string IsShiTiExist(int shiJuanId, long goToShiTiId) { try { IShiTi shiTi = new ShiTi(); ShiTiEntity shiTiEntity = shiTi.GetGoToShiTiByShiJuanIdAndCurrentIdOld(shiJuanId, goToShiTiId); if (shiTiEntity == null) { return(false.ToString()); } else { return(true.ToString()); } } catch { return(false.ToString()); } }
public ShiTiEntity GetNextShiTiByShiJuanIdAndCurrentId(int shiJuanId, long currentShiTiId, int userId) { ShiTiEntity shiTiEntity = null; string sql = string.Format(@"select t.*,ud.da_an my_da_an from shi_ti t left join user_da_an ud on t.shi_juan_id=ud.shi_juan_id and t.id=ud.shi_ti_id and ud.is_deleted=0 and ud.user_id={2} where t.is_deleted=0 and t.shi_juan_id={0} and t.id>{1} limit 1 ", shiJuanId, currentShiTiId, userId); DataTable dtShiTi = MySqlHelper.ExecuteTable(sql); if (dtShiTi != null && dtShiTi.Rows.Count > 0) { DataRow dr = dtShiTi.Rows[0]; shiTiEntity = ConvertDataRowToShiTiEntity(dr); } return(shiTiEntity); }
public IActionResult ShiTiSuiJiGoTo(int shiJuanId, string shiJuanName, long goToShiTiId, int daTiType) { IShiTi shiTi = new ShiTi(); ShiTiNumEntity shiTiNumEntity = shiTi.GetShiTiNum(shiJuanId); ShiTiEntity shiTiEntity = shiTi.GetGoToShiTiByShiJuanIdAndCurrentIdOld(shiJuanId, goToShiTiId); ViewBag.ShiTi = shiTiEntity; ViewBag.shiJuanId = shiJuanId; ViewBag.shiJuanName = shiJuanName; string myDaAn = string.Empty; string doShiTiIdsString = string.Empty;//已答试题编号"1,2" if (this.ControllerContext.HttpContext.Request.Cookies.ContainsKey("DaTi")) { string strCookie = this.ControllerContext.HttpContext.Request.Cookies["DaTi"]; List <DaTiCookieEntity> listDaTiCookie = JsonHelper.DeserializeJsonToList <DaTiCookieEntity>(strCookie); List <DaTiCookieEntity> listDaTiCookieExistThisType = listDaTiCookie.Where(i => i.daTiType == daTiType && i.shiJuanId == shiJuanId).ToList(); if (listDaTiCookieExistThisType != null && listDaTiCookieExistThisType.Count > 0) { foreach (DaTiCookieEntity daTi in listDaTiCookieExistThisType) { doShiTiIdsString += daTi.shiTiId.ToString() + ","; } } List <DaTiCookieEntity> listDaTiCookieExist = listDaTiCookie.Where(i => i.daTiType == daTiType && i.shiJuanId == shiJuanId && i.shiTiId == shiTiEntity.id).ToList(); if (listDaTiCookieExist != null && listDaTiCookieExist.Count > 0) { myDaAn = listDaTiCookieExist[0].myDaAn; } } if (doShiTiIdsString.Length > 0) { doShiTiIdsString = doShiTiIdsString.Substring(0, doShiTiIdsString.Length - 1); } ViewBag.myDaAn = myDaAn; ViewBag.shiTiNumEntity = shiTiNumEntity; ViewBag.daTiType = daTiType; ViewBag.doShiTiIdsString = doShiTiIdsString; string viewName = "ShiTiSuiJi"; if (shiTiEntity.tiXing == "单选题") { viewName = "ShiTiSuiJi_DanXuan"; } else if (shiTiEntity.tiXing == "多选题") { viewName = "ShiTiSuiJi_DuoXuan"; } else if (shiTiEntity.tiXing == "判断题") { viewName = "ShiTiSuiJi_PanDuan"; } else if (shiTiEntity.tiXing == "简答题") { viewName = "ShiTiSuiJi_JianDa"; } else { viewName = "ShiTiSuiJi"; } return(View(viewName)); }
public ReturnResultEntity <PageResultEntity <ShiTiEntity> > GetEnableShiTiByCondition(ShiTiSearchEntity shiTiSearchEntity) { ReturnResultEntity <PageResultEntity <ShiTiEntity> > returnMessageEntity = new ReturnResultEntity <PageResultEntity <ShiTiEntity> >(); if (shiTiSearchEntity == null) { returnMessageEntity.success = false; returnMessageEntity.errorMsg = "传入参数为null"; return(returnMessageEntity); } List <ShiTiEntity> listShiTi = new List <ShiTiEntity>(); int nRowCount = 0; StringBuilder sbWhere = new StringBuilder(); sbWhere.Append(" where is_deleted=0 "); if (shiTiSearchEntity.shiTiId > 0) { sbWhere.Append(string.Format(" and id ={0} ", shiTiSearchEntity.shiTiId)); } else { if (shiTiSearchEntity.shiJuanId > 0) { sbWhere.Append(string.Format(" and shi_juan_id ={0} ", shiTiSearchEntity.shiJuanId)); } if (shiTiSearchEntity.tiXing != null && shiTiSearchEntity.tiXing != "全部") { sbWhere.Append(string.Format(" and ti_xing ='{0}' ", shiTiSearchEntity.tiXing)); } if (shiTiSearchEntity.zhengWen != null) { sbWhere.Append(string.Format(" and zheng_wen like'%{0}%' ", shiTiSearchEntity.zhengWen)); } } string strSqlRowCount = "select count(1) rowCount from shi_ti " + sbWhere.ToString(); object objRowCount = WebApiForShiTiKu.Helper.MySqlHelper.ExecuteScalar(strSqlRowCount); if (objRowCount != null) { nRowCount = Convert.ToInt32(objRowCount); } string strLimit = string.Format(" order by id limit {0},{1}", shiTiSearchEntity.pageIndex * shiTiSearchEntity.pageSize, shiTiSearchEntity.pageSize); string strSql = "select *from shi_ti" + sbWhere.ToString() + strLimit; DataTable dtShiJuan = WebApiForShiTiKu.Helper.MySqlHelper.ExecuteTable(strSql); if (dtShiJuan != null && dtShiJuan.Rows.Count > 0) { foreach (DataRow dr in dtShiJuan.Rows) { ShiTiEntity shiTiEntity = new ShiTiEntity(); shiTiEntity = ConvertDataRowToShiTiEntity(dr); listShiTi.Add(shiTiEntity); } } PageResultEntity <ShiTiEntity> pageResultEntity = new PageResultEntity <ShiTiEntity>(); pageResultEntity.rowCount = nRowCount; pageResultEntity.dataList = listShiTi; returnMessageEntity.success = true; returnMessageEntity.data = pageResultEntity; return(returnMessageEntity); }
private ShiTiEntity ConvertDataRowToShiTiEntity(DataRow dr) { if (dr == null) { return(null); } ShiTiEntity shiTiEntity = new ShiTiEntity(); long id = 0; int shi_juan_id = 0; int shi_yong_deng_ji = 0; string nan_du = string.Empty; int fen_shu = 0; int shi_jian = 0; string bian_hao = string.Empty; string ti_xing = string.Empty; string zheng_wen = string.Empty; string xuan_xiang = string.Empty; string da_an = string.Empty; string zbcsxx = string.Empty; string csmsjj = string.Empty; string ybcsnr = string.Empty; string da_an_jie_xi = string.Empty; string ping_fen_biao_zhun = string.Empty; string chu_chu = string.Empty; string chu_ti_ren = string.Empty; string bei_zhu = string.Empty; string tiao_mu = string.Empty; string fen_ce_ming_cheng = string.Empty; string tiao_kuan = string.Empty; string zhuan_ye = string.Empty; string my_da_an = string.Empty; id = dr["id"] == DBNull.Value ? 0 : Convert.ToInt64(dr["id"].ToString()); shi_juan_id = dr["shi_juan_id"] == DBNull.Value ? 0 : Convert.ToInt32(dr["shi_juan_id"].ToString()); shi_yong_deng_ji = dr["shi_yong_deng_ji"] == DBNull.Value ? 0 : Convert.ToInt32(dr["shi_yong_deng_ji"].ToString()); nan_du = dr["nan_du"] == DBNull.Value ? "" : dr["nan_du"].ToString(); fen_shu = dr["fen_shu"] == DBNull.Value ? 0 : Convert.ToInt32(dr["fen_shu"].ToString()); shi_jian = dr["shi_jian"] == DBNull.Value ? 0 : Convert.ToInt32(dr["shi_jian"].ToString()); bian_hao = dr["bian_hao"] == DBNull.Value ? "" : dr["bian_hao"].ToString(); ti_xing = dr["ti_xing"] == DBNull.Value ? "" : dr["ti_xing"].ToString(); zheng_wen = dr["zheng_wen"] == DBNull.Value ? "" : dr["zheng_wen"].ToString(); xuan_xiang = dr["xuan_xiang"] == DBNull.Value ? "" : dr["xuan_xiang"].ToString(); da_an = dr["da_an"] == DBNull.Value ? "" : dr["da_an"].ToString(); zbcsxx = dr["zbcsxx"] == DBNull.Value ? "" : dr["zbcsxx"].ToString(); csmsjj = dr["csmsjj"] == DBNull.Value ? "" : dr["csmsjj"].ToString(); ybcsnr = dr["ybcsnr"] == DBNull.Value ? "" : dr["ybcsnr"].ToString(); da_an_jie_xi = dr["da_an_jie_xi"] == DBNull.Value ? "" : dr["da_an_jie_xi"].ToString(); ping_fen_biao_zhun = dr["ping_fen_biao_zhun"] == DBNull.Value ? "" : dr["ping_fen_biao_zhun"].ToString(); chu_chu = dr["chu_chu"] == DBNull.Value ? "" : dr["chu_chu"].ToString(); chu_ti_ren = dr["chu_ti_ren"] == DBNull.Value ? "" : dr["chu_ti_ren"].ToString(); bei_zhu = dr["bei_zhu"] == DBNull.Value ? "" : dr["bei_zhu"].ToString(); tiao_mu = dr["tiao_mu"] == DBNull.Value ? "" : dr["tiao_mu"].ToString(); fen_ce_ming_cheng = dr["fen_ce_ming_cheng"] == DBNull.Value ? "" : dr["fen_ce_ming_cheng"].ToString(); tiao_kuan = dr["tiao_kuan"] == DBNull.Value ? "" : dr["tiao_kuan"].ToString(); zhuan_ye = dr["zhuan_ye"] == DBNull.Value ? "" : dr["zhuan_ye"].ToString(); shiTiEntity.id = id; shiTiEntity.shiJuanId = shi_juan_id; shiTiEntity.shiYongDengJi = shi_yong_deng_ji; shiTiEntity.nanDu = nan_du; shiTiEntity.fenShu = fen_shu; shiTiEntity.shiJian = shi_jian; shiTiEntity.bianHao = bian_hao; shiTiEntity.tiXing = ti_xing; shiTiEntity.zhengWen = zheng_wen; shiTiEntity.xuanXiang = xuan_xiang; shiTiEntity.daAn = da_an; shiTiEntity.zbcsxx = zbcsxx; shiTiEntity.csmsjj = csmsjj; shiTiEntity.ybcsnr = ybcsnr; shiTiEntity.daAnJieXi = da_an_jie_xi; shiTiEntity.pingFenBiaoZhun = ping_fen_biao_zhun; shiTiEntity.chuChu = chu_chu; shiTiEntity.chuTiRen = chu_ti_ren; shiTiEntity.beiZhu = bei_zhu; shiTiEntity.tiaoMu = tiao_mu; shiTiEntity.fenCeMingCheng = fen_ce_ming_cheng; shiTiEntity.tiaoKuan = tiao_kuan; shiTiEntity.zhuanYe = zhuan_ye; return(shiTiEntity); }
private void SaveExcelData(DataTable dt, string strFileName) { if (dt == null || dt.Rows.Count == 0) { MessageBox.Show("导入的行数不能为0"); } try { List <ShiTiEntity> listShiTiEntity = new List <ShiTiEntity>(); #region for foreach (DataRow dr in dt.Rows) { try { ShiTiEntity shiTiEntity = new ShiTiEntity(); int shi_yong_deng_ji = 0; string nan_du = string.Empty; int fen_shu = 0; int shi_jian = 0; string bian_hao = string.Empty; string ti_xing = string.Empty; string zheng_wen = string.Empty; string xuan_xiang = string.Empty; string da_an = string.Empty; string zbcsxx = string.Empty; string csmsjj = string.Empty; string ybcsnr = string.Empty; string da_an_jie_xi = string.Empty; string ping_fen_biao_zhun = string.Empty; string chu_chu = string.Empty; string chu_ti_ren = string.Empty; string bei_zhu = string.Empty; string tiao_mu = string.Empty; string fen_ce_ming_cheng = string.Empty; string tiao_kuan = string.Empty; string zhuan_ye = string.Empty; if (dt.Columns.Contains("适用等级")) { shi_yong_deng_ji = dr["适用等级"] == DBNull.Value ? 0 : Convert.ToInt32(dr["适用等级"].ToString() == string.Empty ? "0" : dr["适用等级"].ToString()); } if (dt.Columns.Contains("难度")) { nan_du = dr["难度"] == DBNull.Value ? "" : dr["难度"].ToString(); } if (dt.Columns.Contains("答题分数")) { fen_shu = dr["答题分数"] == DBNull.Value ? 0 : Convert.ToInt32(dr["答题分数"].ToString() == string.Empty ? "0" : dr["答题分数"].ToString()); } if (dt.Columns.Contains("答题时间")) { shi_jian = dr["答题时间"] == DBNull.Value ? 0 : Convert.ToInt32(dr["答题时间"].ToString() == string.Empty ? "0" : dr["答题时间"].ToString()); } if (dt.Columns.Contains("试题编号")) { bian_hao = dr["试题编号"] == DBNull.Value ? "" : dr["试题编号"].ToString(); } if (dt.Columns.Contains("题型")) { ti_xing = dr["题型"] == DBNull.Value ? "" : dr["题型"].ToString(); } if (dt.Columns.Contains("试题正文")) { zheng_wen = dr["试题正文"] == DBNull.Value ? "" : dr["试题正文"].ToString(); } if (ti_xing == "判断题") { xuan_xiang = "A:对 B:错"; if (dt.Columns.Contains("试题答案")) { string importDaAn = dr["试题答案"] == DBNull.Value ? "" : dr["试题答案"].ToString(); if (importDaAn == "A" || importDaAn == "a" || importDaAn == "1" || importDaAn == "对") { da_an = "A"; } else if (importDaAn == "B" || importDaAn == "b" || importDaAn == "0" || importDaAn == "错") { da_an = "B"; } } } else { if (dt.Columns.Contains("试题选项")) { xuan_xiang = dr["试题选项"] == DBNull.Value ? "" : dr["试题选项"].ToString(); } if (dt.Columns.Contains("试题答案")) { da_an = dr["试题答案"] == DBNull.Value ? "" : dr["试题答案"].ToString(); } } if (dt.Columns.Contains("自变参数选项")) { zbcsxx = dr["自变参数选项"] == DBNull.Value ? "" : dr["自变参数选项"].ToString(); } if (dt.Columns.Contains("参数M数据集")) { csmsjj = dr["参数M数据集"] == DBNull.Value ? "" : dr["参数M数据集"].ToString(); } if (dt.Columns.Contains("应变参数内容")) { ybcsnr = dr["应变参数内容"] == DBNull.Value ? "" : dr["应变参数内容"].ToString(); } if (dt.Columns.Contains("答案解析")) { da_an_jie_xi = dr["答案解析"] == DBNull.Value ? "" : dr["答案解析"].ToString(); } if (dt.Columns.Contains("答案要点及评分标准")) { ping_fen_biao_zhun = dr["答案要点及评分标准"] == DBNull.Value ? "" : dr["答案要点及评分标准"].ToString(); } if (dt.Columns.Contains("依据 出处")) { chu_chu = dr["依据 出处"] == DBNull.Value ? "" : dr["依据 出处"].ToString(); } if (dt.Columns.Contains("出题人")) { chu_ti_ren = dr["出题人"] == DBNull.Value ? "" : dr["出题人"].ToString(); } if (dt.Columns.Contains("备注")) { bei_zhu = dr["备注"] == DBNull.Value ? "" : dr["备注"].ToString(); } if (dt.Columns.Contains("条目")) { tiao_mu = dr["条目"] == DBNull.Value ? "" : dr["条目"].ToString(); } if (dt.Columns.Contains("分册名称")) { fen_ce_ming_cheng = dr["分册名称"] == DBNull.Value ? "" : dr["分册名称"].ToString(); } if (dt.Columns.Contains("条款")) { tiao_kuan = dr["条款"] == DBNull.Value ? "" : dr["条款"].ToString(); } if (dt.Columns.Contains("专业")) { zhuan_ye = dr["专业"] == DBNull.Value ? "" : dr["专业"].ToString(); } shiTiEntity.shiYongDengJi = shi_yong_deng_ji; shiTiEntity.nanDu = nan_du; shiTiEntity.fenShu = fen_shu; shiTiEntity.shiJian = shi_jian; shiTiEntity.bianHao = bian_hao; shiTiEntity.tiXing = ti_xing; shiTiEntity.zhengWen = zheng_wen; shiTiEntity.xuanXiang = xuan_xiang; shiTiEntity.daAn = da_an; shiTiEntity.zbcsxx = zbcsxx; shiTiEntity.csmsjj = csmsjj; shiTiEntity.ybcsnr = ybcsnr; shiTiEntity.daAnJieXi = da_an_jie_xi; shiTiEntity.pingFenBiaoZhun = ping_fen_biao_zhun; shiTiEntity.chuChu = chu_chu; shiTiEntity.chuTiRen = chu_ti_ren; shiTiEntity.beiZhu = bei_zhu; shiTiEntity.tiaoMu = tiao_mu; shiTiEntity.fenCeMingCheng = fen_ce_ming_cheng; shiTiEntity.tiaoKuan = tiao_kuan; shiTiEntity.zhuanYe = zhuan_ye; listShiTiEntity.Add(shiTiEntity); } catch (Exception a) { MessageBox.Show("数据导入异常," + a.Message); break; } } #endregion ShiJuanEntity shiJuanEntity = new ShiJuanEntity(); shiJuanEntity.shiJuanName = strFileName + DateTime.Now.ToString("yyyy-MM-dd_HHmmss"); shiJuanEntity.cT = DateTime.Now; shiJuanEntity.uT = DateTime.Now; shiJuanEntity.shiTis = listShiTiEntity; string jsonPar = JsonHelper.ToJson(shiJuanEntity); string urlPart = "ShiJuan/AddShiJuanAndShiTis"; string realUrl = ConfigHelper.ConfigHelper.GetApiRootUrl() + urlPart; doAddShiJuanAndShiTi(realUrl, jsonPar); } catch (Exception ex) { MessageBox.Show("导入试卷失败," + ex.Message); } }