/// <summary> /// 得到一个对象实体 /// </summary> public SHMetroTestSysModel.jc_Paper DataRowToModel(DataRow row) { SHMetroTestSysModel.jc_Paper model = new SHMetroTestSysModel.jc_Paper(); if (row != null) { if (row["ID"] != null && row["ID"].ToString() != "") { model.ID = int.Parse(row["ID"].ToString()); } if (row["SubjectNo"] != null) { model.SubjectNo = row["SubjectNo"].ToString(); } if (row["UnitId"] != null && row["UnitId"].ToString() != "") { model.UnitId = int.Parse(row["UnitId"].ToString()); } if (row["PaperType"] != null) { model.PaperType = row["PaperType"].ToString(); } if (row["PaperText"] != null) { model.PaperText = row["PaperText"].ToString(); } if (row["PaperAnalysis"] != null) { model.PaperAnalysis = row["PaperAnalysis"].ToString(); } if (row["ItemA"] != null) { model.ItemA = row["ItemA"].ToString(); } if (row["ItemB"] != null) { model.ItemB = row["ItemB"].ToString(); } if (row["ItemC"] != null) { model.ItemC = row["ItemC"].ToString(); } if (row["ItemD"] != null) { model.ItemD = row["ItemD"].ToString(); } if (row["ItemE"] != null) { model.ItemE = row["ItemE"].ToString(); } if (row["ItemF"] != null) { model.ItemF = row["ItemF"].ToString(); } if (row["Answer"] != null) { model.Answer = row["Answer"].ToString(); } } return model; }
public bool ImportPaper(string subjectNo, string unitFullSequence, string paperType, string paperText, string paperAnswer, string answer, bool isReallImport) { try { //更具unitFullCode和subjectNo获取到UnitId // 区分判断还是选择题 string unitId = jcUnitBLL.GetUnitId(subjectNo, unitFullSequence); if (!string.IsNullOrEmpty(unitId)) { SHMetroTestSysModel.jc_Paper model = new SHMetroTestSysModel.jc_Paper(); if (paperType == "判断") { model.ItemA = ""; model.ItemB = ""; model.ItemC = ""; model.ItemD = ""; model.ItemE = ""; model.ItemF = ""; model.Answer = answer; model.PaperAnalysis = ""; model.PaperText = paperText; model.PaperType = paperType; model.UnitId = int.Parse(unitId); model.SubjectNo = subjectNo; if (isReallImport) { jcPaperBLL.Add(model); } } else { model.Answer = ""; string itemstring = Regex.Replace(paperAnswer, @"([ABCDEF])", "@") .Replace("(", "") .Replace(")", "") .Replace("(", "") .Replace(")", ""); itemstring = itemstring.TrimStart('@'); string[] answerItem = itemstring.Split('@'); if (answerItem.Length == 4) { model.ItemA = answerItem[0]; model.ItemB = answerItem[1]; model.ItemC = answerItem[2]; model.ItemD = answerItem[3]; } if (answerItem.Length == 5) { model.ItemA = answerItem[0]; model.ItemB = answerItem[1]; model.ItemC = answerItem[2]; model.ItemD = answerItem[3]; model.ItemE = answerItem[4]; } if (answerItem.Length == 6) { model.ItemA = answerItem[0]; model.ItemB = answerItem[1]; model.ItemC = answerItem[2]; model.ItemD = answerItem[3]; model.ItemE = answerItem[4]; model.ItemF = answerItem[5]; } var machCollection = Regex.Matches(paperText, @"([A-F]{1,4})"); if (machCollection.Count > 0) { model.Answer = machCollection[0].Value.Replace("(", "") .Replace(")", "") .Replace("(", "") .Replace(")", "").Trim(); ; } model.PaperAnalysis = ""; model.PaperText = Regex.Replace(paperText, @"([A-F]{1,4})", "()"); model.PaperType = paperType; model.UnitId = int.Parse(unitId); model.SubjectNo = subjectNo; if (isReallImport) { jcPaperBLL.Add(model); } } } } catch (Exception ex) { return false; } return true; }
/// <summary> /// 得到一个对象实体 /// </summary> public SHMetroTestSysModel.jc_Paper GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,SubjectNo,UnitId,PaperType,PaperText,PaperAnalysis,ItemA,ItemB,ItemC,ItemD,ItemE,ItemF,Answer from jc_Paper "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int,4) }; parameters[0].Value = ID; SHMetroTestSysModel.jc_Paper model = new SHMetroTestSysModel.jc_Paper(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }