Esempio n. 1
0
        /// <summary>
        /// Return the row number of this record control.
        /// This function should be called as <Products>TableControlRow.ROWNUM(), not
        /// as shown here. The ROWNUM function in the BaseApplicationRecordControl will call this
        /// function to actually perform the work - so that we can keep all of the formula
        /// functions together in one place.
        /// </summary>
        /// <param name="tableControl">The table control instance.</param>
        /// <param name="recordControl">The record control whose row number is being determined. Row numbers are 1-based.</param>
        /// <param name="ctlName">The string name of the UI control (e.g., "UnitPrice") </param>
        /// <returns>The row number of the recordControl passed in. 0 if this is not a correct row number. </returns>
        public static int RowNum(BaseApplicationTableControl tableControl, BaseApplicationRecordControl recordControl)
        {
            int rowNumber = 1;

            // Get all of the record controls within this table control.
            foreach (BaseApplicationRecordControl recCtl in tableControl.GetBaseRecordControls())
            {
                if (object.ReferenceEquals(recCtl, recordControl))
                {
                    // We found the row.
                    return rowNumber;
                }
                rowNumber += 1;
            }

            return 0;
        }
Esempio n. 2
0
        /// <summary>
        /// Return the running total of the control.
        /// This function should be called as [Products]TableControlRow.RUNNINGTOTAL("UnitPrice"), not
        /// as shown here. The RUNNINGTOTAL function in the BaseApplicationRecordControl will call this
        /// function to actually perform the work - so that we can keep all of the formula
        /// functions together in one place.
        /// Say there are 5 rows and they contain 57, 32, 12, 19, 98.
        /// Their respecitive running totals will be 57, 89, 101, 120, 218
        /// </summary>
        /// <param name="tableControl">The table control instance.</param>
        /// <param name="recordControl">The record control whose running total is being determined.</param>
        /// <param name="ctlName">The string name of the UI control (e.g., "UnitPrice") </param>
        /// <returns>The running total of the recordControl passed in.</returns>
        public static decimal RunningTotal(BaseApplicationTableControl tableControl, BaseApplicationRecordControl recordControl, string ctlName)
        {
            decimal sum = 0;

            // Get all of the record controls within this table control.
            foreach (BaseApplicationRecordControl recCtl in tableControl.GetBaseRecordControls())
            {
                System.Web.UI.Control ctl = default(System.Web.UI.Control);
                // The control itself may be embedded in sub-panels, so we need to use
                // FindControlRecursively starting from the recCtl.
                ctl = MiscUtils.FindControlRecursively(recCtl, ctlName);
                if (!(ctl == null))
                {
                    string textVal = null;
                    decimal val = 0;

                    // Get the value from the textbox, label or literal
                    if (ctl is System.Web.UI.WebControls.TextBox)
                    {
                        textVal = ((System.Web.UI.WebControls.TextBox)ctl).Text;
                    }
                    else if (ctl is System.Web.UI.WebControls.Label)
                    {
                        textVal = ((System.Web.UI.WebControls.Label)ctl).Text;
                    }
                    else if (ctl is System.Web.UI.WebControls.Literal)
                    {
                        textVal = ((System.Web.UI.WebControls.Literal)ctl).Text;
                    }

                    try
                    {
                        // If the value is not a valid number, ignore it.
                        val = StringUtils.ParseDecimal(textVal);
                        sum = val + sum;
                        if (object.ReferenceEquals(recCtl, recordControl))
                        {
                        //Return sum if the row we are looking for is reached
                            return sum;
                        }
                    }
                    catch (Exception)
                    {
                        // Ignore exception.
                    }
                }
            }

            return sum;
        }
Esempio n. 3
0
        /// <summary>
        /// Return the Rank of this control.
        /// This function should be called as <Products>TableControlRow.RANK("UnitPrice"), not
        /// as shown here. The RANK function in the BaseApplicationRecordControl will call this
        /// function to actually perform the work - so that we can keep all of the formula
        /// functions together in one place.
        /// Say there are 5 rows and they contain 57, 32, 12, 19, 98.
        /// Their respecitive ranks will be 4, 3, 1, 2, 5
        /// </summary>
        /// <param name="tableControl">The table control instance.</param>
        /// <param name="recordControl">The record control whose tank is being determined. Rank numbers are 1-based.</param>
        /// <param name="ctlName">The string name of the UI control (e.g., "UnitPrice") </param>
        /// <returns>The row number of the recordControl passed in. 0 if this is not a correct row number. </returns>
        public static int Rank(BaseApplicationTableControl tableControl, BaseApplicationRecordControl recordControl, string ctlName)
        {
            ArrayList rankedArray = new ArrayList();
            decimal lookFor = 0;

            // Get all of the record controls within this table control.
            foreach (BaseApplicationRecordControl recCtl in tableControl.GetBaseRecordControls())
            {
                System.Web.UI.Control ctl = default(System.Web.UI.Control);
                // The control itself may be embedded in sub-panels, so we need to use
                // FindControlRecursively starting from the recCtl.
                ctl = MiscUtils.FindControlRecursively(recCtl, ctlName);
                if (!(ctl == null))
                {
                    string textVal = null;
                    decimal val = 0;

                    // Get the value from the textbox, label or literal
                    if (ctl is System.Web.UI.WebControls.TextBox)
                    {
                        textVal = ((System.Web.UI.WebControls.TextBox)ctl).Text;
                    }
                    else if (ctl is System.Web.UI.WebControls.Label)
                    {
                        textVal = ((System.Web.UI.WebControls.Label)ctl).Text;
                    }
                    else if (ctl is System.Web.UI.WebControls.Literal)
                    {
                        textVal = ((System.Web.UI.WebControls.Literal)ctl).Text;
                    }

                    try
                    {
                        // If the value is not a valid number, ignore it.
                        val = StringUtils.ParseDecimal(textVal);
                        rankedArray.Add(val);
                        // Save the value that we need to look for to determine the rank
                        if (object.ReferenceEquals(recCtl, recordControl))
                        {
                            lookFor = val;
                        }
                    }
                    catch (Exception)
                    {
                        // Ignore exception.
                    }
                }
            }

            // Sort the array now.
            rankedArray.Sort();

            // Rank is always 1 based in our case. So we need to add one to the
            // location returned by IndexOf
            return rankedArray.IndexOf(lookFor) + 1;
        }