AfterCheck
///
lstChapterIds.Add(e.Node.Name);this.btnDelRes.Enabled = true;}else{//取消节点选中状态之后,取消所有父节点的选中状态SetChildNode(e.Node, false);//如果节点存在父节点,取消父节点的选中状态if (e.Node.Parent != null){SetParentNode(e.Node, false);}//获取选中节点值if (lstChapterIds.Contains(e.Node.Name)){lstChapterIds.Remove(e.Node.Name);if (!lstChapterIds.Any()){this.btnDelRes.Enabled = false;}}}}}
设置节点
///
{flag = false;pNode.Checked = flag;break;}//SetParentNode(item, state);
}if (pNode.Checked ){//获取选中节点值
lstChapterIds.Add(pNode.Name);}else{if (lstChapterIds.Contains(pNode.Name)){lstChapterIds.Remove(pNode.Name);}}SetParentNode(pNode, flag);}}///
lstChapterIds.Add(currNode.Name);}else{if (lstChapterIds.Contains(currNode.Name)){lstChapterIds.Remove(currNode.Name);}}SetChildNode(currNode, state);}}}
程序只开一个:program.cs
bool createdNew = false;System.Threading.Mutex instance = new System.Threading.Mutex(true, Application.ProductName, out createdNew);if (createdNew){//...........code
instance.ReleaseMutex();}else{MessageBox.Show("该程序已经在运行!", Application.ProductName,MessageBoxButtons.OK, MessageBoxIcon.Exclamation);Application.Exit();}
委托 不同线程间访问控件
private delegate void UploadPro(int mProgre);private event UploadPro UploadProEvent;UploadProEvent +=ResourceManage_UploadProEvent;void ResourceManage_UploadProEvent(int mProgree)
{//......
}var thread = new Thread(new ThreadStart(method));
thread.Start();
this.Invoke(UploadProEvent,currentPro);
解压缩 文件
ZipInputStream inputStream = new ZipInputStream(File.OpenRead(strFilePath));
ZipEntry theEntry;
//读取文件名List<string> fileNameList &#61; new List<string>();while ((theEntry &#61; inputStream.GetNextEntry()) !&#61; null){totalSize &#43;&#61; theEntry.UncompressedSize;string templateName &#61; theEntry.FileName;string fileName &#61; Path.GetFileName(templateName);if (!string.IsNullOrEmpty(fileName))fileNameList.Add(fileName);}inputStream.Close();#region 解压文件inputStream &#61; new ZipInputStream(File.OpenRead(filePath));//long totalSize &#61; inputStream.Length;long currentSize &#61; 0;int currentPro &#61; 0;ZipEntry theEntry;ZipFile zf &#61; ZipFile.Read(filePath);//以文件流来解压所有文件&#xff0c;同时计算进度while ((theEntry &#61; inputStream.GetNextEntry()) !&#61; null){//totalSize &#43;&#61; theEntry.UncompressedSize;//long totalSize &#61; theEntry.UncompressedSize;//destPath &#43;&#61; "/";//string templateName &#61; theEntry.FileName;//string fileName &#61; Path.GetFileName(templateName);////string dir &#61; Path.GetDirectoryName(templateName);//string dir &#61; templateName;//if (!dir.Contains("\\") && string.IsNullOrEmpty(fileName))//{// continue;//} ////截取目录文件夹//if (dir.Contains("\\"))// dir &#61; dir.Substring(dir.IndexOf("\\") &#43; 1, dir.Length - dir.IndexOf("\\") - 1);//if (templateName.Length &#61;&#61; (dir &#43; "/" &#43; fileName).Length) dir &#61; "";////theEntry.IsDirectory 是否目录//string path &#61; Path.GetDirectoryName(destPath) &#43; "/" &#43; dir &#43; "/";////Path.GetDirectoryName(baseDir) &#43; "/";////if (!Directory.Exists(path)) // Directory.CreateDirectory(path);string strFilePath &#61; string.Empty;string templateName &#61; theEntry.FileName;if (!templateName.Contains("\\")){//文件strFilePath &#61; destPath &#43; "\\" &#43; theEntry.FileName;}else{//文件夹里文件strFilePath &#61; destPath &#43; theEntry.FileName;}if (!Directory.Exists(Path.GetDirectoryName(strFilePath))){Directory.CreateDirectory(Path.GetDirectoryName(strFilePath));}string fileName &#61; Path.GetFileName(templateName);if (fileName !&#61; String.Empty){FileStream streamWriter &#61; File.OpenWrite(strFilePath); //解压文件到指定的目录 int size &#61; 0;byte[] data &#61; new byte[2048];try{while (true){size &#61; inputStream.Read(data, 0, data.Length);if (size > 0){streamWriter.Write(data, 0, size);currentSize &#43;&#61; size;}else{break;}currentPro &#61; Convert.ToInt32(100 * currentSize / totalSize);this.Invoke(UploadProEvent,currentPro);}}catch (Exception ex){LogHelper.Error(this.GetType(), ex);this.Invoke(UploadProEvent, -1); //-1 导入失败
}finally{streamWriter.Close();}}}inputStream.Close();#endregion
检查指导文件盘符&#xff0c;获取空间大盘符
///
获取MAC地址
///
获取远程文件信息
///
response.Close();request.KeepAlive &#61; false;}catch (Exception ex){throw;}return result;}
错误日志
#region 日志方法public void LogTest(string str){string path &#61; System.IO.Directory.GetCurrentDirectory() &#43; "\\log\\";if (!Directory.Exists(path)){DirectoryInfo directorylnfo &#61; new DirectoryInfo(path);directorylnfo.Create();}string dt &#61; "\r\n时间&#xff1a;" &#43; DateTime.Now.ToString("yyyymmddhhmmss") &#43; "\r\n内容&#xff1a;" &#43; str;int len &#61; dt.Length;byte[] inputByts &#61; new byte[len];inputByts &#61; Encoding.GetEncoding("utf-8").GetBytes(dt);System.IO.FileStream fs &#61; new System.IO.FileStream(path &#43; "log.txt", System.IO.FileMode.OpenOrCreate);fs.Seek(0, System.IO.SeekOrigin.End);fs.Write(inputByts, 0, inputByts.Length);fs.Close();//关闭流
} #endregion
///
启动停止服务
///
插入修改表数据
public string InsertORupdateData