protected void RadGridOrders_CustomAggregate(object sender, GridCustomAggregateEventArgs e) { switch (e.Column.UniqueName) { case "AvgPrice": try { GridItem[] arrGroupFooter = RadGridSalesReport.MasterTableView.GetItems(GridItemType.GroupFooter); GridItem[] arrFooter = RadGridSalesReport.MasterTableView.GetItems(GridItemType.Footer); if (arrFooter.Any()) { GridFooterItem footeritem = arrFooter.Last() as GridFooterItem; int qty = int.Parse(footeritem.Cells[4].Text.Replace(",", "")); decimal value = decimal.Parse(footeritem.Cells[6].Text.Replace("$", "").Replace(",", "")); e.Result = "$" + String.Format("{0:n}", value / qty); return; } if (arrGroupFooter.Any()) { GridGroupFooterItem footeritem = arrGroupFooter.Last() as GridGroupFooterItem; int qty = int.Parse(footeritem.Cells[4].Text.Replace(",", "")); decimal value = decimal.Parse(footeritem.Cells[6].Text.Replace("$", "").Replace(",", "")); e.Result = "$" + String.Format("{0:n}", value / qty); } } catch (Exception ex) { IndicoLogging.log.Error("Error occurred while calculating average prices", ex); } break; case "Name": { if (e.Item is GridGroupFooterItem) { GridItem[] arrGroupHeader = RadGridSalesReport.MasterTableView.GetItems(GridItemType.GroupHeader); if (arrGroupHeader.Any()) { var headerItem = arrGroupHeader.Last() as GridGroupHeaderItem; e.Result = "Total For " + headerItem.DataCell.Text; } } else if (e.Item is GridFooterItem) { e.Result = "Grand Total "; } } break; default: break; } }
protected void RadGrid1_CustomAggregate(object sender, GridCustomAggregateEventArgs e) { { if (e.Item is GridGroupFooterItem) { GridGroupFooterItem headerItem = e.Item as GridGroupFooterItem; GridItem[] groups = RadGrid1.MasterTableView.GetItems(GridItemType.GroupHeader); foreach (GridGroupHeaderItem group in groups) { string id = headerItem["qty_required"].Text; } } } }
protected void grdProducto_ItemDataBound(object sender, GridItemEventArgs e) { if (Session["Usuario"] == null) { Response.Redirect("~/Security/frmCerrar.aspx"); } try { if (e.Item is GridGroupFooterItem) { GridGroupFooterItem footerItem = e.Item as GridGroupFooterItem; string strValorVenta = footerItem["ValorVenta"].Text; strValorVenta = strValorVenta.Substring(1, strValorVenta.Length - 1); strValorVenta = strValorVenta.Replace(",", string.Empty); string strValorPlanificado = footerItem["ValorPlanificado"].Text; strValorPlanificado = strValorPlanificado.Substring(1, strValorPlanificado.Length - 1); strValorPlanificado = strValorPlanificado.Replace(",", string.Empty); string strCostoVenta = footerItem["CostoVenta"].Text; strCostoVenta = strCostoVenta.Substring(1, strCostoVenta.Length - 1); strCostoVenta = strCostoVenta.Replace(",", string.Empty); if (decimal.Parse(strValorPlanificado) > 0) { footerItem["Avance"].Text = Math.Round((decimal.Parse(strValorVenta) / decimal.Parse(strValorPlanificado)) * 100, 0).ToString() + "%"; } else { footerItem["Avance"].Text = "100%"; } if (decimal.Parse(strValorVenta) > 0) { footerItem["Rentabiliad"].Text = Math.Round(((decimal.Parse(strValorVenta) - decimal.Parse(strCostoVenta)) * 100 / decimal.Parse(strValorVenta)), 0).ToString() + "%"; } else { footerItem["Rentabiliad"].Text = "100%"; } } if (e.Item is GridFooterItem) { GridFooterItem footerItem = e.Item as GridFooterItem; string strValorVenta = footerItem["ValorVenta"].Text; strValorVenta = strValorVenta.Substring(1, strValorVenta.Length - 1); strValorVenta = strValorVenta.Replace(",", string.Empty); string strValorPlanificado = footerItem["ValorPlanificado"].Text; strValorPlanificado = strValorPlanificado.Substring(1, strValorPlanificado.Length - 1); strValorPlanificado = strValorPlanificado.Replace(",", string.Empty); string strCostoVenta = footerItem["CostoVenta"].Text; strCostoVenta = strCostoVenta.Substring(1, strCostoVenta.Length - 1); strCostoVenta = strCostoVenta.Replace(",", string.Empty); if (decimal.Parse(strValorPlanificado) > 0) { footerItem["Avance"].Text = Math.Round((decimal.Parse(strValorVenta) / decimal.Parse(strValorPlanificado) * 100), 0).ToString() + "%"; } else { footerItem["Avance"].Text = "100%"; } if (decimal.Parse(strCostoVenta) > 0) { footerItem["Rentabiliad"].Text = Math.Round(((decimal.Parse(strValorVenta) - decimal.Parse(strCostoVenta)) * 100 / decimal.Parse(strValorVenta)), 0).ToString() + "%"; } else { footerItem["Rentabiliad"].Text = "100%"; } } } catch (Exception ex) { lblMensaje.Text = ex.Message; lblMensaje.CssClass = "mensajeError"; } }
protected void RadGridSalesReport_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridGroupHeaderItem) { GridGroupHeaderItem item = e.Item as GridGroupHeaderItem; (item.DataCell).Text = (item.DataCell).Text.Replace("MonthAndYear: ", string.Empty); this.HeaderText = (item.DataCell).Text; string monthPart = (item.DataCell).Text.Substring(4); if (monthPart == "01") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "January"; } else if (monthPart == "02") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "February"; } else if (monthPart == "03") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "March"; } else if (monthPart == "04") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "April"; } else if (monthPart == "05") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "May"; } else if (monthPart == "06") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "June"; } else if (monthPart == "07") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "July"; } else if (monthPart == "08") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "August"; } else if (monthPart == "09") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "September"; } else if (monthPart == "10") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "October"; } else if (monthPart == "11") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "November"; } else if (monthPart == "12") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "December"; } } else if (e.Item is GridFooterItem) { var footeritem = (GridFooterItem)e.Item; try { var totalGrossProfit = decimal.Parse(e.Item.Cells[10].Text.Replace("$", string.Empty).Replace(",", string.Empty)); var totalSalesPrice = decimal.Parse(e.Item.Cells[6].Text.Replace("$", string.Empty).Replace(",", string.Empty)); e.Item.Cells[11].Text = ((totalGrossProfit / totalSalesPrice) * 100).ToString("0.00") + "%"; } catch (Exception) { //ignored } //footeritem.Cells[5].Text = string.Empty; //footeritem.Cells[7].Text = string.Empty; //footeritem.Style.Add("text-align", "right"); footeritem.Style.Add("color", "green"); footeritem.Style.Add("font-weight", "bold"); } else if (e.Item is GridDataItem) { var item = (GridDataItem)e.Item; if (!(item.ItemIndex > -1 && item.DataItem is ReturnOrderQuantitiesAndAmountBO)) { return; } var obj = (ReturnOrderQuantitiesAndAmountBO)item.DataItem; var lnkQuentity = (HyperLink)item.FindControl("lnkQuantity"); lnkQuentity.Text = Convert.ToString(obj.Quantity); lnkQuentity.NavigateUrl = "DrillDownReport.aspx?id=" + obj.ID + "&DistributorName=" + obj.Name + "&Start=" + DateTime.Parse(this.txtCheckin.Value).ToShortDateString() + "&End=" + DateTime.Parse(this.txtCheckout.Value).ToShortDateString() + "&Current=" + HeaderText + "&Name=" + txtName.Text + "&Type=" + ((rdoDirectSales.Checked) ? "1" : "2"); var litGrossMargin = (Literal)item.FindControl("litGrossMargin"); litGrossMargin.Text = obj.GrossMargin.ToString("0.00") + "%"; //HyperLink lnkDistributor = (HyperLink)item.FindControl("lnkDistributor"); // lnkDistributor.NavigateUrl = "DrillDownReport.aspx?id=" + obj.ID.ToString() + "&Start=" + DateTime.Parse(this.txtCheckin.Value).ToShortDateString() + "&End=" + DateTime.Parse(this.txtCheckout.Value).ToShortDateString() + "&Current=" + this.HeaderText + "&Name=" + this.txtName.Text + "&Type=" + ((this.rdoDirectSales.Checked)? "1" : "2"); //lnkDistributor.Text = obj.Name; // Literal litGrossMargin = (Literal)item.FindControl("litGrossMargin"); //litGrossMargin.Text = obj.GrossMargin.ToString("0.00") + "%"; } else if (e.Item is GridGroupFooterItem) { GridGroupFooterItem groupFooter = e.Item as GridGroupFooterItem; decimal totalGrossProfit = decimal.Parse(e.Item.Cells[10].Text.Replace("$", string.Empty).Replace(",", string.Empty)); decimal totalSalesPrice = decimal.Parse(e.Item.Cells[6].Text.Replace("$", string.Empty).Replace(",", string.Empty)); e.Item.Cells[11].Text = ((totalGrossProfit / totalSalesPrice) * 100).ToString("0.00") + "%"; groupFooter.Style.Add("color", "blue"); groupFooter.Style.Add("font-weight", "bold"); } }
protected void RadGridDrillDownReport_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridGroupHeaderItem) { GridGroupHeaderItem item = e.Item as GridGroupHeaderItem; (item.DataCell).Text = (item.DataCell).Text.Replace("MonthAndYear: ", string.Empty); string monthPart = (item.DataCell).Text.Substring(4); if (monthPart == "01") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "January"; } else if (monthPart == "02") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "February"; } else if (monthPart == "03") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "March"; } else if (monthPart == "04") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "April"; } else if (monthPart == "05") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "May"; } else if (monthPart == "06") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "June"; } else if (monthPart == "07") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "July"; } else if (monthPart == "08") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "August"; } else if (monthPart == "09") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "September"; } else if (monthPart == "10") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "October"; } else if (monthPart == "11") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "November"; } else if (monthPart == "12") { (item.DataCell).Text = (item.DataCell).Text.Substring(0, 4) + " - " + "December"; } } else if (e.Item is GridFooterItem) { GridFooterItem footeritem = e.Item as GridFooterItem; //footeritem.Cells[5].Text = string.Empty; try { var totalGrossProfit = decimal.Parse(e.Item.Cells[9].Text.Replace("$", string.Empty).Replace(",", string.Empty)); var totalSalesPrice = decimal.Parse(e.Item.Cells[5].Text.Replace("$", string.Empty).Replace(",", string.Empty)); e.Item.Cells[10].Text = ((totalGrossProfit / totalSalesPrice) * 100).ToString("0.00") + "%"; } catch (Exception) { //ignored } footeritem.Style.Add("color", "green"); footeritem.Style.Add("font-weight", "bold"); } else if (e.Item is GridGroupFooterItem) { var totalGrossProfit = decimal.Parse(e.Item.Cells[10].Text.Replace("$", string.Empty).Replace(",", string.Empty)); var totalSalesPrice = decimal.Parse(e.Item.Cells[6].Text.Replace("$", string.Empty).Replace(",", string.Empty)); e.Item.Cells[11].Text = ((totalGrossProfit / totalSalesPrice) * 100).ToString("0.00") + "%"; GridGroupFooterItem groupFooter = e.Item as GridGroupFooterItem; groupFooter.Cells[2].BackColor = Color.Red; groupFooter.Style.Add("color", "blue"); groupFooter.Style.Add("font-weight", "bold"); } else if (e.Item is GridDataItem) { var item = (GridDataItem)e.Item; if (!(item.ItemIndex > -1 && item.DataItem is ReturnDetailReportByDistributorBO)) { return; } var obj = (ReturnDetailReportByDistributorBO)item.DataItem; var lnkQuantity = (HyperLink)item.FindControl("lnkQuantity"); lnkQuantity.NavigateUrl = "DrillDownReportByClient.aspx?Start=" + this.Start.ToShortDateString() + "&End=" + this.End.ToShortDateString() + "&Distributor=" + this.Distributor.ToString() + "&Client=" + obj.ID.ToString() + "&Current=" + this.Current + "&Name=" + this.DistributorName + "&Type=" + this.DistributorType + "&ClientName=" + obj.Client + "&DistributorName=" + CurrentDistributorName; lnkQuantity.Text = Convert.ToString(obj.Quantity); } }