/// <summary>
 /// 执行命令
 /// </summary>
 /// <param name="commandInfo"></param>
 public static void Execute(tb_command_model commandInfo)
 {
     string namespacestr = typeof(BaseCommand).Namespace;
     var obj = Assembly.GetAssembly(typeof(BaseCommand)).CreateInstance(namespacestr + "." + commandInfo.commandname.ToString() + "Command", true);
     if (obj != null && obj is BaseCommand)
     {
         var command = (obj as BaseCommand);
         command.CommandInfo = commandInfo;
         command.Execute();
     }
 }
 public ActionResult Add(tb_command_model model)
 {
     return this.Visit(Core.EnumUserRole.Admin, () =>
     {
         tb_command_dal dal = new tb_command_dal();
         using (DbConn PubConn = DbConfig.CreateConn(Config.TaskConnectString))
         {
             PubConn.Open();
             model.commandcreatetime = DateTime.Now;
             dal.Add(PubConn, model);
         }
         return RedirectToAction("index");
     });
 }
        public virtual bool Edit(DbConn PubConn, tb_command_model model)
        {
            List<ProcedureParameter> Par = new List<ProcedureParameter>()
            {
                    
					//命令json
					new ProcedureParameter("@command",    model.command),
					//命令名,参考代码枚举
					new ProcedureParameter("@commandname",    model.commandname),
					//命令执行状态,参考代码枚举
					new ProcedureParameter("@commandstate",    model.commandstate),
					//任务id
					new ProcedureParameter("@taskid",    model.taskid),
					//节点id
					new ProcedureParameter("@nodeid",    model.nodeid),
					//命令创建时间
					new ProcedureParameter("@commandcreatetime",    model.commandcreatetime)
            };
			Par.Add(new ProcedureParameter("@id",  model.id));

            int rev = PubConn.ExecuteSql("update tb_command set command=@command,commandname=@commandname,commandstate=@commandstate,taskid=@taskid,nodeid=@nodeid,commandcreatetime=@commandcreatetime where id=@id", Par);
            return rev == 1;

        }
        public virtual bool Add(DbConn PubConn, tb_command_model model)
        {

            List<ProcedureParameter> Par = new List<ProcedureParameter>()
                {
					
					//命令json
					new ProcedureParameter("@command",    model.command),
					//命令名,参考代码枚举
					new ProcedureParameter("@commandname",    model.commandname),
					//命令执行状态,参考代码枚举
					new ProcedureParameter("@commandstate",    model.commandstate),
					//任务id
					new ProcedureParameter("@taskid",    model.taskid),
					//节点id
					new ProcedureParameter("@nodeid",    model.nodeid),
					//命令创建时间
					new ProcedureParameter("@commandcreatetime",    model.commandcreatetime)   
                };
            int rev = PubConn.ExecuteSql(@"insert into tb_command(command,commandname,commandstate,taskid,nodeid,commandcreatetime)
										   values(@command,@commandname,@commandstate,@taskid,@nodeid,@commandcreatetime)", Par);
            return rev == 1;

        }
 public int UpdateCommand(DbConn PubConn, tb_command_model model)
 {
     return SqlHelper.Visit(ps =>
     {
         ps.Add("command", model.command);
         ps.Add("commandstate", model.commandstate);
         ps.Add("nodeid", model.nodeid);
         ps.Add("commandname", model.commandname);
         ps.Add("id", model.id);
         string sql = "update tb_command set command=@command,commandstate=@commandstate,commandname=@commandname,nodeid=@nodeid where id=@id";
         return PubConn.ExecuteSql(sql, ps.ToParameters());
     });
 }
		public virtual tb_command_model CreateModel(DataRow dr)
        {
            var o = new tb_command_model();
			
			//
			if(dr.Table.Columns.Contains("id"))
			{
				o.id = dr["id"].Toint();
			}
			//命令json
			if(dr.Table.Columns.Contains("command"))
			{
				o.command = dr["command"].Tostring();
			}
			//命令名,参考代码枚举
			if(dr.Table.Columns.Contains("commandname"))
			{
				o.commandname = dr["commandname"].Tostring();
			}
			//命令执行状态,参考代码枚举
			if(dr.Table.Columns.Contains("commandstate"))
			{
				o.commandstate = dr["commandstate"].ToByte();
			}
			//任务id
			if(dr.Table.Columns.Contains("taskid"))
			{
				o.taskid = dr["taskid"].Toint();
			}
			//节点id
			if(dr.Table.Columns.Contains("nodeid"))
			{
				o.nodeid = dr["nodeid"].Toint();
			}
			//命令创建时间
			if(dr.Table.Columns.Contains("commandcreatetime"))
			{
				o.commandcreatetime = dr["commandcreatetime"].ToDateTime();
			}
			return o;
        }