AfterCheck

  1. /// <summary>
  2. /// 树勾选
  3. /// </summary>
  4. /// <param name="sender"></param>
  5. /// <param name="e"></param>
  6. private void tvCourse_AfterCheck(object sender, TreeViewEventArgs e)
  7. {
  8. if (e.Action ==TreeViewAction.ByMouse)
  9. {
  10. if (e.Node.Checked)
  11. {
  12. SetChildNode(e.Node, true);
  13. if (null!= e.Node.Parent)
  14. {
  15. SetParentNode(e.Node, true);
  16. }
  17. //获取选中节点值
  18. lstChapterIds.Add(e.Node.Name);
  19. this.btnDelRes.Enabled = true;
  20. }
  21. else
  22. {
  23. //取消节点选中状态之后,取消所有父节点的选中状态
  24. SetChildNode(e.Node, false);
  25. //如果节点存在父节点,取消父节点的选中状态
  26. if (e.Node.Parent != null)
  27. {
  28. SetParentNode(e.Node, false);
  29. }
  30. //获取选中节点值
  31. if (lstChapterIds.Contains(e.Node.Name))
  32. {
  33. lstChapterIds.Remove(e.Node.Name);
  34. if (!lstChapterIds.Any())
  35. {
  36. this.btnDelRes.Enabled = false;
  37. }
  38. }
  39. }
  40.  
  41. }
  42. }

AfterCheck

设置节点

  1. /// <summary>
  2. /// 查找根节点
  3. /// </summary>
  4. /// <param name="node">节点node</param>
  5. /// <returns></returns>
  6. private TreeNode FindParentNode(TreeNode node)
  7. {
  8. if (node.Parent == null)
  9. {
  10. return node;
  11. }
  12. else
  13. {
  14. return FindParentNode(node);
  15. }
  16. }
  17.  
  18. /// <summary>
  19. /// 设置父节点
  20. /// </summary>
  21. /// <param name="node">当前节点</param>
  22. /// <param name="state">状态</param>
  23. private void SetParentNode(TreeNode node, bool state)
  24. {
  25. TreeNode pNode = node.Parent;
  26. if (null != pNode)
  27. {
  28. pNode.Checked = state;
  29. bool flag = false;
  30. foreach (TreeNode currNode in pNode.Nodes)
  31. {
  32. if (!currNode.Checked) //控制父节点全选,父节点选中去掉!
  33. {
  34. flag = false;
  35. pNode.Checked = flag;
  36. break;
  37. }
  38. //SetParentNode(item, state);
  39. }
  40. if (pNode.Checked )
  41. {
  42. //获取选中节点值
  43. lstChapterIds.Add(pNode.Name);
  44. }
  45. else
  46. {
  47. if (lstChapterIds.Contains(pNode.Name))
  48. {
  49. lstChapterIds.Remove(pNode.Name);
  50. }
  51. }
  52. SetParentNode(pNode, flag);
  53.  
  54. }
  55. }
  56. /// <summary>
  57. /// 设置子节点
  58. /// </summary>
  59. /// <param name="node">当前节点</param>
  60. /// <param name="state">状态</param>
  61. private void SetChildNode(TreeNode node, bool state)
  62. {
  63. TreeNodeCollection tncNodes = node.Nodes;
  64. if (tncNodes.Count>)
  65. {
  66. foreach (TreeNode currNode in tncNodes)
  67. {
  68. currNode.Checked = state;
  69. if (currNode.Checked)
  70. {
  71. //获取选中节点值
  72. lstChapterIds.Add(currNode.Name);
  73. }
  74. else
  75. {
  76. if (lstChapterIds.Contains(currNode.Name))
  77. {
  78. lstChapterIds.Remove(currNode.Name);
  79. }
  80. }
  81.  
  82. SetChildNode(currNode, state);
  83. }
  84. }
  85. }

