private void btnAdd_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(tbxName.Text)) { XmlNodeList nodelist = configele.SelectNodes(string.Format("Item[@Name='{0}']", ReplaceName)); if (nodelist.Count > 0) { MessageBox.Show(string.Format("已存在名称为({0})的明细", ReplaceName)); } else { //保存XML XmlElement ele = oper.Doc.CreateElement("Item"); ele.SetAttribute("Name", ReplaceName); ele.SetAttribute("Type", cbbConfigType.Text); ele.SetAttribute("DataBase", cbbDataBase.Text); ele.SetAttribute("Path", tbxPath.Text); oper.AddEle(ele, configele); //保存文件 FileStreamHelper.SaveText(string.Format("{0}{1}{2}", Application.StartupPath, configDataPath, configItemName), ReplaceName, Content); RefreshList(); } } else { MessageBox.Show("名称不能为空"); } }
private void btnEdit_Click(object sender, EventArgs e) { TreeNode node = DataTree.SelectedNode; if (node != null && !string.IsNullOrEmpty(ReplaceName)) { if (ReplaceName == node.Text) { XmlNodeList nodelist = configele.SelectNodes(string.Format("Item[@Name='{0}']", ReplaceName)); if (nodelist.Count > 0) { //保存XML XmlElement ele = (XmlElement)nodelist[0]; ele.SetAttribute("Type", cbbConfigType.Text); ele.SetAttribute("DataBase", cbbDataBase.Text); ele.SetAttribute("Path", tbxPath.Text); oper.Save(); //保存文件 FileInfo fi = new FileInfo(string.Format("{0}{1}{2}\\{3}", Application.StartupPath, configDataPath, configItemName, ReplaceName)); if (fi.Exists) { fi.Delete(); } FileStreamHelper.SaveText(fi.DirectoryName, ReplaceName, Content); } } else if (configele.SelectNodes(string.Format("Item[@Name='{0}']", ReplaceName)).Count > 0) { MessageBox.Show(string.Format("已存在名称为({0})的明细", ReplaceName)); } else { XmlNodeList nodelist = configele.SelectNodes(string.Format("Item[@Name='{0}']", node.Text)); if (nodelist.Count > 0) { //保存XML XmlElement ele = (XmlElement)nodelist[0]; ele.SetAttribute("Name", ReplaceName); ele.SetAttribute("Type", cbbConfigType.Text); ele.SetAttribute("DataBase", cbbDataBase.Text); ele.SetAttribute("Path", tbxPath.Text); oper.Save(); //保存文件 FileInfo fi = new FileInfo(string.Format("{0}{1}{2}\\{3}", Application.StartupPath, configDataPath, configItemName, node.Text)); if (fi.Exists) { fi.Delete(); } FileStreamHelper.SaveText(fi.DirectoryName, ReplaceName, Content); RefreshList(); } } } }
/// <summary> /// 回调函数 /// </summary> /// <param name="msg"></param> private void Callback(string msg) { if (msg.StartsWith("length")) { domainlength = int.Parse(msg.Substring(6)); } else { if (!msg.Contains("不可用")) { var d = msg.Substring(0, msg.Length - 2); result.Add(d); this.listBox1.Items.Add(d); if (result.Count % 100 == 0) { FileStreamHelper.SaveText(currentpath, string.Format("{0}.txt", DateTime.Now.ToString("yyyyMMddhhmmss")), string.Join(@" ", result)); result.Clear(); } } //未完成 if (searchindex + 1 < domainlength) { toolStripProgressBar1.Value = domainlength > 0 ? (searchindex + 1) * toolStripProgressBar1.Maximum / domainlength : toolStripProgressBar1.Maximum; toolStripStatusLabel1.Text = string.Format("({1}/{2}){0}", msg, searchindex + 1, domainlength); } //已完成 else { toolStripProgressBar1.Value = toolStripProgressBar1.Maximum; toolStripStatusLabel1.Text = string.Format("({1}/{2}){0} 全部完成", msg, searchindex + 1, domainlength); if (result.Count > 0) { FileStreamHelper.SaveText(currentpath, string.Format("{0}.txt", DateTime.Now.ToString("yyyyMMddhhmmss")), string.Join(@" ", result)); result.Clear(); } } searchindex++; } }