/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.Ptyper GetModel(int Pid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Pid,Ptid,Psnum,Pscore,Pdate,Pip,Ptype,Pdegree,Pgrade,Pterm from Ptyper "); strSql.Append(" where Pid=@Pid "); SqlParameter[] parameters = { new SqlParameter("@Pid", SqlDbType.Int, 4) }; parameters[0].Value = Pid; LearnSite.Model.Ptyper model = new LearnSite.Model.Ptyper(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Pid"].ToString() != "") { model.Pid = int.Parse(ds.Tables[0].Rows[0]["Pid"].ToString()); } if (ds.Tables[0].Rows[0]["Ptid"].ToString() != "") { model.Ptid = int.Parse(ds.Tables[0].Rows[0]["Ptid"].ToString()); } model.Psnum = ds.Tables[0].Rows[0]["Psnum"].ToString(); if (ds.Tables[0].Rows[0]["Pscore"].ToString() != "") { model.Pscore = int.Parse(ds.Tables[0].Rows[0]["Pscore"].ToString()); } if (ds.Tables[0].Rows[0]["Pdate"].ToString() != "") { model.Pdate = DateTime.Parse(ds.Tables[0].Rows[0]["Pdate"].ToString()); } model.Pip = ds.Tables[0].Rows[0]["Pip"].ToString(); if (ds.Tables[0].Rows[0]["Ptype"].ToString() != "") { model.Ptype = int.Parse(ds.Tables[0].Rows[0]["Ptype"].ToString()); } if (ds.Tables[0].Rows[0]["Pdegree"].ToString() != "") { model.Pdegree = int.Parse(ds.Tables[0].Rows[0]["Pdegree"].ToString()); } if (ds.Tables[0].Rows[0]["Pgrade"].ToString() != "") { model.Pdegree = int.Parse(ds.Tables[0].Rows[0]["Pgrade"].ToString()); } if (ds.Tables[0].Rows[0]["Pterm"].ToString() != "") { model.Pdegree = int.Parse(ds.Tables[0].Rows[0]["Pterm"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.Ptyper model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Ptyper("); strSql.Append("Ptid,Psnum,Pscore,Pdate,Pip,Ptype,Pdegree,Pgrade,Pterm,Psid)"); strSql.Append(" values ("); strSql.Append("@Ptid,@Psnum,@Pscore,@Pdate,@Pip,@Ptype,@Pdegree,@Pgrade,@Pterm,@Psid)"); SqlParameter[] parameters = { new SqlParameter("@Ptid", SqlDbType.Int, 4), new SqlParameter("@Psnum", SqlDbType.NVarChar, 50), new SqlParameter("@Pscore", SqlDbType.Int, 4), new SqlParameter("@Pdate", SqlDbType.DateTime), new SqlParameter("@Pip", SqlDbType.NVarChar, 50), new SqlParameter("@Ptype", SqlDbType.Int, 4), new SqlParameter("@Pdegree", SqlDbType.Int, 4), new SqlParameter("@Pgrade", SqlDbType.Int, 4), new SqlParameter("@Pterm", SqlDbType.Int, 4), new SqlParameter("@Psid", SqlDbType.Int, 4) }; parameters[0].Value = model.Ptid; parameters[1].Value = model.Psnum; parameters[2].Value = model.Pscore; parameters[3].Value = model.Pdate; parameters[4].Value = model.Pip; parameters[5].Value = model.Ptype; parameters[6].Value = model.Pdegree; parameters[7].Value = model.Pgrade; parameters[8].Value = model.Pterm; parameters[9].Value = model.Psid; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据,根据学号更新 /// </summary> public int Update(LearnSite.Model.Ptyper model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Ptyper set "); strSql.Append("Ptid=@Ptid,"); strSql.Append("Pscore=@Pscore,"); strSql.Append("Pdate=@Pdate,"); strSql.Append("Pip=@Pip,"); strSql.Append("Ptype=Ptype+1,"); strSql.Append("Pdegree=@Pdegree,"); strSql.Append("Pgrade=@Pgrade,"); strSql.Append("Pterm=@Pterm"); strSql.Append(" where Psid=@Psid and Pscore<@Pscore "); SqlParameter[] parameters = { new SqlParameter("@Pid", SqlDbType.Int, 4), new SqlParameter("@Ptid", SqlDbType.Int, 4), new SqlParameter("@Psid", SqlDbType.Int, 4), new SqlParameter("@Pscore", SqlDbType.Int, 4), new SqlParameter("@Pdate", SqlDbType.DateTime), new SqlParameter("@Pip", SqlDbType.NVarChar, 50), new SqlParameter("@Pdegree", SqlDbType.Int, 4), new SqlParameter("@Pgrade", SqlDbType.Int, 4), new SqlParameter("@Pterm", SqlDbType.Int, 4) }; parameters[0].Value = model.Pid; parameters[1].Value = model.Ptid; parameters[2].Value = model.Psid; parameters[3].Value = model.Pscore; parameters[4].Value = model.Pdate; parameters[5].Value = model.Pip; parameters[6].Value = model.Pdegree; parameters[7].Value = model.Pgrade; parameters[8].Value = model.Pterm; return(DbHelperSQL.ExecuteSql(strSql.ToString(), parameters)); }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LearnSite.Model.Ptyper GetModel(int Pid) { StringBuilder strSql=new StringBuilder(); strSql.Append("select top 1 Pid,Ptid,Psnum,Pscore,Pdate,Pip,Ptype from Ptyper "); strSql.Append(" where Pid=@Pid "); SqlParameter[] parameters = { new SqlParameter("@Pid", SqlDbType.Int,4)}; parameters[0].Value = Pid; LearnSite.Model.Ptyper model=new LearnSite.Model.Ptyper(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["Pid"].ToString()!="") { model.Pid=int.Parse(ds.Tables[0].Rows[0]["Pid"].ToString()); } if(ds.Tables[0].Rows[0]["Ptid"].ToString()!="") { model.Ptid=int.Parse(ds.Tables[0].Rows[0]["Ptid"].ToString()); } model.Psnum=ds.Tables[0].Rows[0]["Psnum"].ToString(); if(ds.Tables[0].Rows[0]["Pscore"].ToString()!="") { model.Pscore=int.Parse(ds.Tables[0].Rows[0]["Pscore"].ToString()); } if(ds.Tables[0].Rows[0]["Pdate"].ToString()!="") { model.Pdate=DateTime.Parse(ds.Tables[0].Rows[0]["Pdate"].ToString()); } model.Pip=ds.Tables[0].Rows[0]["Pip"].ToString(); if(ds.Tables[0].Rows[0]["Ptype"].ToString()!="") { model.Ptype=int.Parse(ds.Tables[0].Rows[0]["Ptype"].ToString()); } return model; } else { return null; } }