程序只开一个:program.cs

  1. bool createdNew = false;
  2. System.Threading.Mutex instance = new System.Threading.Mutex(true, Application.ProductName, out createdNew);
  3. if (createdNew)
  4. {
  5. //...........code
  6. instance.ReleaseMutex();
  7. }
  8. else
  9. {
  10. MessageBox.Show("该程序已经在运行!", Application.ProductName,MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  11. Application.Exit();
  12. }

委托 不同线程间访问控件

  1. private delegate void UploadPro(int mProgre);
  2.  
  3. private event UploadPro UploadProEvent;
  4.  
  5. UploadProEvent +=ResourceManage_UploadProEvent;
  6.  
  7. void ResourceManage_UploadProEvent(int mProgree)
  8. {
  9.  
  10.   //......
  11.  
  12. }
  13.  
  14. var thread = new Thread(new ThreadStart(method));
  15. thread.Start();

this.Invoke(UploadProEvent,currentPro);

解压缩 文件

  1. ZipInputStream inputStream = new ZipInputStream(File.OpenRead(strFilePath));
  2. ZipEntry theEntry;
  3. //读取文件名
  4. List<string> fileNameList = new List<string>();
  5. while ((theEntry = inputStream.GetNextEntry()) != null)
  6. {
  7. totalSize += theEntry.UncompressedSize;
  8. string templateName = theEntry.FileName;
  9. string fileName = Path.GetFileName(templateName);
  10. if (!string.IsNullOrEmpty(fileName))
  11. fileNameList.Add(fileName);
  12. }
  13. inputStream.Close();
  14.  
  15. #region 解压文件
  16.  
  17. inputStream = new ZipInputStream(File.OpenRead(filePath));
  18. //long totalSize = inputStream.Length;
  19. long currentSize = ;
  20. int currentPro = ;
  21. ZipEntry theEntry;
  22. ZipFile zf = ZipFile.Read(filePath);
  23. //以文件流来解压所有文件,同时计算进度
  24. while ((theEntry = inputStream.GetNextEntry()) != null)
  25. {
  26. //totalSize += theEntry.UncompressedSize;
  27. //long totalSize = theEntry.UncompressedSize;
  28. //destPath += "/";
  29. //string templateName = theEntry.FileName;
  30. //string fileName = Path.GetFileName(templateName);
  31. ////string dir = Path.GetDirectoryName(templateName);
  32. //string dir = templateName;
  33. //if (!dir.Contains("\\") && string.IsNullOrEmpty(fileName))
  34. //{
  35. // continue;
  36. //}
  37. ////截取目录文件夹
  38. //if (dir.Contains("\\"))
  39. // dir = dir.Substring(dir.IndexOf("\\") + 1, dir.Length - dir.IndexOf("\\") - 1);
  40.  
  41. //if (templateName.Length == (dir + "/" + fileName).Length) dir = "";
  42.  
  43. ////theEntry.IsDirectory 是否目录
  44.  
  45. //string path = Path.GetDirectoryName(destPath) + "/" + dir + "/";
  46. ////Path.GetDirectoryName(baseDir) + "/";//
  47. //if (!Directory.Exists(path))
  48. // Directory.CreateDirectory(path);
  49.  
  50. string strFilePath = string.Empty;
  51. string templateName = theEntry.FileName;
  52. if (!templateName.Contains("\\"))
  53. {
  54. //文件
  55. strFilePath = destPath + "\\" + theEntry.FileName;
  56. }
  57. else
  58. {
  59. //文件夹里文件
  60. strFilePath = destPath + theEntry.FileName;
  61. }
  62. if (!Directory.Exists(Path.GetDirectoryName(strFilePath)))
  63. {
  64. Directory.CreateDirectory(Path.GetDirectoryName(strFilePath));
  65. }
  66. string fileName = Path.GetFileName(templateName);
  67. if (fileName != String.Empty)
  68. {
  69. FileStream streamWriter = File.OpenWrite(strFilePath); //解压文件到指定的目录
  70. int size = ;
  71. byte[] data = new byte[];
  72. try
  73. {
  74. while (true)
  75. {
  76. size = inputStream.Read(data, , data.Length);
  77. if (size > )
  78. {
  79. streamWriter.Write(data, , size);
  80. currentSize += size;
  81. }
  82. else
  83. {
  84. break;
  85. }
  86. currentPro = Convert.ToInt32( * currentSize / totalSize);
  87.  
  88. this.Invoke(UploadProEvent,currentPro);
  89.  
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. LogHelper.Error(this.GetType(), ex);
  95. this.Invoke(UploadProEvent, -); //-1 导入失败
  96. }
  97. finally
  98. {
  99. streamWriter.Close();
  100. }
  101. }
  102.  
  103. }
  104. inputStream.Close();
  105.  
  106. #endregion

检查指导文件盘符,获取空间大盘符

  1. /// <summary>
  2. /// 检查指导盘符剩余空间
  3. /// </summary>
  4. /// <param name="str_HardDiskName"></param>
  5. /// <returns></returns>
  6. public static long GetHardDiskFreeSpace(string str_HardDiskName)
  7. {
  8. if (string.IsNullOrEmpty(str_HardDiskName)) return ;
  9.  
  10. long freeSpace = new long();
  11. System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
  12. foreach (System.IO.DriveInfo drive in drives)
  13. {
  14. if (drive.Name == str_HardDiskName)
  15. {
  16. freeSpace = drive.TotalFreeSpace;
  17. }
  18. }
  19. return freeSpace;
  20. }
  21.  
  22. /// <summary>
  23. /// 找出当前客户端剩余空间最大盘符
  24. /// </summary>
  25. /// <returns></returns>
  26. public static Dictionary<string, long> GetSystemDirtory()
  27. {
  28. Dictionary<string, long> freeSpace = new Dictionary<string, long>();
  29. DriveInfo[] drives = DriveInfo.GetDrives();
  30. foreach (DriveInfo drive in drives)
  31. {
  32. if (drive.DriveType == DriveType.Fixed)
  33. freeSpace.Add(drive.Name, drive.TotalFreeSpace);
  34. }
  35.  
  36. string hardDiskName = freeSpace.ToArray().Max(x => x.Key);
  37. long hardDiskSize = freeSpace.ToArray().Max(x => x.Value);
  38.  
  39. freeSpace.Clear();
  40. freeSpace.Add(hardDiskName, hardDiskSize);
  41.  
  42. return freeSpace;
  43. }

获取MAC地址

  1. /// <summary>
  2. /// 获取网卡MAC地址
  3. /// </summary>
  4. /// <returns></returns>
  5. public static string GetNetCardMAC()
  6. {
  7. try
  8. {
  9. string stringMAC = "";
  10. ManagementClass MC = new ManagementClass("Win32_NetworkAdapterConfiguration");
  11. ManagementObjectCollection MOC = MC.GetInstances();
  12. foreach (ManagementObject MO in MOC)
  13. {
  14. if ((bool)MO["IPEnabled"] == true)
  15. {
  16. stringMAC += MO["MACAddress"].ToString();
  17.  
  18. }
  19. }
  20. return stringMAC;
  21. }
  22. catch
  23. {
  24. return "";
  25. }
  26. }

获取远程文件信息

  1. /// <summary>
  2. /// 获取远程文件信息
  3. /// </summary>
  4. /// <param name="url"></param>
  5. /// <returns></returns>
  6. public static RemoteFileInfo GetFileInfo(string url)
  7. {
  8. RemoteFileInfo result = new RemoteFileInfo();
  9.  
  10. try
  11. {
  12. GC.Collect();
  13. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  14. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  15. result.MimeType = response.ContentType;
  16. result.LastModified = response.LastModified;
  17. result.FileSize = response.ContentLength;
  18. result.AcceptRanges = String.Compare(response.Headers["Accept-Ranges"], "bytes", true) == ;
  19.  
  20. //关闭连接
  21. response.Close();
  22. request.KeepAlive = false;
  23. }
  24. catch (Exception ex)
  25. {
  26. throw;
  27. }
  28.  
  29. return result;
  30. }

错误日志

  1. #region 日志方法
  2. public void LogTest(string str)
  3. {
  4. string path = System.IO.Directory.GetCurrentDirectory() + "\\log\\";
  5. if (!Directory.Exists(path))
  6. {
  7. DirectoryInfo directorylnfo = new DirectoryInfo(path);
  8. directorylnfo.Create();
  9. }
  10. string dt = "\r\n时间:" + DateTime.Now.ToString("yyyymmddhhmmss") + "\r\n内容:" + str;
  11. int len = dt.Length;
  12. byte[] inputByts = new byte[len];
  13. inputByts = Encoding.GetEncoding("utf-8").GetBytes(dt);
  14. System.IO.FileStream fs = new System.IO.FileStream(path + "log.txt", System.IO.FileMode.OpenOrCreate);
  15. fs.Seek(, System.IO.SeekOrigin.End);
  16. fs.Write(inputByts, , inputByts.Length);
  17. fs.Close();//关闭流
  18. }
  19. #endregion
  1. /// <summary>
  2. /// 错误日志
  3. /// </summary>
  4. /// <param name="errorMsg"></param>
  5. public static void WriteLog(Exception ex)
  6. {
  7. string logPath = GetResDir() + "/log";
  8. string message = string.Format("\r\n\r\n异常时间:{0} \r\n错误源:{1} \r\n异常信息:{2}",
  9. DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss,fff"), ex.Source, ex.Message);
  10. File.AppendAllText(logPath + DateTime.Now.ToString("yyyy.MM.dd") + ".log", message, Encoding.UTF8);
  11. }

启动停止服务

  1. /// <summary>
  2. /// 启动服务sc.DisplayName
  3. /// </summary>
  4. /// <param name="serverName"></param>
  5. public static void StartService(string serverName)
  6. {
  7. if (string.IsNullOrEmpty(serverName)) return;
  8. ServiceController sc = new ServiceController(serverName);
  9. if (sc.DisplayName != null)
  10. {
  11. if (sc.Status == ServiceControllerStatus.Stopped) sc.Start();
  12. }
  13. }
  14.  
  15. /// <summary>
  16. /// 停止服务
  17. /// </summary>
  18. /// <param name="serverName"></param>
  19. public static void StopService(string serverName)
  20. {
  21. if (string.IsNullOrEmpty(serverName)) return;
  22. ServiceController sc = new ServiceController(serverName);
  23. if (sc.DisplayName != null) {
  24. if (sc.Status == ServiceControllerStatus.Running) sc.Stop();
  25. }
  26. }

插入修改表数据

  1. public string InsertORupdateData<T>(List<T> _list, string dtName,string columnName)
  2. {
  3. StringBuilder sbInsert = new StringBuilder();
  4.  
  5. ArrayList list = new ArrayList();
  6. try
  7. {
  8. string sqlstr = "";
  9. if (_list != null && _list.Count > )
  10. {
  11.  
  12. System.Reflection.PropertyInfo[] p = _list[].GetType().GetProperties();
  13. int length = ;
  14. string values = "";
  15.  
  16. for (int i = ; i < _list.Count; i++)
  17. {
  18. string sbUpdateSql = "";
  19. int count = ;
  20. string upwh = "";
  21. length = ;
  22. //通过反射获取list中的字段
  23. foreach (System.Reflection.PropertyInfo pi in p)
  24. {
  25.  
  26. string cName = pi.Name;
  27. string cValue = (pi.GetValue(_list[i], null) == null
  28. ? ""
  29. : (pi.GetValue(_list[i], null)).ToString().Replace("'", "")); //替换 '语法错误的
  30.  
  31. if (cName.ToLower() == columnName.ToLower())
  32. {
  33. string sql = "select count(0) from " + dtName + " where " + columnName + "='"+cValue+"'";
  34. upwh = " where " + columnName + "='" + cValue + "'";
  35. count = ExcelHelper.GetScalar(sql);
  36. }
  37.  
  38. if (length == )
  39. {
  40. sqlstr = "INSERT INTO " + dtName + " (";
  41. values = "(";
  42. sbUpdateSql+="update " + dtName + " set ";
  43. }
  44. length += ;
  45. if (length < p.Length)
  46. {
  47. sbUpdateSql += cName + "= '" + cValue +"',";
  48. sqlstr += cName + ",";
  49. values += "'" + cValue + "',";
  50. }
  51. else
  52. {
  53. sbUpdateSql += cName + "= '" + cValue + "'";
  54. sqlstr += cName + ") Values";
  55. values += "'" + cValue + "'); ";
  56.  
  57. if (count > )
  58. {
  59. sqlstr = sbUpdateSql + upwh;
  60. values = "";
  61. }
  62. }
  63. }
  64. sqlstr += values;
  65. list.Add(sqlstr);
  66. }
  67. }
  68. //for (int i = 0; i < list.Count; i++)
  69. //{
  70. // ArrayList arrList = new ArrayList();
  71. // arrList.Add(list[i]);
  72. // var result = AccessDbHelper.ExecuteSqlTran(arrList);
  73. //}
  74. //string str = string.Join("", list.ToArray());
  75. var result = AccessDbHelper.ExecuteSqlTran(list);
  76. return "success";
  77. }
  78. catch (Exception err)
  79. {
  80. LogTest(err.ToString());
  81. return err.ToString();
  82. }
  83.  
  84. }

winfrom C#树勾选等的更多相关文章

  1. winfrom 树勾选

    树勾选 /// <summary> /// 树勾选 /// </summary> /// <param name="sender"></p ...

  2. Ext.js中树勾选的四种操作

    最近在做控件优化的时候产品提了一个需求,对树的勾选要满足四种勾选方案: 1.点击一次根节点,当根节点和子节点均未选中的情况下,根节点和子节点全都选中. 2.第二次点击根节点,当根节点和部分或全部子节点 ...

  3. Ext树控件第一次勾选父节点子节点没选中

    项目中同事提出了这样一个bug 问题: 第一次勾选父节点子节点竟然没选中,逆天了啊 初步分析: 可能是之前代码的逻辑错误造成的,随进入调试阶段... 调试中发现该参数为空(原来写代码的也太没素质了), ...

  4. Extjs改变树节点的勾选状态

    Extjs改变树节点的勾选状态 今天系统中有处地方需要一个功能点击一个按钮后将树节点前的复选框去掉,变成没有选择的状态.网上搜索了半天,然后自己查查API,终于找到解决办法了,下面把方法贴出来. 在E ...

  5. ztree学习---将默认勾选的展开

    这里只给出前台页面上的代码,数据可以从后台获取,注意,在封装数据的时候,注意:Id(节点的id,可以是数字也可以是字符串) , pid(父亲节点的id) , name(节点名称)不能少 . html页 ...

  6. 解决jquery操作checkbox全选全不选无法勾选问题

    最近在学习中使用jquery操作checkbox,使用下面方法进行全选.反选:$("input[name='checkbox']").attr("checked" ...

  7. 使用递归方法遍历TreeView的节点如配置则勾选

    自己在网上找了一段时间都没有找到取自数据库的值与TreeView中的节点值进行对比如匹配则勾选中CheckBox的资料,后面自己写了一个递归方法实现,现在记录起来以备需要时使用.在没写这递归方法前如果 ...

  8. Unity关于脚本前面的勾选框

    今天做项目时需要在某个事件条件下禁用某个脚本,但是突然发现这个脚本前面没有勾选框,,,就像这样 网上搜了下,原来是需要在脚本中加上void Start()方法,即使这个方法里什么都没有 void St ...

  9. zTree默认勾选指定ID并执行事件

    try { var arrs = $('#subjectClassID').val().split(","); var treeObj = $.fn.zTree.getZTreeO ...

随机推荐

  1. PL/0语言词法分析器

    前言:关于词法分析的基础知识的介绍可以看一下这篇博客,我再累述估计也不会有这篇讲的清楚QAQ. https://www.cnblogs.com/yanlingyin/archive/2012/04/1 ...

  2. 基于vue框架项目开发过程中遇到的问题总结(三)

    这次遇到的一个问题困扰了我很久很久,大致就是vue路由的addRoutes方法的使用,每次在调用了这个之后router对象中并没有将路由添加进去,接下来,我一步一步的分析原因及解决方法(个人见解,仅供 ...

  3. 【bzoj4939】【YNOI2016】掉进兔子洞(莫队)

    题目描述 您正在打galgame,然后突然发现您今天太颓了,于是想写个数据结构题练练手: 一个长为 n 的序列 a. 有 m 个询问,每次询问三个区间,把三个区间中同时出现的数一个一个删掉,问最后三个 ...

  4. P2948 [USACO09OPEN]滑雪课Ski Lessons

    题意:Bessie去滑雪,限时T,滑雪场有S节课 每节课开始于$m_i$,长度为$l_i$,可以将Bessie的能力值变成$a_i$(注意是变成不是增加) 有n个滑雪坡,去滑雪需要$c_i$的能力,并 ...

  5. NOIP后省选集训前文化课划水记

    划水划了一个多月,文化课没啥长进还他妈累死了...--ghj1222 11.11(NOIP Day2) 师傅开车开得很快,晚上8:00多就到了二狱 晚上听毒瘤班主任swh讲了半节语文,我:黑人问号.j ...

  6. matplotlib类

    1.plt.subplot 在matplotlib下,一个Figure对象可以包含多个子图(Axes),可以使用subplot()快速绘制,其调用形式如下:subplot(numRows, numCo ...

  7. 【转】C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉

    http://www.cnblogs.com/summer_adai/archive/2013/04/26/3045261.html

  8. 江西财经大学第一届程序设计竞赛 F

    链接:https://www.nowcoder.com/acm/contest/115/F来源:牛客网 题目描述 对于方程 2018 * x ^ 4 + 21 * x + 5 * x ^ 3 + 5 ...

  9. 兼容IE,chrome,ff的设为首页、加入收藏及保存到桌面

    // JavaScript Document// 加入收藏 < a onclick="AddFavorite(window.location,document.title)" ...

  10. day14 面向对象

    . 面向对象和面向过程 .面向过程:核心是过程,是流水线 优缺点: .流程化,编写简单 .可扩展性差 .面向对象:核心是对象(对象:具有相同属性和动作的结合体) 优缺点: .可扩展行强 .复杂度高于面 ...