private void btnAddUser_ItemClick(object sender, ItemClickEventArgs e) { string name = ""; string result = ""; int min, max; if (!barEditItemUserMin.EditValue.ToString().Equals("") && !barEditItemUserMax.EditValue.ToString().Equals("")) { if (!Regex.IsMatch(barEditItemUserMin.EditValue.ToString(), @"^\d+$") || !Regex.IsMatch(barEditItemUserMax.EditValue.ToString(), @"^\d+$")) { MessageBox.Show("Bạn đã nhập sai định dạng min, max.\n\rChỉ được nhập số tự nhiên", "Thông báo"); return; } min = Int32.Parse(barEditItemUserMin.EditValue.ToString()); max = Int32.Parse(barEditItemUserMax.EditValue.ToString()); } else { min = 0; max = 0; } if (min == 0 && max == 0) { try { name = barEditItemUsername.EditValue.ToString(); result = RunCmd.createUser(name, name); } catch { MessageBox.Show("Vui lòng nhập tên User muốn tạo!!", "Thông báo"); return; } } else { for (int i = min; i <= max; i++) { try { name = barEditItemUsername.EditValue.ToString(); result += RunCmd.createUser(name + i, name + i); } catch (Exception) { result += RunCmd.createUser(i.ToString(), i.ToString()); } } } MessageBox.Show(result); }
private void btnAddUser_ItemClick(object sender, ItemClickEventArgs e) { string name = ""; int min, max, numError = 0; if (!barEditItemUserMin.EditValue.ToString().Equals("") || !barEditItemUserMax.EditValue.ToString().Equals("")) { if (!Regex.IsMatch(barEditItemUserMin.EditValue.ToString(), @"^\d+$") || !Regex.IsMatch(barEditItemUserMax.EditValue.ToString(), @"^\d+$")) { ShowNotification("Bạn đã nhập sai định dạng min, max. Chỉ được nhập số tự nhiên", true); return; } min = Int32.Parse(barEditItemUserMin.EditValue.ToString()); max = Int32.Parse(barEditItemUserMax.EditValue.ToString()); } else { min = 0; max = 0; } if (min == 0 && max == 0) { try { name = barEditItemUsername.EditValue.ToString(); if (RunCmd.createUser(name, name)) { ShowNotification("Thành công", false); } else { ShowNotification("Thất bại", true); } } catch { ShowNotification("Vui lòng nhập tên User muốn thêm", true); return; } } else { for (int i = min; i <= max; i++) { try { name = barEditItemUsername.EditValue.ToString(); if (RunCmd.createUser(name + i, name + i) == false) { numError++; } } catch (Exception) { ShowNotification("Vui lòng nhập tên User muốn thêm", true); break; } if (i >= max) { if (numError != 0) { ShowNotification("Thất bại " + numError + " User", true); } else { ShowNotification("Thành công", false); } } } } }