Пример #1
0
        private void btnImportFrom_Click(object sender, EventArgs e)
        {
            var file = new OpenFileDialog {
                Title = @"导入发件人", Filter = @"TXT文件|*.TXT"
            };
            DataVerifier dv    = new DataVerifier();
            var          error = new List <ErrorVO>();

            if (file.ShowDialog() == DialogResult.OK)
            {
                StreamReader sr = new StreamReader(file.FileName, Encoding.Default);
                String       line;
                int          index = 0;
                Regex        reg   = new Regex(@"^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$");
                while ((line = sr.ReadLine()) != null && dv.Pass)
                {
                    index++;
                    var items = line.Split(' ');
                    dv.Check(items.Length < 5, "请确认导入格式是否正确");
                    string msg = "";
                    if (dv.Pass)
                    {
                        var server   = items[0];
                        var port     = items[1].ToInt32(-1);
                        var username = items[2];
                        var password = items[3];
                        var mail     = items[4];

                        if (string.IsNullOrEmpty(server))
                        {
                            msg = "请输入发送服务器";
                        }

                        if (port == -1)
                        {
                            msg += ";端口号请输入数字";
                        }

                        if (string.IsNullOrEmpty(username))
                        {
                            msg += ";请输入用户名";
                        }

                        if (string.IsNullOrEmpty(password))
                        {
                            msg += ";请输入密码";
                        }

                        if (!reg.Match(mail).Success)
                        {
                            msg += ";发件箱格式错误";
                        }

                        if (string.IsNullOrEmpty(msg))
                        {
                            var data = new MailFrom {
                                Server = server, Port = port, UserName = username, PassWord = password, Mail = mail
                            };
                            dal.AddMailFrom(data);
                        }
                        else
                        {
                            error.Add(new ErrorVO(string.Format("第{0}行", index), msg));
                        }
                    }
                }
            }

            if (error.Count > 0)
            {
                new FormError(error).ShowDialog();
            }

            dv.ShowMsgIfFailed();
            GetSendList();
        }
Пример #2
0
 public int AddMailFrom(MailFrom data)
 {
     return(DB.Context.Insert(data));
 }