public ActionResult Create() { string Operator = ""; if (Session["username"].ToString() != null) { Operator = Session["username"].ToString(); } //Log日志要记录的用户名 string message = ""; string domain = Request.Form["domain"].Trim().ToString(); string computername = Request.Form["computername"].Trim().ToString(); string ou = Request.Form["ou"].Trim().ToString(); string description = Request.Form["description"].Trim().ToString(); Computers ad_computer = HttpContext.Application["ad_computer"] as Computers; ComputerDTO cdt = new ComputerDTO(); cdt.Description = description; cdt.Name = computername; cdt.dNSHostName = computername + "@" + domain; int errLevel = 0; if (ad_computer.CreateComputerDTO(cdt, ou, ref errLevel)) { message = "The name <span style =\"color:green\">" + computername + "</span> is created for the success of the computer"; LogHelper.WriteLog(typeof(ComputerManagementController), Operator, "Create%Computer%named%" + computername, true); XmlDocument doc = new XmlDocument(); doc.Load(Server.MapPath("~/ComputerDetail.xml")); XmlNode rootnode = doc.SelectSingleNode("ADComputerDetail"); XmlElement xe1 = doc.CreateElement("computer"); xe1.SetAttribute("Name", computername); XmlElement xesub1 = doc.CreateElement("CreateBy"); xesub1.InnerText = Operator; xe1.AppendChild(xesub1); XmlElement xesub2 = doc.CreateElement("CreateTime"); xesub2.InnerText = DateTime.Today.ToString("yyyyMMdd"); xe1.AppendChild(xesub2); rootnode.AppendChild(xe1); doc.Save(Server.MapPath("~/ComputerDetail.xml")); } else { message = "Failed to create a computer, may be the name<span style =\"color:green\">" + computername + "</span> already exists"; LogHelper.WriteLog(typeof(ComputerManagementController), Operator, "Create%Computer%named%" + computername, false); } return(Json(new JsonData(message))); }