/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.Mission model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Mission("); strSql.Append("Mtitle,Mcid,Mcontent,Mdate,Mhit,Mfiletype,Mupload,Msort,Mpublish,Mgroup,Mgid,Mexample,Mcategory,Microworld)"); strSql.Append(" values ("); strSql.Append("@Mtitle,@Mcid,@Mcontent,@Mdate,@Mhit,@Mfiletype,@Mupload,@Msort,@Mpublish,@Mgroup,@Mgid,@Mexample,@Mcategory,@Microworld)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Mtitle", SqlDbType.NVarChar, 50), new SqlParameter("@Mcid", SqlDbType.Int, 4), new SqlParameter("@Mcontent", SqlDbType.NText), new SqlParameter("@Mdate", SqlDbType.DateTime), new SqlParameter("@Mhit", SqlDbType.Int, 4), new SqlParameter("@Mfiletype", SqlDbType.NVarChar, 50), new SqlParameter("@Mupload", SqlDbType.Bit, 1), new SqlParameter("@Msort", SqlDbType.Int, 4), new SqlParameter("@Mpublish", SqlDbType.Bit, 1), new SqlParameter("@Mgroup", SqlDbType.Bit, 1), new SqlParameter("@Mgid", SqlDbType.Int, 4), new SqlParameter("@Mexample", SqlDbType.NVarChar, 50), new SqlParameter("@Mcategory", SqlDbType.Int, 4), new SqlParameter("@Microworld", SqlDbType.Bit, 1) }; parameters[0].Value = model.Mtitle; parameters[1].Value = model.Mcid; parameters[2].Value = model.Mcontent; parameters[3].Value = model.Mdate; parameters[4].Value = model.Mhit; parameters[5].Value = model.Mfiletype; parameters[6].Value = model.Mupload; parameters[7].Value = model.Msort; parameters[8].Value = model.Mpublish; parameters[9].Value = model.Mgroup; parameters[10].Value = model.Mgid; parameters[11].Value = model.Mexample; parameters[12].Value = model.Mcategory; parameters[13].Value = model.Microworld; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据(无mcid) /// </summary> public void Update(LearnSite.Model.Mission model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Mission set "); strSql.Append("Mtitle=@Mtitle,"); strSql.Append("Mcontent=@Mcontent,"); strSql.Append("Mdate=@Mdate,"); strSql.Append("Mhit=@Mhit,"); strSql.Append("Mfiletype=@Mfiletype,"); strSql.Append("Mupload=@Mupload,"); strSql.Append("Mpublish=@Mpublish,"); strSql.Append("Mgroup=@Mgroup,"); strSql.Append("Mgid=@Mgid,"); strSql.Append("Mexample=@Mexample,"); strSql.Append("Mcategory=@Mcategory,"); strSql.Append("Microworld=@Microworld"); strSql.Append(" where Mid=@Mid "); SqlParameter[] parameters = { new SqlParameter("@Mid", SqlDbType.Int, 4), new SqlParameter("@Mtitle", SqlDbType.NVarChar, 50), new SqlParameter("@Mcontent", SqlDbType.NText), new SqlParameter("@Mdate", SqlDbType.DateTime), new SqlParameter("@Mhit", SqlDbType.Int, 4), new SqlParameter("@Mfiletype", SqlDbType.NVarChar, 50), new SqlParameter("@Mupload", SqlDbType.Bit, 1), new SqlParameter("@Mpublish", SqlDbType.Bit, 1), new SqlParameter("@Mgroup", SqlDbType.Bit, 1), new SqlParameter("@Mgid", SqlDbType.Int, 4), new SqlParameter("@Mexample", SqlDbType.NVarChar, 50), new SqlParameter("@Mcategory", SqlDbType.Int, 4), new SqlParameter("@Microworld", SqlDbType.Bit, 1) }; parameters[0].Value = model.Mid; parameters[1].Value = model.Mtitle; parameters[2].Value = model.Mcontent; parameters[3].Value = model.Mdate; parameters[4].Value = model.Mhit; parameters[5].Value = model.Mfiletype; parameters[6].Value = model.Mupload; parameters[7].Value = model.Mpublish; parameters[8].Value = model.Mgroup; parameters[9].Value = model.Mgid; parameters[10].Value = model.Mexample; parameters[11].Value = model.Mcategory; parameters[12].Value = model.Microworld; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 添加学案活动ok /// </summary> /// <param name="dtMission"></param> /// <param name="Cid"></param> private static void CreateMission(DataTable dtMission, int Cid) { int mCount = dtMission.Rows.Count; LearnSite.BLL.Mission bll = new LearnSite.BLL.Mission(); for (int i = 0; i < mCount; i++) { LearnSite.Model.Mission ms = new LearnSite.Model.Mission(); ms = bll.GetTableModel(dtMission, i); int oldMcid = ms.Mcid.Value; string thisMcontent = ms.Mcontent; ms.Mcid = Cid;//更换成新学案编号 string oldstr = "Store/" + oldMcid.ToString(); string newstr = "Store/" + Cid.ToString(); ms.Mcontent = thisMcontent.Replace(oldstr, newstr);//替换链接地址 string thisMexample = ms.Mexample; ms.Mexample = thisMexample.Replace(oldstr, newstr); ms.Mgroup = false; bll.Add(ms);//增加学案活动 } }
/// <summary> /// 将指定Mcid指定Tsort的活动从xml内容读到model中 /// </summary> /// <param name="Cid"></param> /// <param name="Tsort"></param> /// <returns></returns> public static LearnSite.Model.Mission mission(int Mcid, int Tsort) { LearnSite.Model.Mission ms = new LearnSite.Model.Mission(); LearnSite.BLL.Mission bll = new LearnSite.BLL.Mission(); string xmlFile = XmlFilename(Mcid); DataSet ds = new DataSet(); DataTable dt = new DataTable(); if (xmlFile != "") { ds.ReadXml(xmlFile);//读取xml文件到ds dt = ds.Tables["Mission"]; ms = bll.GetTableModel(dt, Tsort); ds.Dispose(); return(ms); } else { ds.Dispose(); return(null); } }
/// <summary> /// 添加课程活动 /// </summary> /// <param name="dtMission"></param> /// <param name="Cid"></param> private static void CreateMission(DataTable dtMission,int Cid) { int mCount = dtMission.Rows.Count; LearnSite.BLL.Mission bll = new LearnSite.BLL.Mission(); for (int i = 0; i < mCount; i++) { LearnSite.Model.Mission ms = new LearnSite.Model.Mission(); ms = bll.GetTableModel(dtMission, i); int oldMcid = ms.Mcid.Value; string thisMcontent = ms.Mcontent; ms.Mcid = Cid;//更换成新课程编号 string oldstr = "Store/" + oldMcid.ToString(); string newstr = "Store/" + Cid.ToString(); ms.Mcontent = thisMcontent.Replace(oldstr, newstr);//替换链接地址 bll.Add(ms);//增加课程活动 } }
/// <summary> /// 将指定Mcid指定Tsort的活动从xml内容读到model中 /// </summary> /// <param name="Cid"></param> /// <param name="Tsort"></param> /// <returns></returns> public static LearnSite.Model.Mission mission(int Mcid, int Tsort) { LearnSite.Model.Mission ms = new LearnSite.Model.Mission(); LearnSite.BLL.Mission bll = new LearnSite.BLL.Mission(); string xmlFile = XmlFilename(Mcid); DataSet ds = new DataSet(); DataTable dt = new DataTable(); if (xmlFile != "") { ds.ReadXml(xmlFile);//读取xml文件到ds dt = ds.Tables["Mission"]; ms = bll.GetTableModel(dt, Tsort); ds.Dispose(); return ms; } else { ds.Dispose(); return null; } }
/// <summary> /// 从查询表中得到一个Mission对象实体,Tsort为Table记录序号(从0开始) /// </summary> public LearnSite.Model.Mission GetTableModel(DataTable dt, int Tsort) { LearnSite.Model.Mission model = new LearnSite.Model.Mission(); int Count = dt.Rows.Count; if (Count > 0) { if (Tsort < Count) { if (dt.Rows[Tsort]["Mid"].ToString() != "") { model.Mid = int.Parse(dt.Rows[Tsort]["Mid"].ToString()); } model.Mtitle = dt.Rows[Tsort]["Mtitle"].ToString(); if (dt.Rows[Tsort]["Mcid"].ToString() != "") { model.Mcid = int.Parse(dt.Rows[Tsort]["Mcid"].ToString()); } model.Mcontent = dt.Rows[Tsort]["Mcontent"].ToString(); if (dt.Rows[Tsort]["Mdate"].ToString() != "") { model.Mdate = DateTime.Parse(dt.Rows[Tsort]["Mdate"].ToString()); } if (dt.Rows[Tsort]["Mhit"].ToString() != "") { model.Mhit = int.Parse(dt.Rows[Tsort]["Mhit"].ToString()); } model.Mfiletype = dt.Rows[Tsort]["Mfiletype"].ToString(); if (dt.Rows[Tsort]["Mupload"].ToString() != "") { if ((dt.Rows[Tsort]["Mupload"].ToString() == "1") || (dt.Rows[Tsort]["Mupload"].ToString().ToLower() == "true")) { model.Mupload = true; } else { model.Mupload = false; } } if (dt.Rows[Tsort]["Msort"].ToString() != "") { model.Msort = int.Parse(dt.Rows[Tsort]["Msort"].ToString()); } if (dt.Rows[Tsort]["Mpublish"].ToString() != "") { if ((dt.Rows[Tsort]["Mpublish"].ToString() == "1") || (dt.Rows[Tsort]["Mpublish"].ToString().ToLower() == "true")) { model.Mpublish = true; } else { model.Mpublish = false; } } if (dt.Columns.Contains("Mgid")) { if (dt.Rows[Tsort]["Mgid"] != null && dt.Rows[Tsort]["Mgid"].ToString() != "") { model.Mgid = int.Parse(dt.Rows[Tsort]["Mgid"].ToString()); } } if (dt.Columns.Contains("Mexample")) { model.Mexample = dt.Rows[Tsort]["Mexample"].ToString(); } if (dt.Columns.Contains("Mcategory")) { if (dt.Rows[Tsort]["Mcategory"].ToString() != "") { model.Mcategory = int.Parse(dt.Rows[Tsort]["Mcategory"].ToString()); } } if (dt.Columns.Contains("Microworld")) { if (dt.Rows[Tsort]["Microworld"].ToString() != "") { if ((dt.Rows[Tsort]["Microworld"].ToString() == "1") || (dt.Rows[Tsort]["Microworld"].ToString().ToLower() == "true")) { model.Microworld = true; } else { model.Microworld = false; } } } return(model); } else { return(null); } } else { return(null); } }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.Mission GetModel(int Mid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 * from Mission "); strSql.Append(" where Mid=@Mid"); SqlParameter[] parameters = { new SqlParameter("@Mid", SqlDbType.Int, 4) }; parameters[0].Value = Mid; LearnSite.Model.Mission model = new LearnSite.Model.Mission(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Mid"].ToString() != "") { model.Mid = int.Parse(ds.Tables[0].Rows[0]["Mid"].ToString()); } model.Mtitle = ds.Tables[0].Rows[0]["Mtitle"].ToString(); if (ds.Tables[0].Rows[0]["Mcid"].ToString() != "") { model.Mcid = int.Parse(ds.Tables[0].Rows[0]["Mcid"].ToString()); } model.Mcontent = ds.Tables[0].Rows[0]["Mcontent"].ToString(); if (ds.Tables[0].Rows[0]["Mdate"].ToString() != "") { model.Mdate = DateTime.Parse(ds.Tables[0].Rows[0]["Mdate"].ToString()); } if (ds.Tables[0].Rows[0]["Mhit"].ToString() != "") { model.Mhit = int.Parse(ds.Tables[0].Rows[0]["Mhit"].ToString()); } model.Mfiletype = ds.Tables[0].Rows[0]["Mfiletype"].ToString(); if (ds.Tables[0].Rows[0]["Mupload"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Mupload"].ToString() == "1") || (ds.Tables[0].Rows[0]["Mupload"].ToString().ToLower() == "true")) { model.Mupload = true; } else { model.Mupload = false; } } if (ds.Tables[0].Rows[0]["Msort"].ToString() != "") { model.Msort = int.Parse(ds.Tables[0].Rows[0]["Msort"].ToString()); } if (ds.Tables[0].Rows[0]["Mpublish"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Mpublish"].ToString() == "1") || (ds.Tables[0].Rows[0]["Mpublish"].ToString().ToLower() == "true")) { model.Mpublish = true; } else { model.Mpublish = false; } } if (ds.Tables[0].Rows[0]["Mgroup"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Mgroup"].ToString() == "1") || (ds.Tables[0].Rows[0]["Mgroup"].ToString().ToLower() == "true")) { model.Mgroup = true; } else { model.Mgroup = false; } } if (ds.Tables[0].Rows[0]["Mgid"] != null && ds.Tables[0].Rows[0]["Mgid"].ToString() != "") { model.Mgid = int.Parse(ds.Tables[0].Rows[0]["Mgid"].ToString()); } model.Mexample = ds.Tables[0].Rows[0]["Mexample"].ToString(); if (ds.Tables[0].Rows[0]["Mcategory"].ToString() != "") { model.Mcategory = int.Parse(ds.Tables[0].Rows[0]["Mcategory"].ToString()); } if (ds.Tables[0].Rows[0]["Microworld"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Microworld"].ToString() == "1") || (ds.Tables[0].Rows[0]["Microworld"].ToString().ToLower() == "true")) { model.Microworld = true; } else { model.Microworld = false; } } return(model); } else { return(null); } }
/// <summary> /// �Ӳ�ѯ���еõ�һ��Mission����ʵ��,TsortΪTable��¼��ţ���0��ʼ�� /// </summary> public LearnSite.Model.Mission GetTableModel(DataTable dt, int Tsort) { LearnSite.Model.Mission model = new LearnSite.Model.Mission(); int Count = dt.Rows.Count; if (Count > 0) { if (Tsort < Count) { if (dt.Rows[Tsort]["Mid"].ToString() != "") { model.Mid = int.Parse(dt.Rows[Tsort]["Mid"].ToString()); } model.Mtitle = dt.Rows[Tsort]["Mtitle"].ToString(); if (dt.Rows[Tsort]["Mcid"].ToString() != "") { model.Mcid = int.Parse(dt.Rows[Tsort]["Mcid"].ToString()); } model.Mcontent = dt.Rows[Tsort]["Mcontent"].ToString(); if (dt.Rows[Tsort]["Mdate"].ToString() != "") { model.Mdate = DateTime.Parse(dt.Rows[Tsort]["Mdate"].ToString()); } if (dt.Rows[Tsort]["Mhit"].ToString() != "") { model.Mhit = int.Parse(dt.Rows[Tsort]["Mhit"].ToString()); } model.Mfiletype = dt.Rows[Tsort]["Mfiletype"].ToString(); if (dt.Rows[Tsort]["Mupload"].ToString() != "") { if ((dt.Rows[Tsort]["Mupload"].ToString() == "1") || (dt.Rows[Tsort]["Mupload"].ToString().ToLower() == "true")) { model.Mupload = true; } else { model.Mupload = false; } } if (dt.Rows[Tsort]["Msort"].ToString() != "") { model.Msort = int.Parse(dt.Rows[Tsort]["Msort"].ToString()); } if (dt.Rows[Tsort]["Mpublish"].ToString() != "") { if ((dt.Rows[Tsort]["Mpublish"].ToString() == "1") || (dt.Rows[Tsort]["Mpublish"].ToString().ToLower() == "true")) { model.Mpublish = true; } else { model.Mpublish = false; } } return model; } else { return null; } } else { return null; } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LearnSite.Model.Mission GetModel(int Mid) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Mid,Mtitle,Mcid,Mcontent,Mdate,Mhit,Mfiletype,Mupload,Msort,Mpublish from Mission "); strSql.Append(" where Mid=@Mid "); SqlParameter[] parameters = { new SqlParameter("@Mid", SqlDbType.Int,4)}; parameters[0].Value = Mid; LearnSite.Model.Mission model=new LearnSite.Model.Mission(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["Mid"].ToString()!="") { model.Mid=int.Parse(ds.Tables[0].Rows[0]["Mid"].ToString()); } model.Mtitle=ds.Tables[0].Rows[0]["Mtitle"].ToString(); if(ds.Tables[0].Rows[0]["Mcid"].ToString()!="") { model.Mcid=int.Parse(ds.Tables[0].Rows[0]["Mcid"].ToString()); } model.Mcontent=ds.Tables[0].Rows[0]["Mcontent"].ToString(); if(ds.Tables[0].Rows[0]["Mdate"].ToString()!="") { model.Mdate=DateTime.Parse(ds.Tables[0].Rows[0]["Mdate"].ToString()); } if(ds.Tables[0].Rows[0]["Mhit"].ToString()!="") { model.Mhit=int.Parse(ds.Tables[0].Rows[0]["Mhit"].ToString()); } model.Mfiletype=ds.Tables[0].Rows[0]["Mfiletype"].ToString(); if(ds.Tables[0].Rows[0]["Mupload"].ToString()!="") { if((ds.Tables[0].Rows[0]["Mupload"].ToString()=="1")||(ds.Tables[0].Rows[0]["Mupload"].ToString().ToLower()=="true")) { model.Mupload=true; } else { model.Mupload=false; } } if(ds.Tables[0].Rows[0]["Msort"].ToString()!="") { model.Msort=int.Parse(ds.Tables[0].Rows[0]["Msort"].ToString()); } if(ds.Tables[0].Rows[0]["Mpublish"].ToString()!="") { if((ds.Tables[0].Rows[0]["Mpublish"].ToString()=="1")||(ds.Tables[0].Rows[0]["Mpublish"].ToString().ToLower()=="true")) { model.Mpublish=true; } else { model.Mpublish=false; } } return model; } else { return null; } }