Example #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;
        }
    }
Example #2
0
 public EmailSend()
 {
     srdBUS = new SendRegisterDetailBUS();
     scBUS = new SendContentBUS();
     mcBUS = new MailConfigBUS();
     ctBUS = new CustomerBUS();
     dtGroupBUS = new DetailGroupBUS();
     countBUS = new CountBuyBUS();
 }
 protected void btnOk_Click(object sender, EventArgs e)
 {
     ConnectionData.OpenMyConnection();
     srdBUS = new SendRegisterDetailBUS();
     ctBUS = new CustomerBUS();
     srdBUS.tblSendRegisterDetail_UpdateUnreceve(SendRegisterID, true, DateTime.Now, email);
     DataTable table=   ctBUS.GetByEmail(email);
     int customerID = int.Parse(table.Rows[0]["Id"].ToString());
     ctBUS.tblCustomer_UpdateRecive(customerID, false);
     ConnectionData.CloseMyConnection();
 }
    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);
        }
    }
Example #5
0
    private void LoadCustomer()
    {
        ctBUS = new CustomerBUS();
        int GroupID = 0;
        GroupID = int.Parse(drlNhomMail.SelectedValue.ToString());
        if (getUserLogin().DepartmentId == 1)
        {
            // customerBySelect = ctBUS.GetAll();

            customerBySelect = ctBUS.GetAll(txtName.Text.Trim(), txtPhone.Text.Trim(), txtEmail.Text.Trim(), GroupID);
        }
        else
        {
            customerBySelect = ctBUS.GetAllByUserAssignTo(getUserLogin().UserId, GroupID, txtName.Text.Trim(), txtEmail.Text.Trim(), txtPhone.Text.Trim());
        }
        try
        {
            dlPager.MaxPages = 1000;
            dlPager.PageSize = 50;
            dlPager.DataSource = customerBySelect.DefaultView;
            dlPager.BindToControl = dtlCustomer;
            this.dtlCustomer.DataSource = dlPager.DataSourcePaged;
            this.dtlCustomer.DataBind();
        }
        catch (Exception ex)
        {

            logs.Error(userLogin.Username + "-Client - LoadCustomer", ex);
        }
    }
Example #6
0
 private void InitBUS()
 {
     ctBUS = new CustomerBUS();
     mgBUS = new MailGroupBUS();
     srBUS = new SendRegisterBUS();
     dtgBUS = new DetailGroupBUS();
 }
Example #7
0
 private void InitBUS()
 {
     oBUS = new OrderBUS();
     odBUS = new OrderDatailBUS();
     ctBus = new CustomerBUS();
 }
Example #8
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;
            }
        }
Example #9
0
        public void SendBulkMail(DataTable listSendRegister, DataTable listSendContent, DataTable listCustomer, DataTable listMailConfig)
        {
            //param for send mail
            string EmailTo = "";
            string customerName = "";
            string EmailSubject = "";
            string EmailBody = "";
            string EmailFrom = "";
            string Name = "";
            string Password = "";
            string HostName = "";
            int PortNumber = 0;
            //param for content
            int SendContentId;
            int EmailFromID;
            int SendRegisterID;
            SendRegisterBUS srBus = new SendRegisterBUS();
            CustomerBUS customerBus = new CustomerBUS();
            SendRegisterDetailBUS srdBus = new SendRegisterDetailBUS();
            //Kiểm tra và duyệt
            if (listSendRegister.Rows.Count > 0)
            {
                DataRow Row = null;
                DateTime currentDate = DateTime.Now;
                for (int i = 0; i < listSendRegister.Rows.Count; i++)
                {
                    DataRow rowTemp = listSendRegister.Rows[i];
                    DateTime dateItem = DateTime.Parse(rowTemp["StartDate"].ToString());
                    if (currentDate.Year == dateItem.Year && currentDate.Month == dateItem.Month
                        && currentDate.Day == dateItem.Day && currentDate.Hour == dateItem.Hour
                        && currentDate.Minute == dateItem.Minute)
                    {
                        Row = rowTemp;
                        break;
                    }
                }

                if (Row != null)
                {
                    //stop timer check
                    SendContentId = int.Parse(Row["SendContentId"].ToString());
                    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();
                        Password = resultListMailConfig[0]["Password"].ToString();
                        HostName = resultListMailConfig[0]["Server"].ToString();
                        Name = resultListMailConfig[0]["Name"].ToString();
                        PortNumber = int.Parse(resultListMailConfig[0]["Port"].ToString());
                    }

                    //lấy danh sách mail cần gửi đi
                    string groupId = Row["SendType"].ToString();
                    DataTable tblCustomerByGroup = customerBus.GetByID(int.Parse(groupId));
                    if (tblCustomerByGroup.Rows.Count > 0)
                    {
                        SendRegisterID = int.Parse(Row["Id"].ToString());

                        for (int i = 0; i < tblCustomerByGroup.Rows.Count; i++)
                        {
                            EmailTo = tblCustomerByGroup.Rows[i]["Email"].ToString();
                            customerName = tblCustomerByGroup.Rows[i]["Name"].ToString();
                            DateTime startDate = DateTime.Now;
                            bool send = SendMail(EmailSubject, EmailBody, HostName, PortNumber, EmailFrom, Password, Name, EmailTo);
                            DateTime endDate = DateTime.Now;
                            SendRegisterDetailDTO srdDto = new SendRegisterDetailDTO();
                            srdDto.SendRegisterId = SendRegisterID;
                            srdDto.Email = EmailTo;
                            srdDto.StartDate = startDate;
                            srdDto.EndDate = endDate;
                            srdDto.DayEnd = endDate.Day;
                            srdDto.HoursEnd = endDate.Hour;
                            srdDto.MinuteEnd = endDate.Minute;
                            srdDto.SecondEnd = endDate.Second;
                            srdDto.MailSend = EmailFrom;
                            if (send == true)
                            {
                                srdDto.Status = true;
                            }
                            else
                            {
                                srdDto.Status = false;
                            }
                            ConnectionData.OpenMyConnection();
                            //lưu lại thông tin từng mail đã gửi
                            srdBus.tblSendRegisterDetail_insert(srdDto);
                            ConnectionData.CloseMyConnection();
                        }
                        // 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);
                    }

                }
                else
                    return;
            }
            else
                return;
        }
 private void InitBus()
 {
     cm = new Common();
     ctBUS = new CustomerBUS();
     oBUS = new OrderBUS();
     odBUS = new OrderDatailBUS();
     mgBUS = new MailGroupBUS();
     dgBUS = new DetailGroupBUS();
 }
Example #11
0
 private void InitBUS()
 {
     ctBUS = new CustomerBUS();
     mailGroupBus = new MailGroupBUS();
     dgBUS = new DetailGroupBUS();
 }
 private void InitialBUS()
 {
     scBUS = new SendContentBUS();
     mailConfigBus = new MailConfigBUS();
     mailGroupBus = new MailGroupBUS();
     customerBus = new CustomerBUS();
     srBUS = new SendRegisterBUS();
     common = new Common();
     dsgBUS = new DetailGroupBUS();
 }
    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 = "";
        }
    }
    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");
        }
    }
Example #15
0
    protected void drlMailGroup_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            countBUS = new CountBuyBUS();

            int categoryID = int.Parse(this.drlMailGroup.SelectedValue.ToString());
            DataTable tblCustomer = new DataTable();
            if (categoryID == -1)
            {
                customerBus = new CustomerBUS();
                tblCustomer = customerBus.GetByCountBuy(1);
            }
            else if (categoryID == -2)
            {
                customerBus = new CustomerBUS();
                tblCustomer = customerBus.GetByCountBuy(2);
            }
            else
            {
                tblCustomer = countBUS.GetByCategoryID(categoryID);
            }

            lblCountCustomer.Text = "Hiện có " + tblCustomer.Rows.Count + " khách hàng trong nhóm này !";

        }
        catch (Exception)
        {
            lblCountCustomer.Text = "Lỗi chọn nhóm người nhận";
        }
    }
Example #16
0
 private void InitBUS()
 {
     ulBus = new UserLoginBUS();
     mgBUS = new MailGroupBUS();
     srBUS = new SendRegisterBUS();
     ctBUS = new CustomerBUS();
     dgBUS = new DetailGroupBUS();
 }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        bool status = false;
        InitBus();
        string err = ValidateInput();
        //Thêm khách hàng
        if (err == "")
        {
            try
            {
                if (ctBUS.GetByEmail(GetCustomerDTO().Email).Rows.Count > 0)
                {
                    CustomerID = int.Parse(ctBUS.GetByEmail(GetCustomerDTO().Email).Rows[0]["Id"].ToString());
                    ctBUS.tblCustomer_Update(GetCustomerDTO());
                }
                else
                {
                    CustomerID = ctBUS.tblCustomer_insert(GetCustomerDTO());
                }
                int GroupID = int.Parse(this.drlGroupMail.SelectedValue);
                DetailGroupDTO dgDTO = new DetailGroupDTO() { CustomerID = CustomerID, GroupID = GroupID };
                //Thêm vào nhóm mail
                if (dgBUS.GetByID(GroupID, CustomerID).Rows.Count == 0)
                {
                    dgBUS.tblDetailGroup_insert(dgDTO);
                }
                //Thêm vào hóa đơn
                if (oBUS.tblOrder_GetByID(GetOrderDTO().OrderID).Rows.Count > 0 || hdfUpdate.Value!="")
                {
                    status = GetOrderDTO().Status;
                    oBUS.tblOrder_updateStatus(GetOrderDTO().OrderID, status);
                }
                else
                {
                    oBUS.tblOrder_insert(GetOrderDTO());
                }
                // Thêm vào chi tiết hóa đơn
                DataTable tblProduct = (DataTable)Session["orderList"];
                if (tblProduct.Rows.Count > 0)
                {
                    OrderDatailDTO odDTO = new OrderDatailDTO();
                    for (int i = 0; i < tblProduct.Rows.Count; i++)
                    {
                        //Thêm từng sản phẩm vào chi tiết đơn hàng
                        odDTO.ProductID = int.Parse(tblProduct.Rows[i]["ProductID"].ToString());
                        odDTO.OrderID = txtOrderID.Text;
                        odDTO.ProductName = tblProduct.Rows[i]["ProductName"].ToString();
                        odDTO.DeliveryCode = tblProduct.Rows[i]["DeliveryCode"].ToString();
                        odDTO.UnitPrice = float.Parse(tblProduct.Rows[i]["UnitPrice"].ToString());
                        odDTO.Quantity = int.Parse(tblProduct.Rows[i]["Quantity"].ToString());
                        odDTO.Total = odDTO.Quantity * odDTO.UnitPrice;
                        odDTO.Note = tblProduct.Rows[i]["Note"].ToString();
                        odDTO.Size = "M";
                        int CateGoryID;
                        if (odBUS.tblOrderDetail_GetByID(txtOrderID.Text, odDTO.ProductID).Rows.Count > 0)
                        {
                            odBUS.tblOrderDetail_update(odDTO);
                        }
                        else
                        {
                            odBUS.tblOrderDetail_insert(odDTO);
                        }

                        if (status == true)
                        {
                            prBUS = new ProductBUS();
                            //Lấy nhóm của sản phẩm
                            CateGoryID = int.Parse(prBUS.GetByID(odDTO.ProductID).Rows[0]["Category"].ToString());
                            countBUS = new CountBuyBUS();
                            if (countBUS.GetByID(CustomerID, CateGoryID).Rows.Count > 0)
                            {
                                //Cập nhật số lần mua của khách hàng này theo nhóm sản phẩm
                                countBUS.tblCountBuy_UpdateCountBuy(CustomerID, CateGoryID);
                            }
                            else
                            {
                                //Thêm vào đếm lần mua theo nhóm
                                countBUS.tblCountBuy_insert(CustomerID, CateGoryID, 1);
                            }
                        }

                    }
                    //Cập nhật số lần mua cho khách hàng
                    if (status == true)
                    {
                        ctBUS = new CustomerBUS();
                        ctBUS.tblCustomer_UpdateCountBuy(CustomerID);
                    }
                    //Load lại thông tin khách hàng
                    Visible(false);
                    pnSuccess.Visible = true;
                    lblSuccess.Text = "Cập nhật thành công một đơn hàng";
                    LoadDefautlValue();
                    Session["orderList"] = null;
                    //Tạo mã hóa đơn tự động
                    AutoCreateID();
                }
            }
            catch (Exception ex)
            {
                Visible(false);
                pnError.Visible = true;
                lblError.Text = "Lỗi xảy ra trong quá trình nhập:" + ex.Message;
            }
        }
        else
        {
            Visible(false);
            pnError.Visible = true;
            lblError.Text = err;
        }
    }