/// <summary> /// 添加学案调查试题ok /// </summary> /// <param name="dt"></param> /// <param name="Cid"></param> private static void CreateSurveyQuestion(DataTable dt, DataTable dtitems, int Cid, int oldVid, int newVid) { int dCount = dt.Rows.Count; LearnSite.BLL.SurveyQuestion bll = new LearnSite.BLL.SurveyQuestion(); if (dCount > 0) { for (int j = 0; j < dCount; j++) { LearnSite.Model.SurveyQuestion model = new LearnSite.Model.SurveyQuestion(); model = bll.GetModel(dt, j); if (model.Qvid.Value == oldVid) { model.Qvid = newVid;//如果是这个调查的试题,则换成新的 int oldMcid = model.Qcid.Value; string thisMcontent = model.Qtitle; model.Qcid = Cid;//更换成新学案编号 string oldstr = "Store/" + oldMcid.ToString(); string newstr = "Store/" + Cid.ToString(); model.Qtitle = thisMcontent.Replace(oldstr, newstr); //替换链接地址 int oldQid = model.Qid; int newQid = bll.Add(model); //增加学案调查试题 if (dtitems != null) { DataView dv = new DataView(dtitems); dv.RowFilter = "Mqid=" + oldQid.ToString();//直接过滤得到该试题的选项 CreateSurveyItem(dv.ToTable(), Cid, oldQid, newQid, newVid); } } } } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.SurveyQuestion model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into SurveyQuestion("); strSql.Append("Qvid,Qcid,Qtitle,Qcount)"); strSql.Append(" values ("); strSql.Append("@Qvid,@Qcid,@Qtitle,@Qcount)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Qvid", SqlDbType.Int, 4), new SqlParameter("@Qcid", SqlDbType.Int, 4), new SqlParameter("@Qtitle", SqlDbType.NText), new SqlParameter("@Qcount", SqlDbType.Int, 4) }; parameters[0].Value = model.Qvid; parameters[1].Value = model.Qcid; parameters[2].Value = model.Qtitle; parameters[3].Value = model.Qcount; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LearnSite.Model.SurveyQuestion model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update SurveyQuestion set "); strSql.Append("Qvid=@Qvid,"); strSql.Append("Qcid=@Qcid,"); strSql.Append("Qtitle=@Qtitle,"); strSql.Append("Qcount=@Qcount"); strSql.Append(" where Qid=@Qid"); SqlParameter[] parameters = { new SqlParameter("@Qvid", SqlDbType.Int, 4), new SqlParameter("@Qcid", SqlDbType.Int, 4), new SqlParameter("@Qtitle", SqlDbType.NText), new SqlParameter("@Qcount", SqlDbType.Int, 4), new SqlParameter("@Qid", SqlDbType.Int, 4) }; parameters[0].Value = model.Qvid; parameters[1].Value = model.Qcid; parameters[2].Value = model.Qtitle; parameters[3].Value = model.Qcount; parameters[4].Value = model.Qid; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.SurveyQuestion GetModel(int Qid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Qid,Qvid,Qcid,Qtitle,Qcount from SurveyQuestion "); strSql.Append(" where Qid=@Qid"); SqlParameter[] parameters = { new SqlParameter("@Qid", SqlDbType.Int, 4) }; parameters[0].Value = Qid; LearnSite.Model.SurveyQuestion model = new LearnSite.Model.SurveyQuestion(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Qid"] != null && ds.Tables[0].Rows[0]["Qid"].ToString() != "") { model.Qid = int.Parse(ds.Tables[0].Rows[0]["Qid"].ToString()); } if (ds.Tables[0].Rows[0]["Qvid"] != null && ds.Tables[0].Rows[0]["Qvid"].ToString() != "") { model.Qvid = int.Parse(ds.Tables[0].Rows[0]["Qvid"].ToString()); } if (ds.Tables[0].Rows[0]["Qcid"] != null && ds.Tables[0].Rows[0]["Qcid"].ToString() != "") { model.Qcid = int.Parse(ds.Tables[0].Rows[0]["Qcid"].ToString()); } if (ds.Tables[0].Rows[0]["Qtitle"] != null && ds.Tables[0].Rows[0]["Qtitle"].ToString() != "") { model.Qtitle = ds.Tables[0].Rows[0]["Qtitle"].ToString(); } if (ds.Tables[0].Rows[0]["Qcount"] != null && ds.Tables[0].Rows[0]["Qcount"].ToString() != "") { model.Qcount = int.Parse(ds.Tables[0].Rows[0]["Qcount"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.SurveyQuestion GetModel(DataTable dt, int Tsort) { LearnSite.Model.SurveyQuestion model = new LearnSite.Model.SurveyQuestion(); int Count = dt.Rows.Count; if (Count > 0) { if (Tsort < Count) { if (dt.Rows[Tsort]["Qid"] != null && dt.Rows[Tsort]["Qid"].ToString() != "") { model.Qid = int.Parse(dt.Rows[Tsort]["Qid"].ToString()); } if (dt.Rows[Tsort]["Qvid"] != null && dt.Rows[Tsort]["Qvid"].ToString() != "") { model.Qvid = int.Parse(dt.Rows[Tsort]["Qvid"].ToString()); } if (dt.Rows[Tsort]["Qcid"] != null && dt.Rows[Tsort]["Qcid"].ToString() != "") { model.Qcid = int.Parse(dt.Rows[Tsort]["Qcid"].ToString()); } if (dt.Rows[Tsort]["Qtitle"] != null && dt.Rows[Tsort]["Qtitle"].ToString() != "") { model.Qtitle = dt.Rows[Tsort]["Qtitle"].ToString(); } if (dt.Rows[Tsort]["Qcount"] != null && dt.Rows[Tsort]["Qcount"].ToString() != "") { model.Qcount = int.Parse(dt.Rows[Tsort]["Qcount"].ToString()); } return(model); } else { return(null); } } else { return(null); } }