protected void GVComputer_RowCommand(object sender, GridViewCommandEventArgs e) { if (Request.Cookies[LearnSite.Common.CookieHelp.teaCookieNname] != null) { if (e.CommandName.Equals("Lock")) { string myPid = e.CommandArgument.ToString(); LearnSite.BLL.Computers cbll = new LearnSite.BLL.Computers(); cbll.UpLock(Int32.Parse(myPid)); System.Threading.Thread.Sleep(500); showIpMachine(); } if (e.CommandName.Equals("Del")) { string myPid = e.CommandArgument.ToString(); LearnSite.BLL.Computers cbll = new LearnSite.BLL.Computers(); cbll.Delete(Int32.Parse(myPid)); System.Threading.Thread.Sleep(500); showIpMachine(); } if (e.CommandName.Equals("Upd")) { string myPid = e.CommandArgument.ToString(); int i = ((GridViewRow)((Button)e.CommandSource).NamingContainer).RowIndex; //(该方法不需要html中的绑定,取id.刚刚看到的,加上来,好方法.......) TextBox tb = (TextBox)GVComputer.Rows[i].FindControl("TextBoxp"); LearnSite.BLL.Computers cbll = new LearnSite.BLL.Computers(); cbll.UpdateByPid(Int32.Parse(myPid), tb.Text.Trim()); System.Threading.Thread.Sleep(500); showIpMachine(); } if (e.CommandName.Equals("Can")) { System.Threading.Thread.Sleep(500); showIpMachine(); } } else { string ch = "请登录后执行操作!"; LearnSite.Common.WordProcess.Alert(ch, this.Page); } }
/// <summary> /// 获取IP对应机器名,返回主机名 /// </summary> /// <param name="Pip"></param> /// <returns></returns> private string GetHostNameMy(string aPip) { string msg = "否";//表示不自动获取主机名 if (!string.IsNullOrEmpty(aPip)) { LearnSite.BLL.Computers cbll = new LearnSite.BLL.Computers(); LearnSite.Model.Computers cmodel = new LearnSite.Model.Computers(); cmodel = cbll.GetModelByIp(aPip); bool autohostname = LearnSite.Common.XmlHelp.GetAutoHostName(); //自动取主机名开关 if (cmodel != null) //如果存在 { msg = cmodel.Pmachine; //获取主机名 if (!cmodel.Plock && autohostname) //如果未锁定,更新主机名并锁定 { string newMachine = LearnSite.Common.Computer.GetGuestHost(aPip); cbll.UpdateByPid(cmodel.Pid, newMachine); msg = newMachine;//返回新主机名 } } else { if (autohostname) { LearnSite.Model.Computers newmodel = new LearnSite.Model.Computers();//会丢失?不能过早定义? newmodel.Pip = aPip; newmodel.Plock = true; string addMachine = LearnSite.Common.Computer.GetGuestHost(aPip); newmodel.Pmachine = addMachine; newmodel.Pdate = DateTime.Now; cbll.Add(newmodel); msg = addMachine; } } } else { msg = "空";//表示获取不到IP,反回主机名为空 } return(msg); }