public static void Delete(string[] args, bool exit = false) { if (args.Length == 2) { args = (string.Join(" ", args) + " *").Split(" "); } if (args[1].Trim().ToLower() == "smtp") { WriteLog("delete(d) smtp * 删除SMTP数据"); } if (args[1].Trim().ToLower() == "email") { WriteLog("delete(d) email * 删除邮箱数据"); } WriteLog("==============================================================================="); if (args[1].Trim().ToLower() == "smtp") { args = string.Join(" ", args, 2, args.Length - 2).Split(' '); int len = 0; if (args.Length == 1 && args [0] == "*") { len = new SQL().Delete(SmtpList._).ToExec(); } else { foreach (string s in args) { string[] ss = s.Split(','); if (ss.Length != 3) { continue; } len += SmtpListHelper.DeleteByID(ss[0], ss[1].ToInt(25), ss[2]) ? 1 : 0; } } WriteLog("删除影响行数:{0}", len); SmtpListHelper.ClearCacheAll(); } else if (args[1].Trim().ToLower() == "email") { args = string.Join(" ", args, 2, args.Length - 2).Split(' '); int len = 0; if (args.Length == 1 && args [0] == "*") { len = new SQL().Delete(EmailList._).ToExec(); } else { foreach (string s in args) { len += EmailListHelper.DeleteByID(s) ? 1 : 0; } } WriteLog("删除影响行数:{0}", len); EmailListHelper.ClearCacheAll(); } WriteLog("END"); Input(exit); }
private void mnuDelete_Click(object sender, EventArgs e) { switch (type) { case 1: if (listView1.CheckedItems.Count == 0) { MessageBox.Show("请选择你要删除的记录!", " 系统提示"); return; } if (MessageBox.Show("确认要删除选中的记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { IList <string> data = new List <string>(); foreach (ListViewItem item in listView1.Items) { if (item.Checked) { data.Add(item.Tag.ToString()); } } int rows = new SQL().Database("ConnString").Delete(EmailList._) .Where(new Where() .And(EmailList._EmailAddress, "('" + data.Select(p => p.SafeSql()).Join("','") + "')", Operator.In) ).ToExec(); EmailListHelper.ClearCacheAll(); BindData(); } break; case 2: if (listView1.CheckedItems.Count == 0) { MessageBox.Show("请选择你要删除的记录!", " 系统提示"); return; } if (MessageBox.Show("确认要删除选中的记录吗?", " 系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { foreach (ListViewItem item in listView1.Items) { if (item.Checked) { string[] list = item.Tag.ToString().Split(','); string id = list[0].ToString(); int port = list[1].ToString().ToInt(25); string username = list[2].ToString(); string password = list[3].ToString(); SmtpListHelper.DeleteByID(id, port, username, password); } } SmtpListHelper.ClearCacheAll(); BindData(); } break; } }