Esempio n. 1
0
    protected void btnDelete_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            ctBUS = new CustomerBUS();
            dtgBUS = new DetailGroupBUS();
            int CustomerID = int.Parse(((ImageButton)sender).CommandArgument.ToString());
            ConnectionData.OpenMyConnection();
            ctBUS.tblCustomer_Delete(CustomerID);
            dtgBUS.tblDetailGroup_DeleteByCustomerID(CustomerID);
            pnError.Visible = false;
            pnSuccess.Visible = true;
            lblSuccess.Text = "Xóa thành công một khách hàng ID: " + CustomerID.ToString();
            LoadCustomer();
            ConnectionData.CloseMyConnection();
        }
        catch (Exception ex)
        {

            logs.Error(userLogin.Username + "-Client - btnDelete_Click", ex);
            pnSuccess.Visible = false;
            pnError.Visible = true;
            lblError.Text = ex.Message;
        }
    }
Esempio n. 2
0
 public EmailSend()
 {
     srdBUS = new SendRegisterDetailBUS();
     scBUS = new SendContentBUS();
     mcBUS = new MailConfigBUS();
     ctBUS = new CustomerBUS();
     dtGroupBUS = new DetailGroupBUS();
     countBUS = new CountBuyBUS();
 }
    protected void btnFilter_Click(object sender, EventArgs e)
    {
        try
        {
            //  GetExpresion();
            //  createTable();
            customer = new DataTable();
            ctBUS = new CustomerBUS();
            dsgBUS = new DetailGroupBUS();
            int GroupID = 0;
            GroupID = int.Parse(drlSubGroup.SelectedValue.ToString());

            if (getUserLogin().DepartmentId == 1)
            {
                //customer = ctBUS.GetAll();
                customer = ctBUS.GetAllFilterCustomer(txtName.Text.Trim(), txtEmail.Text.Trim(), GroupID,txtPhone.Text.Trim());

            }
            else
                customer = ctBUS.GetAllByUserAssignTo(getUserLogin().UserId, GroupID, txtName.Text.Trim(), txtEmail.Text.Trim(),txtPhone.Text.Trim());

            //row = customer.Select(expresion);
            //foreach (DataRow rowItem in row)
            //{
            //    DataRow rowFilter = result.NewRow();
            //    rowFilter["Id"] = rowItem["Id"];
            //    rowFilter["Name"] = rowItem["Name"];
            //    rowFilter["Gender"] = rowItem["Gender"];
            //    rowFilter["Birthday"] = rowItem["Birthday"];
            //    rowFilter["Email"] = rowItem["Email"];
            //    rowFilter["Phone"] = rowItem["Phone"];
            //    rowFilter["Address"] = rowItem["Address"];
            //    result.Rows.Add(rowFilter);
            //}

            dlPager.MaxPages = 1000;
            dlPager.PageSize = 50;
            dlPager.DataSource = customer.DefaultView;
            dlPager.BindToControl = dtlCustomer;
            this.dtlCustomer.DataSource = dlPager.DataSourcePaged;
            this.dtlCustomer.DataBind();
            pnSuccess.Visible = false;

        }
        catch (Exception ex)
        {

            logs.Error(userLogin.Username + "-Client - btnFilter_Click", ex);
        }
    }
Esempio n. 4
0
 private void InitBUS()
 {
     ulBus = new UserLoginBUS();
     mgBUS = new MailGroupBUS();
     srBUS = new SendRegisterBUS();
     ctBUS = new CustomerBUS();
     dgBUS = new DetailGroupBUS();
 }
Esempio n. 5
0
 private void InitBUS()
 {
     ctBUS = new CustomerBUS();
     mgBUS = new MailGroupBUS();
     srBUS = new SendRegisterBUS();
     dtgBUS = new DetailGroupBUS();
 }
