/// <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); }
/// <summary> /// 获得数据列表 /// </summary> public List <LearnSite.Model.Computers> DataTableToList(DataTable dt) { List <LearnSite.Model.Computers> modelList = new List <LearnSite.Model.Computers>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { LearnSite.Model.Computers model; for (int n = 0; n < rowsCount; n++) { model = new LearnSite.Model.Computers(); if (dt.Rows[n]["Pid"].ToString() != "") { model.Pid = int.Parse(dt.Rows[n]["Pid"].ToString()); } model.Pip = dt.Rows[n]["Pip"].ToString(); model.Pmachine = dt.Rows[n]["Pmachine"].ToString(); if (dt.Rows[n]["Plock"].ToString() != "") { if ((dt.Rows[n]["Plock"].ToString() == "1") || (dt.Rows[n]["Plock"].ToString().ToLower() == "true")) { model.Plock = true; } else { model.Plock = false; } } if (dt.Rows[n]["Pdate"].ToString() != "") { model.Pdate = DateTime.Parse(dt.Rows[n]["Pdate"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 根据Pid更新一条数据Pmachine,Plock,Pdate /// </summary> public bool UpdateMachine(LearnSite.Model.Computers model) { return(UpdateMachine(model)); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LearnSite.Model.Computers model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据Pip,Pmachine,Plock,Pdate,Px,Py,Pm /// </summary> public int AddModel(LearnSite.Model.Computers model) { return(dal.AddModel(model)); }