/// <summary> /// 根据班级模型读取IP的x坐标和y坐标 /// </summary> /// <param name="xdoc"></param> /// <param name="classname"></param> public static int SetIpxy(string xmlfile, string Pm) { XmlDocument xmlsave = new XmlDocument(); xmlsave = ReadXml(xmlfile); XmlNode root = xmlsave.SelectSingleNode("classmodel"); XmlNodeList nodeList = root.ChildNodes; if (nodeList[0].Name != "student") { XmlNode newroot = root.SelectSingleNode("students"); nodeList = newroot.ChildNodes; } LearnSite.BLL.Computers cbll = new BLL.Computers(); foreach (XmlNode xn in nodeList) { XmlNode addressNode = xn.SelectSingleNode("address"); string ip = addressNode.Attributes["IP"].Value; XmlNode posNode = xn.SelectSingleNode("posThumb"); string px = posNode.Attributes["x"].Value; string py = posNode.Attributes["y"].Value; string machine = xn.SelectSingleNode("name").InnerText;//主机名 if (WordProcess.IsZh(machine)) { machine = ""; //如果班级模型的主机名是中文,则留空 } if (!cbll.UpdateIpPxPy(ip, Int32.Parse(px), Int32.Parse(py), Pm)) { //如果没更新,则插入一条 LearnSite.Model.Computers cmodel = new Model.Computers(); cmodel.Pdate = DateTime.Now; cmodel.Pip = ip; cmodel.Plock = true; cmodel.Pm = Pm; cmodel.Pmachine = machine; cmodel.Px = Int32.Parse(px); cmodel.Py = Int32.Parse(py); cbll.AddModel(cmodel); } } return(nodeList.Count); }
/// <summary> /// 根据IP更新主机名,不存在则添加 /// </summary> public bool UpdateIp(string Pip, string Pmachine) { bool isok = false; if (!ExistsIp(Pip)) { Model.Computers cmodel = new Model.Computers(); cmodel.Pdate = DateTime.Now; cmodel.Pip = Pip; cmodel.Plock = true; cmodel.Pmachine = Pmachine; BLL.Computers cbll = new Computers(); if (cbll.Add(cmodel) > 0) { isok = true; } } else { isok = dal.UpdateIp(Pip, Pmachine); } return(isok); }
public static string DataSettoComputers(string savepath) { DataSet ds = ExcelHostnameToDataSet(savepath); string msg = ""; if (ds != null) { int count = ds.Tables[0].Rows.Count; int columnscount = ds.Tables[0].Columns.Count; int isright = 0; string[] strColumn = { "ip", "hostname" }; for (int k = 0; k < columnscount; k++) { string strname = ds.Tables[0].Columns[k].ColumnName; foreach (string str in strColumn) { if (strname == str) { isright++; } } } if (isright == strColumn.Length) { if (count > 0) { Model.Computers cmodel = new Model.Computers(); BLL.Computers cbll = new BLL.Computers(); int right = 0; DateTime dt = DateTime.Now; for (int i = 0; i < count; i++) { string Pip = ds.Tables[0].Rows[i]["ip"].ToString(); string Pmachine = ds.Tables[0].Rows[i]["hostname"].ToString(); if (!string.IsNullOrEmpty(Pip) && !string.IsNullOrEmpty(Pmachine)) { cmodel.Pdate = dt; cmodel.Pip = Pip; cmodel.Plock = true; cmodel.Pmachine = Pmachine; if (!cbll.ExistsIp(Pip)) { if (cbll.Add(cmodel) > 0) { right++; } } else { if (cbll.UpdateIp(Pip, Pmachine)) { right++; } } } } int repc = count - right; msg = "Excel表格数据共" + count + "条,导入数据库成功共" + right + "条,重复" + repc + "条"; } else { msg = "无数据!"; } } else { msg = "Excel数据格式不正确,请导入ip和hostname对应的Excel表格"; } } else { msg = "网站UpExcel目录下无hostname.xls文件!"; } return(msg); }