private void btnAdd_Click(object sender, EventArgs e) { try { if (!Regex.IsMatch(tbNewestVersion2.Text.Trim(), versionRegex)) { MessageBox.Show("最新版本号的格式必须是:数字.数字.数字"); return; } using (DbOperator dbOperator = new DbOperator(selectedConnection)) { string sql = string.Format("insert into version_config(version,must) values('{0}','{1}')", tbNewestVersion2.Text.Trim(), cbIsMust.Checked ? "yes" : "no"); dbOperator.ExecuteNonQuery(sql); sql = string.Format("update sign_transfer set version='{0}' where type=1", tbNewestVersion2.Text.Trim()); dbOperator.ExecuteNonQuery(sql); MessageBox.Show("添加成功!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void button1_Click(object sender, EventArgs e) { try { using (DbOperator dbOperator = new DbOperator(selectedConnection)) { List<string> addressConfigItems = GetAddressConfig(dbOperator); SetAddressConfigItems(addressConfigItems); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
List<string> GetAddressConfig(DbOperator dbOperator) { List<string> configItems = new List<string>(); string sql = "select sign,maxnum from sign_transfer where type=1"; DataSet ds = dbOperator.Execute(sql); DataRow firstRow = ds.Tables[0].Rows[0]; string sign = firstRow[0].ToString(); string maxnum = firstRow[1].ToString(); configItems.Add(sign); configItems.Add(maxnum); return configItems; }
private void btnChange_Click(object sender, EventArgs e) { #region Validate inputs if (string.IsNullOrEmpty(tbAddress.Text.Trim())) { MessageBox.Show("请输入下载地址"); return; } if (string.IsNullOrEmpty(tbMaxConnection.Text.Trim())) { MessageBox.Show("请输入最大下载链接数"); return; } if (cmbDownloadType.Text == "ftp") { if (!Regex.IsMatch(tbAddress.Text.Trim(), ftpRegex)) { MessageBox.Show(string.Format("下载地址请以'{0}'开头", ftpRegex)); return; } } if (cmbDownloadType.Text == "http") { if (!Regex.IsMatch(tbAddress.Text.Trim(), httpRegex)) { MessageBox.Show(string.Format("下载地址请以'{0}'开头", httpRegex)); return; } } int maxNum; string info = "最大下载链接数必须为一个大于0的整数"; if (int.TryParse(tbMaxConnection.Text.Trim(), out maxNum)) { if (maxNum < 1) { MessageBox.Show(info); return; } } else { MessageBox.Show(info); return; } #endregion string sign = cmbDownloadType.Text == "http" ? tbAddress.Text.Trim() : string.Format("{0}##{1}##{2}", tbAddress.Text.Trim(), tbFtpUsername.Text.Trim(), tbFtpPwd.Text.Trim()); string maxnum = tbMaxConnection.Text; string sql = string.Format("update sign_transfer set sign='{0}',maxnum='{1}' where type=1", sign, maxnum); try { using (DbOperator dbOperator = new DbOperator(selectedConnection)) { dbOperator.ExecuteNonQuery(sql); MessageBox.Show("修改成功!"); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }