Ejemplo n.º 1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            btnStart.Enabled = false;
            string[] filelist = new string[listFile.Items.Count];
            for (UInt16 i = 0; i < listFile.Items.Count; i++)
            {
                filelist[i] = ((string)listFile.Items[i]);
            }
            Dictionary <string, string> stringDict = new Dictionary <string, string>();

            stringDict.Add("userName", txtName.Text);
            stringDict.Add("password", txtPassword.Text);
            //stringDict.Add("extension", "jpg");
            string[] result     = NetUL.httpUploadFile(txtURL.Text, filelist, stringDict);
            string   resultErr  = result[0];
            string   resultInfo = result[1];

            if (resultErr != null && resultErr.Length > 0)
            {
                MessageBox.Show(resultErr, "网络通信失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnStart.Enabled = true;
                return;
            }
            switch (resultInfo)
            {
            case "100":
                MessageBox.Show("上传成功", resultInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); break;

            case "101":
                MessageBox.Show("上传成功,原文件删除失败", resultInfo, MessageBoxButtons.OK, MessageBoxIcon.Information); break;

            case "200":
                MessageBox.Show("用户名或密码不正确", resultInfo, MessageBoxButtons.OK, MessageBoxIcon.Error); break;

            case "202":
                MessageBox.Show("创建文件失败", resultInfo, MessageBoxButtons.OK, MessageBoxIcon.Error); break;

            case "203":
                MessageBox.Show("保存文件失败", resultInfo, MessageBoxButtons.OK, MessageBoxIcon.Error); break;

            case "204":
                MessageBox.Show("解密失败", resultInfo, MessageBoxButtons.OK, MessageBoxIcon.Error); break;

            default:
                MessageBox.Show(resultInfo, "返回信息", MessageBoxButtons.OK, MessageBoxIcon.Information); break;
            }
            btnStart.Enabled = true;
        }
Ejemplo n.º 2
0
        static private void uploadThreadRun()
        {
            netuploadThreadWorking = true;
            string nowThreadID = threadID.ToString();

            printf("启动网络上载线程 " + nowThreadID + " ...", 0);
            foreach (string file in getTempFiles(encType))
            {
                printf("正在处理文件 " + file + " ...", 0);
                string[] extFileName = file.Split('.');
                extFileName[extFileName.Length - 1] = encKeyType;
                string kFile = string.Join(".", extFileName);
                if (File.Exists(kFile))
                {
                    string[] fileList = { file, kFile };
                    Dictionary <string, string> netArgv = new Dictionary <string, string>();
                    netArgv.Add("userName", uUsername);
                    netArgv.Add("password", uPassword);
                    netArgv.Add("extension", imgType);
                    string[] result     = NetUL.httpUploadFile(uURL, fileList, netArgv);
                    string   resultErr  = result[0];
                    string   resultInfo = result[1];
                    if (resultErr != null && resultErr.Length > 0)
                    {
                        printf(resultErr, 3);
                        return;
                    }
                    string msg = "";
                    switch (resultInfo)
                    {
                    case "100":
                        msg = "上传成功"; break;

                    case "101":
                        msg = "上传成功,原文件删除失败"; break;

                    case "200":
                        msg = "用户名或密码不正确"; break;

                    case "202":
                        msg = "创建文件失败"; break;

                    case "203":
                        msg = "保存文件失败"; break;

                    case "204":
                        msg = "解密失败"; break;

                    default:
                        msg = "返回信息"; break;
                    }
                    msg = resultInfo + msg;
                    printf(msg, 0);
                    printf("删除已上传数据文件 " + file + " ...", 0);
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    printf("删除已上传密钥文件 " + kFile + " ...", 0);
                    if (File.Exists(kFile))
                    {
                        File.Delete(kFile);
                    }
                }
                else if (File.Exists(file))
                {
                    File.Delete(file);
                }
                Thread.Sleep(workSleepTime);
            }
            printf("结束网络上载线程 " + nowThreadID + " 。", 0);
            netuploadThreadWorking = false;
        }