private int importHostDomain(string filename) { int j = 0; int type = HostTypeDao.getIdByStr(comboBox1.SelectedItem.ToString()); string[] lines = File.ReadAllLines(filename, Encoding.Default); foreach (string line in lines) { string[] fields = line.Trim().Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries); if (!HostDomainDao.checkIp(fields[0]) || !HostDomainDao.checkDomain(fields[1])) { continue; } try { int i = hddao.add(new HostDomain() { Ip = fields[0].Trim(), Domain = fields[1].Trim(), Type = type }); if (i > 0) { j++; } } catch (Exception ex) { string s = ex.Message; } } reflushTableHostDomain(type); return(j); }
private void deleteTableHostDomain(DataGridViewCellEventArgs e) { string sql = "delete from tbl_host_domain where id={0}"; sql = String.Format(sql, dataGridView1[0, e.RowIndex].Value.ToString()); try { if (hddao.ExecuteNonQuery(sql) == 0) { MessageBox.Show("删除失败!"); return; } int type = HostTypeDao.getIdByStr(comboBox1.SelectedItem.ToString()); reflushTableHostDomain(type); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void insertTableHostDomain() { string sql = "insert into tbl_host_domain(id,ip,domain,type) values(null,'{0}','{1}',{2})"; int type = HostTypeDao.getIdByStr(comboBox2.SelectedItem.ToString()); sql = String.Format(sql, textBox1.Text.Trim(), textBox2.Text.Trim(), type.ToString()); try { if (hddao.ExecuteNonQuery(sql) == 0) { MessageBox.Show("添加失败!"); return; } if (comboBox2.SelectedIndex != -1 && comboBox1.SelectedIndex != -1 && comboBox1.SelectedItem.ToString().Trim() == comboBox2.SelectedItem.ToString().Trim()) { reflushTableHostDomain(type); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void updateTableHostDomain() { string sql = "update tbl_host_domain set ip='{0}',domain='{1}',type={2} where id={3}"; int type = HostTypeDao.getIdByStr(comboBox2.SelectedItem.ToString()); sql = String.Format(sql, textBox1.Text.Trim(), textBox2.Text.Trim(), type.ToString(), label6.Text.Trim()); try { if (hddao.ExecuteNonQuery(sql) == 0) { MessageBox.Show("添加失败!"); return; } label6.Text = "empty"; textBox1.Text = ""; textBox2.Text = ""; comboBox2.SelectedIndex = -1; tabControl1.SelectedIndex = 0; button1.Text = "新增"; tabControl1.TabPages[1].Text = "新增绑定"; reflushTableHostDomain(type); } catch (Exception ex) { MessageBox.Show(ex.Message); } }