/// <summary> /// Handles the ElementsFetched event of the LLBLGenProDataSource /// Use it in case of empty data. To change the mode of the FormView to the InsertMode. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OrdersDS_ElementsFetched(object sender, EventArgs e) { // if there are no orders, go to Insert Mode of the FormView // and hide the Order-Details Grid and the total summary. if (OrdersDS.EntityCollection.Count <= 0) { OrdersFormView.ChangeMode(FormViewMode.Insert); OrderDetailsGridView.Visible = false; TotalAmount.Visible = false; } }
/// <summary> /// Calculates the Total Order Amount. /// By summing the totals of all order-detail lines in addition to the freight value of the order. /// </summary> private void CalculateOrderTotalAmount() { string freightText = string.Empty; // Get the Freight amount from the FormView // If the GridView is in the ReadOnly mode then the Freight will be written in a label. if (OrdersFormView.CurrentMode == FormViewMode.ReadOnly) { Label control = (Label)OrdersFormView.FindControl("Freight"); if (control != null) { freightText = control.Text; } } // Else the Freight will be written in a TextBox. else { TextBox control = (TextBox)OrdersFormView.FindControl("Freight"); if (control != null) { freightText = control.Text; } } decimal freight = 0; decimal totalAmount = 0; if (decimal.TryParse(freightText, System.Globalization.NumberStyles.Currency, null, out freight)) { totalAmount += freight; } // Sum all order-details total values. foreach (OrderDetailEntity orderDetail in OrderDetailsDS.EntityCollection) { totalAmount += orderDetail.Total; } TotalAmount.Text = "Order total amount including freight = " + totalAmount.ToString("$ #,#0.##"); }