/// <summary> /// 根据组长学号和活动编号得到一个对象实体 /// </summary> public LearnSite.Model.GroupWork GetModelBySnum(string Gnum, int Gmid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Gid,Gnum,Gstudents,Gterm,Ggrade,Gclass,Gcid,Gmid,Gfilename,Gtype,Gurl,Glengh,Gscore,Gtime,Gvote,Gcheck,Gnote,Grank,Ghit,Gip,Gdate from GroupWork "); strSql.Append(" where Gmid=@Gmid and Gnum=@Gnum "); SqlParameter[] parameters = { new SqlParameter("@Gnum", SqlDbType.NVarChar, 50), new SqlParameter("@Gmid", SqlDbType.Int, 4) }; parameters[0].Value = Gnum; parameters[1].Value = Gmid; LearnSite.Model.GroupWork model = new LearnSite.Model.GroupWork(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Gid"].ToString() != "") { model.Gid = int.Parse(ds.Tables[0].Rows[0]["Gid"].ToString()); } model.Gnum = ds.Tables[0].Rows[0]["Gnum"].ToString(); model.Gstudents = ds.Tables[0].Rows[0]["Gstudents"].ToString(); if (ds.Tables[0].Rows[0]["Gterm"].ToString() != "") { model.Gterm = int.Parse(ds.Tables[0].Rows[0]["Gterm"].ToString()); } if (ds.Tables[0].Rows[0]["Ggrade"].ToString() != "") { model.Ggrade = int.Parse(ds.Tables[0].Rows[0]["Ggrade"].ToString()); } if (ds.Tables[0].Rows[0]["Gclass"].ToString() != "") { model.Gclass = int.Parse(ds.Tables[0].Rows[0]["Gclass"].ToString()); } if (ds.Tables[0].Rows[0]["Gcid"].ToString() != "") { model.Gcid = int.Parse(ds.Tables[0].Rows[0]["Gcid"].ToString()); } if (ds.Tables[0].Rows[0]["Gmid"].ToString() != "") { model.Gmid = int.Parse(ds.Tables[0].Rows[0]["Gmid"].ToString()); } model.Gfilename = ds.Tables[0].Rows[0]["Gfilename"].ToString(); model.Gtype = ds.Tables[0].Rows[0]["Gtype"].ToString(); model.Gurl = ds.Tables[0].Rows[0]["Gurl"].ToString(); if (ds.Tables[0].Rows[0]["Glengh"].ToString() != "") { model.Glengh = int.Parse(ds.Tables[0].Rows[0]["Glengh"].ToString()); } if (ds.Tables[0].Rows[0]["Gscore"].ToString() != "") { model.Gscore = int.Parse(ds.Tables[0].Rows[0]["Gscore"].ToString()); } if (ds.Tables[0].Rows[0]["Gtime"].ToString() != "") { model.Gtime = int.Parse(ds.Tables[0].Rows[0]["Gtime"].ToString()); } if (ds.Tables[0].Rows[0]["Gvote"].ToString() != "") { model.Gvote = int.Parse(ds.Tables[0].Rows[0]["Gvote"].ToString()); } if (ds.Tables[0].Rows[0]["Gcheck"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Gcheck"].ToString() == "1") || (ds.Tables[0].Rows[0]["Gcheck"].ToString().ToLower() == "true")) { model.Gcheck = true; } else { model.Gcheck = false; } } model.Gnote = ds.Tables[0].Rows[0]["Gnote"].ToString(); if (ds.Tables[0].Rows[0]["Grank"].ToString() != "") { model.Grank = int.Parse(ds.Tables[0].Rows[0]["Grank"].ToString()); } if (ds.Tables[0].Rows[0]["Ghit"].ToString() != "") { model.Ghit = int.Parse(ds.Tables[0].Rows[0]["Ghit"].ToString()); } model.Gip = ds.Tables[0].Rows[0]["Gip"].ToString(); if (ds.Tables[0].Rows[0]["Gdate"].ToString() != "") { model.Gdate = DateTime.Parse(ds.Tables[0].Rows[0]["Gdate"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.GroupWork model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into GroupWork("); strSql.Append("Gnum,Gstudents,Gterm,Ggrade,Gclass,Gcid,Gmid,Gfilename,Gtype,Gurl,Glengh,Gscore,Gtime,Gvote,Gcheck,Gnote,Grank,Ghit,Gip,Gdate,Ggroup)"); strSql.Append(" values ("); strSql.Append("@Gnum,@Gstudents,@Gterm,@Ggrade,@Gclass,@Gcid,@Gmid,@Gfilename,@Gtype,@Gurl,@Glengh,@Gscore,@Gtime,@Gvote,@Gcheck,@Gnote,@Grank,@Ghit,@Gip,@Gdate,@Ggroup)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Gnum", SqlDbType.NVarChar, 50), new SqlParameter("@Gstudents", SqlDbType.NVarChar, 200), new SqlParameter("@Gterm", SqlDbType.Int, 4), new SqlParameter("@Ggrade", SqlDbType.Int, 4), new SqlParameter("@Gclass", SqlDbType.Int, 4), new SqlParameter("@Gcid", SqlDbType.Int, 4), new SqlParameter("@Gmid", SqlDbType.Int, 4), new SqlParameter("@Gfilename", SqlDbType.NVarChar, 50), new SqlParameter("@Gtype", SqlDbType.NVarChar, 50), new SqlParameter("@Gurl", SqlDbType.NVarChar, 200), new SqlParameter("@Glengh", SqlDbType.Int, 4), new SqlParameter("@Gscore", SqlDbType.Int, 4), new SqlParameter("@Gtime", SqlDbType.Int, 4), new SqlParameter("@Gvote", SqlDbType.Int, 4), new SqlParameter("@Gcheck", SqlDbType.Bit, 1), new SqlParameter("@Gnote", SqlDbType.NText), new SqlParameter("@Grank", SqlDbType.Int, 4), new SqlParameter("@Ghit", SqlDbType.Int, 4), new SqlParameter("@Gip", SqlDbType.NVarChar, 50), new SqlParameter("@Gdate", SqlDbType.DateTime), new SqlParameter("@Ggroup", SqlDbType.Int, 4) }; parameters[0].Value = model.Gnum; parameters[1].Value = model.Gstudents; parameters[2].Value = model.Gterm; parameters[3].Value = model.Ggrade; parameters[4].Value = model.Gclass; parameters[5].Value = model.Gcid; parameters[6].Value = model.Gmid; parameters[7].Value = model.Gfilename; parameters[8].Value = model.Gtype; parameters[9].Value = model.Gurl; parameters[10].Value = model.Glengh; parameters[11].Value = model.Gscore; parameters[12].Value = model.Gtime; parameters[13].Value = model.Gvote; parameters[14].Value = model.Gcheck; parameters[15].Value = model.Gnote; parameters[16].Value = model.Grank; parameters[17].Value = model.Ghit; parameters[18].Value = model.Gip; parameters[19].Value = model.Gdate; parameters[20].Value = model.Ggroup; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(LearnSite.Model.GroupWork model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update GroupWork set "); strSql.Append("Gnum=@Gnum,"); strSql.Append("Gstudents=@Gstudents,"); strSql.Append("Gterm=@Gterm,"); strSql.Append("Ggrade=@Ggrade,"); strSql.Append("Gclass=@Gclass,"); strSql.Append("Gcid=@Gcid,"); strSql.Append("Gmid=@Gmid,"); strSql.Append("Gfilename=@Gfilename,"); strSql.Append("Gtype=@Gtype,"); strSql.Append("Gurl=@Gurl,"); strSql.Append("Glengh=@Glengh,"); strSql.Append("Gscore=@Gscore,"); strSql.Append("Gtime=@Gtime,"); strSql.Append("Gvote=@Gvote,"); strSql.Append("Gcheck=@Gcheck,"); strSql.Append("Gnote=@Gnote,"); strSql.Append("Grank=@Grank,"); strSql.Append("Ghit=@Ghit,"); strSql.Append("Gip=@Gip,"); strSql.Append("Gdate=@Gdate"); strSql.Append(" where Gid=@Gid "); SqlParameter[] parameters = { new SqlParameter("@Gid", SqlDbType.Int, 4), new SqlParameter("@Gnum", SqlDbType.NVarChar, 50), new SqlParameter("@Gstudents", SqlDbType.NVarChar, 200), new SqlParameter("@Gterm", SqlDbType.Int, 4), new SqlParameter("@Ggrade", SqlDbType.Int, 4), new SqlParameter("@Gclass", SqlDbType.Int, 4), new SqlParameter("@Gcid", SqlDbType.Int, 4), new SqlParameter("@Gmid", SqlDbType.Int, 4), new SqlParameter("@Gfilename", SqlDbType.NVarChar, 50), new SqlParameter("@Gtype", SqlDbType.NVarChar, 50), new SqlParameter("@Gurl", SqlDbType.NVarChar, 200), new SqlParameter("@Glengh", SqlDbType.Int, 4), new SqlParameter("@Gscore", SqlDbType.Int, 4), new SqlParameter("@Gtime", SqlDbType.Int, 4), new SqlParameter("@Gvote", SqlDbType.Int, 4), new SqlParameter("@Gcheck", SqlDbType.Bit, 1), new SqlParameter("@Gnote", SqlDbType.NText), new SqlParameter("@Grank", SqlDbType.Int, 4), new SqlParameter("@Ghit", SqlDbType.Int, 4), new SqlParameter("@Gip", SqlDbType.NVarChar, 50), new SqlParameter("@Gdate", SqlDbType.DateTime) }; parameters[0].Value = model.Gid; parameters[1].Value = model.Gnum; parameters[2].Value = model.Gstudents; parameters[3].Value = model.Gterm; parameters[4].Value = model.Ggrade; parameters[5].Value = model.Gclass; parameters[6].Value = model.Gcid; parameters[7].Value = model.Gmid; parameters[8].Value = model.Gfilename; parameters[9].Value = model.Gtype; parameters[10].Value = model.Gurl; parameters[11].Value = model.Glengh; parameters[12].Value = model.Gscore; parameters[13].Value = model.Gtime; parameters[14].Value = model.Gvote; parameters[15].Value = model.Gcheck; parameters[16].Value = model.Gnote; parameters[17].Value = model.Grank; parameters[18].Value = model.Ghit; parameters[19].Value = model.Gip; parameters[20].Value = model.Gdate; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }