private void uploadFile(string filename, string sid) { isupload = true; label4.Text = "开始上传..."; IPHostEntry host = Dns.GetHostByName("d.icodef.com"); IPAddress ip = host.AddressList[0]; m_ftc = new ftc(ip.ToString(), FtcCallBack);//10.127.134.51 m_ftc.SetFileId(long.Parse(sid)); m_ftc.SendFileMsg(filename); }
private void button1_Click(object sender, EventArgs e) { if (isupload) { MessageBox.Show("正在上传,请等待"); return; } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { string fName = openFileDialog.FileName; //先获取id if (listBox1.SelectedIndex < 0) { MessageBox.Show("未选择上传分区"); return; } sortItem tmpItem = (sortItem)listBox1.Items[listBox1.SelectedIndex]; string retData = Functions.HttpPost(Functions.URL + "/index/api/isUpload", "name=" + Functions.URLEncode(textBox1.Text) + "&filename=" + Functions.URLEncode(Path.GetFileName(fName)) + "&exp=" + Functions.URLEncode(textBox2.Text) + "&sort_id=" + tmpItem.ID + "&price=" + textBox3.Text + "&logo=" + Functions.URLEncode(m_image)); JObject jo = (JObject)JsonConvert.DeserializeObject(retData); string msg = jo["msg"].ToString(); string code = jo["code"].ToString(); if (code == "0") { retData = Functions.HttpPost(Functions.URL + "/index/api/applyUpload", "name=" + Functions.URLEncode(textBox1.Text) + "&filename=" + Functions.URLEncode(Path.GetFileName(fName)) + "&exp=" + Functions.URLEncode(textBox2.Text) + "&sort_id=" + tmpItem.ID + "&price=" + textBox3.Text + "&logo=" + Functions.URLEncode(m_image)); jo = (JObject)JsonConvert.DeserializeObject(retData); uploadFile(fName, jo["id"].ToString()); } else if (code == "-2") { DialogResult dr = MessageBox.Show("你有一个未完成的任务,是否先将未完成的任务上传?\n点击是将先上传之前的文件,否将上一个任务删除,直接进行新任务的上传", "提示", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { string filePath = Functions.ReadIni("sid_" + jo["sid"].ToString(), "filename"); if (!File.Exists(filePath)) { if (MessageBox.Show("在这台电脑上没有找到相应的上传记录,是否删除记录?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes) { Functions.HttpPost(Functions.URL + "/index/user/remove_upload?sid=" + jo["sid"].ToString()); } return; } isupload = true; label4.Text = "准备上传..."; IPHostEntry host = Dns.GetHostByName("d.icodef.com"); IPAddress ip = host.AddressList[0]; m_ftc = new ftc(ip.ToString(), FtcCallBack);//10.127.134.51 m_ftc.SetFileId(long.Parse(jo["sid"].ToString())); m_ftc.SendToSid(); } else { Functions.HttpPost(Functions.URL + "/index/user/remove_upload?sid=" + jo["sid"].ToString()); retData = Functions.HttpPost(Functions.URL + "/index/api/applyUpload", "name=" + Functions.URLEncode(textBox1.Text) + "&filename=" + Functions.URLEncode(Path.GetFileName(fName)) + "&exp=" + Functions.URLEncode(textBox2.Text) + "&sort_id=" + tmpItem.ID + "&price=" + textBox3.Text + "&logo=" + Functions.URLEncode(m_image)); jo = (JObject)JsonConvert.DeserializeObject(retData); uploadFile(fName, jo["id"].ToString()); } } else { MessageBox.Show(msg); } } }