/// <summary> /// 增加一条数据 /// </summary> public int Add(TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into TAB_Base_TrainJiaolu_DutyPlace("); strSql.Append("strTrainJiaoluGUID,strPlaceID,nPlaceIndex)"); strSql.Append(" values ("); strSql.Append("@strTrainJiaoluGUID,@strPlaceID,@nPlaceIndex)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@strTrainJiaoluGUID", SqlDbType.VarChar, 50), new SqlParameter("@strPlaceID", SqlDbType.VarChar, 50), new SqlParameter("@nPlaceIndex", SqlDbType.Int, 4) }; parameters[0].Value = model.strTrainJiaoluGUID; parameters[1].Value = model.strPlaceID; parameters[2].Value = model.nPlaceIndex; object obj = SqlHelper.ExecuteScalar(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update TAB_Base_TrainJiaolu_DutyPlace set "); strSql.Append("strTrainJiaoluGUID=@strTrainJiaoluGUID,"); strSql.Append("strPlaceID=@strPlaceID,"); strSql.Append("nPlaceIndex=@nPlaceIndex"); strSql.Append(" where nId=@nId"); SqlParameter[] parameters = { new SqlParameter("@strTrainJiaoluGUID", SqlDbType.VarChar, 50), new SqlParameter("@strPlaceID", SqlDbType.VarChar, 50), new SqlParameter("@nPlaceIndex", SqlDbType.Int, 4), new SqlParameter("@nId", SqlDbType.Int, 4) }; parameters[0].Value = model.strTrainJiaoluGUID; parameters[1].Value = model.strPlaceID; parameters[2].Value = model.nPlaceIndex; parameters[3].Value = model.nId; int rows = (int)SqlHelper.ExecuteNonQuery(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace DataRowToModel(DataRow row) { TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace model = new TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace(); if (row != null) { if (row["nId"] != null && row["nId"].ToString() != "") { model.nId = int.Parse(row["nId"].ToString()); } if (row["strTrainJiaoluGUID"] != null) { model.strTrainJiaoluGUID = row["strTrainJiaoluGUID"].ToString(); } if (row["strPlaceID"] != null) { model.strPlaceID = row["strPlaceID"].ToString(); } if (row["nPlaceIndex"] != null && row["nPlaceIndex"].ToString() != "") { model.nPlaceIndex = int.Parse(row["nPlaceIndex"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace GetModel(int nId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 nId,strTrainJiaoluGUID,strPlaceID,nPlaceIndex from TAB_Base_TrainJiaolu_DutyPlace "); strSql.Append(" where nId=@nId"); SqlParameter[] parameters = { new SqlParameter("@nId", SqlDbType.Int, 4) }; parameters[0].Value = nId; TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace model = new TF.RunSafty.Model.TAB_Base_TrainJiaolu_DutyPlace(); DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }