예제 #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(demo1.Model.gn model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_gn set ");
            strSql.Append("controller=@controller,");
            strSql.Append("action=@action,");
            strSql.Append("controllername=@controllername,");
            strSql.Append("actionname=@actionname,");
            strSql.Append("method=@method,");
            strSql.Append("version=@version,");
            strSql.Append("addtime=@addtime,");
            strSql.Append("ispublic=@ispublic,");
            strSql.Append("islock=@islock");
            strSql.Append(" where gnid=@gnid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@controller",     SqlDbType.NVarChar,  50),
                new SqlParameter("@action",         SqlDbType.NVarChar,  50),
                new SqlParameter("@controllername", SqlDbType.NVarChar,  50),
                new SqlParameter("@actionname",     SqlDbType.NVarChar,  50),
                new SqlParameter("@method",         SqlDbType.NVarChar,  50),
                new SqlParameter("@version",        SqlDbType.NVarChar,  50),
                new SqlParameter("@addtime",        SqlDbType.DateTime),
                new SqlParameter("@ispublic",       SqlDbType.Int,        4),
                new SqlParameter("@islock",         SqlDbType.Int,        4),
                new SqlParameter("@gnid",           SqlDbType.Int, 4)
            };
            parameters[0].Value = model.controller;
            parameters[1].Value = model.action;
            parameters[2].Value = model.controllername;
            parameters[3].Value = model.actionname;
            parameters[4].Value = model.method;
            parameters[5].Value = model.version;
            parameters[6].Value = model.addtime;
            parameters[7].Value = model.ispublic;
            parameters[8].Value = model.islock;
            parameters[9].Value = model.gnid;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public demo1.Model.gn DataRowToModel(DataRow row)
 {
     demo1.Model.gn model = new demo1.Model.gn();
     if (row != null)
     {
         if (row["gnid"] != null && row["gnid"].ToString() != "")
         {
             model.gnid = int.Parse(row["gnid"].ToString());
         }
         if (row["controller"] != null)
         {
             model.controller = row["controller"].ToString();
         }
         if (row["action"] != null)
         {
             model.action = row["action"].ToString();
         }
         if (row["controllername"] != null)
         {
             model.controllername = row["controllername"].ToString();
         }
         if (row["actionname"] != null)
         {
             model.actionname = row["actionname"].ToString();
         }
         if (row["method"] != null)
         {
             model.method = row["method"].ToString();
         }
         if (row["version"] != null)
         {
             model.version = row["version"].ToString();
         }
         if (row["addtime"] != null && row["addtime"].ToString() != "")
         {
             model.addtime = DateTime.Parse(row["addtime"].ToString());
         }
         if (row["ispublic"] != null && row["ispublic"].ToString() != "")
         {
             model.ispublic = int.Parse(row["ispublic"].ToString()) == 1 ? true : false;
         }
         if (row["islock"] != null && row["islock"].ToString() != "")
         {
             model.islock = int.Parse(row["islock"].ToString()) == 1 ? true : false;
         }
     }
     return(model);
 }
예제 #3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(demo1.Model.gn model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_gn(");
            strSql.Append("controller,action,controllername,actionname,method,version,addtime,ispublic,islock)");
            strSql.Append(" values (");
            strSql.Append("@controller,@action,@controllername,@actionname,@method,@version,SYSDATETIME(),@ispublic,@islock)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@controller",     SqlDbType.NVarChar, 50),
                new SqlParameter("@action",         SqlDbType.NVarChar, 50),
                new SqlParameter("@controllername", SqlDbType.NVarChar, 50),
                new SqlParameter("@actionname",     SqlDbType.NVarChar, 50),
                new SqlParameter("@method",         SqlDbType.NVarChar, 50),
                new SqlParameter("@version",        SqlDbType.NVarChar, 50),
                new SqlParameter("@ispublic",       SqlDbType.Int,       4),
                new SqlParameter("@islock",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.controller;
            parameters[1].Value = model.action;
            parameters[2].Value = model.controllername;
            parameters[3].Value = model.actionname;
            parameters[4].Value = model.method;
            parameters[5].Value = model.version;
            parameters[6].Value = model.ispublic ? 1 : 0;
            parameters[7].Value = model.islock ? 1 : 0;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
예제 #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public demo1.Model.gn GetModel(int gnid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 gnid,controller,action,controllername,actionname,method,version,addtime,ispublic,islock from t_gn ");
            strSql.Append(" where gnid=@gnid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@gnid", SqlDbType.Int, 4)
            };
            parameters[0].Value = gnid;

            demo1.Model.gn model = new demo1.Model.gn();
            DataSet        ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public IList <demo1.Model.gn> GetAllActionByAssembly()
        {
            var result = new List <demo1.Model.gn>();

            var types = Assembly.Load("demo1").GetTypes();

            foreach (var type in types)
            {
                if (type.IsClass)
                {
                    if (type.BaseType.Name == "BaseController")//如果是Controller
                    {
                        string actionname = "", actionversion = "1.0";
                        bool   actionispublic = false;
                        string controllername = "", controllerversion = "1.0";
                        bool   controllerispublic = false;

                        //获取controller信息
                        object[] gnattrs = type.GetCustomAttributes(typeof(GnAtrAttribute), true);
                        if (gnattrs.Length > 0)
                        {
                            GnAtrAttribute gnatr = gnattrs[0] as GnAtrAttribute;
                            controllername     = gnatr.name;
                            controllerversion  = gnatr.version;
                            controllerispublic = gnatr.ispublic;
                        }
                        //获取action信息
                        var members = type.GetMethods();
                        foreach (var member in members)
                        {
                            if (member.ReturnType.Name == "ActionResult")
                            {
                                object[] deattrs = member.GetCustomAttributes(typeof(GnAtrAttribute), true);
                                if (deattrs.Length > 0)
                                {
                                    GnAtrAttribute deatr = deattrs[0] as GnAtrAttribute;
                                    actionname     = deatr.name;
                                    actionversion  = deatr.version;
                                    actionispublic = deatr.ispublic;

                                    var ap = new demo1.Model.gn();
                                    ap.action         = member.Name;
                                    ap.controller     = member.DeclaringType.Name.Substring(0, member.DeclaringType.Name.Length - 10);
                                    ap.actionname     = actionname;
                                    ap.controllername = controllername;
                                    ap.version        = actionversion;
                                    ap.ispublic       = actionispublic;

                                    //action http请求方式
                                    object[] meattrs = member.GetCustomAttributes(typeof(System.Web.Mvc.ActionMethodSelectorAttribute), true);
                                    if (meattrs.Length > 0)
                                    {
                                        if (meattrs[0] is System.Web.Mvc.HttpPostAttribute)
                                        {
                                            ap.method = "POST";
                                        }
                                        else if (meattrs[0] is System.Web.Mvc.HttpPutAttribute)
                                        {
                                            ap.method = "PUT";
                                        }
                                        else if (meattrs[0] is System.Web.Mvc.HttpPatchAttribute)
                                        {
                                            ap.method = "PATCH";
                                        }
                                        else
                                        {
                                            ap.method = "";
                                        }
                                    }
                                    else
                                    {
                                        ap.method = "GET";
                                    }
                                    result.Add(ap);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }