/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.BankAccountInList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BankAccountInList("); strSql.Append("AccountNo,InMoney,Type,Memo,Time,Status,EmplId,EmpId,AuditTime)"); strSql.Append(" values ("); strSql.Append("@AccountNo,@InMoney,@Type,@Memo,@Time,@Status,@EmplId,@EmpId,@AuditTime)"); strSql.Append(";select @@IDENTITY"); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AccountNo", DbType.AnsiString, model.AccountNo); db.AddInParameter(dbCommand, "InMoney", DbType.Currency, model.InMoney); db.AddInParameter(dbCommand, "Type", DbType.Byte, model.Type); db.AddInParameter(dbCommand, "Memo", DbType.String, model.Memo); db.AddInParameter(dbCommand, "Time", DbType.DateTime, model.Time); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "EmplId", DbType.Int32, model.EmplId); db.AddInParameter(dbCommand, "EmpId", DbType.Int32, model.EmpId); db.AddInParameter(dbCommand, "AuditTime", DbType.DateTime, model.AuditTime); int result; object obj = db.ExecuteScalar(dbCommand); if (!int.TryParse(obj.ToString(), out result)) { return(0); } return(result); }
/// <summary> /// 对象实体绑定数据 /// </summary> public Model.BankAccountInList ReaderBind(IDataReader dataReader) { Model.BankAccountInList model = new Model.BankAccountInList(); object ojb; ojb = dataReader["InId"]; if (ojb != null && ojb != DBNull.Value) { model.InId = Convert.ToInt32(ojb); } model.AccountNo = dataReader["AccountNo"].ToString(); ojb = dataReader["InMoney"]; if (ojb != null && ojb != DBNull.Value) { model.InMoney = Convert.ToDecimal(ojb); } ojb = dataReader["Type"]; if (ojb != null && ojb != DBNull.Value) { model.Type = Convert.ToInt32(ojb); } model.Memo = dataReader["Memo"].ToString(); ojb = dataReader["Time"]; if (ojb != null && ojb != DBNull.Value) { model.Time = Convert.ToDateTime(ojb); } ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = Convert.ToInt32(ojb); } ojb = dataReader["EmplId"]; if (ojb != null && ojb != DBNull.Value) { model.EmplId = Convert.ToInt32(ojb); } ojb = dataReader["EmpId"]; if (ojb != null && ojb != DBNull.Value) { model.EmpId = Convert.ToInt32(ojb); } ojb = dataReader["AuditTime"]; if (ojb != null && ojb != DBNull.Value) { model.AuditTime = Convert.ToDateTime(ojb); } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.BankAccountInList DataRowToModel(DataRow row) { Model.BankAccountInList model = new Model.BankAccountInList(); if (row != null) { if (row["InId"] != null && row["InId"].ToString() != "") { model.InId = Convert.ToInt32(row["InId"].ToString()); } if (row["AccountNo"] != null) { model.AccountNo = row["AccountNo"].ToString(); } if (row["InMoney"] != null && row["InMoney"].ToString() != "") { model.InMoney = Convert.ToDecimal(row["InMoney"].ToString()); } if (row["Type"] != null && row["Type"].ToString() != "") { model.Type = Convert.ToInt32(row["Type"].ToString()); } if (row["Memo"] != null) { model.Memo = row["Memo"].ToString(); } if (row["Time"] != null && row["Time"].ToString() != "") { model.Time = Convert.ToDateTime(row["Time"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = Convert.ToInt32(row["Status"].ToString()); } if (row["EmplId"] != null && row["EmplId"].ToString() != "") { model.EmplId = Convert.ToInt32(row["EmplId"].ToString()); } if (row["EmpId"] != null && row["EmpId"].ToString() != "") { model.EmpId = Convert.ToInt32(row["EmpId"].ToString()); } if (row["AuditTime"] != null && row["AuditTime"].ToString() != "") { model.AuditTime = Convert.ToDateTime(row["AuditTime"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.BankAccountInList GetModel(int InId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select InId,AccountNo,InMoney,Type,Memo,Time,Status,EmplId,EmpId,AuditTime from BankAccountInList "); strSql.Append(" where InId=@InId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "InId", DbType.Int32, InId); Model.BankAccountInList model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.BankAccountInList model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BankAccountInList set "); strSql.Append("AccountNo=@AccountNo,"); strSql.Append("InMoney=@InMoney,"); strSql.Append("Type=@Type,"); strSql.Append("Memo=@Memo,"); strSql.Append("Time=@Time,"); strSql.Append("Status=@Status,"); strSql.Append("EmplId=@EmplId,"); strSql.Append("EmpId=@EmpId,"); strSql.Append("AuditTime=@AuditTime"); strSql.Append(" where InId=@InId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "InId", DbType.Int32, model.InId); db.AddInParameter(dbCommand, "AccountNo", DbType.AnsiString, model.AccountNo); db.AddInParameter(dbCommand, "InMoney", DbType.Currency, model.InMoney); db.AddInParameter(dbCommand, "Type", DbType.Byte, model.Type); db.AddInParameter(dbCommand, "Memo", DbType.String, model.Memo); db.AddInParameter(dbCommand, "Time", DbType.DateTime, model.Time); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "EmplId", DbType.Int32, model.EmplId); db.AddInParameter(dbCommand, "EmpId", DbType.Int32, model.EmpId); db.AddInParameter(dbCommand, "AuditTime", DbType.DateTime, model.AuditTime); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }