/// <summary> /// 开始发送文件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void bt_SendFile_Click(object sender, EventArgs e) { if (System.IO.File.Exists(Text_FilePath.Text)) { //FileSendThread_Class _SendFile = new FileSendThread_Class(); D_StartSendFIle my_D_StartSendFIle = new D_StartSendFIle(StartSendFile); //调用文件发送函数 my_D_StartSendFIle.BeginInvoke(true, Text_ServerIP.Text, Text_ServerPort.Value.ToString(), Text_FilePath.Text, Text_PackSize.Value.ToString(), Text_LastPackSize.Text, Text_PackCount.Text.Trim().ToString(), Text_FileName.Text, Text_FileSize.Text, null, null); bt_SendFile.Enabled = false; } else { MyInvoke _myInvoke = new MyInvoke(UpMsgLog); BeginInvoke(_myInvoke, new object[] { "ERROR:" + Text_FilePath.Text + "文件不存在!" }); } }
private void timer1_Tick(object sender, EventArgs e) { //获取计算机当前时间 int intHour = DateTime.Now.Hour; int intMinute = DateTime.Now.Minute; int intSecond = DateTime.Now.Second; //获取设定的时间 int _intHour = Convert.ToInt32(Text_Time_Hour.Value); int _intMinute = Convert.ToInt32(Text_Time_Minute.Value); int _intSecond = Convert.ToInt32(Text_Time_Second.Value); if (intHour == _intHour && intMinute == _intMinute && intSecond == _intSecond) { string XmlFilePath = Application.StartupPath + "\\FilePath.xml"; if (System.IO.File.Exists(XmlFilePath)) { //创建XML实例 XmlDocument xmlDoc = new XmlDocument(); //加载XML文件 xmlDoc.Load(XmlFilePath); //选择一个匹配的节点 XmlNode xn = xmlDoc.SelectSingleNode("FileLists"); //获取这个节点的所有子节点 XmlNodeList xnl = xn.ChildNodes; string[,] datalist = new string[xnl.Count, 2]; //循环读取所有子节点,并显示节点的信息 foreach (XmlNode xnf in xnl) { XmlElement xe = (XmlElement)xnf; //想ListView中添加数据 //ListViewItem p = new ListViewItem(); //p = new ListViewItem(new string[] { xe.GetAttribute("FileName"), xe.GetAttribute("FilePath") }); if (System.IO.File.Exists(xe.GetAttribute("FilePath"))) { System.IO.FileInfo fi = new System.IO.FileInfo(xe.GetAttribute("FilePath")); //文件包数量 string tmp_BagCount = Convert.ToInt32(fi.Length / (long)Text_PackSize.Value).ToString(); //最后一个包的大小 string tmp_LastBagSize = (fi.Length - Convert.ToInt32(tmp_BagCount) * (long)(Text_PackSize.Value)).ToString(); D_StartSendFIle my_D_StartSendFIle = new D_StartSendFIle(StartSendFile); my_D_StartSendFIle.BeginInvoke( false, Text_ServerIP.Text, Text_ServerPort.Value.ToString(), xe.GetAttribute("FilePath"), Text_PackSize.Value.ToString(), tmp_LastBagSize, tmp_BagCount, xe.GetAttribute("FileName"), fi.Length.ToString(), null, null ); } else { MyInvoke _myInvoke = new MyInvoke(UpMsgLog); BeginInvoke(_myInvoke, new object[] { "ERROR:" + xe.GetAttribute("FilePath") + "文件不存在!" }); } } } } }