Example #1
0
        public int UpdateLog(Model.LogInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update Logs set");
            strSql.Append(" LogInfo = @LogInfo");
            strSql.Append(", ModificationTime = @ModificationTime");
            strSql.Append(" where Id = @Id");

            Database  db        = DatabaseFactory.CreateDatabase("MYLOGConn");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "LogInfo", DbType.String, model.Text);
            db.AddInParameter(dbCommand, "ModificationTime", DbType.DateTime, model.ModificationTime);
            db.AddInParameter(dbCommand, "Id", DbType.Int32, model.Id);

            return(db.ExecuteNonQuery(dbCommand));
        }
Example #2
0
        public int AddLog(Model.LogInfo model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into Logs(");
            strSql.Append("LogInfo,CreateTime)");
            strSql.Append(" values (");
            strSql.Append("@LogInfo,@CreateTime)");

            // Database, DatabaseFactory 需要 Microsoft.Practices.EnterpriseLibrary.Data,用NuGet安装即可。
            Database  db        = DatabaseFactory.CreateDatabase("MYLOGConn");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            db.AddInParameter(dbCommand, "LogInfo", DbType.String, model.Text);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, model.CreateTime);

            return(db.ExecuteNonQuery(dbCommand));
        }
Example #3
0
        public Model.LogInfo GetLog(int Id)
        {
            try
            {
                StringBuilder strSql = new StringBuilder();
                strSql.Append("select Id, LogInfo, CreateTime, ModificationTime from Logs");
                strSql.Append(" where Id = @Id");

                Database  db        = DatabaseFactory.CreateDatabase("MYLOGConn");
                DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
                db.AddInParameter(dbCommand, "Id", DbType.Int32, Id);

                DataTable dt = db.ExecuteDataSet(dbCommand).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    Model.LogInfo log = new Model.LogInfo();
                    log.Id   = int.Parse(dt.Rows[0]["Id"].ToString());
                    log.Text = dt.Rows[0]["LogInfo"].ToString();
                    DateTime CreateTime;
                    if (DateTime.TryParse(dt.Rows[0]["CreateTime"].ToString(), out CreateTime))
                    {
                        log.CreateTime = CreateTime;
                    }
                    DateTime ModificationTime;
                    if (DateTime.TryParse(dt.Rows[0]["ModificationTime"].ToString(), out ModificationTime))
                    {
                        log.ModificationTime = ModificationTime;
                    }
                    return(log);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Example #4
0
        public List <Model.LogInfo> GetAllLogs()
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select Id, LogInfo, CreateTime, ModificationTime from Logs");

            Database  db        = DatabaseFactory.CreateDatabase("MYLOGConn");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());

            DataTable dt = db.ExecuteDataSet(dbCommand).Tables[0];

            if (dt.Rows.Count > 0)
            {
                List <Model.LogInfo> logs = new List <Model.LogInfo>();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    Model.LogInfo log = new Model.LogInfo();
                    log.Id   = int.Parse(dt.Rows[i]["Id"].ToString());
                    log.Text = dt.Rows[i]["LogInfo"].ToString();
                    DateTime CreateTime;
                    if (DateTime.TryParse(dt.Rows[i]["CreateTime"].ToString(), out CreateTime))
                    {
                        log.CreateTime = CreateTime;
                    }
                    DateTime ModificationTime;
                    if (DateTime.TryParse(dt.Rows[i]["ModificationTime"].ToString(), out ModificationTime))
                    {
                        log.ModificationTime = ModificationTime;
                    }

                    logs.Add(log);
                }
                return(logs);
            }
            else
            {
                return(null);
            }
        }