/// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.SYS_DepartmentInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into SYS_DepartmentInfo(");
            strSql.Append("Dpt_Name,Dpt_ParentId,Dpt_Level,Dpt_SecurityID)");

            strSql.Append(" values (");
            strSql.Append("@Dpt_Name,@Dpt_ParentId,@Dpt_Level,@Dpt_SecurityID)");
            strSql.Append(";select @@IDENTITY");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "Dpt_Name", DbType.String, model.Dpt_Name);
            db.AddInParameter(dbCommand, "Dpt_ParentId", DbType.Int32, model.Dpt_ParentId);
            db.AddInParameter(dbCommand, "Dpt_Level", DbType.Int32, model.Dpt_Level);
            db.AddInParameter(dbCommand, "Dpt_SecurityID", DbType.AnsiString, model.Dpt_SecurityID);
            int    result;
            object obj = db.ExecuteScalar(dbCommand);

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.SYS_DepartmentInfo DataRowToModel(DataRow row)
 {
     Model.SYS_DepartmentInfo model=new Model.SYS_DepartmentInfo();
     if (row != null)
     {
         if(row["Dpt_Id"]!=null && row["Dpt_Id"].ToString()!="")
         {
             model.Dpt_Id=int.Parse(row["Dpt_Id"].ToString());
         }
         if(row["Dpt_Name"]!=null)
         {
             model.Dpt_Name=row["Dpt_Name"].ToString();
         }
         if(row["Dpt_ParentId"]!=null && row["Dpt_ParentId"].ToString()!="")
         {
             model.Dpt_ParentId=int.Parse(row["Dpt_ParentId"].ToString());
         }
         if(row["Dpt_Level"]!=null && row["Dpt_Level"].ToString()!="")
         {
             model.Dpt_Level=int.Parse(row["Dpt_Level"].ToString());
         }
         if(row["Dpt_SecurityID"]!=null)
         {
             model.Dpt_SecurityID=row["Dpt_SecurityID"].ToString();
         }
     }
     return model;
 }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.SYS_DepartmentInfo DataRowToModel(DataRow row)
 {
     Model.SYS_DepartmentInfo model = new Model.SYS_DepartmentInfo();
     if (row != null)
     {
         if (row["Dpt_Id"] != null && row["Dpt_Id"].ToString() != "")
         {
             model.Dpt_Id = int.Parse(row["Dpt_Id"].ToString());
         }
         if (row["Dpt_Name"] != null)
         {
             model.Dpt_Name = row["Dpt_Name"].ToString();
         }
         if (row["Dpt_ParentId"] != null && row["Dpt_ParentId"].ToString() != "")
         {
             model.Dpt_ParentId = int.Parse(row["Dpt_ParentId"].ToString());
         }
         if (row["Dpt_Level"] != null && row["Dpt_Level"].ToString() != "")
         {
             model.Dpt_Level = int.Parse(row["Dpt_Level"].ToString());
         }
         if (row["Dpt_SecurityID"] != null)
         {
             model.Dpt_SecurityID = row["Dpt_SecurityID"].ToString();
         }
     }
     return(model);
 }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.SYS_DepartmentInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update SYS_DepartmentInfo set ");
            strSql.Append("Dpt_Name=@Dpt_Name,");
            strSql.Append("Dpt_ParentId=@Dpt_ParentId,");
            strSql.Append("Dpt_Level=@Dpt_Level,");
            strSql.Append("Dpt_SecurityID=@Dpt_SecurityID");
            strSql.Append(" where Dpt_Id=@Dpt_Id ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "Dpt_Id", DbType.Int32, model.Dpt_Id);
            db.AddInParameter(dbCommand, "Dpt_Name", DbType.String, model.Dpt_Name);
            db.AddInParameter(dbCommand, "Dpt_ParentId", DbType.Int32, model.Dpt_ParentId);
            db.AddInParameter(dbCommand, "Dpt_Level", DbType.Int32, model.Dpt_Level);
            db.AddInParameter(dbCommand, "Dpt_SecurityID", DbType.AnsiString, model.Dpt_SecurityID);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.SYS_DepartmentInfo GetModel(int Dpt_Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Dpt_Id,Dpt_Name,Dpt_ParentId,Dpt_Level,Dpt_SecurityID from SYS_DepartmentInfo ");
            strSql.Append(" where Dpt_Id=@Dpt_Id ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "Dpt_Id", DbType.Int32, Dpt_Id);
            Model.SYS_DepartmentInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.SYS_DepartmentInfo ReaderBind(IDataReader dataReader)
        {
            Model.SYS_DepartmentInfo model = new Model.SYS_DepartmentInfo();
            object ojb;

            ojb = dataReader["Dpt_Id"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Dpt_Id = (int)ojb;
            }
            model.Dpt_Name = dataReader["Dpt_Name"].ToString();
            ojb            = dataReader["Dpt_ParentId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Dpt_ParentId = (int)ojb;
            }
            ojb = dataReader["Dpt_Level"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Dpt_Level = (int)ojb;
            }
            model.Dpt_SecurityID = dataReader["Dpt_SecurityID"].ToString();
            return(model);
        }
 /// <summary>
 /// 对象实体绑定数据
 /// </summary>
 public Model.SYS_DepartmentInfo ReaderBind(IDataReader dataReader)
 {
     Model.SYS_DepartmentInfo model=new Model.SYS_DepartmentInfo();
     object ojb;
     ojb = dataReader["Dpt_Id"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.Dpt_Id=(int)ojb;
     }
     model.Dpt_Name=dataReader["Dpt_Name"].ToString();
     ojb = dataReader["Dpt_ParentId"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.Dpt_ParentId=(int)ojb;
     }
     ojb = dataReader["Dpt_Level"];
     if(ojb != null && ojb != DBNull.Value)
     {
         model.Dpt_Level=(int)ojb;
     }
     model.Dpt_SecurityID=dataReader["Dpt_SecurityID"].ToString();
     return model;
 }