Example #1
0
        /// <summary>
        /// This function returns the list of record controls within the table control.
        /// There is a more specific GetRecordControls function generated in the
        /// derived classes, but in some cases, we do not know the specific type of
        /// the table control, so we need to call this method. This is also used by the
        /// Formula evaluator to perform Sum, Count and CountA functions.
        /// </summary>
        public virtual BaseApplicationRecordControl[] GetBaseRecordControls()
        {
            ArrayList recList = new ArrayList();

            // First get the repeater inside the Table Control.
            System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater) this.FindControl(this.RepeaterName);
            if ((rep == null) || (rep.Items == null))
            {
                return(null);
            }

            // We now go inside the repeater to find all the record controls.
            // Note that we only find the first level record controls. We do not
            // descend down and find other record controls belonging to tables-inside-table.

            foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
            {
                BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)repItem.FindControl(this.RowName);
                if (!((recControl == null)))
                {
                    recList.Add(recControl);
                }
            }

            return((BaseApplicationRecordControl[])recList.ToArray(typeof(BaseApplicationRecordControl)));
        }
Example #2
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);
        }
Example #3
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);
        }
Example #4
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);
        }
Example #5
0
        /// <summary>
        /// Method will loop through the literal controls inside the repeater.
        /// Assign the id value if found the duplicate items
        /// </summary>
        /// <param name="ids">Name of the literal controls who has duplicate values</param>
        public virtual void InitializeDuplicateItems(ArrayList ids)
        {
            if (ids.Count == 0)
            {
                return;
            }

            ArrayList          listOfDups = new ArrayList();
            ListItemCollection itemsList  = new ListItemCollection();
            int index = 0;

            if (ids.Count == 1)
            {
                System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this as BaseApplicationTableControl, this.RepeaterName));
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    PrimaryKeyRecord             pkRecord   = ((PrimaryKeyRecord)(this._DataSource[index]));
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        Literal    ltlCtrl;
                        Label      lblCtrl;
                        LinkButton lbtnCtrl;
                        string     txtValue = "";
                        if (ctrlItem.ID == ids[0].ToString())
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal)
                            {
                                ltlCtrl  = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                txtValue = ltlCtrl.Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label)
                            {
                                lblCtrl  = (System.Web.UI.WebControls.Label)(ctrlItem);
                                txtValue = lblCtrl.Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton)
                            {
                                lbtnCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                txtValue = lbtnCtrl.Text;
                            }

                            if (txtValue != "")
                            {
                                ListItem dupItem = itemsList.FindByText(txtValue);
                                if (dupItem != null)
                                {
                                    listOfDups.Add(dupItem.Text);
                                    dupItem.Text = dupItem.Text + " (ID " + dupItem.Value + ")";
                                }

                                ListItem newItem = new ListItem(txtValue, pkRecord.GetID().ToDisplayString());
                                itemsList.Add(newItem);

                                if (listOfDups.Contains(newItem.Text))
                                {
                                    newItem.Text = newItem.Text + " (ID " + newItem.Value + ")";
                                }
                                break;
                            }
                        }
                    }
                    index++;
                }

                index = 0;
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        if (ctrlItem.ID == ids[0].ToString())
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal && itemsList.Count != 0)
                            {
                                Literal ltCtrl = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                ltCtrl.Text = itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label && itemsList.Count != 0)
                            {
                                Label ltCtrl = (System.Web.UI.WebControls.Label)(ctrlItem);
                                ltCtrl.Text = itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton && itemsList.Count != 0)
                            {
                                LinkButton ltCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                ltCtrl.Text = itemsList[index].Text;
                            }
                        }
                    }
                    index++;
                }
            }
            else if (ids.Count == 2)
            {
                System.Web.UI.WebControls.Repeater rep = (System.Web.UI.WebControls.Repeater)(BaseClasses.Utils.MiscUtils.FindControlRecursively(this as BaseApplicationTableControl, this.RepeaterName));
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    int                          count      = 0;
                    string                       ltText     = "";
                    PrimaryKeyRecord             pkRecord   = ((PrimaryKeyRecord)(this._DataSource[index]));
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        if (ctrlItem.ID == ids[0].ToString() || ctrlItem.ID == ids[1].ToString())
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal)
                            {
                                Literal ltCtrl = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                ltText += ltCtrl.Text;

                                count++;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label)
                            {
                                Label ltCtrl = (System.Web.UI.WebControls.Label)(ctrlItem);
                                ltText += ltCtrl.Text;

                                count++;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton)
                            {
                                LinkButton ltCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                ltText += ltCtrl.Text;

                                count++;
                            }
                        }

                        if (count == ids.Count)
                        {
                            ListItem dupItem = itemsList.FindByText(ltText);
                            if (dupItem != null)
                            {
                                listOfDups.Add(dupItem.Text);
                                dupItem.Text = " (ID " + dupItem.Value + ")";
                            }

                            ListItem newItem = new ListItem(ltText, pkRecord.GetID().ToDisplayString());
                            itemsList.Add(newItem);

                            if (listOfDups.Contains(newItem.Text))
                            {
                                newItem.Text = " (ID " + newItem.Value + ")";
                            }
                            break;
                        }
                    }
                    index++;
                }

                index = 0;
                foreach (System.Web.UI.WebControls.RepeaterItem repItem in rep.Items)
                {
                    BaseApplicationRecordControl recControl = (BaseApplicationRecordControl)(repItem.FindControl(this.RowName));
                    foreach (System.Web.UI.Control ctrlItem in recControl.Controls)
                    {
                        if ((ctrlItem.ID == ids[0].ToString() || ctrlItem.ID == ids[1].ToString()) && itemsList.Count != 0)
                        {
                            if (ctrlItem is System.Web.UI.WebControls.Literal && itemsList[index].Text.Contains(" (ID "))
                            {
                                Literal ltCtrl = (System.Web.UI.WebControls.Literal)(ctrlItem);
                                ltCtrl.Text = ltCtrl.Text + itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.Label && itemsList[index].Text.Contains(" (ID "))
                            {
                                Label ltCtrl = (System.Web.UI.WebControls.Label)(ctrlItem);
                                ltCtrl.Text = ltCtrl.Text + itemsList[index].Text;
                            }
                            else if (ctrlItem is System.Web.UI.WebControls.LinkButton && itemsList[index].Text.Contains(" (ID "))
                            {
                                LinkButton ltCtrl = (System.Web.UI.WebControls.LinkButton)(ctrlItem);
                                ltCtrl.Text = ltCtrl.Text + itemsList[index].Text;
                            }
                        }
                    }
                    index++;
                }
            }
        }