private async void btn_update_Click(object sender, EventArgs e) { //chưa sửa if (txt_ip.Text.Replace(".", "_") == ip.ipAddress) { this.Close(); } //check IP ipCheck = Task.Run(() => ipConn.GetWithKey(txt_ip.Text.Replace(".", "_"))).Result; if (ipCheck != null) { MessageBox.Show("IP đã tồn tại!"); return; } this.Enabled = false; bool success = false; int loop = 0; do { if (loop == 10) { break; } try { //Xóa cái cũ await ipConn.Delete(ip.ipAddress); //Thêm cái mới ip.ipAddress = txt_ip.Text.Replace(".", "_"); await ipConn.Insert(ip); success = true; } catch { loop++; Thread.Sleep(2000); } } while (!success); if (!success) { MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))"); this.Enabled = true; } this.Enabled = true; this.Close(); }
private async void btn_addIP_Click(object sender, EventArgs e) { this.Enabled = false; bool success = false; int loop = 0; do { if (loop == 10) { break; } try { IPConnection ipConn = new IPConnection(); IP ip = new IP(); ip.ipAddress = txt_ip.Text.Replace(".", "_"); ip.availability = rb_availability_true.Checked; await ipConn.Insert(ip); success = true; loadIPWithWaitForm(); resetInputIP(); } catch { loop++; Thread.Sleep(2000); } } while (!success); if (!success) { MessageBox.Show("Đã thử " + loop + " lần mà *** đc :))"); this.Enabled = true; } this.Enabled = true; }