示例#1
0
        private void inportSmtpList(object o)
        {
            int totals = 0; int success = 0;

            WriteLog("");
            WriteLog("正在读取数据.....");
            IList <string> data = FileDirectory.FileRead(fileName, FileDirectory.FileEncoding(fileName));

            totals = data.Count;
            WriteLog("读取到:" + totals + " 行记录!");

            WriteLog("正在导入数据.....");
            int index = 1;
            int port  = 25;

            foreach (string str in data)
            {
                string[] list = str.Split(',');
                if (list.Length != 3)
                {
                    WriteLog("第" + index.ToString() + "行数据格式不正确:" + str);
                }
                else
                {
                    string smtp     = list[0].Trim();
                    string userName = list[1].Trim();

                    if (!IsSmtp(smtp))
                    {
                        WriteLog("第" + index.ToString() + "行Smtp服务器地址格式不正确:" + str);
                    }
                    else
                    {
                        if (SmtpListHelper.IsExistByID(smtp, port, userName))
                        {
                            WriteLog("第" + index.ToString() + "行数据已存在:" + str);
                        }
                        else
                        {
                            //bool isTrue = NetHelper.CheckSMTP(list[1], list[2], list[0]);
                            //if (isTrue) {
                            SmtpList info = new SmtpList();
                            info.SmtpServer = list[0];
                            info.UserName   = list[1];
                            info.SPassword  = list[2];
                            info.SmtpPort   = 25;
                            info.CreateTime = DateTime.Now.ToDateTime().ToDateTime();
                            SmtpListHelper.Insert(info);
                            success++;
                            //} else {
                            //    WriteLog("第" + index.ToString() + "行SMTP无法连接到服务器,请检查用户名和密码是否正确和账号是否被封:" + str);
                            //}
                        }
                    }
                }
                index++;
            }
            SmtpListHelper.ClearCacheAll();
            WriteLog("导入Smtp服务器列表完成:共 {0} 条记录,成功 {1} 条记录,失败 {2} 条记录!".FormatWith(totals, success, totals - success));
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtSmtpServer.Text))
            {
                MessageBox.Show("SMTP服务器不能为空", "系统提示");
                return;
            }
            if (string.IsNullOrEmpty(this.txtSmtpPort.Text))
            {
                MessageBox.Show("SMTP服务器端口不能为空", "系统提示");
                return;
            }
            if (string.IsNullOrEmpty(this.txtUserName.Text))
            {
                MessageBox.Show("登录用户名不能为空", "系统提示");
                return;
            }

            SmtpList info = new SmtpList();

            info.SmtpServer = this.txtSmtpServer.Text;
            info.SmtpPort   = this.txtSmtpPort.Text.ToInt(25);
            info.UserName   = this.txtUserName.Text;
            info.SPassword  = this.txtSPassword.Text;
            info.SSL        = this.checkBoxSSL.Checked;
            info.Status     = this.checkBoxStatus.Checked == true ? 0 : 1;

            //bool isTrue = NetHelper.CheckSMTP(info.UserName, info.SPassword, info.SmtpServer);
            //if (!isTrue) {
            //    MessageBox.Show("无法连接SMTP服务器,请检查用户名和密码是否正确和账号是否被封。", " 系统提示");
            //    return;
            //}

            DialogResult = System.Windows.Forms.DialogResult.OK;

            if (!smtp.IsNullEmpty() || SmtpListHelper.IsExistByID(info.SmtpServer, info.SmtpPort.Value, info.UserName))
            {
                SmtpListHelper.Update(info);
            }
            else
            {
                info.CreateTime = DateTime.Now.ToDateTime().ToDateTime();
                SmtpListHelper.Insert(info);
            }
            SmtpListHelper.ClearCacheAll();

            MessageBox.Show("保存数据成功!", " 系统提示");
            this.Close();
        }