Exemplo n.º 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Trim().Length == 0 || textBox2.Text.Trim().Length == 0 || comboBox2.SelectedIndex == -1)
     {
         return;
     }
     if (!HostDomainDao.checkIp(textBox1.Text.Trim()))
     {
         MessageBox.Show("【ip地址】格式有误!");
         return;
     }
     if (!HostDomainDao.checkDomain(textBox2.Text.Trim()))
     {
         MessageBox.Show("【域名】格式有误!");
         return;
     }
     if (Regex.IsMatch(label6.Text.Trim(), @"^\d+$"))
     {
         updateTableHostDomain();
     }
     else if (label5.Text.Trim() == "empty")
     {
         insertTableHostDomain();
     }
 }
Exemplo n.º 2
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);
        }