Example #1
0
        protected void RadGridRegex_ItemCommand(object sender, GridCommandEventArgs e)
        {
            if (!(e.Item is GridDataItem item))
            {
                return;
            }
            var textBox = item["Rank"];

            if (textBox == null)
            {
                return;
            }
            int rank = Utils.StringToInt(textBox.Text);

            List <Models.RegExpression> regExpList = (DataItem as Models.Channel).RegularExpressions;

            if (e.CommandName == "Up" || e.CommandName == "Down")
            {
                Models.RegExpression rx2 = null;
                Models.RegExpression rx1 = regExpList.FirstOrDefault(p => p.Rank == rank);
                if (e.CommandName == "Up")
                {
                    rx2 = regExpList.FirstOrDefault(p => p.Rank == rank - 1);
                }
                else
                {
                    rx2 = regExpList.FirstOrDefault(p => p.Rank == rank + 1);
                }
                if (rx1 != null && rx2 != null)
                {
                    int t = rx1.Rank;
                    rx1.Rank = rx2.Rank;
                    rx2.Rank = t;
                }
                (DataItem as Models.Channel).RegularExpressions = regExpList.OrderBy(p => p.Rank).ToList();;
                RadGridRegex.Rebind();
            }
        }
        /*        protected void RadGridRegex_UpdateCommand(object source, GridCommandEventArgs e)
         *      {
         *          GridEditableItem editedItem = e.Item as GridEditableItem;
         *          GridTextBoxColumnEditor r = (GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("Rank");
         *          GridTextBoxColumnEditor me = (GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("MatchExpression");
         *          GridTextBoxColumnEditor fe = (GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("FormatExpression");
         *          GridTextBoxColumnEditor cm = (GridTextBoxColumnEditor)editedItem.EditManager.GetColumnEditor("Comment");
         *          if (r == null || me == null || fe == null || cm == null)
         *          {
         *              RadGridRegex.Controls.Add(new LiteralControl("Unable to locate the Rank for updating."));
         *              e.Canceled = true;
         *              return;
         *          }
         *          int rank = Utils.StringToInt(r.Text);
         *          if (rank == 0)
         *          {
         *              RadGridRegex.Controls.Add(new LiteralControl("Unable to locate the Rank for updating."));
         *              e.Canceled = true;
         *              return;
         *          }
         *
         *          List<Models.RegExpression> regExpList = Channel.RegularExpressions;
         *          Models.RegExpression rx = regExpList.FirstOrDefault(p => p.Rank == rank);
         *          if (rx != null)
         *          {
         *              rx.MatchExpression = me.Text;
         *              rx.FormatExpression = fe.Text;
         *              rx.Comment = cm.Text;
         *          }
         *      }
         */
        /*     protected void RadGridRegex_ItemInserted(object sender, GridInsertedEventArgs e)
         *  {
         *     GridEditableItem newItem = e.Item as GridEditableItem;
         *      GridTextBoxColumnEditor rk = (GridTextBoxColumnEditor)newItem.EditManager.GetColumnEditor("Rank");
         *      GridTextBoxColumnEditor me = (GridTextBoxColumnEditor)newItem.EditManager.GetColumnEditor("MatchExpression");
         *      GridTextBoxColumnEditor fe = (GridTextBoxColumnEditor)newItem.EditManager.GetColumnEditor("FormatExpression");
         *
         *      if (me == null || fe == null || rk == null)
         *      {
         *          RadGridRegex.Controls.Add(new LiteralControl("Unable to locate the row for inserting."));
         *          e.KeepInInsertMode = false;
         *          return;
         *      }
         *
         *      List<Models.RegExpression> regExpList = Channel.RegularExpressions;
         *      regExpList.Add(new Models.RegExpression() { Rank = regExpList.Count + 1, MatchExpression = me.Text, FormatExpression = fe.Text, Comment = ""});
         *
         *  }
         */
        /*        protected void RadGridRegex_DeleteCommand(object source, GridCommandEventArgs e)
         *      {
         *          string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Rank"].ToString();
         *          GridEditableItem deleteItem = e.Item as GridEditableItem;
         *          GridTextBoxColumnEditor r = (GridTextBoxColumnEditor)deleteItem.EditManager.GetColumnEditor("Rank");
         *          if (r == null)
         *          {
         *              RadGridRegex.Controls.Add(new LiteralControl("Unable to locate the item for deleting."));
         *              //e.Canceled = true;
         *              return;
         *          }
         *          int rank = Utils.StringToInt(r.Text);
         *          if (rank == 0)
         *          {
         *              RadGridRegex.Controls.Add(new LiteralControl("Unable to locate the item for deleting."));
         *              //e.Canceled = true;
         *              return;
         *          }
         *          List<Models.RegExpression> regExpList = Channel.RegularExpressions;
         *          Models.RegExpression rx = regExpList.FirstOrDefault(p => p.Rank == rank);
         *          if (rx != null)
         *              regExpList.Remove(rx);
         *      }
         */
        protected void RadGridRegex_ItemCommand(object sender, GridCommandEventArgs e)
        {
            List <Models.RegExpression> regExpList = Channel.RegularExpressions;

            if (e.CommandName == "Up" || e.CommandName == "Down")
            {
                GridDataItem item = e.Item as GridDataItem;
                if (item == null)
                {
                    return;
                }
                var textBox = item["Rank"];
                if (textBox == null)
                {
                    return;
                }
                int rank = Utils.StringToInt(textBox.Text);

                Models.RegExpression rx2 = null;
                Models.RegExpression rx1 = regExpList.FirstOrDefault(p => p.Rank == rank);
                if (e.CommandName == "Up")
                {
                    rx2 = regExpList.FirstOrDefault(p => p.Rank == rank - 1);
                }
                else
                {
                    rx2 = regExpList.FirstOrDefault(p => p.Rank == rank + 1);
                }
                if (rx1 != null && rx2 != null)
                {
                    int t = rx1.Rank;
                    rx1.Rank = rx2.Rank;
                    rx2.Rank = t;
                }

                Channel.RegularExpressions = regExpList.OrderBy(p => p.Rank).ToList();;
                RadGridRegex.Rebind();
            }

            if (e.CommandName == "Delete")
            {
                string r    = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["Rank"].ToString();
                int    rank = r != null?Utils.StringToInt(r) : 0;

                Models.RegExpression rx = regExpList.FirstOrDefault(p => p.Rank == rank);
                if (rx != null)
                {
                    regExpList.Remove(rx);
                }
            }

            if (e.CommandName == "PerformInsert" || e.CommandName == "Update")
            {
                GridEditableItem item = e.Item as GridEditableItem;

                GridTextBoxColumnEditor r = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("Rank");

                GridTextBoxColumnEditor me = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("MatchExpression");
                string match = me != null ? me.Text : "";
                GridTextBoxColumnEditor fm = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("FormatExpression");
                string format = fm != null ? fm.Text : "";
                GridTextBoxColumnEditor co = (GridTextBoxColumnEditor)item.EditManager.GetColumnEditor("Comment");
                string comment             = co != null ? co.Text : "";

                if (e.CommandName == "PerformInsert")
                {
                    regExpList.Add(new Models.RegExpression()
                    {
                        Rank = regExpList.Count + 1, MatchExpression = match, FormatExpression = format, Comment = comment
                    });
                }
                else
                {
                    int rank = r != null?Utils.StringToInt(r.Text) : 0;

                    Models.RegExpression rx = regExpList.FirstOrDefault(p => p.Rank == rank);


                    if (rx != null)
                    {
                        rx.MatchExpression  = me.Text;
                        rx.FormatExpression = fm.Text;
                        rx.Comment          = co.Text;
                    }
                }
            }
        }