コード例 #1
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            HocsinhInfo info = HocsinhDB.GetInfo(_hocsinhid);

            if (info == null)
            {
                return;
            }

            lblDateTime.Text        = ConvertUtility.ToDateTime(info.Hocsinh_CreateDate).ToString("dd/MM/yyyy HH:mm");
            lnkFullname.Text        = info.Hocsinh_Name;
            lnkFullname.NavigateUrl = "mailto:" + info.Hocsinh_Email;
            lblPhuHuynh.Text        = info.Hocsinh_Parent;
            lblEmail.Text           = info.Hocsinh_Email;
            lblPhone.Text           = info.Hocsinh_Tel;
            lblAddress.Text         = info.Hocsinh_Address.Replace("\n", "<br>");
            lblBirthday.Text        = info.Hocsinh_Birthday;
            lblContent.Text         = info.Hocsinh_Note.Replace("\n", "<br>");
            chkIsLearning.Checked   = info.Hocsinh_IsLearning;

            dtlProduct.DataSource = HocsinhRegisterDB.GetKhoahoc(_hocsinhid);
            dtlProduct.DataBind();
        }
コード例 #2
0
        protected void dtlProduct_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "delete")
            {
                var contentid = ConvertUtility.ToInt32(e.CommandArgument);
                try
                {
                    HocsinhRegisterDB.Delete(_hocsinhid, contentid);

                    lblUpdateStatus.Text = MiscUtility.UPDATE_SUCCESS;
                }
                catch
                {
                    lblUpdateStatus.Text = MiscUtility.UPDATE_ERROR;
                }
            }
        }
