protected void AddShop_Click(object sender, EventArgs e) { //get input values string shopName = ShopName.Text; string shopManagerId = ShopMSelect.SelectedValue; if (Page.IsValid && ShopName.Text != "")//if all validator is valid { BlShop shop = null; try { shop = new BlShop(shopManagerId, shopName);//crate the new shop } catch (Exception exception) { MSG.Text = "fail to add shop " + exception.Message;//ex massage } if (shop == null || shop.Id == -1)//if id=-1 of shop is null add shop fail { MSG.Text = "fail to add shop"; } else//if not add shop success { MSG.Text = "shop added seccsessfully!!!"; } } else { MSG.Text = "Please type all details"; } ShopName.CssClass = ShopNameValidator.IsValid ? "TextBox" : "TextBoxUnValidValue";//convert the the bob style by the validator }
protected void Shops_OnSelectedIndexChanged(object sender, EventArgs e) { ChangeShop.Visible = true; searchPanel.Visible = true; Products.Visible = true; shopSelectDiv.Visible = false; List <BLProduct> productsCart = (List <BLProduct>)Session["productsCart"]; bool toChangeShop = true; if (productsCart != null && productsCart.Count > 0) { //massage to delete all products in cart /* bool ToDelete= */ Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "Confirm()", true); string isConfirmString = isConfirm.Value; if (isConfirmString == "1") { Session["productsCart"] = null; toChangeShop = false; } isConfirm.Value = "0"; //DialogResult dialogResult = MessageBox.Show("Sure", "Some Title", MessageBoxButtons.YesNo); //if (dialogResult == DialogResult.Yes) //{ // //do something //} //else if (dialogResult == DialogResult.No) //{ // //do something else //} } if (toChangeShop) { int shopId = int.Parse(Shops.SelectedValue);//get shop id if (shopId == -1) { Products.ProductsCollections = BLProduct.GetAllProducts(""); } else { shopName.Text = BlShop.GetShopById(shopId).ShopName; //set data source List <BLProduct> products = BLProduct.GetAllProductsByShopId(shopId, ""); if (products != null && products.Count > 0) { Products.ProductsCollections = products; } else { Products.ProductsCollections = null; } } } }
public void UpdateWayString(List <BlShop> bestWayShops, List <BlCustomersAddress> bestWayCustomers) { string way = "start point >> "; BlCustomersAddress blCustomersAddress = bestWayCustomers[0]; for (int i = 0; i < bestWayCustomers.Count; i++) { BlCustomersAddress blCustomer = bestWayCustomers[i]; BlShop blShop = bestWayShops[i]; way += blShop.ShopName + " >> " + blCustomer.CustomerName; if (i + 1 != bestWayCustomers.Count) { way += " >> "; } } WayString.Text = way; }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { OrderStartedSucces.InnerHtml = Request.QueryString.Get("text"); } catch { OrderStartedSucces.InnerHtml = ""; } } //Session["user"] = new Deliver("shlakot1"); //BlOrderUser user = (BlOrderUser)Session["user"]; /*(BLUser)Session["user"];*/ //GlobalVariable.UnVerifyEmail.Add(user.UserId, "111111"); BlOrderUser user = /*(BlOrderUser)Session["user"];*/ (BlOrderUser)Session["user"]; //to check if user verify email!!!!!!!!!!!!!!!!!!!!!!!!!! //try //{ // Dictionary<string, string> VerifyEmail = ((Dictionary<string, string>) Application["UnVerifyEmail"]); // if (VerifyEmail!=null) // { // string verifyCode = VerifyEmail[user.UserId]; // Response.Redirect("VerifyEmail.aspx"); // return; // } // else // { // errorMSG.Text = "VerifyEmail null"; // } //} //catch //{ //} if (!(user is Deliver)) { return; } //get the new orders of the deliver List <BlOrder> orders = user.GetOrdersListByTime(); //set the road lists List <BlShop> shops = new List <BlShop>(); List <BlCustomersAddress> customersAddresses = new List <BlCustomersAddress>(); //full road lists foreach (BlOrder order in orders) { shops.Add(BlShop.GetShopById(order.ShopId)); Point customerAddress = order.Location != null ? new Point(order.Location) : new Point(BlUser.UserById(order.CustomerId).Location); customersAddresses.Add(new BlCustomersAddress(customerAddress, order.NumOfFloor, user.GetName())); } if (orders.Count == 0) { errorMSG.Text = "there is no orders"; return; } else { errorMSG.Text = ""; } if (orders.Count > 1)//to change to orders.Count>1!!!!!!!!!!!!!####$$$$$$$$########@@@@@@@*********#########&&&&&&&&&&$$$$$$$$$$^^^^^^^^^^%%%%%%%%%********** { //List<BlShop> sameShops = BlShop.isHaveSameShop(shops); //bool isHaveSameShop = sameShops.Count > 0; //if (isHaveSameShop) //{ //} bool isAllSameShop = BlShop.isAllSameShop(shops); //calculate shorter way to deliver GetBestWayLists(isAllSameShop, shops, customersAddresses, orders, (Deliver)user); } else { //update the Page vars Shops = Json.Encode(shops); Customers = Json.Encode(customersAddresses); UpdateWayString(shops, customersAddresses); //update the global vars Deliver deliver = (Deliver)user; double minutes = deliver.GetDistanceToCustomerHome(shops, customersAddresses); GlobalVariable.Distance = minutes; } }
protected void OrderTable_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); //get row index DataTable orders = (DataTable)OrderTable.DataSource; //get data int orderId = int.Parse(orders.Rows[index]["ID"].ToString()); BlOrder order = new BlOrder(BlOrder.GetOrderById(orderId)); int status = order.GetOrderStatus(); if (e.CommandName == "updateArrivalTime" && status == 3) { if (!(Session["user"] is Deliver)) { Response.Redirect("HomePage.aspx"); return; } // calculate the best way time Deliver deliver = (Deliver)Session["user"]; //get the new orders of the deliver List <BlOrder> Orders = deliver.GetOrdersListByTime(); //set the road lists List <BlShop> shops = new List <BlShop>(); List <BlCustomersAddress> customersAddresses = new List <BlCustomersAddress>(); //full road lists foreach (BlOrder Order in Orders) { shops.Add(BlShop.GetShopById(Order.ShopId)); Point customerAddress = Order.Location != null ? new Point(Order.Location) : new Point(BlUser.UserById(Order.CustomerId).Location); customersAddresses.Add(new BlCustomersAddress(customerAddress, Order.NumOfFloor, "")); } //calculate minutes double minutes = deliver.GetDistanceToCustomerHome(shops, customersAddresses); DateTime exitTime = DateTime.Now; DateTime arrivalTime = exitTime.AddMinutes(5 + minutes); //add 5 minute of insure bool success = order.UpdateArrivalTime(arrivalTime) && BlOrder.UpdateStatus(status + 1, orderId); //update arrive time and order status if (!success) { Response.Redirect("ViewOrders.aspx"); //go back to page when there is a error MSG.Visible = true; MSG.Text = "fail to start order "; //massage error } else { //Button myButton = null; //GridViewRow row = OrderTable.Rows[index]; //myButton = (Button)row.Cells[row.Cells.Count - 1].Controls[0]; //myButton.Text = "Order started"; //myButton.CommandName = "started"; MSG.Visible = true; MSG.Text = "success to start order!!!"; //massage error UpOrders((BlUser)Session["user"], ""); //update table UpdateButtonsText(3); //3=delivery } } else if (e.CommandName == "updateReadyTime" && status == 1) { DateTime readyTime = DateTime.Now; //get the order object //get the shop object BlShop shop = BlShop.GetShopById(order.ShopId); //get the Id of the closest delivery string matchDeliveryId = Deliver.GetMatchesDeliveryId(shop.Location);; if (matchDeliveryId == "") { List <int> orderWait = null; if (Application["updateReadyTime"] == null) { orderWait = new List <int> { orderId }; } else { orderWait = (List <int>)Application["updateReadyTime"]; orderWait.Add(orderId); } Application["updateReadyTime"] = orderWait; //update button Button myButton = null; GridViewRow row = OrderTable.Rows[index]; myButton = (Button)(row.Cells[4].Controls[0]); myButton.Text = "Product Ready"; myButton.CommandName = "Ready"; UpOrders((BlUser)Session["user"], "");//update table MSG.Text = " update ready time!"; } else { bool success = UpdateReadytime(order, readyTime, matchDeliveryId); if (!success) { ErMSG.Text = "fail to update ready time";//massage error } else { //update button Button myButton = null; GridViewRow row = OrderTable.Rows[index]; myButton = (Button)(row.Cells[4].Controls[0]); myButton.Text = "Product Ready"; myButton.CommandName = "Ready"; UpOrders((BlUser)Session["user"], "");//update table BlUser userToSendMailTo = BlUser.UserById(order.DeliveryId); List <BLOrderDetailsDB> Details = BLOrderDetailsDB.DetailsListOfOrder(orderId); string productsString = BLOrderDetailsDB.GetProductString(Details); bool isEmailSent = Register.sendEmail(userToSendMailTo.Email, " Fly pack you have a new order to deliver", $"Hi,{userToSendMailTo} please accept your order as soon as you can.Here a summery of the order's products <br/> {productsString} <br/> Have a nice day,The Fly Pack Team"); if (!isEmailSent) { //take care if email dont send } MSG.Text = " update ready time!"; } } } else if (e.CommandName == "finish") { if (status == 4 && BlOrder.UpdateStatus(status + 1, orderId))//update order status { BlUser customer = BlUser.UserById(order.CustomerId); NewOrOld.SelectedIndex = 1;//to see that the orders turn to old one BlUser CurrentUser = (BlUser)Session["user"]; NewOrOld.SelectedIndex = 0; UpOrders(CurrentUser, "");//update table UpdateButtonsText(CurrentUser.Type); if (Application["updateReadyTime"] != null) { List <int> orderWait = (List <int>)Application["updateReadyTime"]; int waitOrderId = orderWait[0]; BlOrder waitOrder = new BlOrder(BlOrder.GetOrderById(waitOrderId)); bool success = UpdateReadytime(waitOrder, DateTime.Now, CurrentUser.UserId); if (success) { orderWait.Remove(0); BlUser userToSendMailTo = BlUser.UserById(order.DeliveryId); List <BLOrderDetailsDB> Details = BLOrderDetailsDB.DetailsListOfOrder(orderId); string productsString = BLOrderDetailsDB.GetProductString(Details); bool isEmailSent1 = Register.sendEmail(userToSendMailTo.Email, " Fly pack you have a new order to deliver", $"Hi,{userToSendMailTo} please accept your order as soon as you can.Here a summery of the order's products <br/> {productsString} <br/> Have a nice day,The Fly Pack Team"); if (!isEmailSent1) { //take care if email dont send } } } //send email to customer bool isEmailSent = Register.sendEmail(customer.Email, " Fly pack your order arrived!!!", $"Hi,{customer} the drone arrive to your home please take your order.Have a nice day,The Fly Pack Team"); if (!isEmailSent) { //take care if email don't send } MSG.Text = "success to update status"; } else { ErMSG.Text = "fail to update status";//massage error } } else if (e.CommandName == "ShowOrderDetails") { List <BLOrderDetail> orderDetails = BLOrderDetail.GetOrderDetailsByOrderId(orderId); Update(orderDetails); OrderDetailsPanel.Visible = true; } if (e.CommandName == "not ready to start") { MSG.Text = "wait to shop manager to confirm order ";//massage } }
public string GetShopName(int ShopId) { return(BlShop.GetShopById(ShopId).ShopName); }//get SHOP name by shop id
public List <BlShop> GetAllShops() { List <BlShop> shops = BlShop.GetShops(); return(shops); }//get all shop in DB