public void tblDetailGroup_Update(DetailGroupDTO dt) { dsgDAO.tblDetailGroup_Update(dt); }
public void tblDetailGroup_Update(DetailGroupDTO dt) { dgDao.tblDetailGroup_Update(dt); }
public void tblDetailGroup_insert(DetailGroupDTO dt) { dsgDAO.tblDetailGroup_insert(dt); }
public void tblDetailGroup_Update(DetailGroupDTO dt) { string sql = "UPDATE tblDetailGroup SET countReceivedMail = @countReceivedMail, LastReceivedMail = @LastReceivedMail " + " WHERE GroupID = @GroupID and CustomerID=@CustomerID"; cmd = new SqlCommand(sql, ConnectionData._MyConnection); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@GroupID", SqlDbType.Int).Value = dt.GroupID; cmd.Parameters.Add("@CustomerID", SqlDbType.Int).Value = dt.GroupID; cmd.Parameters.Add("@countReceivedMail", SqlDbType.Int).Value = dt.CountReceivedMail; cmd.Parameters.Add("@LastReceivedMail", SqlDbType.DateTime).Value = dt.LastReceivedMail; if (ConnectionData._MyConnection.State == ConnectionState.Closed) { ConnectionData._MyConnection.Open(); } cmd.ExecuteNonQuery(); cmd.Dispose(); }
public void tblDetailGroup_insert(DetailGroupDTO dt) { dgDao.tblDetailGroup_insert(dt); }
// 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 tblDetailGroup_insert(DetailGroupDTO dt) { string sql = "INSERT INTO tblDetailGroup(GroupID, CustomerID,countReceivedMail,LastReceivedMail) " + "VALUES(@GroupID, @CustomerID, @countReceivedMail, @LastReceivedMail)"; cmd = new SqlCommand(sql, ConnectionData._MyConnection); cmd.CommandType = CommandType.Text; cmd.Parameters.Add("@GroupID", SqlDbType.Int).Value = dt.GroupID; cmd.Parameters.Add("@CustomerID", SqlDbType.Int).Value = dt.CustomerID; cmd.Parameters.Add("@countReceivedMail", SqlDbType.Int).Value = dt.CountReceivedMail; cmd.Parameters.Add("@LastReceivedMail", SqlDbType.DateTime).Value = dt.LastReceivedMail; if (ConnectionData._MyConnection.State == ConnectionState.Closed) { ConnectionData._MyConnection.Open(); } cmd.ExecuteNonQuery(); cmd.Dispose(); }
protected void btnAdd_Click(object sender, EventArgs e) { try { InitBUS(); Visible(false); int GroupID = 0; if (drlGroup.SelectedIndex >= 0) { GroupID = int.Parse(drlGroup.SelectedValue.ToString()); } int CustomerID = 0; string message = checkInputCustomer(); if (message != "") { pnError.Visible = true; lblError.Text = message; } else { ConnectionData.OpenMyConnection(); CustomerDTO ctDTO = new CustomerDTO(); ctDTO.Address = this.txtAddress.Text; ctDTO.BirthDay = convertStringToDate(txtBirthday.Text); ctDTO.City = ""; ctDTO.Company = ""; ctDTO.Country = ""; ctDTO.Email = txtEmail.Text.Trim(); ctDTO.Fax = ""; ctDTO.Gender = drlGender.SelectedItem.ToString(); ctDTO.Name = txtName.Text; ctDTO.Phone = this.txtPhone.Text; ctDTO.Province = ""; ctDTO.SecondPhone = txtHomePhone.Text; ctDTO.Type = ""; ctDTO.UserID = getUserLogin().UserId; ctDTO.createBy = getUserLogin().UserId; DataTable table = null; if (drlGroup.SelectedIndex >= 0) { ctDTO.AssignTo = int.Parse(drlGroup.SelectedValue.ToString()); } long countEmail = 0; //them moi if (hdfCustomerId.Value == null || hdfCustomerId.Value == "") { if (getUserLogin().DepartmentId == 2) { table = ctBUS.GetClientId(getUserLogin().UserId); } else { table = ctBUS.GetClientIdSub(getUserLogin().UserId); } if (table.Rows.Count > 0) { int clienID = int.Parse(table.Rows[0]["clientId"].ToString()); DataTable dtCountEmail = ctBUS.GetCountEmail(clienID); if (dtCountEmail.Rows[0]["isUnLimit"] + "" != "" && Convert.ToBoolean(dtCountEmail.Rows[0]["isUnLimit"])) countEmail = 1000000000000000000; else countEmail = int.Parse(dtCountEmail.Rows[0]["under"].ToString()); } int statusclient = int.Parse(table.Rows[0]["Status"].ToString()); DataTable dtEmail = ctBUS.GetCountCustomerCreatedMail(getUserLogin().UserId); int numbermail = int.Parse(dtEmail.Rows[0]["numberMail"].ToString()); DateTime NgayHetHan = Convert.ToDateTime(table.Rows[0]["expireDate"].ToString()); //string todays = DateTime.Now.ToString("yyyy-MM-dd"); DateTime today = DateTime.Now.Date; DateTime expireDay = Convert.ToDateTime(NgayHetHan); DataTable checkEmail = ctBUS.GetCheckEmailByUserId(txtEmail.Text.Trim(), userLogin.UserId); if (statusclient == 2 || expireDay < today) { lblError.Text = "Thời gian đăng ký của bạn đã hết hạn, Vui lòng liên hệ quản trị hoặc vào thông tin tài khoản để gia hạn thêm!"; pnSuccess.Visible = false; pnError.Visible = true; return; } else { if (numbermail < countEmail) { if (checkEmail.Rows.Count > 0) { pnSuccess.Visible = false; pnError.Visible = true; lblError.Text = "Email đã được sử dụng. Vui lòng chọn email khác !"; this.txtEmail.Focus(); } else { CustomerID = ctBUS.tblCustomer_insert(ctDTO); if (dgBUS.GetByID(GroupID, CustomerID).Rows.Count > 0) { pnSuccess.Visible = false; pnError.Visible = true; lblError.Text = "Khách hàng này đã tồn tại trong nhóm này !"; } else { DetailGroupDTO dgDTO = new DetailGroupDTO(); dgDTO.GroupID = GroupID; dgDTO.CustomerID = CustomerID; dgDTO.CountReceivedMail = 0; dgDTO.LastReceivedMail = DateTime.Now; dgBUS.tblDetailGroup_insert(dgDTO); pnError.Visible = false; pnSuccess.Visible = true; lblSuccess.Text = "Bạn đã thêm thành công 1 khách hàng vào nhóm: " + drlGroup.SelectedItem.ToString(); // Update limit send and create. updateLimitSendAndCreate(1, 0); setTextDefault(); } } } else { lblError.Text = "Vượt quá hạng ngạch tạo khách hàng!"; pnSuccess.Visible = false; pnError.Visible = true; } } } //update else { CustomerID = int.Parse(this.CustomerID.Value.ToString()); GroupID = int.Parse(drlGroup.SelectedValue.ToString()); ctDTO.Id = int.Parse(this.CustomerID.Value.ToString()); // CustomerID = int.Parse(ctBUS.GetByEmail(txtEmail.Text).Rows[0]["Id"].ToString()); DataTable checkEmail = ctBUS.GetEmailByUser(CustomerID, txtEmail.Text.Trim()); if (checkEmail.Rows.Count > 0) { pnSuccess.Visible = false; pnError.Visible = true; lblError.Text = "Email đã được sử dụng. Vui lòng chọn email khác !"; this.txtEmail.Focus(); } else { ctBUS.tblCustomer_Update(ctDTO); pnError.Visible = false; pnSuccess.Visible = true; lblSuccess.Text = "Bạn đã cập nhật thành công 1 khách hàng"; } //if (dgBUS.GetByID(GroupID, CustomerID).Rows.Count > 0) //{ // pnSuccess.Visible = false; // pnError.Visible = true; // lblError.Text = "Khách hàng này đã tồn tại trong nhóm này !"; //} //else //{ // DetailGroupDTO dgDTO = new DetailGroupDTO(); // dgDTO.GroupID = GroupID; // dgDTO.CustomerID = CustomerID; // dgDTO.LastReceivedMail = DateTime.Now; // dgBUS.tblDetailGroup_insert(dgDTO); // pnError.Visible = false; // pnSuccess.Visible = true; // lblSuccess.Text = "Bạn đã cập nhật thành công 1 khách hàng vào nhóm: " + drlGroup.SelectedItem.ToString(); // // Update limit send and create. // updateLimitSendAndCreate(1, 0); //} } //tam edit // if (this.CustomerID.Value.ToString() == "") // { /// DataTable tblCheckByEmail = ctBUS.GetByEmail(txtEmail.Text); // if (tblCheckByEmail.Rows.Count > 0) // { // CustomerID = int.Parse(tblCheckByEmail.Rows[0]["Id"].ToString()); // ctDTO.Id = CustomerID; // ctBUS.tblCustomer_Update(ctDTO); // pnError.Visible = false; // pnSuccess.Visible = true; //lblSuccess.Text = "Bạn đã cập nhật thông thành công 1 khách hàng ! <br/>"; // } //tamhm edit //else //{ // CustomerID = ctBUS.tblCustomer_insert(ctDTO); //} //if (dgBUS.GetByID(GroupID, CustomerID).Rows.Count > 0) //{ // pnSuccess.Visible = false; // pnError.Visible = true; // lblError.Text = "Khách hàng này đã tồn tại trong nhóm này !"; //} //else //{ // DetailGroupDTO dgDTO = new DetailGroupDTO(); // dgDTO.GroupID = GroupID; // dgDTO.CustomerID = CustomerID; // dgDTO.CountReceivedMail = 0; // dgDTO.LastReceivedMail = DateTime.Now; // dgBUS.tblDetailGroup_insert(dgDTO); // pnError.Visible = false; // pnSuccess.Visible = true; // lblSuccess.Text = "Bạn đã thêm thành công 1 khách hàng vào nhóm: " + drlGroup.SelectedItem.ToString(); // // Update limit send and create. // updateLimitSendAndCreate(1, 0); //} // } // else // { // CustomerID = int.Parse(this.CustomerID.Value.ToString()); // GroupID = int.Parse(drlGroup.SelectedValue.ToString()); // ctDTO.Id = int.Parse(this.CustomerID.Value.ToString()); // CustomerID = int.Parse(ctBUS.GetByEmail(txtEmail.Text).Rows[0]["Id"].ToString()); // ctBUS.tblCustomer_Update(ctDTO); // pnError.Visible = false; // pnSuccess.Visible = true; //// lblSuccess.Text = "Bạn đã cập nhật thông thành công 1 khách hàng ! <br/>"; // if (dgBUS.GetByID(GroupID, CustomerID).Rows.Count > 0) // { // pnSuccess.Visible = false; // pnError.Visible = true; // lblError.Text = "Khách hàng này đã tồn tại trong nhóm này !"; // } // else // { // DetailGroupDTO dgDTO = new DetailGroupDTO(); // dgDTO.GroupID = GroupID; // dgDTO.CustomerID = CustomerID; // dgBUS.tblDetailGroup_insert(dgDTO); // pnError.Visible = false; // pnSuccess.Visible = true; // lblSuccess.Text = "Bạn đã thêm thành công 1 khách hàng vào nhóm: " + drlGroup.SelectedItem.ToString(); // // Update limit send and create. // updateLimitSendAndCreate(1, 0); // } //} ConnectionData.CloseMyConnection(); //setTextDefault(); } } catch (Exception ex) { logs.Error(userLogin.Username + "-Client - btnAdd_Click", ex); pnError.Visible = true; lblError.Text = "Lỗi trong quá trình thêm khách hàng!" + ex.Message.ToString(); } }
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; } }
protected void btnSave_Click(object sender, EventArgs e) { CustomerDTO ctDTO = new CustomerDTO(); int groupID = int.Parse(drlMailGroup.SelectedValue.ToString()); int CustomerID = 0; int count = 0; int err = 0; long countEmail = 0; try { for (int i = 0; i < dtlCustomer.Items.Count; i++) { DataListItem item = dtlCustomer.Items[i]; CheckBox chkXoa = (CheckBox)item.FindControl("chkCheck"); Label lblName = (Label)item.FindControl("lblName"); Label lblGender = (Label)item.FindControl("lblGender"); Label lblBirthDay = (Label)item.FindControl("lblBirthDay"); Label lblEmail = (Label)item.FindControl("lblEmail"); Label lblPhone = (Label)item.FindControl("lblPhone"); Label lblAddr = (Label)item.FindControl("lblAddr"); InitBUS(); if (chkXoa.Checked == true && EmailTools.IsEmail(lblEmail.Text.Trim())) { try { ConnectionData.OpenMyConnection(); ctDTO.Name = (lblName.Text == null || lblName.Text == "") ? "Không có" : lblName.Text; ctDTO.Email = lblEmail.Text.Trim(); ctDTO.BirthDay = (lblBirthDay.Text == null || lblBirthDay.Text == "") ? DateTime.Now : DateTime.Parse(lblBirthDay.Text); ctDTO.Gender = (lblGender.Text == null || lblGender.Text == "") ? "Không có" : lblGender.Text; ctDTO.Phone = (lblPhone.Text == null || lblPhone.Text == "") ? "Không có" : lblPhone.Text; ctDTO.Address = (lblAddr.Text == null || lblAddr.Text == "") ? "Không có" : lblAddr.Text; ctDTO.City = ""; ctDTO.Job = ""; ctDTO.Company = ""; ctDTO.Country = ""; ctDTO.Province = ""; ctDTO.Fax = ""; ctDTO.SecondPhone = ""; ctDTO.Type = ""; ctDTO.UserID = getUserLogin().UserId; ctDTO.createBy = getUserLogin().UserId; ctDTO.AssignTo = int.Parse(drlMailGroup.SelectedItem.Value); count++; DataTable checkExistsMail = ctBUS.GetByEmail(lblEmail.Text, getUserLogin().UserId); if (checkExistsMail.Rows.Count > 0) { CustomerID = int.Parse(checkExistsMail.Rows[0]["Id"].ToString()); } else { if (getUserLogin().DepartmentId == 2) { table = ctBUS.GetClientId(getUserLogin().UserId); } else { table = ctBUS.GetClientIdSub(getUserLogin().UserId); } if (table.Rows.Count > 0) { int clienID = int.Parse(table.Rows[0]["clientId"].ToString()); DataTable dtCountEmail = ctBUS.GetCountEmail(clienID); if (dtCountEmail.Rows[0]["isUnLimit"] + "" != "" || Convert.ToBoolean(dtCountEmail.Rows[0]["isUnLimit"])) countEmail = 1000000000000000000; countEmail = int.Parse(dtCountEmail.Rows[0]["under"].ToString()); } int statusclient = int.Parse(table.Rows[0]["Status"].ToString()); DateTime NgayHetHan = Convert.ToDateTime(table.Rows[0]["expireDate"].ToString()); string todays = DateTime.Now.ToString("yyyy-MM-dd"); DateTime today = Convert.ToDateTime(todays); DateTime expireDay = Convert.ToDateTime(NgayHetHan); DataTable dtEmail = ctBUS.GetCountCustomerCreatedMail(getUserLogin().UserId); int numbermail = int.Parse(dtEmail.Rows[0]["numberMail"].ToString()); if (statusclient == 2 || expireDay < today) { lblError.Text = "Thời gian đăng ký của bạn đã hết hạn, Vui lòng liên hệ quản trị hoặc vào thông tin tài khoản để gia hạn thêm!"; pnSuccess.Visible = false; pnError.Visible = true; break; } else { if (numbermail < countEmail) { CustomerID = ctBUS.tblCustomer_insert(ctDTO); } else { lblError.Text = "Vượt quá hạng ngạch tạo khách hàng!"; pnSuccess.Visible = false; pnError.Visible = true; } } } if (dgBUS.GetByID(groupID, CustomerID).Rows.Count > 0) { count--; err++; } else { DetailGroupDTO dgDTO = new DetailGroupDTO(); dgDTO.GroupID = groupID; dgDTO.CustomerID = CustomerID; dgDTO.CountReceivedMail = 0; dgDTO.LastReceivedMail = DateTime.Now; dgBUS.tblDetailGroup_insert(dgDTO); } ConnectionData.OpenMyConnection(); } catch (Exception exx) { logs.Error(userLogin.Username + "-Add Customer - btnSave_Click", exx); continue; } } } if (count != 0 || err != 0) { Visible(false); pnSuccess.Visible = true; lblSuccess.Text = "- Bạn đã thêm thành công " + count + " khách hàng vào nhóm: " + drlMailGroup.SelectedItem.ToString() + " </br> - Trùng :" + err.ToString() + " khách hàng."; // Update limit send and create customer. updateLimitSendAndCreate(count, 0); } } catch (Exception ex) { logs.Error(userLogin.Username + "-Client - btnSave_Click", ex); } }
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"); } }
/** * Part send mail. * Param: countReceivedMail, customerName, emailTo **/ public void callPartSend(int countReceivedMail, string customerName, string emailTo, int customerId) { // 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, groupId); if (tblPartSend.Rows.Count > 0) { // 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(); bool send = false; sendMail(send, port, hostName, userSmtp, passSmtp, mailFrom, senderName, subjectDetail, contentDetail, customerName, emailTo, sendRegisterId, 0); // Ghi lại nhật ký gửi mail. logHistoryForSend(sendRegisterId, mailTo, mailFrom, senderName, send); } } // Cập nhật số lượng mail đã nhận sau khi đã gửi đi đầy đủ. DetailGroupDTO dgDto = new DetailGroupDTO(); dgDto.CustomerID = customerId; dgDto.GroupID = groupId; dgDto.CountReceivedMail = arrayContent.Length; dgBUS.tblDetailGroup_Update(dgDto); } } } }
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); } }
protected void btnSave_Click(object sender, EventArgs e) { CustomerDTO ctDTO = new CustomerDTO(); InitBUS(); int count = 0; int err = 0; try { for (int i = 0; i < dtlCustomer.Items.Count; i++) { DataListItem item = dtlCustomer.Items[i]; CheckBox chkXoa = (CheckBox)item.FindControl("chkCheck"); HiddenField CustomerID = (HiddenField)item.FindControl("hdfId"); if (chkXoa.Checked == true) { try { ConnectionData.OpenMyConnection(); DetailGroupDTO dsgDTO = new DetailGroupDTO(); dsgDTO.GroupID = int.Parse(drlSubGroup.SelectedValue.ToString()); dsgDTO.CustomerID = int.Parse(CustomerID.Value.ToString()); dsgDTO.CountReceivedMail = 0; dsgDTO.LastReceivedMail = DateTime.Now; if (dsgBUS.GetByID(dsgDTO.GroupID, dsgDTO.CustomerID).Rows.Count > 0) { err++; } else { dsgBUS.tblDetailGroup_insert(dsgDTO); count++; } btnFilter_Click(sender, e); ConnectionData.CloseMyConnection(); } catch (Exception ex) { logs.Error("FillterCustomer - Save", ex); continue; } } } Visible(false); pnSuccess.Visible = true; lblSuccess.Text = "Bạn đã thêm thành công " + count + " khách hàng vào nhóm: " + drlSubGroup.SelectedItem.ToString() + " và trùng :" + err.ToString() + " khách hàng."; } catch (Exception ex) { logs.Error(userLogin.Username + "-Client - btnSave_Click", ex); } }