Exemple #1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.OrgOrganize GetModel(string strWhere, List <SqlParameter> parameters)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from OrgOrganize ");
            Database db = DatabaseFactory.CreateDatabase();

            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            if (parameters.Count > 0)
            {
                foreach (SqlParameter sqlParameter in parameters)
                {
                    dbCommand.Parameters.Add(sqlParameter);
                }
            }
            Model.OrgOrganize model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }
Exemple #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public long Add(Model.OrgOrganize model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into OrgOrganize(");
            strSql.Append("AreaId,OrgName,OrgAddress,OrgPhone,EnName,OrgFax,OrgType,OrgParentId,AddTime,Status,EndDate)");

            strSql.Append(" values (");
            strSql.Append("@AreaId,@OrgName,@OrgAddress,@OrgPhone,@EnName,@OrgFax,@OrgType,@OrgParentId,@AddTime,@Status,@EndDate)");
            strSql.Append(";select @@IDENTITY");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "AreaId", DbType.AnsiString, model.AreaId);
            db.AddInParameter(dbCommand, "OrgName", DbType.String, model.OrgName);
            db.AddInParameter(dbCommand, "OrgAddress", DbType.String, model.OrgAddress);
            db.AddInParameter(dbCommand, "OrgPhone", DbType.AnsiString, model.OrgPhone);
            db.AddInParameter(dbCommand, "EnName", DbType.String, model.EnName);
            db.AddInParameter(dbCommand, "OrgFax", DbType.AnsiString, model.OrgFax);
            db.AddInParameter(dbCommand, "OrgType", DbType.Byte, model.OrgType);
            db.AddInParameter(dbCommand, "OrgParentId", DbType.Int64, model.OrgParentId);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            db.AddInParameter(dbCommand, "EndDate", DbType.DateTime, model.EndDate);
            int    result;
            object obj = db.ExecuteScalar(dbCommand);

            if (!int.TryParse(obj.ToString(), out result))
            {
                return(0);
            }
            return(result);
        }
Exemple #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.OrgOrganize DataRowToModel(DataRow row)
 {
     Model.OrgOrganize model = new Model.OrgOrganize();
     if (row != null)
     {
         if (row["OrgId"] != null && row["OrgId"].ToString() != "")
         {
             model.OrgId = Convert.ToInt64(row["OrgId"].ToString());
         }
         if (row["AreaId"] != null)
         {
             model.AreaId = row["AreaId"].ToString();
         }
         if (row["OrgName"] != null)
         {
             model.OrgName = row["OrgName"].ToString();
         }
         if (row["OrgAddress"] != null)
         {
             model.OrgAddress = row["OrgAddress"].ToString();
         }
         if (row["OrgPhone"] != null)
         {
             model.OrgPhone = row["OrgPhone"].ToString();
         }
         if (row["EnName"] != null)
         {
             model.EnName = row["EnName"].ToString();
         }
         if (row["OrgFax"] != null)
         {
             model.OrgFax = row["OrgFax"].ToString();
         }
         if (row["OrgType"] != null && row["OrgType"].ToString() != "")
         {
             model.OrgType = Convert.ToInt32(row["OrgType"].ToString());
         }
         if (row["OrgParentId"] != null && row["OrgParentId"].ToString() != "")
         {
             model.OrgParentId = Convert.ToInt64(row["OrgParentId"].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["EndDate"] != null && row["EndDate"].ToString() != "")
         {
             model.EndDate = Convert.ToDateTime(row["EndDate"].ToString());
         }
     }
     return(model);
 }
Exemple #4
0
        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public Model.OrgOrganize ReaderBind(IDataReader dataReader)
        {
            Model.OrgOrganize model = new Model.OrgOrganize();
            object            ojb;

            ojb = dataReader["OrgId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrgId = Convert.ToInt64(ojb);
            }
            model.AreaId     = dataReader["AreaId"].ToString();
            model.OrgName    = dataReader["OrgName"].ToString();
            model.OrgAddress = dataReader["OrgAddress"].ToString();
            model.OrgPhone   = dataReader["OrgPhone"].ToString();
            model.EnName     = dataReader["EnName"].ToString();
            model.OrgFax     = dataReader["OrgFax"].ToString();
            ojb = dataReader["OrgType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrgType = Convert.ToInt32(ojb);
            }
            ojb = dataReader["OrgParentId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.OrgParentId = Convert.ToInt64(ojb);
            }
            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["EndDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EndDate = Convert.ToDateTime(ojb);
            }
            return(model);
        }
Exemple #5
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.OrgOrganize model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update OrgOrganize set ");
            strSql.Append("AreaId=@AreaId,");
            strSql.Append("OrgName=@OrgName,");
            strSql.Append("OrgAddress=@OrgAddress,");
            strSql.Append("OrgPhone=@OrgPhone,");
            strSql.Append("EnName=@EnName,");
            strSql.Append("OrgFax=@OrgFax,");
            strSql.Append("OrgType=@OrgType,");
            strSql.Append("OrgParentId=@OrgParentId,");
            strSql.Append("AddTime=@AddTime,");
            strSql.Append("Status=@Status,");
            strSql.Append("EndDate=@EndDate");
            strSql.Append(" where OrgId=@OrgId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "OrgId", DbType.Int64, model.OrgId);
            db.AddInParameter(dbCommand, "AreaId", DbType.AnsiString, model.AreaId);
            db.AddInParameter(dbCommand, "OrgName", DbType.String, model.OrgName);
            db.AddInParameter(dbCommand, "OrgAddress", DbType.String, model.OrgAddress);
            db.AddInParameter(dbCommand, "OrgPhone", DbType.AnsiString, model.OrgPhone);
            db.AddInParameter(dbCommand, "EnName", DbType.String, model.EnName);
            db.AddInParameter(dbCommand, "OrgFax", DbType.AnsiString, model.OrgFax);
            db.AddInParameter(dbCommand, "OrgType", DbType.Byte, model.OrgType);
            db.AddInParameter(dbCommand, "OrgParentId", DbType.Int64, model.OrgParentId);
            db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime);
            db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status);
            db.AddInParameter(dbCommand, "EndDate", DbType.DateTime, model.EndDate);
            int rows = db.ExecuteNonQuery(dbCommand);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #6
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.OrgOrganize GetModel(long OrgId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select OrgId,AreaId,OrgName,OrgAddress,OrgPhone,EnName,OrgFax,OrgType,OrgParentId,AddTime,Status,EndDate from OrgOrganize ");
            strSql.Append(" where OrgId=@OrgId ");
            Database  db        = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "OrgId", DbType.Int64, OrgId);
            Model.OrgOrganize model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
            }
            return(model);
        }