protected string getEventName(string eventID) { int eID = int.Parse(eventID); EventClient evClient = new EventClient(); string evName = evClient.GetEventName(eID); evClient.Close(); return evName; }
/// <summary> /// Loads the list of goods in a cart with a definite cart_id from an XML file into DataSet /// </summary> /// <param name="cart_id">the cart idetntifier</param> /// <returns>The DataSet with the list of goods in the cart with the cart_id.</returns> public static DataSet LoadCart(string cart_id) { DataSet currentCart = new DataSet(); string cartsFile = HttpContext.Current.Server.MapPath("~/App_Data/Carts.xml"); cart.Clear(); if (File.Exists(cartsFile)) { cart.ReadXml(cartsFile); } else { Carts.CreateXml(cartsFile, "Carts"); cart.ReadXml(cartsFile); } // creates a copy of all carts currentCart = cart.Copy(); string expression = null; DataRow[] foundRows = null; //an expression for searching for a cart with a cart_id expression = "cart_id NOT LIKE '" + cart_id + "'"; try { if (currentCart.Tables.Count == 0) { // WriteFile("Error in Carts.LoadCart(): " + "currentCart.Tables.Count = 0"); Alert.Show("You got no item in your cart", true, "ParticipantEvents.aspx"); } if (currentCart.Tables[0].Rows.Count == 0) { // WriteFile("Error in Carts.LoadCart(): " + "currentCart.Rows.Count = 0"); Alert.Show("You got no item in your cart", true, "ParticipantEvents.aspx"); } // remove all goods from the current cart with the cart_id that does not ocincide with the specified one foundRows = currentCart.Tables[0].Select(expression); int i = 0; for (i = 0; i <= foundRows.GetUpperBound(0); i++) { foundRows[i].Delete(); } // getting a name of item for its Event_ID in order to display it further in GridView DataColumn column = currentCart.Tables[0].Columns["Event_ID"]; currentCart.Tables[0].Columns.Add("Name", System.Type.GetType("System.String")); foreach (DataRow row in currentCart.Tables[0].Rows) { //TODO: Get the event name via its ID EventClient client = new EventClient(); string name = client.GetEventName(int.Parse(row["Event_ID"].ToString())); if (!string.IsNullOrEmpty(name)) { row["Name"] = name; } } return currentCart; } catch (Exception ex) { currentCart.Clear(); //Alert.Show("Error in Carts.LoadCart(): " + ex.Message); //WriteFile("Error in Carts.LoadCart(): " + ex.Message); //HttpContext.Current.Response.Redirect("~/Default.aspx") return null; } }