/// <summary> /// 增加一条数据 /// </summary> public int Add(VAN_OA.Model.BaseInfo.Base_UseType model) { StringBuilder strSql = new StringBuilder(); StringBuilder strSql1 = new StringBuilder(); StringBuilder strSql2 = new StringBuilder(); if (model.Name != null) { strSql1.Append("Name,"); strSql2.Append("'" + model.Name + "',"); } strSql1.Append("Type,"); strSql2.Append("" + model.Type + ","); strSql.Append("insert into Base_UseType("); strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1)); strSql.Append(")"); strSql.Append(" values ("); strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1)); strSql.Append(")"); strSql.Append(";select @@IDENTITY"); object obj = DBHelp.ExeScalar(strSql.ToString()); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public VAN_OA.Model.BaseInfo.Base_UseType ReaderBind(IDataReader dataReader) { VAN_OA.Model.BaseInfo.Base_UseType model = new VAN_OA.Model.BaseInfo.Base_UseType(); object ojb; ojb = dataReader["Id"]; if (ojb != null && ojb != DBNull.Value) { model.Id = (int)ojb; } model.Name = dataReader["Name"].ToString(); model.Type = Convert.ToInt32(dataReader["Type"]); model.Type_String = model.Type == 1? "电子票据A" : "电子票据B"; return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(VAN_OA.Model.BaseInfo.Base_UseType model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Base_UseType set "); if (model.Name != null) { strSql.Append("Name='" + model.Name + "',"); } strSql.Append("Type='" + model.Type + "',"); int n = strSql.ToString().LastIndexOf(","); strSql.Remove(n, 1); strSql.Append(" where Id=" + model.Id + ""); bool rowsAffected = DBHelp.ExeCommand(strSql.ToString()); return(rowsAffected); }
/// <summary> /// 得到一个对象实体 /// </summary> public VAN_OA.Model.BaseInfo.Base_UseType GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Id,Name,Type "); strSql.Append(" FROM Base_UseType "); strSql.Append(" where ID=" + ID + ""); VAN_OA.Model.BaseInfo.Base_UseType model = null; using (SqlConnection conn = DBHelp.getConn()) { conn.Open(); SqlCommand objCommand = new SqlCommand(strSql.ToString(), conn); using (SqlDataReader objReader = objCommand.ExecuteReader()) { if (objReader.Read()) { model = ReaderBind(objReader); } } } return(model); }