protected void Page_Load(object sender, EventArgs e) { if ((Request.Cookies["FirstName"] != null)) { string name = Request.Cookies["FirstName"].Value; lblConfirmation.Text = "Thank you for your order, " + name + " !"; } Order currentOrder; //retrieve cart object from session state on every post back if (Session["OrderIDReciept"] != null) { string orderid = Session["OrderIDReciept"].ToString(); currentOrder = OrderDA.OrderReceipt(orderid); //pull receipt from DB string subtotal = String.Format("\tORDER SUBTOTAL: ${0:C}", Math.Round((currentOrder.Subtotal), 2).ToString()); string tax = String.Format("\tTAX: ${0:C}", Math.Round((currentOrder.Tax), 2).ToString()); string discount = String.Format("\tAPPLIED DISCOUNTS: ${0:C} saved on your order today", Math.Round((currentOrder.Discount), 2).ToString()); string total = String.Format("\tORDER TOTAL: ${0:C}", Math.Round((currentOrder.OrderTotal), 2).ToString()); Subtotal.Text = subtotal; Tax.Text = tax; Discount.Text = discount; Total.Text = total; Label5.Text = "*An email confirmation will be sent when your order is ready to be picked up"; } //on initial page load, add cart items to list control //assign values to text boxes }
private void buttonSearch_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textboxSearch.Text)) { MessageBox.Show("Enter Order ID", "Search not Possible"); } else { Order order = OrderDA.Search(Convert.ToInt32(textboxSearch.Text)); if (order != null) { textboxOrderId.Text = order.OrderID.ToString(); textboxClientId.Text = order.ClientID.ToString(); textboxBookId.Text = order.BookID.ToString(); textboxbQuantity.Text = order.Quantity.ToString(); textboxSearch.Clear(); } else { MessageBox.Show("Order Not Found", "Search Failed"); textboxSearch.Clear(); } } }
private void buttonOrdDelete_Click(object sender, EventArgs e) { DialogResult answer = MessageBox.Show("Do you want to delete this Order?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (answer == DialogResult.Yes) { OrderDA.Delete(Convert.ToInt32((textBoxOrdNumber.Text))); //int BookQuantity = OrderDA.SearchByNumber(Convert.ToInt32(textBoxOrdNumber.Text)).OrdQuantity; //decimal orderCost = OrderDA.SearchByNumber(Convert.ToInt32(textBoxOrdNumber.Text)).OrdTotal; //Books abook = new Books(); //Clients aclient = new Clients(); //abook = BooksDA.SearchByTitle(comboBoxOrdProduct.Text); //aclient = ClientsDA.Search(comboBoxOrdClient.Text); //abook.QOH = abook.QOH + BookQuantity; //aclient.creditLimit = aclient.creditLimit + orderCost; OrderDA.ListOrder(listViewOrd); buttonOrdList.PerformClick(); UpdateComboBoxes(); } }
private void buttonOrdUpdate_Click(object sender, EventArgs e) { if (!Validator.IsEmpty(textBoxOrdQuantity)) { MessageBox.Show("Orders must have a valid quantity.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxAutID.Clear(); textBoxAutID.Focus(); return; } Order aorder = createOrder(); Order xorder = OrderDA.SearchByNumber(Convert.ToInt32(textBoxOrdNumber.Text)); Books abook = BooksDA.SearchByTitle(comboBoxOrdProduct.Text); Clients aclient = ClientsDA.Search(comboBoxOrdClient.Text); abook.QOH = (abook.QOH + xorder.OrdQuantity) - aorder.OrdQuantity; BooksDA.Update(abook); aclient.creditLimit = (aclient.creditLimit + aorder.OrdTotal) - aorder.OrdTotal; ClientsDA.Update(aclient); OrderDA.Update(aorder); OrderDA.ListOrder(listViewOrd); buttonOrdList.PerformClick(); UpdateComboBoxes(); }
private void buttonUpdateOrder_Click(object sender, EventArgs e) { List <Orders> listO = OrderDA.ListOrder(); if (IsValidOrderData()) { Orders aOrder = new Orders(); aOrder.OrderNumber = Convert.ToInt32(textBoxOnumber.Text); aOrder.ISBNProduct = Convert.ToInt32(textBoxISBN.Text); aOrder.ProductTitle = textBoxOProductTitle.Text; aOrder.ProductDescription = textBoxProductDescription.Text; aOrder.ClientName = comboBoxClientID.Text; aOrder.OrderDate = dateTimePickerOdate.Text; aOrder.ShippingDate = dateTimePickerSDate.Text; aOrder.OrderQuantity = Convert.ToInt32(textBoxOQty.Text); aOrder.ProductPrice = Convert.ToDouble(textBoxProductPrice.Text); aOrder.FinalAmount = Convert.ToDouble(textBoxFinalAmount.Text); DialogResult ans = MessageBox.Show("Do you really want to update this Order?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ans == DialogResult.Yes) { OrderDA.Update(aOrder); MessageBox.Show("Order record has been updated successfully", "Confirmation"); ClearAll(); textBoxOnumber.Focus(); } } }
public string ReorderInfo(int orderid, int lineid) { try { string prod = ""; prod = OrderDA.ReorderInfo(orderid, lineid); return(prod); } finally { } }
protected async override void OnNavigatedTo(NavigationEventArgs e) { OrderDA orderHeaderDA = await OrderDA.Create(); List <OrderHeader> orderList = await orderHeaderDA.GetOrders(true); List <OrderHeader> orderList2 = await orderHeaderDA.GetOrders(false); DeliveryData.Text = orderList.Count.ToString(); InStoreData.Text = orderList2.Count.ToString(); }
//Automatic ComboBoxes Method public void UpdateComboBoxes() { comboBoxOrdClient.Items.Clear(); comboBoxOrdISBN.Items.Clear(); comboBoxBkAuthor.Items.Clear(); comboBoxBkPub.Items.Clear(); OrderDA.clientSelection(comboBoxOrdClient); OrderDA.bookSelection(comboBoxOrdISBN); BookDA.authorSelection(comboBoxBkAuthor); BookDA.publisherSelection(comboBoxBkPub); }
public static void SaveOrder() { string[] keys = TradeRA.KeySearch("O_*"); foreach (string key in keys) { Order order = OrderRA.Get(key); if (order.state_enum == OrderStatusEnum.Submitted) { order.state_enum = OrderStatusEnum.Abnormal; } OrderDA.Add(order); } }
private void buttonSaveOrder_Click_1(object sender, EventArgs e) { List <Orders> listO = OrderDA.ListOrder(); if (IsValidOrderData()) { Inventory product = InventoryDA.Search(Convert.ToInt32(textBoxISBN.Text)); Client client = ClientDA.Search(Convert.ToInt32(comboBoxClientID.Text)); string isbn = textBoxISBN.Text; int quantityproduct = Convert.ToInt32(textBoxOQty.Text); int id = (Convert.ToInt32(comboBoxClientID.Text)); if (product == null) { MessageBox.Show("Wrong Information product, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (product.ProductQuantity < Convert.ToInt32(textBoxOQty.Text)) { MessageBox.Show("We do not have the quantity required on Inventory", "Missing Product"); textBoxOQty.Clear(); return; } else { if (client.ClientID == (Convert.ToInt32(comboBoxClientID.Text))) { textBoxClientName.Text = client.InstitutionName; } Int32 quantityselected = Convert.ToInt32(textBoxOQty.Text); Double priceselected = Convert.ToDouble(textBoxProductPrice.Text); Double finalamout = quantityselected * priceselected; textBoxFinalAmount.Text = finalamout.ToString(); Orders aOrder = new Orders(); aOrder.OrderNumber = Convert.ToInt32(textBoxOnumber.Text); aOrder.ISBNProduct = Convert.ToInt32(textBoxISBN.Text); aOrder.ProductTitle = textBoxOProductTitle.Text; aOrder.ProductDescription = textBoxProductDescription.Text; aOrder.ClientID = (Convert.ToInt32(comboBoxClientID.Text)); aOrder.ClientName = textBoxClientName.Text; aOrder.OrderDate = dateTimePickerOdate.Text; aOrder.ShippingDate = dateTimePickerSDate.Text; aOrder.OrderQuantity = Convert.ToInt32(textBoxOQty.Text); aOrder.ProductPrice = Convert.ToDouble(textBoxProductPrice.Text); aOrder.FinalAmount = Convert.ToDouble(textBoxFinalAmount.Text); OrderDA.Save(aOrder); listO.Add(aOrder); ClearAll(); } } }
private void buttonOrdPlaceOrder_Click(object sender, EventArgs e) { //Order Validators if (!Validator.IsEmptyComboBox(comboBoxOrdClient)) { MessageBox.Show("Order must have a valid Client.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxAutID.Clear(); textBoxAutID.Focus(); return; } if (!Validator.IsEmptyComboBox(comboBoxOrdProduct)) { MessageBox.Show("Order must have a valid Product.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxAutID.Clear(); textBoxAutID.Focus(); return; } if (!Validator.IsEmpty(textBoxOrdQuantity)) { MessageBox.Show("Orders must have a valid quantity.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxAutID.Clear(); textBoxAutID.Focus(); return; } int temp = 0; if ((!int.TryParse((textBoxOrdQuantity.Text), out temp))) { MessageBox.Show("Quantity of Products must be a integer number.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error); textBoxOrdQuantity.Clear(); textBoxOrdQuantity.Focus(); return; } Order aOrder = createOrder(); Books aBook = BooksDA.SearchByTitle(comboBoxOrdProduct.Text); Clients aClient = ClientsDA.Search(comboBoxOrdClient.Text); aBook.QOH = aBook.QOH - aOrder.OrdQuantity; BooksDA.Update(aBook); aClient.creditLimit = aClient.creditLimit - aOrder.OrdTotal; ClientsDA.Update(aClient); OrderDA.SaveOrder(aOrder); buttonOrdList.PerformClick(); UpdateComboBoxes(); }
private void btn_Save_Click(object sender, EventArgs e) { if ((Validation.IsValidID(txt_OrID))) { Order ord = new Order(); ord.OrderID = Convert.ToInt32(txt_OrID.Text); ord.Title = txt_title.Text; ord.quentity = txt_que.Text; ord.phone = txt_phone.Text; OrderDA.Save(ord); } }
public List <OrderEntity> GetOrderListByCondition(string name, string orderNo, string startDate, string endDate) { OrderDA da = new OrderDA(); var result = da.GetOrderListByCondition(name, orderNo, startDate, endDate); if (result != null && result.Count > 0) { foreach (var item in result) { item.OrderSource = new BaseSetBC().GetDicItemValueByKey(item.OrderSource, DictionaryConstant.OSKey).ItemValue; } } return(result); }
private void buttonAddToList_Click(object sender, EventArgs e) { Order order = new Order(); if (OrderValidation.isValidID(textboxOrderId) && OrderValidation.isValidClient(textboxClientId) && OrderValidation.isValidBooks(textboxBookId) && OrderValidation.isValidValues(textboxbQuantity)) { order.OrderID = Convert.ToInt32(textboxOrderId.Text); order.ClientID = Convert.ToInt32(textboxClientId.Text); order.BookID = Convert.ToInt64(textboxBookId.Text); order.Quantity = Convert.ToInt32(textboxbQuantity.Text); OrderDA.Add(order); ClearAll(); } }
private void buttonDeleteOrder_Click(object sender, EventArgs e) { if (IsValidOrderData()) { DialogResult ans = MessageBox.Show("Do you really want to delete this Employee?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ans == DialogResult.Yes) { OrderDA.Delete(textBoxOnumber.Text); MessageBox.Show("Order record has been deleted successfully", "Confirmation"); ClearAll(); textBoxOnumber.Focus(); } } }
protected void btnUpdate_Click(object sender, EventArgs e) { Order order = OrderDA.GetOrderByID(Convert.ToInt32(orderID.Value)); Employee employee = EmployeeDA.GetEmployeeByID(Convert.ToInt32(driverList.SelectedValue)); if (DeliveryDA.GetDeliveryByOrderID(order.OrderID) != null) { DeliveryDA.UpdateDriverForOrder(order, employee); } else { DeliveryDA.AddDriverToOrder(order, employee); } Response.Redirect("OrdersList.aspx"); }
//save order method public void SaveOrder(Order theOrder) { try { //save to DB OrderDA.AddNewOrder(theOrder); } catch (SqlException ex) { throw new SavingException("Something went wrong saving your order. Please send us a message via the Contact Page."); //error saving to DB } finally { } }
//Delete private void buttonClDel_Click(object sender, EventArgs e) { DialogResult ans = MessageBox.Show("Are you sure you want to delete the Client information?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ans == DialogResult.Yes) { if (OrderDA.SearchByClientID(Convert.ToInt32(textBoxClID.Text)) != null) { MessageBox.Show("This client has open orders in the system, please verify the orders before deleting this client.", "ALERT!"); return; } ClientDA.Delete(Convert.ToInt32(textBoxClID.Text)); ClientDA.List(listViewSales); UpdateComboBoxes(); } }
//Delete private void buttonBkDel_Click(object sender, EventArgs e) { DialogResult ans = MessageBox.Show("Are you sure you want to delete the Book information?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ans == DialogResult.Yes) { if (OrderDA.SearchByBook(Convert.ToInt64(textBoxBkISBN.Text)) != null) { MessageBox.Show("This book has open orders in the system, please verify the orders before deleting this book.", "ALERT!"); return; } BookDA.Delete(createBook().BkISBN); BookDA.ListBooks(listViewBooks); UpdateComboBoxes(); } }
public BookBizApp() { InitializeComponent(); //Disables the access to any other tab that the currently user is not supossed to use tabPage1.Enabled = false; tabPage2.Enabled = false; tabPage3.Enabled = false; tabPage4.Enabled = false; //Automatic ComboBoxes OrderDA.clientSelection(comboBoxOrdClient); OrderDA.bookSelection(comboBoxOrdISBN); BookDA.authorSelection(comboBoxBkAuthor); BookDA.publisherSelection(comboBoxBkPub); }
//Add private void buttonOrdAdd_Click(object sender, EventArgs e) { Validator checker = new Validator(); if (checker.isNotNull(comboBoxOrdClient.Text, "Client") && checker.isNotNull(comboBoxOrdISBN.Text, "Book ISBN") && checker.isNotNull(textBoxOrdBkQt.Text, "Quantity") && checker.isNotNull(comboBoxOrdMadeBy.Text, "Order made by?")) { Order aorder = createOrder(); Book abook = BookDA.SearchISBN(Convert.ToInt64(comboBoxOrdISBN.Text)); Client aclient = ClientDA.SearchName(comboBoxOrdClient.Text); abook.BkQOH = abook.BkQOH - aorder.OrdBkQuantity; BookDA.Update(abook); aclient.ClientCredit = aclient.ClientCredit - aorder.OrdCost; ClientDA.Update(aclient); OrderDA.SaveOrder(aorder); UpdateComboBoxes(); } }
//Enable the buttons delete and update in case of a valid entered ID private void textBoxOrId_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxOrId.Text)) { buttonOrdDel.Enabled = false; buttonOrdUpd.Enabled = false; return; } if (OrderDA.SearchID(Convert.ToInt32(textBoxOrId.Text)) != null) { buttonOrdDel.Enabled = true; buttonOrdUpd.Enabled = true; return; } buttonOrdDel.Enabled = false; buttonOrdUpd.Enabled = false; }
//Search button private void buttonOrdSearch_Click(object sender, EventArgs e) { Order aorder = new Order(); if (!string.IsNullOrEmpty(textBoxOrdSearch.Text)) { switch (comboBoxOrdSearch.SelectedIndex) { case 0: int tempId; if (!int.TryParse(textBoxOrdSearch.Text, out tempId)) { MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; } aorder = OrderDA.SearchID(Convert.ToInt32(textBoxOrdSearch.Text)); break; case 1: if (!int.TryParse(textBoxOrdSearch.Text, out tempId)) { MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; } aorder = OrderDA.SearchByClientID(Convert.ToInt32(textBoxOrdSearch.Text)); break; case 2: aorder = OrderDA.SearchByClientName(textBoxOrdSearch.Text); break; } if (aorder == null) { MessageBox.Show("Order not found!", "Not found!"); textBoxOrdSearch.Clear(); textBoxOrdSearch.Focus(); return; } OrderDA.ListSearch(aorder, listViewOrder); return; } MessageBox.Show("Please enter a valid term to be searched.", "No search information!"); return; }
private void buttonAddOrder_Click(object sender, EventArgs e) { if ((Validator.IsValidID(textBoxOrderId)) && (Validator.IsValidID(textBoxIsbn)) && (Validator.IsValidID(textBoxClientId))) { Order order = new Order(); order.orderId = Convert.ToInt32(textBoxOrderId.Text); order.orderDate = textBoxOrderDate.Text; order.clientId = Convert.ToInt32(textBoxClientId.Text); order.orderTakenBy = textBoxTakenBy.Text; order.ISBN = Convert.ToInt32(textBoxIsbn.Text); listOrder.Add(order); OrderDA.Save(order); buttonListOrder.Enabled = true; } }
//Update private void buttonOrdUpd_Click(object sender, EventArgs e) { Order aorder = createOrder(); Order oldorder = OrderDA.SearchID(Convert.ToInt32(textBoxOrId.Text)); Book abook = BookDA.SearchISBN(Convert.ToInt64(comboBoxOrdISBN.Text)); Client aclient = ClientDA.SearchName(comboBoxOrdClient.Text); abook.BkQOH = (abook.BkQOH + oldorder.OrdBkQuantity) - aorder.OrdBkQuantity; BookDA.Update(abook); aclient.ClientCredit = (aclient.ClientCredit + aorder.OrdCost) - aorder.OrdCost; ClientDA.Update(aclient); OrderDA.Update(aorder); OrderDA.ListOrder(listViewOrder); UpdateComboBoxes(); }
private void btn_Search_Click(object sender, EventArgs e) { Order cust = OrderDA.Search(Convert.ToInt32(txt_input.Text)); if (cust != null) { txt_OrID.Text = (cust.OrderID).ToString(); txt_title.Text = (cust.Title); txt_que.Text = cust.quentity; txt_phone.Text = cust.phone; } else { MessageBox.Show("Order not Found"); txt_input.Clear(); txt_input.Focus(); } }
protected void btnSubmitOrder_Click(object sender, EventArgs e) { List <CartItem> cartItems = (List <CartItem>)Session["items"]; if (currentCustomer != null) { currentOrder.CustomerFirst = currentCustomer.CustomerFirst; currentOrder.CustomerLast = currentCustomer.CustomerLast; currentOrder.OrderDate = DateTime.Now; currentOrder.OrderTotal = total; OrderDA.SaveOrder(currentOrder); currentOrder = OrderDA.GetCustomersLatestOrder(currentCustomer.CustomerFirst, currentCustomer.CustomerLast); foreach (CartItem item in cartItems) { int productID = item.ProductID; int orderID = currentOrder.OrderID; string productDetail = item.Description; OrderDA.SaveOrderLineItems(orderID, productID, productDetail); } Session["Receipt"] = currentOrder; } else { currentOrder.CustomerFirst = txtFirstName.Text; currentOrder.CustomerLast = txtLastName.Text; currentOrder.OrderDate = DateTime.Now; currentOrder.OrderTotal = total; OrderDA.SaveOrder(currentOrder); currentOrder = OrderDA.GetCustomersLatestOrder(currentOrder.CustomerFirst, currentOrder.CustomerLast); foreach (CartItem item in cartItems) { int productID = item.ProductID; int orderID = currentOrder.OrderID; string productDetail = item.ProductDetail; OrderDA.SaveOrderLineItems(orderID, productID, productDetail); } Session["Receipt"] = currentOrder; } Response.Redirect("OrderReciept.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (Session["customer"] == null) { Response.Redirect("~"); } Customer theCustomer = (Customer)Session["Customer"]; List <Order> customerOrders = OrderDA.GetAllOrdersByCustomer(theCustomer.CustomerFirst, theCustomer.CustomerLast); foreach (Order o in customerOrders) { lblFirst.Text = o.CustomerFirst; lblLast.Text = o.CustomerLast; lblOrderTotal.Text = o.OrderTotal.ToString("c2"); lblStoreNumber.Text = Convert.ToString(o.StoreNum); lblOrderType.Text = o.OrderType; } }
//===================================================================================================================================== //=============================END OF INVENTORY MANAGER PROGRAM======================================================================== //===================================================================================================================================== //===================================================================================================================================== //=============================BEGINNING OF ORDER CLERKS PROGRAM======================================================================= //===================================================================================================================================== // Create object Order private Order createOrder() { Order aorder = new Order(); Book abook = new Book(); Client aclient = new Client(); abook = BookDA.SearchISBN(Convert.ToInt64(comboBoxOrdISBN.Text)); aclient = ClientDA.SearchName(comboBoxOrdClient.Text); aorder.OrdId = OrderDA.OrderID() + 1; aorder.OrdClient = aclient; aorder.OrdBbook = abook; aorder.OrdBkQuantity = Convert.ToInt32(textBoxOrdBkQt.Text); aorder.OrdCost = aorder.OrdBkQuantity * BookDA.SearchISBN(Convert.ToInt64(comboBoxOrdISBN.Text)).BkUnitPrice; aorder.OrdDate = Convert.ToDateTime(dateTimePickerOrder.Value); aorder.OrdType = comboBoxOrdMadeBy.Text; textBoxOrId.Text = aorder.OrdId.ToString(); return(aorder); }
private void buttonSearchOrder_Click(object sender, EventArgs e) { Order order = OrderDA.Search(Convert.ToInt32(buttonSearchOrder.Text)); if (order != null) { textBoxOrderId.Text = (order.orderId).ToString(); textBoxOrderDate.Text = order.orderDate; textBoxClientId.Text = (order.clientId).ToString(); textBoxTakenBy.Text = order.orderTakenBy; textBoxIsbn.Text = (order.ISBN).ToString(); } else { MessageBox.Show("Order not Found!"); textBoxSearch.Clear(); buttonSearchOrder.Focus(); } }
protected void btnAddToCart_Click(object sender, EventArgs e) { // try catch for notifying the user when they // try to enter an item to their shopping cart // that is already in their shopping cart try { // call method to get values from the labels and textboxes // on the formview GetItems(); // check to see if user is logged on if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { // get the customerID of the user who is logged on // get the id of the user that I just created Customer customer = new Customer(); customer.Username = User.Identity.Name; CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomersID = customerIDDA.Get(customer); customerID = getCustomersID[0].Id; // clear customer = null; customerIDDA = null; // count how many orders that have not been verified exist in the orders table Order order = new Order(); order.CustomerId = int.Parse(customerID.ToString()); order.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrders = orderDA.Get(order); // returns one item countOrders = getOrders.Count; //clear order = null; orderDA = null; getOrders = null; // if there are no orders with a txnID = "" then add a new order // then get the OrderID of the Order to add items to the shopping // cart using that OrderID // if there are orders with a txnID = "" then select the OrderID // and add orders to the shopping cart using that OrderID if (int.Parse(countOrders.ToString()) == 0) { // add a new order to the order table // instantiate class DAL.DataAccess da6 = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); // make command statement string comm6 = "INSERT INTO Orders VALUES (@customerID, @grossTotal, @tax, @netTotal, @txnID, @paymentStatus)"; // make arrays for paramaters and input string[] s6 = { "@customerID", "@grossTotal", "@tax", "@netTotal", "@txnID", "@paymentStatus" }; string[] v6 = { customerID.ToString(), "0", "0", "0", "", "" }; da6.ExecuteNonQuery(comm6, s6, v6); //clear s6 = null; v6 = null; // get the orderID of the order that was just created // insert sale price Order orderIID = new Order(); orderIID.CustomerId = int.Parse(customerID.ToString()); orderIID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrder = orderIDDA.Get(orderIID); orderID = getOrder[0].Id; //clear orderIID = null; getOrder = null; // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the OrderID that was created // instantiate class // insert sale price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; //// tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; Response.Redirect(Request.RawUrl); } else { // insert regular price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString("n2")); orderItem.TotalPrice = decimal.Parse(price.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); // Response.Redirect(Request.RawUrl); } } else { // get the orderID of the user that has a txnID = "" // instantiate class Order orderIID = new Order(); orderIID.CustomerId = int.Parse(customerID.ToString()); orderIID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrder = orderIDDA.Get(orderIID); orderID = getOrder[0].Id; //clear orderIID = null; getOrder = null; // check to see if the customer has the item in their cart already. // if they do, do not insert item into database OrderItem orderItemExistence = new OrderItem(); orderItemExistence.OrderId = int.Parse(orderID.ToString()); orderItemExistence.ItemId = itemID.Text; OrderItemDA orderItemExistenceDA = new OrderItemDA(); Collection<OrderItem> getOrderItemExistence = orderItemExistenceDA.Get(orderItemExistence); countItems = getOrderItemExistence.Count; if (countItems > 0) { error.Text = "This item is in your shopping cart."; error.Visible = true; } else { // see if item is on sale if (isItemOnSale() == true) { // insert sale price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert regular price OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString("n2")); orderItem.TotalPrice = decimal.Parse(price.ToString("n2")); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } } } // if user is not logged on make up and account else { // if the anonymous session anonymouscustomerID is empty // create a new username and customerID if (Session["AnonymousUserName"] == null) { // get all rows to get maximum customerID CustomerDA customerDA = new CustomerDA(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomers = customerDA.Get(null); // gets max customerID in table // adds one and combines websites domain name // with the anonymousID max = (int)getCustomers[getCustomers.Count - 1].Id; usernameID = int.Parse(max.ToString()) + 1; anonymousUserName = "******" + usernameID; //clear customerDA = null; getCustomers = null; // insert the anonymousCustomerID into the customer table with the username of // and the usernameID/customerID // mypetsfw.com + customerID Customer customer = new Customer(usernameID, true, anonymousUserName, "Fill In", "Fill In", "Fill In", "Fill In", "Fill In", "", "Fill In", ""); CustomerDA customerDA1 = new CustomerDA(); customerDA1.Save(customer); // clear customer = null; customerDA = null; // put the anonymoususername in a session Session["AnonymousUserName"] = anonymousUserName.ToString(); // create a new order of the anonymous user // add a new order to the order table // instantiate class Order oID1 = new Order(); oID1.Id = GetOrderIDPlusOne(); oID1.CustomerId = usernameID; oID1.GrossTotal = 0; oID1.Tax = 0; oID1.NetTotal = 0; // for payment status oID1.TxnId = ""; OrderDA orderIDDA1 = new OrderDA(); // save orderIDDA1.Save(oID1); //DAL.DataAccess da11 = // new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //// make command statement //string comm11 = "INSERT INTO Orders VALUES (@customerID, @grossTotal, @tax, @netTotal, @txnID, @paymentStatus)"; //// make arrays for paramaters and input //string[] s11 = { "@customerID", "@grossTotal", "@tax", "@netTotal", "@txnID", "@paymentStatus" }; //string[] v11 = { usernameID.ToString(), "0", "0", "0", "", "" }; //da11.ExecuteNonQuery(comm11, s11, v11); //clear oID1 = null; orderIDDA1 = null; // get the orderID of the anonymoususer // get the id of the user that I just created Order oID = new Order(); oID.CustomerId = usernameID; oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderID = getOrderID[0].Id; //clear oID = null; getOrderID = null; // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell anonymous the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString()); orderItem.TotalPrice = decimal.Parse(price.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell anonymous the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } // if the session doesn't != null else { // get the customerID of the user that I just created Customer customer2 = new Customer(); customer2.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerDA2 = new CustomerDA(); Collection<Customer> getCustomers2 = customerDA2.Get(customer2); customerID = getCustomers2[0].Id; // clear customer2 = null; customerDA2 = null; getCustomers2 = null; // see if an order doesn't already exist for the anonymousUser // count how many orderIDs that have not been verified exist in the orders table Order orders = new Order(); orders.CustomerId = int.Parse(customerID.ToString()); orders.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrder = orderDA.Get(orders); // returns one item countOrders = getOrder.Count; //clear orders = null; orderDA = null; getOrder = null; // if there are no orders with a txnID = "" then add a new order // then get the OrderID of the Order to add items to the shopping // cart using that OrderID // if there are orders with a txnID = "" then select the OrderID // and add orders to the shopping cart using that OrderID if (int.Parse(countOrders.ToString()) == 0) { // get the customerID of the user that I just created Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomers3 = customerIDDA.Get(customerIDID); customerID = getCustomers3[0].Id; // clear customerIDID = null; customerIDDA = null; getCustomers3 = null; // create a new order of the anonymous user // add a new order to the order table // instantiate class Order oID1 = new Order(); oID1.Id = GetOrderIDPlusOne(); oID1.CustomerId = usernameID; oID1.GrossTotal = 0; oID1.Tax = 0; oID1.NetTotal = 0; // for payment status oID1.TxnId = ""; OrderDA orderIDDA1 = new OrderDA(); // save orderIDDA1.Save(oID1); //DAL.DataAccess da11 = // new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //// make command statement //string comm11 = "INSERT INTO Orders VALUES (@customerID, @grossTotal, @tax, @netTotal, @txnID, @paymentStatus)"; //// make arrays for paramaters and input //string[] s11 = { "@customerID", "@grossTotal", "@tax", "@netTotal", "@txnID", "@paymentStatus" }; //string[] v11 = { customerID.ToString(), "0", "0", "0", "", "" }; //da11.ExecuteNonQuery(comm11, s11, v11); //clear oID1 = null; orderIDDA1 = null; // get the orderid for the anonymous users new order Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderID = int.Parse(getOrderID[0].Id.ToString()); //clear oID = null; orderIDDA = null; getOrderID = null; // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert item into the database using the OrderID that was created // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString()); orderItem.TotalPrice = decimal.Parse(price.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } // if an order is open and exists for the anonymous user else { // get the customerID of the user that I just created Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); CustomerDA customerIDDA = new CustomerDA(); Collection<Customer> getCustomers3 = customerIDDA.Get(customerIDID); customerID = getCustomers3[0].Id; // clear customerIDID = null; customerIDDA = null; getCustomers3 = null; // get the orderID of the anonymoususer that has a txnID = "" // instantiate class Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderID = getOrderID[0].Id; //clear oID = null; orderIDDA = null; getOrderID = null; // check to see if the anonymous user has the item in their cart already. // if they do, do not insert item into database OrderItem orderItemExistence = new OrderItem(); orderItemExistence.OrderId = int.Parse(orderID.ToString()); orderItemExistence.ItemId = itemID.Text; OrderItemDA orderItemExistenceDA = new OrderItemDA(); Collection<OrderItem> getOrderItemExistence = orderItemExistenceDA.Get(orderItemExistence); countItems = getOrderItemExistence.Count; if (countItems > 0) { error.Text = "This item is in your shopping cart."; error.Visible = true; } else { // see if item is on sale if (isItemOnSale() == true) { // insert item into the database using the existing OrdersID // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.TotalPrice = decimal.Parse(salePriceAnswerDouble.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // clear orderItem = null; orderItemDA = null; // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } else { // insert item into the database using the existing OrdersID // instantiate class OrderItem orderItem = new OrderItem(); orderItem.OrderId = int.Parse(orderID.ToString()); orderItem.ItemId = itemID.Text; orderItem.VendorId = int.Parse(vendorID.Text); orderItem.Price = decimal.Parse(price.ToString()); orderItem.TotalPrice = decimal.Parse(price.ToString()); orderItem.Quantity = int.Parse(quantity.Text); OrderItemDA orderItemDA = new OrderItemDA(); //Save the Objects to the Database orderItemDA.Save(orderItem); // tell user the item was added to their cart successfully successful.Text = "Added to shopping cart successfully!"; successful.Visible = true; // refresh page Response.AppendHeader("Refresh", "0;URL=ItemDetails.aspx?ItemID=" + Request.QueryString["ItemID"]); } } } } } } catch (SqlException) { // error.Text = "The item is in your shopping cart already."; // error.Visible = true; } catch (Exception) { } }
// gets orderID plus one to enter a new order private int GetOrderIDPlusOne() { // get orderID + 1 Order orderID = new Order(); OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(null); int orderIDPlusOne = (int)getOrderID[getOrderID.Count - 1].Id + 1; // clear orderID = null; orderIDDA = null; getOrderID = null; return orderIDPlusOne; }
// on logged in protected void LoggedIn(object sender, EventArgs e) { // seeing if there is an order just in case I missed something if (Session["AnonymousUserName"] != null) { // if the user has an order on going delete it and replace it // with the items that the anonymous user just made(which is really a customer) //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer = new Customer(); //gets customer info based on customer username customer.Username = UserLogin.UserName; //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer = customerDA.Get(customer); // count orders with customerid = @customerid and txtnid = @txnid // instantiate class Order orders = new Order(); orders.CustomerId = getCustomer[0].Id; orders.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrders = orderDA.Get(orders); // returns number of orders object getOrder = getOrders.Count; //clear orders = null; orderDA = null; getOrders = null; // if the user who is logged has items in his cart as an anonymous user // delete the items he had previously on his cart and add the new items and order // that they just put into his cart if (int.Parse(getOrder.ToString()) > 0) { // get the orderID of the customer that he had on going order // instantiate class Order oID = new Order(); oID.CustomerId = getCustomer[0].Id; oID.TxnId = ""; OrderDA ordersDA = new OrderDA(); Collection<Order> getOID = ordersDA.Get(oID); // returns one item object getOrderID = getOID[0].Id; //clear oID = null; ordersDA = null; getOID = null; // delete the order and items that involve the order above // delete items from the orderItem table associated with that order if any //Create an Object that specifies what we want to Get // OrderItem deleteOrderItem = new OrderItem(); //OrderItemDA deleteOrderItemDA = new OrderItemDA(); ////gets orderItem info based on customerID //deleteOrderItem.OrderId = int.Parse(getOrderID.ToString()); //// deletes the orderItems with that customerID //deleteOrderItemDA.Delete(deleteOrderItem); //// clear //deleteOrderItemDA = null; //deleteOrderItem = null; DAL.DataAccess da5 = new DAL.DataAccess( ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); string comm5 = "Delete FROM OrderItem WHERE OrderID = @orderID"; // array with orderID string[] p5 = { "@orderID" }; string[] v5 = { getOrderID.ToString() }; da5.ExecuteNonQuery(comm5, p5, v5); // clear p5 = null; v5 = null; // delete order //Instantiate our Order specific DataAccess Class OrderDA deleteOrderDA = new OrderDA(); //Create an Object that specifies what we want to Get Order deleteOrder = new Order(); //gets order info based on customerID deleteOrder.Id = int.Parse(getOrderID.ToString()); // deletes the order with that customerID deleteOrderDA.Delete(deleteOrder); // clear deleteOrderDA = null; deleteOrder = null; // get cusotmerID of anonymous user //Instantiate our Category specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer2 = new Customer(); //gets customer info based on customer username customer2.Username = Session["AnonymousUserName"].ToString(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer2 = customerDA2.Get(customer2); //for (int i = 0; i < getCustomer2.Count; i++) //{ // getCustomer2[i].Id; //} // get orderID of anonymous user //Create an Object that specifies what we want to Get Order ordersID = new Order(); //gets order info based on customerID ordersID.CustomerId = getCustomer2[0].Id; OrderDA ordersIDDA = new OrderDA(); // deletes the order with that customerID Collection<Order> getOrder2 = ordersIDDA.Get(ordersID); // update the customerid of the anonymous order to the customer, of the user who just logged on DAL.DataAccess da4 = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); string comm4 = "UPDATE Orders SET CustomerID = @customerID WHERE OrderID = @orderID AND TXNID = @txnID"; // empty array string[] p4 = { "@customerID", "@orderID", "@txnID" }; string[] v4 = { getCustomer[0].Id.ToString(), getOrder2[0].Id.ToString(), "" }; // new cus old get order da4.ExecuteNonQuery(comm4, p4, v4); // clear p4 = null; v4 = null; // delete anonymous customer from customer table Customer customers = new Customer(); customers.Id = getCustomer2[0].Id; CustomerDA customersDA = new CustomerDA(); customersDA.Delete(customers); // clear customers = null; customersDA = null; //abandon session Session.Abandon(); Session.Clear(); } // if user doesn't have an on going order just // change the customer ID on the order else { // get cusotmerID of anonymous user //Instantiate our Category specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); // check to see if user has items in their cart //Create an Object that specifies what we want to Get Customer customer2 = new Customer(); //gets customer info based on customer username customer2.Username = Session["AnonymousUserName"].ToString(); //We will be returned a collection so lets Declare that and fill it using Get() Collection<Customer> getCustomer2 = customerDA2.Get(customer2); //for (int i = 0; i < getCustomer2.Count; i++) //{ // getCustomer2[i].Id; //} // get orderID of anonymous user based on customerID OrderDA ordersIDDA = new OrderDA(); //Create an Object that specifies what we want to Get Order ordersID = new Order(); //gets order info based on customerID ordersID.CustomerId = getCustomer2[0].Id; // deletes the order with that customerID Collection<Order> getOrder2 = ordersIDDA.Get(ordersID); // update the customerid of the anonymous order to the customer, of the user who just logged on DAL.DataAccess da4 = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); string comm4 = "UPDATE Orders SET CustomerID = @customerID WHERE OrderID = @orderID AND TXNID = @txnID"; // empty array string[] p4 = { "@customerID", "@orderID", "@txnID" }; string[] v4 = { getCustomer[0].Id.ToString(), getOrder2[0].Id.ToString(), "" }; // new cus old get order da4.ExecuteNonQuery(comm4, p4, v4); // clear p4 = null; v4 = null; // delete anonymous customer from customer table Customer customers = new Customer(); customers.Id = getCustomer2[0].Id; CustomerDA customersDA = new CustomerDA(); customersDA.Delete(customers); // clear customers = null; customersDA = null; //DAL.DataAccess da8 = // new DAL.DataAccess( // ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, // "System.Data.SqlClient"); //string comm8 = // "Delete FROM Customer WHERE CustomerID = @customerID"; //// array with customerID //string[] p8 = { "@customerID" }; //string[] v8 = { getCustomer2[0].Id.ToString() }; //da8.ExecuteNonQuery(comm8, p8, v8); //// clear //p8 = null; //v8 = null; //abandon session Session.Abandon(); Session.Clear(); } } }
protected void Page_Load(object sender, EventArgs e) { lblItemsInCart.Text = "0"; if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { // get the customerID of the user who is logged on // update customer information Customer customerIDID = new Customer(); customerIDID.Username = Membership.GetUser().UserName; //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); Collection<Customer> getCustomerID = customerDA.Get(customerIDID); // returns one item // customerID = ds5.Tables[0].Rows[0].ItemArray[0]; // if statement added by Ethan, will set customerID = 0 if no rows returned. if (getCustomerID.Count > 0) { customerID = getCustomerID[0].Id; ; } else { customerID = 0; } //clear customerIDID = null; customerDA = null; getCustomerID = null; // count how many orders exists from the user that is logged on Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderCount = getOrderID.Count; // clear oID = null; orderIDDA = null; getOrderID = null; if (int.Parse(orderCount.ToString()) == 0) { // display answer on label lblItemsInCart.Text = "0"; } else { // get the orderID of the order that has a txnid = "" of the customer Order orderIDID = new Order(); orderIDID.CustomerId = int.Parse(customerID.ToString()); orderIDID.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrderIDID = orderDA.Get(orderIDID); orderID = getOrderIDID[0].Id; // clear oID = null; orderIDDA = null; getOrderID = null; //count how many items are in the shopping cart for the user //and display them //instantiate class OrderItem orderItemCount = new OrderItem(); orderItemCount.OrderId = int.Parse(orderID.ToString()); OrderItemDA orderItemCountDA = new OrderItemDA(); Collection<OrderItem> getOrderItemCount = orderItemCountDA.Get(orderItemCount); items = getOrderItemCount.Count; // clear orderItemCount = null; orderItemCountDA = null; getOrderItemCount = null; // display answer on label lblItemsInCart.Text = items.ToString(); } } else { // if the customer is not logged on but has an item in there cart if (Session["AnonymousUserName"] != null) { // get the customerID Customer customerIDID = new Customer(); customerIDID.Username = Session["AnonymousUserName"].ToString(); //Instantiate our Category specific DataAccess Class CustomerDA customerDA = new CustomerDA(); Collection<Customer> getCustomerID = customerDA.Get(customerIDID); customerID = getCustomerID[0].Id.ToString(); //clear customerIDID = null; customerDA = null; getCustomerID = null; // get the current orderID if any if not make shopping cart items 0 // count how many orders exists from the user that is logged on Order oID = new Order(); oID.CustomerId = int.Parse(customerID.ToString()); oID.TxnId = ""; OrderDA orderIDDA = new OrderDA(); Collection<Order> getOrderID = orderIDDA.Get(oID); orderCount = getOrderID.Count; // clear oID = null; orderIDDA = null; getOrderID = null; if (int.Parse(orderCount.ToString()) == 0) { // display answer on label lblItemsInCart.Text = "0"; } else { // get the customerID // get the customerID Customer customerIDID2 = new Customer(); customerIDID2.Username = Session["AnonymousUserName"].ToString(); //Instantiate our Category specific DataAccess Class CustomerDA customerDA2 = new CustomerDA(); Collection<Customer> getCustomerID2 = customerDA2.Get(customerIDID2); customerID = getCustomerID2[0].Id; //clear customerIDID2 = null; customerDA2 = null; getCustomerID2 = null; // get the orderID of the order with the txnid = "" for the anonyomous user Order oID2 = new Order(); oID2.CustomerId = int.Parse(customerID.ToString()); oID2.TxnId = ""; OrderDA orderIDDA2 = new OrderDA(); Collection<Order> getOrderID2 = orderIDDA2.Get(oID2); orderID = getOrderID2[0].Id; // clear oID2 = null; orderIDDA2 = null; getOrderID2 = null; //count how many items are in the shopping cart for the anonymous user //and display them //instantiate class OrderItem orderItemCount = new OrderItem(); orderItemCount.OrderId = int.Parse(orderID.ToString()); OrderItemDA orderItemCountDA = new OrderItemDA(); Collection<OrderItem> getOrderItemCount = orderItemCountDA.Get(orderItemCount); items = getOrderItemCount.Count; // clear orderItemCount = null; orderItemCountDA = null; getOrderItemCount = null; // display answer on label lblItemsInCart.Text = items.ToString(); } } } }
private void BindGridRepeater() { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated || Session["AnonymousUserName"] != null) { // fill up gridview // instantiate class DAL.DataAccess da = new DAL.DataAccess(ConfigurationManager.ConnectionStrings["MyPetStoreDB"].ConnectionString, "System.Data.SqlClient"); // sql command string comm = "SELECT Orders.OrderID, Orders.CustomerID, OrderItem.ItemID, OrderItem.Price, OrderItem.TotalPrice, OrderItem.Quantity, Items.ItemID, Items.ProductName, Items.Description, Items.PhotoLocation, Items.QuantityAvailable, Items.MinQuantity, Items.VendorID FROM Orders, OrderItem, Items WHERE Orders.OrderID = OrderItem.OrderID and OrderItem.ItemID = Items.ItemID and Orders.CustomerID = @customerID AND Orders.TXNID = @txnID"; // data set DataSet ds = new DataSet(); // empty array string[] p = { "@customerID", "@txnID" }; string[] v = { GetCustomerID(), "" }; ds = da.ExecuteQuery(comm, p, v); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); // clear p = null; v = null; // fill up repeater // instantiate class Order order = new Order(); order.CustomerId = int.Parse(GetCustomerID()); order.TxnId = ""; OrderDA orderDA = new OrderDA(); Collection<Order> getOrder = orderDA.Get(order); rptOne.DataSource = getOrder; rptOne.DataBind(); // clear p = null; v = null; } else { items.InnerHtml = "<h1>" + "Your Shopping Cart is Empty." + "</h1>"; } }