/// <summary> /// 批量开户 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButton1_Click(object sender, EventArgs e) { BatchOpenAccount batchOpenAccount = BatchOpenAccount.GetBatchOpenAccount(async nums => await Task.Run(() => { this.lbl_showOpen.Text = "正在批量开户,请耐心等待......."; this.btn_opne.Enabled = false; this.toolStripButton1.Enabled = false; for (int i = 0; i < nums; i++) { this.isFlagByOpenAccount = false; this.secondsOpenAccount = 0; Tuple <string, string> infos = AutoCreateAnyCode.GetUserName1(); AccountUsers user = new AccountUsers { CellPhone = infos.Item2, Pwd = "111111", RealName = infos.Item1, BankCardNo = AutoCreateAnyCode.GetBankCardNo(), CredentialNo = AutoCreateAnyCode.GetCredentialNo(), UserMac = AutoCreateAnyCode.GetMacAddressByNetworkInformation(), CgCellPhone = AutoCreateAnyCode.GetCellPhone(), RigisterTime = DateTime.Now.ToString("yyyyMMdd HH:mm:ss") }; if (!this.jymService.CheckCellPhone(user.CellPhone).Result) { continue; } this.btn_opne.Enabled = false; user.RealName = user.RealName == "" ? AutoCreateAnyCode.GetUserName() : user.RealName; user.InviteBy = user.InviteBy == "" ? "22222" : user.InviteBy; user.CgCellPhone = user.CgCellPhone == "" ? AutoCreateAnyCode.GetCellPhone() : user.CgCellPhone; //注册认证 int i1 = i + 1; AccountUsers successAccountUsers = this.Register(user).Result; if (successAccountUsers != null) { //存管开户 bool result = this.bankPageCommon.OpenBankAccount(successAccountUsers, this.webBrowser_OpenAccount, () => { this.lbl_showOpen.Text = $"正在批量开户,请耐心等待....... 已经开户数量{i1}"; this.isFlagByOpenAccount = true; }).Result; } else { this.lbl_showOpen.Text = $"第{i1}个用户开户失败"; } while (!this.isFlagByOpenAccount) { Thread.Sleep(2000); this.secondsOpenAccount += 2000; if (this.secondsOpenAccount >= 35000) { this.lbl_showOpen.Text = $"第{i1}个用户开户失败"; break; } } } this.lbl_showOpen.Text = "批量开户结束"; this.btn_opne.Enabled = true; this.toolStripButton1.Enabled = true; })); batchOpenAccount.ShowDialog(); }
/// <summary> /// 点击开始注册 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button6_Click(object sender, EventArgs e) { try { this.lbl_msg.Text = string.Empty; this.txb_SuccessNums.Text = "0"; long totalNums = Convert.ToInt64(this.txb_Nums.Text.Trim()); if (totalNums == 0) { MessageBox.Show("请输入注册数量"); return; } this.btn_Submit.Enabled = false; this.lbl_msg.Text = "正在开始注册....."; List <Task> listTasks = new List <Task>(); List <long> listDatas = new List <long>(); for (int i = 1; i <= totalNums; i++) { listDatas.Add(i); } for (int i = 0; i < 3; i++) { Task task = Task.Run(async() => { //执行 while (listDatas.Count > 0) { long data = 0; lock (this.objLock) { if (listDatas.Count > 0) { data = listDatas[0]; listDatas.Remove(data); } } if (data == 0) { continue; } Tuple <string, string> infos = AutoCreateAnyCode.GetUserName1(); AccountUsers user = new AccountUsers { CellPhone = infos.Item2, Pwd = "111111", RealName = infos.Item1, BankCardNo = AutoCreateAnyCode.GetBankCardNo(), CredentialNo = AutoCreateAnyCode.GetCredentialNo(), UserMac = AutoCreateAnyCode.GetMacAddressByNetworkInformation(), CgCellPhone = AutoCreateAnyCode.GetCellPhone(), RigisterTime = DateTime.Now.ToString("yyyyMMdd HH:mm:ss") }; if (!this.jymService.CheckCellPhone(user.CellPhone).Result) { continue; } user.RealName = user.RealName == "" ? AutoCreateAnyCode.GetUserName() : user.RealName; user.InviteBy = user.InviteBy == "" ? "22222" : user.InviteBy; user.CgCellPhone = user.CgCellPhone == "" ? AutoCreateAnyCode.GetCellPhone() : user.CgCellPhone; //注册认证 AccountUsers successAccountUsers = await this.Register(user); if (successAccountUsers != null) { //成功 lock (this.objLock) { this.txb_SuccessNums.Text = (Convert.ToInt64(this.txb_SuccessNums.Text) + 1).ToString(); } } } }); listTasks.Add(task); } Task.WhenAll(listTasks); this.btn_Submit.Enabled = true; } catch (Exception exception) { this.btn_Submit.Enabled = true; this.lbl_msg.Text = exception.Message; } }