Esempio n. 6
0
    protected void getRegisterSendList()
    {
        try
        {
            cateBUs = new CategoryBUS();
            srBUS = new SendRegisterBUS();
            srdBus = new SendRegisterDetailBUS();
            mailConfigBus = new MailConfigBUS();
            mailGroupBus = new MailGroupBUS();
            sendContentBus = new SendContentBUS();
            dsgBus = new DetailGroupBUS();
            UserLoginDTO userLogin = getUserLogin();
            DataTable tblSendRegister = new DataTable();
            if (userLogin.DepartmentId == 1)
            {
                tblSendRegister = srBUS.GetAll();
            }
            else
            {
                tblSendRegister = srBUS.GetAll(userLogin.UserId);
            }
            if (tblSendRegister.Rows.Count > 0)
            {
                dlWaitSend.DataSource = tblSendRegister;
                dlWaitSend.DataBind();
                for (int i = 0; i < tblSendRegister.Rows.Count; i++)
                {
                    try
                    {

                        DataRow row = tblSendRegister.Rows[i];
                        int Sendtype = int.Parse(row["Sendtype"].ToString());
                        HiddenField hdfId = (HiddenField)dlWaitSend.Items[i].FindControl("hdfId");
                        hdfId.Value = row["Id"].ToString();
                        int contentId = int.Parse(row["SendContentId"].ToString());
                        //DataTable tblContent = sendContentBus.GetByID(contentId);
                        Label lblSubject = (Label)dlWaitSend.Items[i].FindControl("lblSubject");
                        //if (tblContent.Rows.Count > 0)
                        //{
                        //    lblSubject.Text = tblContent.Rows[0]["Subject"].ToString();
                        //}
                        //else
                        lblSubject.Text = row["Subject"] + "";

                        int mailConfig = int.Parse(row["MailConfigID"].ToString());
                        DataTable tblMailConfig = mailConfigBus.GetByID(mailConfig);
                        if (tblMailConfig.Rows.Count > 0)
                        {
                            Label lblMailConfig = (Label)dlWaitSend.Items[i].FindControl("lblMailConfig");
                            lblMailConfig.Text = tblMailConfig.Rows[0]["Email"].ToString();
                        }
                        int groupTo = int.Parse(row["GroupTo"].ToString());
                        if (groupTo == -3)
                        {
                            Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                            lblGroupTo.Text = "Tất cả khách hàng";
                        }
                        else if (groupTo == -2)
                        {
                            Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                            lblGroupTo.Text = "Nhóm mua nhiều lần";
                        }
                        else if (groupTo == -1)
                        {
                            Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                            lblGroupTo.Text = "Nhóm mua lần đầu";
                        }
                        else
                        {
                            DataTable tblGroupTo = new DataTable();
                            if (Sendtype == 1)
                            {
                                tblGroupTo = mailGroupBus.GetByID(groupTo);

                                if (tblGroupTo.Rows.Count > 0)
                                {
                                    Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                                    lblGroupTo.Text = tblGroupTo.Rows[0]["Name"].ToString();
                                }
                            }
                            else
                            {
                                tblGroupTo = cateBUs.GetByID(groupTo);
                                if (tblGroupTo.Rows.Count > 0)
                                {
                                    Label lblGroupTo = (Label)dlWaitSend.Items[i].FindControl("lblGroupTo");
                                    lblGroupTo.Text = tblGroupTo.Rows[0]["Title"].ToString();
                                }
                            }

                        }

                        Label lblStartDate = (Label)dlWaitSend.Items[i].FindControl("lblStartDate");
                        lblStartDate.Text = row["StartDate"].ToString();

                        Label lblEndDate = (Label)dlWaitSend.Items[i].FindControl("lblEndDate");

                        int status = int.Parse(row["Status"].ToString());

                        Panel panel = (Panel)dlWaitSend.Items[i].FindControl("Panel1");
                        TextBox progressbar = (TextBox)dlWaitSend.Items[i].FindControl("progressbar");
                        LinkButton lbtDetail = (LinkButton)dlWaitSend.Items[i].FindControl("lbtDetail");

                        //get list detail
                        DataTable listDetail = srdBus.GetByID(int.Parse(row["Id"].ToString()));
                        int hasSend = 0, sumSend = dsgBus.GetByID(groupTo).Rows.Count;
                        for (int k = 0; k < listDetail.Rows.Count; k++)
                        {
                            hasSend++;
                        }

                        //calc percent has send
                        int percent = 0;
                        if (sumSend != 0)
                        {
                            percent = (hasSend * 100) / sumSend;
                        }

                        if (status == 0)
                        {
                            //display process bar
                            panel.Visible = true;
                            progressbar.BackColor = System.Drawing.Color.Cornsilk;
                            progressbar.Width = percent + 20;
                            progressbar.Text = percent + "%";

                            lbtDetail.Visible = false;
                            lbtDetail.Text = "";
                            lblEndDate.Text = "Chưa xác định ";
                        }
                        else
                        {
                            //hidden process bar
                            panel.Visible = false;
                            lbtDetail.Text = "Xem chi tiết";
                            lbtDetail.PostBackUrl = "reportSend.aspx?campaign-id=" + row["Id"].ToString();
                            lblEndDate.Text = row["EndDate"].ToString();
                        }

                        LinkButton lbtDelete = (LinkButton)dlWaitSend.Items[i].FindControl("lbtDelete");
                        lbtDelete.CommandArgument = row["Id"].ToString();
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

        }
        catch (Exception)
        {

        }
    }
Esempio n. 7
0
        // Thêm ngày 16/09 by Viết Hùng
        //Thêm ngày 26/9
        public void callSendBulkMail_BySubGroup(DataRow Row, DataTable listSendContent, DataTable listCustomer, DataTable listMailConfig)
        {
            //param for send mail
            string EmailTo = "";
            string customerName = "";
            string EmailSubject = "";
            string EmailBody = "";
            string EmailFrom = "";
            string Name = "";
            string username = "";
            string Password = "";
            string HostName = "";
            int PortNumber = 0;
            bool isSSL = false;
            //param for content
            int SendContentId;
            int EmailFromID;
            int SendRegisterID = 0;
            int AccountId = 0;
            SendRegisterBUS srBus = new SendRegisterBUS();
            CustomerBUS customerBus = new CustomerBUS();
            SendRegisterDetailBUS srdBus = new SendRegisterDetailBUS();
            dgBUS = new DetailGroupBUS();
            PartSendBUS psBus = new PartSendBUS();
            SendContentBUS scBus = new SendContentBUS();

            try
            {
                if (Row != null)
                {
                    // Stop timer check
                    SendContentId = int.Parse(Row["SendContentId"].ToString());
                    AccountId = int.Parse(Row["AccountId"].ToString());

                    // Lấy nội dung đăng ký gửi đi
                    DataRow[] resultListSendContend = listSendContent.Select(String.Format("Id = {0}", SendContentId));
                    if (resultListSendContend.Length > 0)
                    {
                        EmailSubject = resultListSendContend[0]["Subject"].ToString();
                        EmailBody = resultListSendContend[0]["Body"].ToString();
                    }

                    //Lấy cấu hình mail gửi
                    EmailFromID = int.Parse(Row["MailConfigID"].ToString());
                    DataRow[] resultListMailConfig = listMailConfig.Select(String.Format("Id = {0}", EmailFromID));
                    if (resultListMailConfig.Length > 0)
                    {
                        EmailFrom = resultListMailConfig[0]["Email"].ToString();
                        username = resultListMailConfig[0]["username"].ToString();
                        Password = resultListMailConfig[0]["Password"].ToString();
                        HostName = resultListMailConfig[0]["Server"].ToString();
                        Name = resultListMailConfig[0]["Name"].ToString();
                        PortNumber = int.Parse(resultListMailConfig[0]["Port"].ToString());
                        isSSL = bool.Parse(resultListMailConfig[0]["isSSL"].ToString());
                    }

                   // ID nhóm mail cần gửi đi
                    string groupId = Row["SendType"].ToString();

                   //Lấy danh sách khách hàng của nhóm
                   DataTable tblCustomerBySubGroup = dgBUS.GetByID(int.Parse(groupId));
                   if (tblCustomerBySubGroup.Rows.Count > 0)
                    {
                        // Kiểm tra chiến dịch này có thuộc nhóm gửi mail từng phần
                        DataTable tblPartSend = psBus.GetByUserIdAndGroupId(AccountId, int.Parse(groupId));

                        SendRegisterID = int.Parse(Row["Id"].ToString());
                        for (int i = 0; i < tblCustomerBySubGroup.Rows.Count; i++)
                        {
                            Stop = true;
                            DataTable tblCustomerByID = customerBus.GetByID(int.Parse(tblCustomerBySubGroup.Rows[i]["CustomerID"].ToString()));
                            if (tblCustomerByID.Rows.Count > 0)
                            {
                                EmailTo = tblCustomerByID.Rows[0]["Email"].ToString();
                                customerName = (tblCustomerByID.Rows[0]["Name"].ToString() == null || tblCustomerByID.Rows[0]["Name"].ToString() == "") ? EmailTo : tblCustomerByID.Rows[0]["Name"].ToString();
                            }
                            // Xử lý câu chào cho nội dung mail
                            string body = EmailBody.Replace("[khachhang]", customerName);
                            body = body.Replace("[email]", EmailTo);

                            // Xử lý câu chào cho tiêu đề mail
                            string subject = EmailSubject.Replace("[khachhang]", customerName).ToUpper();

                            // Thời gian bắt đầu gửi
                            DateTime startDate = DateTime.Now;
                            // Thời gian kết thúc gửi
                            DateTime endDate = DateTime.Now;
                            SendRegisterDetailDTO srdDto = new SendRegisterDetailDTO() {
                                SendRegisterId = SendRegisterID,
                                Email = EmailTo,
                                StartDate = startDate,
                                EndDate = endDate,
                                DayEnd = endDate.Day,
                                HoursEnd = endDate.Hour,
                                MinuteEnd = endDate.Minute,
                                SecondEnd = endDate.Second,
                                MailSend = EmailFrom,
                                Status = false,
                                ErrorType = "0" };
                            int sendetailID = 0;

                            // Lưu lại thông tin từng mail đã gửi
                            sendetailID = srdBus.tblSendRegisterDetail_insert(srdDto);
                            srdDto.SendRegisterDetailId = sendetailID;
                            body += String.Format("<IMG height=1 src=\"http://fastautomaticmail.com/emailtrack.aspx?emailsentID={0}\" width=1>", sendetailID);

                            //Update thời gian bắt đầu gửi
                            startDate = DateTime.Now;
                            srdDto.StartDate = DateTime.Now;
                            bool send = false;
                            try
                            {
                                //===============================================================================
                                //        Edit by HThanhHai for part send mail
                                //===============================================================================

                                // Nếu nhóm này nằm trong danh sách gửi từng phần
                                if (tblPartSend.Rows.Count > 0)
                                {
                                    // Kiểm tra số lượng mail khách hàng này đã nhận được
                                    int countReceivedMail = int.Parse(tblCustomerBySubGroup.Rows[i]["countReceivedMail"].ToString());

                                    // Nội dung mail đã gửi cho nhóm này
                                    string hasContentSend = tblPartSend.Rows[0]["hasContentSend"].ToString();
                                    string[] arrayContent = hasContentSend.Split(',');

                                    if (arrayContent.Length > 0)
                                    {
                                        // Nếu số lượng mail khách hàng này nhận ít hơn số nội dung đã gửi đi
                                        if (countReceivedMail < arrayContent.Length)
                                        {
                                            // Duyệt qua những nội dung mà khách hàng này chưa nhận                                            //
                                            for (int k = countReceivedMail; k < arrayContent.Length; k++)
                                            {
                                                string contentId = arrayContent[k];
                                                string contentDetail, subjectDetail;
                                                DataTable tblContent = scBus.GetByID(int.Parse(contentId));
                                                if (tblContent.Rows.Count > 0)
                                                {
                                                    subjectDetail = tblContent.Rows[0]["Subject"].ToString();
                                                    contentDetail = tblContent.Rows[0]["Body"].ToString();

                                                    contentDetail = contentDetail.Replace("[khachhang]", customerName);
                                                    contentDetail = contentDetail.Replace("[email]", EmailTo);

                                                    // Xử lý câu chào cho tiêu đề mail
                                                    subjectDetail = subjectDetail.Replace("[khachhang]", customerName).ToUpper();
                                                }
                                                else
                                                {
                                                    subjectDetail = "No subject";
                                                    contentDetail = "Nội dung không tồn tại !";
                                                }

                                                if (HostName == "Amazon API")
                                                {
                                                    send = SendEmailWithAmazone(EmailFrom, EmailTo, subjectDetail, contentDetail, username, Password, Name);
                                                }
                                                else
                                                {
                                                    send = SendMail(subjectDetail, contentDetail, HostName, PortNumber, EmailFrom, Password, Name, EmailTo, username, isSSL);
                                                }
                                            }

                                            // Update số lượng mail đã nhận sau khi đã gửi đi đầy đủ
                                            DetailGroupDTO dgDto = new DetailGroupDTO();
                                            dgDto.CustomerID = AccountId;
                                            dgDto.GroupID = int.Parse(groupId);
                                            dgDto.CountReceivedMail = arrayContent.Length;
                                            dgBUS.tblDetailGroup_Update(dgDto);
                                        }
                                    }
                                }
                                else
                                {
                                    // Không phải chiến dịch gửi mail từng phần
                                    if (HostName == "Amazon API")
                                    {
                                        send = SendEmailWithAmazone(EmailFrom, EmailTo, subject, body, username, Password, Name);
                                    }
                                    else
                                    {
                                        send = SendMail(subject, body, HostName, PortNumber, EmailFrom, Password, Name, EmailTo, username, isSSL);
                                    }
                                }

                            }
                            catch (Exception ex)
                            {
                                const string errSubject = "Error from FAMail";
                                string errBody = ex.Message + DateTime.Now; ;
                                const string errHost = "smtp.gmail.com";
                                const string errUser = "******";
                                const string errPass = "******";
                                SendMail(errSubject, errBody, errHost, 587, errUser, errPass, "Error from FAMail", "*****@*****.**");
                                SendMail(errSubject, errBody, errHost, 587, errUser, errPass, "Error from FAMail", "*****@*****.**");
                            }

                            //Update thời gian bắt kết thúc
                            srdDto.EndDate = endDate;
                            endDate = DateTime.Now;
                            srdBus.tblSendRegisterDetail_Update(sendetailID, startDate, endDate, send);
                        }
                    }
                }
                else
                {
                    return;
                }
            }
            catch (Exception )
            {
                throw;
            }
            finally
            {
                // cập nhật trạng thái đã gửi mail & thời gian kết thúc cho chiến dịch gửi mail này
                // trạng thái 1 - đã gửi, 0 - chưa gửi
                srBus.tblSendRegister_UpdateStatus(SendRegisterID, 1, DateTime.Now);
                Stop = false;
            }
        }
 private void InitBus()
 {
     cm = new Common();
     ctBUS = new CustomerBUS();
     oBUS = new OrderBUS();
     odBUS = new OrderDatailBUS();
     mgBUS = new MailGroupBUS();
     dgBUS = new DetailGroupBUS();
 }
Esempio n. 9
0
 private void InitBUS()
 {
     ctBUS = new CustomerBUS();
     mailGroupBus = new MailGroupBUS();
     dgBUS = new DetailGroupBUS();
 }
Esempio n. 10
0
 private void InitialBUS()
 {
     scBUS = new SendContentBUS();
     mailConfigBus = new MailConfigBUS();
     mailGroupBus = new MailGroupBUS();
     customerBus = new CustomerBUS();
     srBUS = new SendRegisterBUS();
     common = new Common();
     dsgBUS = new DetailGroupBUS();
 }
Esempio n. 11
0
    protected void drlMailGroup_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            if (this.drlMailGroup.SelectedValue != null)
            {
                DataTable tblCustomer = new DataTable();
                dsgBUS = new DetailGroupBUS();
                psBus = new PartSendBUS();
                int groupID = int.Parse(this.drlMailGroup.SelectedValue.ToString());
                int numbermail = 0;
                if (groupID == -3)
                {
                    customerBus = new CustomerBUS();
                    //tblCustomer = dsgBUS.GetAll();
                    DataTable dtEmail = customerBus.GetCountCustomerCreatedMail(userLogin.UserId);
                    numbermail = int.Parse(dtEmail.Rows[0]["numberMail"].ToString());
                }
                else
                {
                    int.TryParse(dsgBUS.GetCountByGroupID(groupID) + "", out numbermail);
                    //numbermail = tblCustomer.Rows.Count;
                }

                //string countCustomer = tblCustomer.Rows.Count.ToString();
                lblCountCustomer.Text = "Hiện có " + numbermail + " khách hàng trong nhóm này !";
                hdfCountCustomer.Value = numbermail + "";

                // Đếm số lượng mail đã gửi trong group trong chiến dịch gửi từng phần
                //DataTable tblPartSend = psBus.GetByUserIdAndGroupId(getUserLogin().UserId, groupID);
                //if (tblPartSend.Rows.Count > 0)
                //{
                //    string strContentList = tblPartSend.Rows[0]["hasContentSend"].ToString();
                //    string[] arrayContentList = strContentList.Split(',');
                //    hplCountPartSend.Text = arrayContentList.Length + " nội dung";
                //    hplCountPartSend.NavigateUrl = "view-content-send.aspx?groupId=" + groupID;
                //}

            }
        }
        catch (Exception ex)
        {
            lblCountCustomer.Text = "";
        }
    }
Esempio n. 12
0
 protected int calcTimeForGroup(int groupid)
 {
     dsgBUS = new DetailGroupBUS();
     common = new Common();
     DataTable tblCustomer = dsgBUS.GetByID(groupid);
     int calcMinute = 0;
     if (tblCustomer.Rows.Count > 0)
     {
         calcMinute = common.calculatorMinuteQuantityEmail(tblCustomer.Rows.Count) + 1;
     }
     return calcMinute;
 }
Esempio n. 13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string eventId, name, email, company, phone, secondPhone, address1,
                address2, city, province, country, zipcode, fax, groupId,
                visibleField, gender, requireTime, UserID, Job;

            eventId = Request.Params["eventId"];
            name = Request.Params["Name"];
            if (name == null || name == "")
            {
                name = "";
            }
            email = Request.Params["Email"];
            if (email == null || email == "")
            {
                Session["Error"] = "Vui lòng kiểm tra lại thông tin đăng ký !";
                Response.Redirect("event-register-error.aspx", false);
                return;
            }
            gender = Request.Params["Gender"];
            if (gender == null || gender == "")
            {
                gender = "Nam";
            }
            Job = Request.Params["Job"];
            if (Job == null || Job == "")
            {
                Job = "";
            }
            company = Request.Params["Company"];
            if (company == null || company == "")
            {
                company = "";
            }
            phone = Request.Params["Phone"];
            if (phone == null || phone == "")
            {
                phone = "";
            }
            secondPhone = Request.Params["SecondPhone"];
            if (secondPhone == null || secondPhone == "")
            {
                secondPhone = "";
            }
            address1 = Request.Params["Address1"];
            if (address1 == null || address1 == "")
            {
                address1 = "";
            }
            address2 = Request.Params["Address2"];
            if (address2 == null || address2 == "")
            {
                address2 = "";
            }
            city = Request.Params["City"];
            if (city == null || city == "")
            {
                city = "";
            }
            province = Request.Params["Province"];
            if (province == null || province == "")
            {
                province = "";
            }
            country = Request.Params["Country"];
            if (country == null || country == "")
            {
                country = "";
            }
            zipcode = Request.Params["ZipCode"];
            if (zipcode == null || zipcode == "")
            {
                zipcode = "";
            }
            fax = Request.Params["Fax"];
            if (fax == null || fax == "")
            {
                fax = "";
            }

            requireTime = Request.Params["requireTime"];

            groupId = Request.Params["groupId"];
            UserID = Request.Params["UserID"];
            //startDate = Request.Params["startDate"];
            //endDate = Request.Params["endDate"];
            visibleField = Request.Params["visibleField"];
            string[] arrVisible = visibleField.Trim().Split(' ');

            eventDetailBus = new EventDetailBUS();
            eventBus = new EventBUS();

            EventDetailDTO eventDetailDto = new EventDetailDTO();
            eventDetailDto.EventId = int.Parse(eventId);
            eventDetailDto.FullName = name;
            eventDetailDto.EmailID = email;
            eventDetailDto.Job = Job;
            eventDetailDto.Company = company;
            eventDetailDto.Phone = phone;
            eventDetailDto.SecondPhone = secondPhone;
            eventDetailDto.Address = address1;
            eventDetailDto.Address2 = address2;
            eventDetailDto.City = city;
            eventDetailDto.Province = province;
            eventDetailDto.Country = country;
            eventDetailDto.ZipCode = zipcode;
            eventDetailDto.Fax = fax;
            eventDetailDto.CreateDate = DateTime.Now;
            eventDetailDto.GroupId = int.Parse(groupId);
            eventDetailDto.CountReceivedMail = 0;
            eventDetailDto.LastReceivedMail = DateTime.Now;

            // Kiem tra dieu kien
            // Check thời gian của sự kiện
            DataTable tblEvent = eventBus.GetByID(int.Parse(eventId));
            if (tblEvent.Rows.Count > 0)
            {
                if (requireTime.Equals("true"))
                {
                    if (DateTime.Parse(tblEvent.Rows[0]["StartDate"].ToString()) <= DateTime.Now
                            && DateTime.Now <= DateTime.Parse(tblEvent.Rows[0]["EndDate"].ToString()))
                    {
                    }
                    else
                    {
                        Session["Error"] = "Thời hạn đăng ký đã hết, vui lòng chờ sự kiện kế tiếp. Cảm ơn !";
                        Response.Redirect("event-register-error.aspx", false);
                        return;
                    }
                }

            }

            // Mot email chi dang ky duoc mot event
            DataTable checkEmail = eventDetailBus.GetByIdAndEmail(int.Parse(eventId), email);
            if (checkEmail.Rows.Count > 0)
            {
                Session["Error"] = "Email đã được sử dụng. Vui lòng chọn email khác !";
                Response.Redirect("event-register-error.aspx", false);
                return;
            }

            // Gui mail
            // Lay thong tin event
            eventBus = new EventBUS();
            DataTable tbEvent = eventBus.GetByID(int.Parse(eventId));
            //get mail config
            if (tbEvent.Rows.Count > 0)
            {
                DataRow rEvent = tbEvent.Rows[0];
                mailConfigBus = new MailConfigBUS();
                DataTable tbMailConfig = mailConfigBus.GetByID(int.Parse(tbEvent.Rows[0]["ConfigId"].ToString()));

                // Them khach hang vao bang event detail
                eventDetailBus.tblEventDetail_insert(eventDetailDto);

                try
                {
                    // Them khach hang vao danh sach khach hang
                    customerBus = new CustomerBUS();
                    DataTable tblCustomer = customerBus.GetByEmail(email, int.Parse(UserID));
                    int customerId = 0;
                    if (tblCustomer.Rows.Count == 0)
                    {
                        CustomerDTO customerDto = new CustomerDTO();
                        customerDto.Name = name;
                        customerDto.Gender = gender;
                        customerDto.BirthDay = DateTime.Now;
                        customerDto.Email = email;
                        customerDto.Phone = phone;
                        customerDto.SecondPhone = secondPhone;
                        customerDto.Address = address1;
                        customerDto.Fax = fax;
                        customerDto.Company = company;
                        customerDto.Job = Job;
                        customerDto.City = city;
                        customerDto.Province = province;
                        customerDto.Country = country;
                        customerDto.Type = "0";
                        customerDto.UserID = int.Parse(UserID);
                        customerDto.createBy = int.Parse(UserID);
                        customerDto.AssignTo = int.Parse(UserID);

                        customerId = customerBus.tblCustomer_insert(customerDto);
                        this.SendMail(customerDto);
                        logs_info.Info("Email Register: " + email);
                    }
                    else
                    {
                        customerId = int.Parse(tblCustomer.Rows[0]["Id"].ToString());
                    }

                    // Them khach hang vao detail group.
                    dgBus = new DetailGroupBUS();
                    DataTable tblDetailGroup = dgBus.GetByID(int.Parse(groupId), customerId);
                    if (tblDetailGroup.Rows.Count <= 0)
                    {
                        DetailGroupDTO dgDto = new DetailGroupDTO();

                        dgDto.GroupID = int.Parse(groupId);
                        dgDto.CustomerID = customerId;
                        dgDto.CountReceivedMail = 0;
                        dgDto.LastReceivedMail = DateTime.Now;
                        dgBus.tblDetailGroup_insert(dgDto);
                    }
                    eventBus.tblEventCustomer_Insert(customerId, eventId);

                }
                catch (Exception)
                {
                }

                if (tbMailConfig.Rows.Count > 0)
                {
                    DataRow rConfig = tbMailConfig.Rows[0];
                    ProcessSendEmail process = new ProcessSendEmail();

                    // Xu ly them loi chao trong noi dung mail
                    string body = rEvent["Body"].ToString();
                    string welcome = (name == "" || name == null) ? email : name;

                    // Replace with [khachhang] or [email]
                    body = body.Replace("[khachhang]", welcome);
                    body = body.Replace("[email]", email);

                    bool rsSend = true;

                    //rsSend = process.SendMail(rEvent["Subject"].ToString(),
                    //    body, rConfig["Server"].ToString(), int.Parse(rConfig["Port"].ToString()),
                    //    rConfig["Email"].ToString(), rConfig["Password"].ToString(), rConfig["Name"].ToString(),
                    //    email, rConfig["username"].ToString(),bool.Parse(rConfig["isSSL"].ToString()));

                    if (rsSend)
                    {
                        // chuyen den trang success
                        string url = rEvent["ResponeUrl"].ToString();
                        if (url.Equals("Default"))
                        {
                            Response.Redirect("event-register-success.aspx", false);
                        }
                        else
                        {
                            Response.Redirect(url, false);
                        }
                    }
                    else
                    {
                        Session["Error"] = "Bạn đã đăng ký không thành công.";
                        Response.Redirect("event-register-error.aspx", false);
                    }

                }
                else
                {
                    Session["Error"] = "Bạn đã đăng ký không thành công.";
                    Response.Redirect("event-register-error.aspx", false);
                }

            }

        }
        catch (Exception ex)
        {
            Session["Error"] = "Một số lỗi hệ thống đã xảy ra. Vui lòng kiểm tra lại thông tin !\n" + ex.Message;
            Response.Redirect("event-register-error.aspx");
        }
    }
