/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.Pfinger GetModel(int Pid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Pid,Psnum,Pspd,Pyear,Pmonth,Pdate,Pdegree,Pgrade,Pterm from Pfinger "); strSql.Append(" where Pid=@Pid"); SqlParameter[] parameters = { new SqlParameter("@Pid", SqlDbType.Int, 4) }; parameters[0].Value = Pid; LearnSite.Model.Pfinger model = new LearnSite.Model.Pfinger(); 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()); } model.Psnum = ds.Tables[0].Rows[0]["Psnum"].ToString(); if (ds.Tables[0].Rows[0]["Pspd"].ToString() != "") { model.Pspd = decimal.Parse(ds.Tables[0].Rows[0]["Pspd"].ToString()); } if (ds.Tables[0].Rows[0]["Pyear"].ToString() != "") { model.Pyear = int.Parse(ds.Tables[0].Rows[0]["Pyear"].ToString()); } if (ds.Tables[0].Rows[0]["Pmonth"].ToString() != "") { model.Pmonth = int.Parse(ds.Tables[0].Rows[0]["Pmonth"].ToString()); } if (ds.Tables[0].Rows[0]["Pdate"].ToString() != "") { model.Pdate = DateTime.Parse(ds.Tables[0].Rows[0]["Pdate"].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.Pgrade = int.Parse(ds.Tables[0].Rows[0]["Pgrade"].ToString()); } if (ds.Tables[0].Rows[0]["Pterm"].ToString() != "") { model.Pterm = int.Parse(ds.Tables[0].Rows[0]["Pterm"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LearnSite.Model.Pfinger model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Pfinger set "); strSql.Append("Psnum=@Psnum,"); strSql.Append("Pspd=@Pspd,"); strSql.Append("Pyear=@Pyear,"); strSql.Append("Pmonth=@Pmonth,"); strSql.Append("Pdate=@Pdate,"); strSql.Append("Pdegree=@Pdegree"); strSql.Append(" where Pid=@Pid"); SqlParameter[] parameters = { new SqlParameter("@Pid", SqlDbType.Int, 4), new SqlParameter("@Psnum", SqlDbType.NVarChar, 50), new SqlParameter("@Pspd", SqlDbType.Decimal, 9), new SqlParameter("@Pyear", SqlDbType.Int, 4), new SqlParameter("@Pmonth", SqlDbType.Int, 4), new SqlParameter("@Pdate", SqlDbType.DateTime), new SqlParameter("@Pdegree", SqlDbType.Int, 4) }; parameters[0].Value = model.Pid; parameters[1].Value = model.Psnum; parameters[2].Value = model.Pspd; parameters[3].Value = model.Pyear; parameters[4].Value = model.Pmonth; parameters[5].Value = model.Pdate; parameters[6].Value = model.Pdegree; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.Pfinger model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Pfinger("); strSql.Append("Psnum,Pspd,Pyear,Pmonth,Pdate,Pgrade,Pterm)"); strSql.Append(" values ("); strSql.Append("@Psnum,@Pspd,@Pyear,@Pmonth,@Pdate,@Pgrade,@Pterm)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Psnum", SqlDbType.NVarChar, 50), new SqlParameter("@Pspd", SqlDbType.Decimal, 9), new SqlParameter("@Pyear", SqlDbType.Int, 4), new SqlParameter("@Pmonth", SqlDbType.Int, 4), new SqlParameter("@Pdate", SqlDbType.DateTime), new SqlParameter("@Pgrade", SqlDbType.Int, 4), new SqlParameter("@Pterm", SqlDbType.Int, 4) }; parameters[0].Value = model.Psnum; parameters[1].Value = model.Pspd; parameters[2].Value = model.Pyear; parameters[3].Value = model.Pmonth; parameters[4].Value = model.Pdate; parameters[5].Value = model.Pgrade; parameters[6].Value = model.Pterm; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }