public EmailSend() { srdBUS = new SendRegisterDetailBUS(); scBUS = new SendContentBUS(); mcBUS = new MailConfigBUS(); ctBUS = new CustomerBUS(); dtGroupBUS = new DetailGroupBUS(); countBUS = new CountBuyBUS(); }
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; } }
private void LoadMailGroupLists() { countBUS = new CountBuyBUS(); DataTable MailGroup = countBUS.GetGroup(); if (MailGroup.Rows.Count > 0) { createTableMail(); DataRow rowE = group.NewRow(); rowE["Id"] = -1; rowE["Name"] = "Nhóm mua lần đầu"; group.Rows.Add(rowE); DataRow rowE2 = group.NewRow(); rowE2["Id"] = -2; rowE2["Name"] = "Nhóm mua nhiều lần"; group.Rows.Add(rowE2); foreach (DataRow rowItem in MailGroup.Rows) { rowE = group.NewRow(); rowE["Id"] = rowItem["CategoryID"]; rowE["Name"] = rowItem["Title"]; group.Rows.Add(rowE); } this.drlMailGroup.DataSource = group; this.drlMailGroup.DataTextField = "Name"; this.drlMailGroup.DataValueField = "Id"; this.drlMailGroup.DataBind(); } }
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"; } }