Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 public HOST()
 {
     InitializeComponent();
     hddao = new HostDomainDao();
     htdao = new HostTypeDao();
     bandComb();
     tabControl1.SelectedIndex = 0;
     reflushTableEnvirment();
 }
Esempio n. 3
0
 private void bandComb()
 {
     htlist = htdao.fetchAll("select id,name from tbl_host_type");
     comboBox1.Items.Clear();
     comboBox2.Items.Clear();
     foreach (HostType ht in htlist)
     {
         comboBox1.Items.Add(HostTypeDao.formatItemByItem(ht));
         comboBox2.Items.Add(HostTypeDao.formatItemByItem(ht));
     }
 }
Esempio n. 4
0
        private void reflushTableHostDomain(int type)
        {
            dataGridView1.Rows.Clear();
            hdlist = hddao.fetchAll("select id,ip,domain,type from tbl_host_domain where type=" + type);
            foreach (HostDomain host in hdlist)
            {
                int index = dataGridView1.Rows.Add();
                dataGridView1.Rows[index].Cells["id"].Value     = host.Id;
                dataGridView1.Rows[index].Cells["ip"].Value     = host.Ip;
                dataGridView1.Rows[index].Cells["domain"].Value = host.Domain;

                ht = htdao.fetch("select id,name from tbl_host_type where id=" + host.Type);
                dataGridView1.Rows[index].Cells["type"].Value = HostTypeDao.formatItemByItem(ht);
            }
        }
Esempio n. 5
0
        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); }
        }
Esempio n. 6
0
        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); }
        }
Esempio n. 7
0
        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); }
        }