private void btnCancel_Click(object sender, EventArgs e) { if (this.AfterInputCredential != null) { EmailCredentialEventArgs arg = new EmailCredentialEventArgs(string.Empty, string.Empty, string.Empty, true); this.AfterInputCredential(this, arg); } this.Close(); }
void frmCred_AfterInputCredential(object sender, EmailCredentialEventArgs args) { if (args.Cancel) return; this.SenderEmail = args.UserID; this.SenderPassword = args.Password; this.CC = args.CC; this.validated_cc.Clear(); //處理寄件備份 string[] ccs = this.CC.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string cc in ccs) { if (cc.Trim().Length > 0) this.validated_cc.Add(cc); } }
private void btnOK_Click(object sender, EventArgs e) { bool isOk = true ; //Validate UserID if (string.IsNullOrWhiteSpace(this.txtUserID.Text)) { this.errorProvider1.SetError(this.txtUserID, "請輸入帳號。"); isOk = false; } else { if (!this.isValidEmail(this.txtUserID.Text.Trim())) { this.errorProvider1.SetError(this.txtUserID, string.Format("帳號『{0}』是不正確的電子郵件格式。", this.txtUserID.Text)); isOk = false; } else this.errorProvider1.SetError(this.txtUserID, ""); } // 驗證副本是否符合電子郵件格式 string[] ccs = this.txtCC.Text.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List<string> err_emails = new List<string>(); foreach (string cc in ccs) { if (cc.Trim().Length > 0) { if (!this.isValidEmail(cc)) err_emails.Add(cc); } } if (err_emails.Count > 0) { this.errorProvider1.SetError(this.txtCC, string.Format("寄信副本『{0}』是不正確的電子郵件格式。", string.Join(",", err_emails))); isOk = false; } else this.errorProvider1.SetError(this.txtCC, ""); if (isOk) { //Validate Password if (string.IsNullOrWhiteSpace(this.txtPassword.Text)) { if (MessageBox.Show("確定密碼是空白嗎?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Information) != System.Windows.Forms.DialogResult.Yes) { isOk = false; } } } if (isOk) { if (this.AfterInputCredential != null) { EmailCredentialEventArgs arg = new EmailCredentialEventArgs(this.txtUserID.Text, this.txtPassword.Text, this.txtCC.Text); this.AfterInputCredential(this, arg); } this.Close(); } }