Exemplo n.º 1
0
 private void superGridControl3_BeginEdit(object sender, GridEditEventArgs e)
 {
     // 取消编辑
     e.Cancel = true;
 }
Exemplo n.º 2
0
 private void superGridControl1_EditorValueChanged(object sender, GridEditEventArgs e)
 {
 }
Exemplo n.º 3
0
 /// <summary>
 /// Resets the cell level InfoText upon
 /// user cancel of the edit operation
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SuperGridControl1CancelEdit(
     object sender, GridEditEventArgs e)
 {
     e.GridCell.InfoText = null;
 }
 /// <summary>
 /// This routine is called when the user attempts to edit
 /// a given cell. We are using this as an illustration of one way
 /// to prevent edits while yet keeping all other behavior and
 /// functionality the same. Edits could be canceled for any
 /// programmatic reason through this mechanism.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void SuperGridControl2BeginEdit(object sender, GridEditEventArgs e)
 {
     e.Cancel = true;
 }
Exemplo n.º 5
0
 private void ProjectGrid_EditorValueChanged(object sender, GridEditEventArgs e)
 {
 }
Exemplo n.º 6
0
 private void ProjectGrid_BeginEdit(object sender, GridEditEventArgs e)
 {
     preEditValue = (null == e.GridCell.Value) ? "" : e.GridCell.Value;
 }
Exemplo n.º 7
0
 private void ProjectGrid_RowMarkedDirty(object sender, GridEditEventArgs e)
 {
 }
Exemplo n.º 8
0
 public GridEditEventArgs(GridEditEventArgs args)
     : this(args.DataKeyValue)
 {
 }
