/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.OrgCustomer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into OrgCustomer("); strSql.Append("OrgId,Name,Sex,Birthday,HomeAddress,SelfCard,AddTime,Status,UId,UserName,Password,Mobile)"); strSql.Append(" values ("); strSql.Append("@OrgId,@Name,@Sex,@Birthday,@HomeAddress,@SelfCard,@AddTime,@Status,@UId,@UserName,@Password,@Mobile)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "OrgId", DbType.Int64, model.OrgId); db.AddInParameter(dbCommand, "Name", DbType.String, model.Name); db.AddInParameter(dbCommand, "Sex", DbType.String, model.Sex); db.AddInParameter(dbCommand, "Birthday", DbType.DateTime, model.Birthday); db.AddInParameter(dbCommand, "HomeAddress", DbType.String, model.HomeAddress); db.AddInParameter(dbCommand, "SelfCard", DbType.AnsiString, model.SelfCard); db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "UId", DbType.Int32, model.UId); db.AddInParameter(dbCommand, "UserName", DbType.AnsiString, model.UserName); db.AddInParameter(dbCommand, "Password", DbType.AnsiString, model.Password); db.AddInParameter(dbCommand, "Mobile", DbType.AnsiString, model.Mobile); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.OrgCustomer DataRowToModel(DataRow row) { Model.OrgCustomer model = new Model.OrgCustomer(); if (row != null) { if (row["CId"] != null && row["CId"].ToString() != "") { model.CId = Convert.ToInt32(row["CId"].ToString()); } if (row["OrgId"] != null && row["OrgId"].ToString() != "") { model.OrgId = Convert.ToInt64(row["OrgId"].ToString()); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Sex"] != null) { model.Sex = row["Sex"].ToString(); } if (row["Birthday"] != null && row["Birthday"].ToString() != "") { model.Birthday = Convert.ToDateTime(row["Birthday"].ToString()); } if (row["HomeAddress"] != null) { model.HomeAddress = row["HomeAddress"].ToString(); } if (row["SelfCard"] != null) { model.SelfCard = row["SelfCard"].ToString(); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = Convert.ToDateTime(row["AddTime"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = Convert.ToInt32(row["Status"].ToString()); } if (row["UId"] != null && row["UId"].ToString() != "") { model.UId = Convert.ToInt32(row["UId"].ToString()); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["Password"] != null) { model.Password = row["Password"].ToString(); } if (row["Mobile"] != null) { model.Mobile = row["Mobile"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.OrgCustomer model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update OrgCustomer set "); strSql.Append("OrgId=@OrgId,"); strSql.Append("Name=@Name,"); strSql.Append("Sex=@Sex,"); strSql.Append("Birthday=@Birthday,"); strSql.Append("HomeAddress=@HomeAddress,"); strSql.Append("SelfCard=@SelfCard,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("Status=@Status,"); strSql.Append("UId=@UId,"); strSql.Append("UserName=@UserName,"); strSql.Append("Password=@Password,"); strSql.Append("Mobile=@Mobile"); strSql.Append(" where CId=@CId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "CId", DbType.Int32, model.CId); db.AddInParameter(dbCommand, "OrgId", DbType.Int64, model.OrgId); db.AddInParameter(dbCommand, "Name", DbType.String, model.Name); db.AddInParameter(dbCommand, "Sex", DbType.String, model.Sex); db.AddInParameter(dbCommand, "Birthday", DbType.DateTime, model.Birthday); db.AddInParameter(dbCommand, "HomeAddress", DbType.String, model.HomeAddress); db.AddInParameter(dbCommand, "SelfCard", DbType.AnsiString, model.SelfCard); db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "UId", DbType.Int32, model.UId); db.AddInParameter(dbCommand, "UserName", DbType.AnsiString, model.UserName); db.AddInParameter(dbCommand, "Password", DbType.AnsiString, model.Password); db.AddInParameter(dbCommand, "Mobile", DbType.AnsiString, model.Mobile); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.OrgCustomer ReaderBind(IDataReader dataReader) { Model.OrgCustomer model = new Model.OrgCustomer(); object ojb; ojb = dataReader["CId"]; if (ojb != null && ojb != DBNull.Value) { model.CId = Convert.ToInt32(ojb); } ojb = dataReader["OrgId"]; if (ojb != null && ojb != DBNull.Value) { model.OrgId = Convert.ToInt64(ojb); } model.Name = dataReader["Name"].ToString(); model.Sex = dataReader["Sex"].ToString(); ojb = dataReader["Birthday"]; if (ojb != null && ojb != DBNull.Value) { model.Birthday = Convert.ToDateTime(ojb); } model.HomeAddress = dataReader["HomeAddress"].ToString(); model.SelfCard = dataReader["SelfCard"].ToString(); ojb = dataReader["AddTime"]; if (ojb != null && ojb != DBNull.Value) { model.AddTime = Convert.ToDateTime(ojb); } ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = Convert.ToInt32(ojb); } ojb = dataReader["UId"]; if (ojb != null && ojb != DBNull.Value) { model.UId = Convert.ToInt32(ojb); } model.UserName = dataReader["UserName"].ToString(); model.Password = dataReader["Password"].ToString(); model.Mobile = dataReader["Mobile"].ToString(); return(model); }
/// <summary> /// 根据用户名获取用户ID /// </summary> public Model.OrgCustomer GetModelByUserName(string UserName) { StringBuilder strSql = new StringBuilder(); strSql.Append("select CId,OrgId,Name,Sex,Birthday,HomeAddress,SelfCard,AddTime,Status,UId,UserName,Password,Mobile,Des,Age,Nickname,WineAge,ProductLike,Point,RecName from OrgCustomer "); strSql.Append(" where UserName=@UserName "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "UserName", DbType.String, UserName); Model.OrgCustomer model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.OrgCustomer GetModel(int CId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select CId,OrgId,Name,Sex,Birthday,HomeAddress,SelfCard,AddTime,Status,UId,UserName,Password,Mobile from OrgCustomer "); strSql.Append(" where CId=@CId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "CId", DbType.Int32, CId); Model.OrgCustomer model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }