protected void lbtExecute_Click(object sender, EventArgs e) { try { DataListItem footer = (DataListItem)dlReport.Controls[dlReport.Controls.Count - 1]; DropDownList drlType = (DropDownList)footer.FindControl("drlType"); Label lblMessage = (Label)footer.FindControl("lblMessage"); if (drlType.SelectedValue == "1") { int countDelete = 0; for (int i = 0; i < dlReport.Items.Count; i++) { DataListItem item = dlReport.Items[i]; HiddenField id = (HiddenField)item.FindControl("hdfId"); CheckBox chkXoa = (CheckBox)item.FindControl("chkXoa"); srBUS = new SendRegisterBUS(); if (chkXoa.Checked == true) { srBUS.tblSendRegister_Delete(int.Parse(id.Value.ToString())); countDelete++; } } LoadDataListContent(); lblMessage.Text = countDelete.ToString(); } } catch (Exception ex) { pnError.Visible = true; lblError.Text = ex.Message; } }
protected void btnDelete_Click(object sender, ImageClickEventArgs e) { try { int ContentId = int.Parse(((ImageButton)sender).CommandArgument); ConnectionData.OpenMyConnection(); SendRegisterBUS srBUS = new SendRegisterBUS(); if (srBUS.GetByContentID(ContentId) > 0) { visibleMessage(false); pnError.Visible = true; lblError.Text = "Bạn không thể xóa nội dung này! Nội dung này đang chờ gửi!"; } else { scBus.tblSendContent_Delete(ContentId); //Response.Redirect(Request.RawUrl); LoadDataListContent(); visibleMessage(false); pnSuccess.Visible = true; lblSuccess.Text = "Bạn vừa xóa thành công nội dung mail !"; } ConnectionData.CloseMyConnection(); } catch (Exception ex) { pnError.Visible = true; lblError.Text = ex.Message; } }
protected void drlCampaign_SelectedIndexChanged(object sender, EventArgs e) { int readMail = 0; try { srBUS = new SendRegisterBUS(); srdBus = new SendRegisterDetailBUS(); sendContentBus = new SendContentBUS(); mgBus = new MailGroupBUS(); int sendId = int.Parse(drlCampaign.SelectedValue.ToString()); DataTable campain = srdBus.GetByID(sendId); DataTable errSend = srdBus.GetByStatus(false, sendId); DataTable unreceve = srdBus.GetByNotReceve(sendId); int err = errSend.Rows.Count; this.lblTotalMailSend.Text = campain.Rows.Count.ToString(); int notreceve = unreceve.Rows.Count; lblEmailSend.Text = new MailConfigBUS().GetByID(int.Parse(srBUS.GetByID(sendId).Rows[0]["mailconfigid"]+"")).Rows[0]["eMail"].ToString(); if (campain.Rows.Count > 0) { foreach (DataRow row in campain.Rows) { if (row["isOpenMail"].ToString() == "True") { readMail++; } } lblNotOpen2.Text = (campain.Rows.Count - readMail).ToString(); } lblNotOpen2.Text = "0"; lblOpened.Text = readMail.ToString(); DataTable sendregisteDetail = srBUS.GetByID(sendId); if (sendregisteDetail.Rows.Count > 0) { int contentID = int.Parse(sendregisteDetail.Rows[0]["SendContentId"].ToString()); lblDateStart.Text = sendregisteDetail.Rows[0]["StartDate"].ToString(); lblDateEnd.Text = sendregisteDetail.Rows[0]["EndDate"].ToString(); int groupSend = int.Parse(sendregisteDetail.Rows[0]["GroupTo"].ToString()); if (groupSend == -3) lblGroupEmailTo.Text = "Tất cả"; else lblGroupEmailTo.Text = mgBus.GetByID(groupSend).Rows[0]["Name"].ToString(); if (sendContentBus.GetByID(contentID).Rows.Count > 0) { lblCampianName.Text = sendContentBus.GetByID(contentID).Rows[0]["Subject"].ToString(); } } if (campain.Rows.Count > 0) CreateChart(campain.Rows.Count, err, readMail, 1, notreceve, lblCampianName.Text); else lblChart.Text = ""; LoadOpenEmail(sendId); } catch (Exception ex) { //pnError.Visible = true; //lblError.Text = ex.Message; } }
protected void loadDetailReport(bool status) { srBUS = new SendRegisterBUS(); srdBus = new SendRegisterDetailBUS(); DataTable tblSendDetail = new DataTable(); UserLoginDTO userLogin = getUserLogin(); if (userLogin.DepartmentId == 1) { tblSendDetail = srdBus.GetByStatus(status); } else if (userLogin.DepartmentId == 2) { tblSendDetail = srdBus.GetByStatus_User(status, userLogin.UserId); } else tblSendDetail = srdBus.GetByStatus_SubUser(status, userLogin.UserId); if (tblSendDetail.Rows.Count > 0) { dlPager.MaxPages = 1000; dlPager.PageSize = 100; dlPager.DataSource = tblSendDetail.DefaultView; dlPager.BindToControl = dlReport; this.dlReport.DataSource = dlPager.DataSourcePaged; this.dlReport.DataBind(); int count = 0; for (int i = 0; i < tblSendDetail.Rows.Count; i++) { count++; DataRow row = tblSendDetail.Rows[i]; Label lblNo = (Label)dlReport.Items[i].FindControl("lblNo"); lblNo.Text = count.ToString(); HiddenField hdfId = (HiddenField)dlReport.Items[i].FindControl("hdfId"); hdfId.Value = row["SendRegisterId"].ToString(); Label lblEmail = (Label)dlReport.Items[i].FindControl("lblEmail"); lblEmail.Text = row["Email"].ToString(); Label lblStartDate = (Label)dlReport.Items[i].FindControl("lblStartDate"); lblStartDate.Text = row["StartDate"].ToString(); Label lblEndDate = (Label)dlReport.Items[i].FindControl("lblEndDate"); lblEndDate.Text = row["EndDate"].ToString(); ImageButton ibtStatus = (ImageButton)dlReport.Items[i].FindControl("ibtStatus"); bool check = Boolean.Parse(row["Status"].ToString()); if (check == true) { ibtStatus.ImageUrl = "~/webapp/resource/images/ok.png"; } else { ibtStatus.ImageUrl = "~/webapp/resource/images/warning.png"; } } } }
protected void btnDelete_Click(object sender, ImageClickEventArgs e) { try { UserLoginDTO userLogin = getUserLogin(); ConnectionData.OpenMyConnection(); int Id = int.Parse(((ImageButton)sender).CommandArgument.ToString()); mcBUS = new MailConfigBUS(); SendRegisterBUS srBUS = new SendRegisterBUS(); if (srBUS.GetByMailConfigID(Id) > 0) { visibleMessage(false); pnError.Visible = true; lblError.Text = "Bạn vừa không thể xóa cấu hình này được. Cấu hình này đang có mail chờ gửi !"; } else { int IDCurrent = userLogin.UserId; if (Id != IDCurrent) { mcBUS.tblMailConfig_Delete(Id); //Response.Redirect(Request.RawUrl); dlMailConfig.DataSource = mcBUS.GetAll(); dlMailConfig.DataBind(); visibleMessage(false); pnSuccess.Visible = true; lblSuccess.Text = "Bạn vừa xóa thành một cấu hình !"; } else { visibleMessage(false); pnError.Visible = true; lblError.Text = "Bạn vừa không thể xóa cấu hình này được. Cấu hình này đang là cấu hình bạn đang đăng nhập!"; } } ConnectionData.CloseMyConnection(); } catch (Exception ex) { //pnError.Visible = true; //lblError.Text = ex.Message; } }
protected void loadSendRegisterList(int status) { srBUS = new SendRegisterBUS(); sendContentBus = new SendContentBUS(); DataTable tblSendList = new DataTable(); if (getUserLogin().DepartmentId==1) { tblSendList = srBUS.GetByStatus(status); } else { tblSendList = srBUS.GetByStatusUser(status, getUserLogin().UserId); } if (tblSendList.Rows.Count > 0) { DataTable temp = new DataTable(); for (int i = 0; i < tblSendList.Rows.Count; i++) { try { //temp = sendContentBus.GetByID(int.Parse(tblSendList.Rows[i]["SendContentId"].ToString())); //if (temp.Rows.Count > 0) //{ drlCampaign.Items.Add( new ListItem(tblSendList.Rows[i]["Subject"].ToString() + " - " + tblSendList.Rows[i]["StartDate"].ToString(), tblSendList.Rows[i]["Id"].ToString())); //} } catch (Exception) { continue; } } } else { drlCampaign.Items.Add(new ListItem("Không có chiến dịch nào !", "1")); pnReport.Visible = false; } }
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) { } }
private void LoadDataListContent() { srBUS = new SendRegisterBUS(); this.dlWaitSend.DataSource = srBUS.GetWailSend(DateTime.Now); this.dlWaitSend.DataBind(); }
protected void lbtDelete_Click(object sender, EventArgs e) { try { srBUS = new SendRegisterBUS(); int sendRegisterId = int.Parse(((LinkButton)sender).CommandArgument.ToString()); ConnectionData.OpenMyConnection(); srBUS.tblSendRegister_Delete(sendRegisterId); ConnectionData.CloseMyConnection(); pnError.Visible = false; pnSuccess.Visible = true; lblSuccess.Text = "Bạn đã xóa thành công !"; getRegisterSendList(); } catch (Exception ex) { pnSuccess.Visible = false; pnError.Visible = true; lblError.Text = ex.Message; } }
// 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; } }
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() { ulBus = new UserLoginBUS(); mgBUS = new MailGroupBUS(); srBUS = new SendRegisterBUS(); ctBUS = new CustomerBUS(); dgBUS = new DetailGroupBUS(); }
private void Insert(DateTime startDate, bool isSave) { srBUS = new SendRegisterBUS(); scBUS = new SendContentBUS(); SendContentDTO scDTO = new SendContentDTO(); scDTO = getContentDTO(); //Lấy thời gian của người dùng Thiết lập DateTime timeEnd = startDate.AddMinutes(calcTimeForGroup(int.Parse(drlMailGroup.SelectedValue)) + 1); DateTime timeStart = startDate; int GroupID = 0; DataTable tableFirt = new DataTable(); tableFirt = srBUS.GetByTimeCheck(startDate, 0);// 0 là chưa gửi. if (tableFirt.Rows.Count > 0) { GroupID = int.Parse(tableFirt.Rows[0]["GroupTo"].ToString()); timeStart = DateTime.Parse(tableFirt.Rows[0]["StartDate"].ToString()).AddMinutes(calcTimeForGroup(GroupID) + 1); if (timeStart < startDate) { timeStart = startDate; } else { } timeEnd = timeStart.AddMinutes(calcTimeForGroup(int.Parse(drlMailGroup.SelectedValue)) + 1); } else { } SelectTime: ; tableFirt = srBUS.GetByTimeNext(timeStart, timeEnd, 0); if (tableFirt.Rows.Count > 0) { GroupID = int.Parse(tableFirt.Rows[0]["GroupTo"].ToString()); timeStart = DateTime.Parse(tableFirt.Rows[0]["StartDate"].ToString()).AddMinutes(calcTimeForGroup(GroupID) + 1); timeEnd = timeStart.AddMinutes(calcTimeForGroup(int.Parse(drlMailGroup.SelectedValue)) + 1); goto SelectTime; } else { int contentID = 0; if (isSave) { contentID = scBUS.tblSendContent_insert(scDTO); } SendRegisterDTO srDto = getSendRegister(); srDto.SendContentId = contentID; srDto.StartDate = timeStart; srDto.Subject = txtSubject.Text; srDto.Body = txtBody.Text; srBUS.tblSendRegister_insert(srDto); } Response.Redirect("wait-send.aspx", false); }
private void InitialBUS() { scBUS = new SendContentBUS(); mailConfigBus = new MailConfigBUS(); mailGroupBus = new MailGroupBUS(); customerBus = new CustomerBUS(); srBUS = new SendRegisterBUS(); common = new Common(); dsgBUS = new DetailGroupBUS(); }
private void InitBUS() { ctBUS = new CustomerBUS(); mgBUS = new MailGroupBUS(); srBUS = new SendRegisterBUS(); dtgBUS = new DetailGroupBUS(); }
protected void Page_Load(object sender, EventArgs e) { userLogin = getUserLogin(); if (!IsPostBack) { try { srBUS = new SendRegisterBUS(); loadDetailReport(true); } catch (Exception ex) { pnError.Visible = true; lblError.Text = ex.Message; logs.Error(userLogin.Username+"-mailSend-load",ex); } } srBUS = new SendRegisterBUS(); }
public void RunActiveMail(DataTable listSendRegister, DataTable listSendContent, DataTable listCustomer, DataTable listMailConfig) { //Biến sendMail string EmailTo = ""; string EmailSubject = ""; string EmailBody = ""; string EmailFrom = ""; string Name = ""; string Password = ""; string HostName = ""; int PortNumber = 0; //Biến lấy nội dung int SendContentId; int EmailFromID; int SendRegisterID; SendRegisterBUS srBus = new SendRegisterBUS(); //Kiểm tra và duyệt if (listSendRegister.Rows.Count > 0) { //So sánh thời gian hiện tại với thời gian cần gửi mail DataRow[] resultListSendRegister = listSendRegister.Select(String.Format("StartDate = #{0}#", String.Format("{0:yyyy-M-d HH:mm:ss}", DateTime.Now))); if (resultListSendRegister.Length > 0) { foreach (DataRow Row in resultListSendRegister) { 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(); } //Mail nhận EmailTo = Row["AccountId"].ToString(); SendRegisterID = int.Parse(Row["Id"].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(); //Name = "Chợ Mỹ tại Việt Nam"; PortNumber = int.Parse(resultListMailConfig[0]["Port"].ToString()); } bool send; send = SendMail(EmailSubject, EmailBody, HostName, PortNumber, EmailFrom, Password, Name, EmailTo); if (send == true) { ConnectionData.OpenMyConnection(); srBus.tblSendRegister_UpdateStatus(SendRegisterID, 2, DateTime.Now); ConnectionData.CloseMyConnection(); } } } else return; } else return; }
protected string LoadChart(object id) { int readMail = 0; try { //int i=0; for (int i = 0; i < dlContentSendEvent.Items.Count; i++) { HiddenField hdfId = (HiddenField)dlContentSendEvent.Items[i].FindControl("hdfId"); if (hdfId.Value + "" == id + "") { SendRegisterBUS srBUS = new SendRegisterBUS(); SendRegisterDetailBUS srdBus = new SendRegisterDetailBUS(); SendContentBUS sendContentBus = new SendContentBUS(); MailGroupBUS mgBus = new MailGroupBUS(); int sendId = int.Parse(id + ""); DataTable campain = srdBus.GetByContentID(sendId); DataTable errSend = srdBus.GetContentSendEventDetailByStatus(false, sendId); DataTable unreceve = srdBus.GetByNotReceve(sendId); int err = errSend.Rows.Count; Label lblTotalMailSend = (Label)dlContentSendEvent.Items[i].FindControl("lblTotalMailSend"); Label lblEmailSend = (Label)dlContentSendEvent.Items[i].FindControl("lblEmailSend"); Label lblNotOpen2 = (Label)dlContentSendEvent.Items[i].FindControl("lblNotOpen2"); Label lblOpened = (Label)dlContentSendEvent.Items[i].FindControl("lblOpened"); Label lblDateStart = (Label)dlContentSendEvent.Items[i].FindControl("lblDateStart"); Label lblDateEnd = (Label)dlContentSendEvent.Items[i].FindControl("lblDateEnd"); Label lblGroupEmailTo = (Label)dlContentSendEvent.Items[i].FindControl("lblGroupEmailTo"); Label lblCampianName = (Label)dlContentSendEvent.Items[i].FindControl("lblCampianName"); Label lblChart = (Label)dlContentSendEvent.Items[i].FindControl("lblChart"); lblTotalMailSend.Text = campain.Rows.Count.ToString(); int notreceve = unreceve.Rows.Count; if (campain.Rows.Count > 0) { lblEmailSend.Text = campain.Rows[0]["MailSend"].ToString(); foreach (DataRow row in campain.Rows) { if (row["isOpenMail"].ToString() == "True") { readMail++; } } lblNotOpen2.Text = (campain.Rows.Count - readMail).ToString(); } lblOpened.Text = readMail.ToString(); DataTable sendregisteDetail = cseBus.GetById(sendId); if (sendregisteDetail.Rows.Count > 0) { int contentID = int.Parse(sendregisteDetail.Rows[0]["id"].ToString()); //lblDateStart.Text = sendregisteDetail.Rows[0]["StartDate"].ToString(); //lblDateEnd.Text = sendregisteDetail.Rows[0]["EndDate"].ToString(); int groupSend = int.Parse(sendregisteDetail.Rows[0]["GroupTo"].ToString()); if (groupSend == -3) lblGroupEmailTo.Text = "Tất cả"; else lblGroupEmailTo.Text = mgBus.GetByID(groupSend).Rows[0]["Name"].ToString(); if (sendContentBus.GetByID(contentID).Rows.Count > 0) { lblCampianName.Text = sendContentBus.GetByID(contentID).Rows[0]["Subject"].ToString(); } } CreateChart(campain.Rows.Count, err, readMail, 1, notreceve, lblCampianName.Text, lblChart); } } } catch (Exception ex) { pnError.Visible = true; lblError.Text = ex.Message; } return ""; }
private void LoadDataListContent() { srBUS = new SendRegisterBUS(); this.dlReport.DataSource = srBUS.GetSended(); this.dlReport.DataBind(); }