Exemplo n.º 9
0
        private void CreateRows(RaWebControl table)
        {
            Node node = new Node();
            List<Node> tmp = new List<Node>(RowsFiltered);
            tmp.Sort(
                delegate(Node left, Node right)
                {
                    if (SortColumn == null)
                    {
                        // Defaulting to first "sane" sortable... (which is "ID" if given)
                        if (left[0].Name == "ID" && left[0].Value is int)
                            return ((int)left[0].Value).CompareTo((int)right[0].Value);
                        if (left[0].Value == null)
                            return right[0].Value == null ? 0 : - 1;
                        if (right[0].Value == null)
                            return 1;
                        return left[0].Value.ToString().CompareTo(right[0].Value.ToString());
                    }
                    bool isBackwards = SortColumn[0] == '-';
                    string sortCol = SortColumn.Replace("-", "");
                    if (left[sortCol].Value == null)
                        return right[sortCol].Value == null ? 0 : (isBackwards ? 1 : -1);
                    if (right[sortCol].Value == null)
                        return isBackwards ? -1 : 1;

                    object leftObj = left[sortCol].Value;
                    object rightObj = right[sortCol].Value;
                    if (leftObj == null)
                        return rightObj == null ? 0 : (isBackwards ? -1 : 1);
                    if (rightObj == null)
                        return isBackwards ? 1 : -1;
                    if (!isBackwards)
                        return ((IComparable)leftObj).CompareTo(rightObj);
                    return ((IComparable)rightObj).CompareTo(leftObj);
                });
            foreach (Node idx in tmp)
            {
                node.Add(idx);
            }

            // Settings previous and next buttons to disabled/enabled according to placement in
            // the datasource paging logic...
            _previous.CssClass = CurrentPage == 0 ? "previous-disabled" : "previous";
            _next.CssClass = (CurrentPage * PageSize) + PageSize >= node.Count ? "next-disabled" : "next";

            int idxNo = 0;
            int idxStartBinding = 0;
            foreach (Node idxRow in node)
            {
                if (PageSize == -1 || idxStartBinding >= CurrentPage * PageSize)
                {
                    // If PageSize == -1 we add ALL records...!!!!
                    Label row = new Label
                    {
                        Tag = "tr", 
                        CssClass = idxNo%2 == 0 ? "even" : "odd", 
                        ID = "row" + idxNo
                    };
                    table.Controls.Add(row);
                    int idxNoCell = 0;
                    foreach (Node idxCell in idxRow)
                    {
                        if (idxCell.Name == "ID")
                            continue;
                        HtmlTableCell cell = new HtmlTableCell
                        {
                            ID = "cell" + idxNo + "x" + idxNoCell
                        };
                        row.Controls.Add(cell);
                        string fieldType = DataSource["Columns"][idxCell.Name]["ControlType"].Get<string>();
                        switch (fieldType)
                        {
                            case "LinkButton":
                                {
                                    LinkButton lb = new LinkButton
                                    {
                                        ID = "ctrl" + idxNo + "x" + idxNoCell,
                                        Xtra = idxRow["ID"].Value + "|" + idxCell.Name,
                                        Text = idxCell.Get<string>()
                                    };
                                    if (Action != null)
                                    {
                                        lb.Click +=
                                            delegate(object sender, EventArgs e)
                                            {
                                                LinkButton rl = sender as LinkButton;
                                                if (rl == null)
                                                    return;
                                                string id = rl.Xtra.Split('|')[0];
                                                string columnName = rl.Xtra.Split('|')[1];
                                                Action(this, new GridActionEventArgs(id, columnName));
                                            }; 
                                    }
                                    cell.Controls.Add(lb);
                                } break;
                            case "InPlaceEdit":
                                {
                                    InPlaceEdit edit = new InPlaceEdit
                                    {
                                        ID = "ctrl" + idxNo + "x" + idxNoCell,
                                        CssClass = "edit",
                                        Xtra = idxRow["ID"].Value + "|" + idxCell.Name,
                                        Text = idxCell.Get<string>()
                                    };
                                    if (CellEdited != null)
                                    {
                                        edit.TextChanged +=
                                            delegate(object sender, EventArgs e)
                                            {
                                                InPlaceEdit ed = sender as InPlaceEdit;
                                                if (ed != null)
                                                {
                                                    string id = ed.Xtra.Split('|')[0];
                                                    string cellName = ed.Xtra.Split('|')[1];
                                                    GridEditEventArgs eIn = new GridEditEventArgs(id, cellName, ed.Text);
                                                    CellEdited(this, eIn);
                                                    if (!eIn.AcceptChange)
                                                        return;
                                                    Node rowNode = DataSource["Rows"].Find(
                                                        delegate(Node idxNode)
                                                        {
                                                            if (idxNode.Name != "ID")
                                                            {
                                                                return false;
                                                            }
                                                            return idxNode.Value.ToString() == id;
                                                        }).Parent;
                                                    Node cellNode = rowNode.Find(
                                                        delegate(Node idxNode)
                                                        {
                                                            return idxNode.Name == cellName;
                                                        });
                                                    cellNode.Value = eIn.NewValue.ToString();
                                                }
                                            };
                                    }
                                    cell.Controls.Add(edit);
                                } break;
                            case "List":
                                {
                                    SelectList edit = new SelectList
                                    {
                                        ID = "ctrl" + idxNo + "x" + idxNoCell + idxRow["ID"].Value,
                                        Xtra = idxRow["ID"].Value + "|" + idxCell.Name
                                    };
                                    string valueSelected = idxCell.Get<string>();
                                    foreach (Node idx in DataSource["Columns"][idxCell.Name]["Values"])
                                    {
                                        string idxValue = idx.Get<string>();
                                        ListItem l = new ListItem(idxValue, idxValue);
                                        if(idxValue == valueSelected)
                                            l.Selected = true;
                                        edit.Items.Add(l);
                                    }
                                    if (CellEdited != null)
                                    {
                                        edit.SelectedIndexChanged +=
                                            delegate(object sender, EventArgs e)
                                            {
                                                SelectList ed = sender as SelectList;
                                                if (ed != null)
                                                {
                                                    string id = ed.Xtra.Split('|')[0];
                                                    string cellName = ed.Xtra.Split('|')[1];
                                                    GridEditEventArgs eIn = new GridEditEventArgs(id, cellName, ed.SelectedItem.Value);
                                                    CellEdited(this, eIn);
                                                    if (!eIn.AcceptChange)
                                                        return;
                                                    Node rowNode = DataSource["Rows"].Find(
                                                        delegate(Node idxNode)
                                                        {
                                                            if (idxNode.Name != "ID")
                                                            {
                                                                return false;
                                                            }
                                                            return idxNode.Value.ToString() == id;
                                                        }).Parent;
                                                    Node cellNode = rowNode.Find(
                                                        delegate(Node idxNode)
                                                        {
                                                            return idxNode.Name == cellName;
                                                        });
                                                    cellNode.Value = eIn.NewValue.ToString();
                                                }
                                            };
                                    }
                                    cell.Controls.Add(edit);
                                } break;
                            case "Label":
                                if (idxCell.Value is string)
                                {
                                    cell.InnerHtml = idxCell.Get<string>();
                                }
                                else if (idxCell.Value is DateTime)
                                {
                                    cell.InnerHtml = idxCell.Get<DateTime>().ToString(
                                        idxCell["Format"].Get<string>(), CultureInfo.CurrentUICulture);
                                }
                                break;
                            case "Link":
                                {
                                    if (idxCell["target"].Value != null && 
                                        idxCell["target"].Get<string>() == "same")
                                        cell.InnerHtml =
                                            string.Format(@"<a href=""{0}"">{1}</a>",
                                                idxCell["href"].Value,
                                                idxCell.Get<string>());
                                    else
                                        cell.InnerHtml =
                                            string.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>",
                                                idxCell["href"].Value,
                                                idxCell.Get<string>());
                                } break;
                            default:
                                {
                                    if (fieldType.IndexOf("TextAreaEdit") == 0)
                                    {
                                        int lengthOfText = -1;
                                        if (fieldType.Contains("["))
                                        {
                                            lengthOfText = int.Parse(fieldType.Split('[', ']')[1]);
                                        }
                                        TextAreaEdit edit = new TextAreaEdit();
                                        if (lengthOfText != -1)
                                        {
                                            edit.TextLength = lengthOfText;
                                        }
                                        edit.ID = "ctrl" + idxNo + "x" + idxNoCell;
                                        edit.CssClass = "edit";
                                        edit.Xtra = idxRow["ID"].Value + "|" + idxCell.Name;
                                        edit.Text = idxCell.Get<string>();
                                        if (CellEdited != null)
                                        {
                                            edit.TextChanged +=
                                                delegate(object sender, EventArgs e)
                                                {
                                                    TextAreaEdit ed = sender as TextAreaEdit;
                                                    if (ed == null) 
                                                        return;
                                                    string id = ed.Xtra.Split('|')[0];
                                                    string cellName = ed.Xtra.Split('|')[1];
                                                    GridEditEventArgs eIn = new GridEditEventArgs(id, cellName, ed.Text);
                                                    CellEdited(this, eIn);
                                                    if (eIn.AcceptChange)
                                                    {
                                                        Node rowNode = DataSource["Rows"].Find(
                                                            delegate(Node idxNode)
                                                                {
                                                                    if (idxNode.Name != "ID")
                                                                    {
                                                                        return false;
                                                                    }
                                                                    return idxNode.Get<string>() == id;
                                                                }).Parent;
                                                        Node cellNode = rowNode.Find(
                                                            delegate(Node idxNode)
                                                                {
                                                                    return idxNode.Name == cellName;
                                                                });
                                                        cellNode.Value = eIn.NewValue.ToString();
                                                    }
                                                };
                                        }
                                        cell.Controls.Add(edit);
                                    }
                                    else
                                    {
                                        Node getColType = new Node();
                                        getColType["ColumnType"].Value = DataSource["Columns"][idxCell.Name]["ControlType"].Get<string>();
                                        getColType["Row"].Value = row;
                                        getColType["Value"].Value = idxCell.Value;
                                        getColType["DataSource"].Value = DataSource;
                                        getColType["ID"].Value = idxRow["ID"].Value;
                                        getColType["CellName"].Value = idxCell.Name;
                                        ActiveEvents.Instance.RaiseActiveEvent(
                                            this,
                                            "GetGridColumnType",
                                            getColType);
                                        RaWebControl ctrl = getColType["Control"].Get<RaWebControl>();
                                        ctrl.ID = idxRow["ID"].Value + "x" + idxCell.Name.GetHashCode().ToString().Replace("|", "");
                                        ctrl.Xtra = string.Format("{0}|{1}", idxRow["ID"].Value, idxCell.Name);
                                        if (getColType["ExtraCssClass"].Value != null)
                                        {
                                            if(!table.CssClass.Contains(getColType["ExtraCssClass"].Get<string>()))
                                            {
                                                table.CssClass += " " + getColType["ExtraCssClass"].Get<string>();
                                            }
                                        }
                                        cell.Controls.Add(ctrl);
                                    }
                                } break;
                        }
                        idxNoCell += 1;
                    }

                    // Adding delete row (if we should)
                    if (RowDeleted != null)
                    {
                        HtmlTableCell delete = new HtmlTableCell {ID = "del" + idxNo};

                        LinkButton lb = new LinkButton
                        {
                            ID = "delBtn" + idxNo,
                            Text = "&nbsp;",
                            CssClass = "deleteBtn",
                            Xtra = idxRow["ID"].Value.ToString(),
                            Visible = EnableDeletion
                        };
                        lb.Click +=
                            delegate(object sender, EventArgs e)
                            {
                                LinkButton bt = sender as LinkButton;
                                if (bt != null)
                                {
                                    RowDeleted(this, new GridActionEventArgs(bt.Xtra, null));
                                    if (AutoDeleteRowOnDeletion)
                                    {
                                        foreach (Node idx in DataSource["Rows"])
                                        {
                                            if (idx["ID"].Value.ToString() == bt.Xtra)
                                            {
                                                DataSource["Rows"].Remove(idx);
                                                DataBindGrid();
                                                _lstWrappers.ReRender();
                                                break;
                                            }
                                        }
                                    }
                                }
                            };

                        delete.Controls.Add(lb);
                        row.Controls.Add(delete);
                    }
                }
                idxNo += 1;
                idxStartBinding += 1;
                if (idxNo == (PageSize * CurrentPage) + PageSize)
                    break;
            }
        }