Esempio n. 14
0
        private void event_worker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                EmailSend mailSend = new EmailSend();
                DetailGroupBUS dgBus = new DetailGroupBUS();
                ContentSendEventBUS cseBus = new ContentSendEventBUS();
                SendContentBUS scBus = new SendContentBUS();
                EventBUS eventBUS = new EventBUS();

                DataTable tblSendList = dgBus.getGroupListByEventList();
                if (tblSendList.Rows.Count > 0)
                {

                    List<SendMailDTO> sendList = mailSend.convetToSendMail(tblSendList);
                    int totalCnt = sendList.Count;
                    foreach (SendMailDTO sendItem in sendList)
                    {
                        int eventId = sendItem.eventId;
                        DataTable dtContentSendEvent = cseBus.GetByEventId(eventId);
                        if (dtContentSendEvent.Rows.Count > 0)
                        {
                            if (sendItem.countReceivedMail == 0
                                && sendItem.lastReceivedMail == "") // Gui lan dau
                            {
                                int id = int.Parse(dtContentSendEvent.Rows[0]["id"].ToString());
                                int contentId = int.Parse(dtContentSendEvent.Rows[0]["ContentId"].ToString());
                                int hourSend = int.Parse(dtContentSendEvent.Rows[0]["HourSend"].ToString());
                                DataTable dtSendContent = scBus.GetByID(contentId);
                                subject = dtContentSendEvent.Rows[0]["Subject"].ToString();
                                body = dtContentSendEvent.Rows[0]["Body"].ToString();

                                bool sendRs = false;
                                // Send normal.
                                bool send = sendMail(sendRs, sendItem.port, sendItem.hostName, sendItem.userSmtp, sendItem.passSmtp, sendItem.mailFrom, sendItem.senderName,
                                        subject, body, sendItem.recieveName, sendItem.mailTo, 0, id);
                                logs_info.Info("Status: " + send + ", sendRegisterId:" + sendRegisterId + ", MailTo: " + sendItem.mailTo + ", mailFrom: " + mailFrom + ", Name: " + sendItem.recieveName);

                                // Update tblDetailGroup.
                                DetailGroupDTO dgDto = new DetailGroupDTO();
                                dgDto.CustomerID = sendItem.customerId;
                                dgDto.GroupID = sendItem.groupId;
                                dgDto.CountReceivedMail = sendItem.countReceivedMail + 1;
                                dgDto.LastReceivedMail = DateTime.Now;
                                dgBus.tblDetailGroup_Update(dgDto);

                                eventBUS.tblEventCustomer_Update(eventId, sendItem.customerId, sendItem.countReceivedMail + 1);

                                logHistoryForSendEvent(id, sendItem.mailTo, mailFrom, sendItem.recieveName, send);
                            }
                            else if (sendItem.countReceivedMail < dtContentSendEvent.Rows.Count)
                            {
                                string strReceivedMail = sendItem.lastReceivedMail;
                                DateTime lastReceivedMail = DateTime.Now;
                                if (strReceivedMail != "")
                                {
                                    lastReceivedMail = DateTime.Parse(strReceivedMail);
                                }
                                int hourSend = int.Parse(dtContentSendEvent.Rows[sendItem.countReceivedMail]["HourSend"].ToString());
                                DateTime currentTime = lastReceivedMail.AddHours(hourSend);
                                TimeSpan time = currentTime - DateTime.Now;
                                /*if (DateTime.Now.Year == currentTime.Year
                                    && DateTime.Now.Month == currentTime.Month
                                    && DateTime.Now.Day == currentTime.Day
                                    && DateTime.Now.Hour == currentTime.Hour
                                    && DateTime.Now.Minute == currentTime.Minute)*/
                                if (time.Days < 0 || time.Hours < 0 || time.Minutes < 0 || time.Seconds < 0)
                                {
                                    int contentId = int.Parse(dtContentSendEvent.Rows[sendItem.countReceivedMail]["ContentId"].ToString());
                                    //DataTable dtSendContent = scBus.GetByID(contentId);
                                    //if (dtSendContent.Rows.Count > 0)
                                    //{
                                    //    subject = dtSendContent.Rows[0]["Subject"].ToString();
                                    //    body = dtSendContent.Rows[0]["Body"].ToString();
                                    //}
                                    subject = dtContentSendEvent.Select("hoursend=" + hourSend)[0]["Subject"].ToString();
                                    body = dtContentSendEvent.Select("hoursend=" + hourSend)[0]["Body"].ToString();

                                    int id = Convert.ToInt32(dtContentSendEvent.Select("hoursend=" + hourSend)[0]["id"] + "");
                                    bool sendRs = false;
                                    // Send normal.
                                    bool send = sendMail(sendRs, sendItem.port, sendItem.hostName, sendItem.userSmtp, sendItem.passSmtp, sendItem.mailFrom, sendItem.senderName,
                                            subject, body, sendItem.recieveName, sendItem.mailTo, 0, id);

                                    logHistoryForSendEvent(id, sendItem.mailTo, mailFrom, sendItem.recieveName, send);
                                    logs_info.Info("Status: " + send + ", sendRegisterId:" + sendRegisterId + ", MailTo: " + sendItem.mailTo + ", mailFrom: " + mailFrom + ", Name: " + sendItem.recieveName);
                                    // Update tblDetailGroup.
                                    DetailGroupDTO dgDto = new DetailGroupDTO();
                                    dgDto.CustomerID = sendItem.customerId;
                                    dgDto.GroupID = sendItem.groupId;
                                    dgDto.CountReceivedMail = sendItem.countReceivedMail + 1;
                                    dgDto.LastReceivedMail = DateTime.Now;
                                    dgBus.tblDetailGroup_Update(dgDto);
                                    eventBUS.tblEventCustomer_Update(eventId, sendItem.customerId, sendItem.countReceivedMail + 1);
                                }
                            }
                        }
                    }// End forEach.

                }
            }
            catch (Exception ex)
            {
                logs.Error("timer2_tick", ex);
            }
        }