Beispiel #1
0
        private void BindPerUseBilling(DateTime period, int clientId)
        {
            gvRoom.DataSource = null;
            gvRoom.DataBind();

            //Create the list to contain all summary total for each organization
            //IList<UsageSummaryTotal> mylist = new List<UsageSummaryTotal>();

            DataTable SummaryTable = new DataTable();

            SummaryTable.Columns.Add("OrgID", typeof(int));
            SummaryTable.Columns.Add("OrgName", typeof(string));
            SummaryTable.Columns.Add("BillingTypeID", typeof(int));
            SummaryTable.Columns.Add("RoomTotal", typeof(double));
            SummaryTable.Columns.Add("ToolTotal", typeof(double));
            SummaryTable.Columns.Add("StoreTotal", typeof(double));

            double sumCost = 0.0;

            var dsReport = ContextBase.GetCacheData();

            gvRoom.DataSource = BillingManager.GetRoomCost(dsReport, period, clientId, SummaryTable, ref sumCost);
            gvRoom.DataBind();
            lblRoom2.Text = string.Format("Total lab usage fees: {0:C}", sumCost);

            DataTable dtCancelled = null;
            DataTable dtForgiven  = null;

            gvTool2.DataSource = BillingManager.GetToolCost(dsReport, period, clientId, SummaryTable, ref sumCost, dtCancelled, dtForgiven);
            gvTool2.DataBind();

            gvToolCancelled2.DataSource = dtCancelled;
            gvToolCancelled2.DataBind();

            gvToolForgiven2.DataSource = dtForgiven;
            gvToolForgiven2.DataBind();

            double cancelledCost;
            double forgivenCost;

            if (dtCancelled == null || dtCancelled.Rows.Count == 0)
            {
                cancelledCost = 0;
            }
            else
            {
                cancelledCost = Convert.ToDouble(dtCancelled.Compute("SUM(TotalCalcCost)", string.Empty));
            }

            if (dtForgiven == null || dtForgiven.Rows.Count == 0)
            {
                forgivenCost = 0;
            }
            else
            {
                forgivenCost = Convert.ToDouble(dtForgiven.Compute("SUM(TotalCalcCost)", string.Empty));
            }

            lblTool2.Text             = string.Format("Total tool usage fees: {0:C}", sumCost + cancelledCost);
            lblActivatedToolFee2.Text = string.Format("Sub Total: {0:C}", sumCost);
            lblCancelledToolFee2.Text = string.Format("Sub Total: {0:C}", cancelledCost);
            lblForgivenToolFee2.Text  = string.Format("Sub Total: {0:$#,##0.00;($#,##0.00)}", forgivenCost);

            //Store
            //gvStore2.DataSource = BillingManager.GetStoreCost(period, clientId, SummaryTable, sumCost);
            //gvStore2.DataBind();
            //lblStore2.Text = string.Format("Total store usage fees: {0:C}", sumCost);
            if (dtStore2.Rows.Count > 0)
            {
                foreach (DataRow r in SummaryTable.Rows)
                {
                    r["StoreTotal"] = dtStore2.Compute("SUM(CalcCost)", string.Format("OrgID = {0}", r["OrgID"]));

                    if (r["StoreTotal"] == null || r["StoreTotal"] == DBNull.Value)
                    {
                        r["StoreTotal"] = 0.0;
                    }
                }

                gvStore2.DataSource = dtStore2;
                gvStore2.DataBind();
                object sumobj;

                //2009-08-05 it's possible that a user bought stuff but didn't use the lab at all
                sumobj = SummaryTable.Compute("SUM(StoreTotal)", string.Empty);
                if (sumobj == null || sumobj == DBNull.Value)
                {
                    sumCost = 0.0;
                    //no lab usage, only store usage
                    sumobj = dtStore2.Compute("SUM(CalcCost)", string.Empty);
                    if (sumobj != null && sumobj != DBNull.Value)
                    {
                        sumCost = Convert.ToDouble(sumobj);
                    }
                }
                else
                {
                    sumCost = Convert.ToDouble(sumobj);
                }

                lblStore2.Text = string.Format("Total store usage fees: {0:C}", sumCost);
            }
            else
            {
                lblStore2.Text = "No store usage during period";

                foreach (DataRow r in SummaryTable.Rows)
                {
                    r["StoreTotal"] = 0.0;
                }
            }

            dlSummary2.DataSource = SummaryTable;
            dlSummary2.DataBind();
        }