コード例 #3
0
        protected void butSend_Click(object sender, EventArgs e)
        {
            var contactEmail = AppEnv.ContactEmail;

            var hocsinhname     = txtHocsinhName.Text.Trim();
            var phuhuynhname    = txtPhuHuynh.Text.Trim();
            var emailregister   = txtEmail.Text.Trim();
            var phoneregister   = txtPhone.Text.Trim();
            var addressregister = txtAddress.Text.Trim();
            var noteregister    = txtContent.Text;


            if (hocsinhname.Length == 0 || phuhuynhname.Length == 0 || emailregister.Length == 0 || phoneregister.Length == 0 || addressregister.Length == 0)
            {
                MessageBox.Show("Bạn phải điền tất cả các ô có dấu (*)");
                return;
            }
            //if(txtCode.Text.Trim() != FormShield1.GetText())
            //{
            //    MessageBox.Show("Bạn nhập không đúng mã bảo vệ");
            //    return;
            //}

            const string matchEmailPattern = @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
                                             + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
                                             + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?
				[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
                                             + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

            if (Regex.IsMatch(txtEmail.Text.Trim(), matchEmailPattern) == false)
            {
                MessageBox.Show("Email không đúng !!!");
                return;
            }

            //insert db
            var hocsinhinfo = new HocsinhInfo();

            hocsinhinfo.Hocsinh_Name     = hocsinhname;
            hocsinhinfo.Hocsinh_Parent   = phuhuynhname;
            hocsinhinfo.Hocsinh_Email    = emailregister;
            hocsinhinfo.Hocsinh_Tel      = phoneregister;
            hocsinhinfo.Hocsinh_Address  = addressregister;
            hocsinhinfo.Hocsinh_Birthday = dropDay.SelectedValue + "/" + dropMonth.SelectedValue + "/" +
                                           dropYear.SelectedValue;
            hocsinhinfo.Hocsinh_Note       = noteregister;
            hocsinhinfo.Hocsinh_CreateDate = DateTime.Now;
            hocsinhinfo.Hocsinh_IsLearning = true;

            int hocsinhId = HocsinhDB.Insert(hocsinhinfo);

            var i = 0;

            foreach (DataGridItem item in dtgClass.Items)
            {
                var chkSelect = (CheckBox)item.FindControl("chkSelect");
                if (chkSelect.Checked)
                {
                    var id = ConvertUtility.ToInt32(item.Cells[0].Text);

                    var registerInfo = new HocsinhRegisterInfo();
                    registerInfo.Hocsinh_ID   = hocsinhId;
                    registerInfo.Content_ID   = id;
                    registerInfo.RegisterTime = DateTime.Now;

                    HocsinhRegisterDB.Insert(registerInfo);

                    i = 1 + 1;
                }
            }

            //noi dung mail

            var contentmail = string.Empty;

            if (i == 0)
            {
                contentmail  = "Dang ky cho lop khai giang";
                contentmail += "<br /><br />" + noteregister;
            }
            else
            {
                contentmail = noteregister;
            }

            var sb = new StringBuilder();

            sb.Append("<b>Ho ten hoc sinh</b>: ");
            sb.Append(hocsinhname);
            sb.Append("<br /><b>Ten phu huynh</b>: ");
            sb.Append(phuhuynhname);
            sb.Append("<br /><b>Email</b>: ");
            sb.Append(emailregister);
            sb.Append("<br /><b>Dien thoai</b>:<br />");
            sb.Append(phoneregister);
            sb.Append("<br /><b>Dia chi</b>: ");
            sb.Append(addressregister);
            sb.Append("<br /><b>Ngay sinh</b>:<br />");
            sb.Append(dropDay.SelectedValue + "/" + dropMonth.SelectedValue + "/" + dropYear.SelectedValue);
            sb.Append("<br /><b>Thong tin them</b>:<br />");
            sb.Append(contentmail);


            // new email solution start
            var email = new MailMessage(txtEmail.Text, contactEmail)
            {
                Subject    = "Dang ky khoa hoc tu website",
                IsBodyHtml = true,
                Body       = sb.ToString()
            };

            var smtp = new SmtpClient
            {
                Host = AppEnv.MailServer.Length == 0 ? "localhost" : AppEnv.MailServer,
                Port =
                    AppEnv.MailServerPort.Length == 0 ? 25 : ConvertUtility.ToInt32(AppEnv.MailServerPort)
            };



            // if authentication
            if (AppEnv.MailUsername.Length > 0 && AppEnv.MailPassword.Length > 0)
            {
                smtp.Credentials    = new NetworkCredential(AppEnv.MailUsername, AppEnv.MailPassword);
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            }
            // if authentication end

            var info = new MailInfo
            {
                Mail_Kind     = "lienhe",
                Mail_Name     = HTMLUtility.SecureHTML(txtHocsinhName.Text),
                Mail_Email    = HTMLUtility.SecureHTML(txtEmail.Text),
                Mail_Phone    = HTMLUtility.SecureHTML(txtPhone.Text),
                Mail_Address  = HTMLUtility.SecureHTML(txtAddress.Text),
                Mail_Content  = HTMLUtility.SecureHTML(sb.ToString()),
                Pix_ID        = 0,
                Mail_Answer   = ConvertUtility.ToBoolean(false),
                Mail_Datetime = DateTime.Now
            };

            MailDB.Insert(info);

            try
            {
                smtp.Send(email);
                notice.InnerHtml = "<br><br><br><font color=red><b>Thông tin đăng ký đã được gửi tới " + contactEmail + "...<br />Chúng tôi sẽ liên hệ lại trong thời gian ngắn nhất.<br />Xin chân thành cảm ơn.</b></font>";
            }
            catch (Exception ex)
            {
                notice.InnerHtml = "<br><br><br><font color=red><b>Thông tin đăng ký đã được gửi đi...<br />Chúng tôi sẽ liên hệ lại trong thời gian ngắn nhất.<br />Xin chân thành cảm ơn.</b></font>";
                ErrorReportDB.NewReport(Request.RawUrl, ex.ToString());
                //notice.InnerHtml = "<br><br><br><font color=red><b>Lỗi trong quá trình gửi mail...</b></font><br>" + ex.Message;
            }
            finally
            {
                pnform.Visible = false;
                notice.Visible = true;
            }
        }