예제 #1
0
 protected Trigger(Trigger source)
 {
     _triggerOccurs = source._triggerOccurs;
     _type          = source._type;
     //_eachRow = source._eachRow;
     _when    = source._when;
     _table   = source._table;
     _name    = source._name;
     _columns = source._columns;
     _action  = source._action;
     _dirty   = source._dirty;
 }
예제 #2
0
        override public object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
        {
            Index         idx    = ctx.Instance as Index;
            Trigger       trig   = ctx.Instance as Trigger;
            ViewTableBase parent = null;

            if (idx != null)
            {
                parent = idx.Table;
            }
            else if (trig != null)
            {
                parent = trig.ViewTableBase;
            }

            // initialize editor service
            _edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
            if (_edSvc == null)
            {
                return(value);
            }

            if (value == null)
            {
                value = String.Empty;
            }
            if (String.IsNullOrEmpty(value.ToString()) == true)
            {
                value = String.Empty;
            }

            string[] values = value.ToString().Split(',');

            // populate the list
            _list.Items.Clear();

            if (parent is Table)
            {
                foreach (Column c in ((Table)parent).Columns)
                {
                    CheckState check = CheckState.Unchecked;
                    for (int n = 0; n < values.Length; n++)
                    {
                        if (values[n].Trim() == String.Format(CultureInfo.InvariantCulture, "[{0}]", c.ColumnName))
                        {
                            check = CheckState.Checked;
                            break;
                        }
                    }
                    _list.Items.Add(c.ColumnName, check);
                }
            }
            else
            {
                try
                {
                    using (DbCommand cmd = trig.GetConnection().CreateCommand())
                    {
                        cmd.CommandText = ((View)parent).SqlText;
                        using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly))
                            using (DataTable tbl = reader.GetSchemaTable())
                            {
                                foreach (DataRow row in tbl.Rows)
                                {
                                    CheckState check = CheckState.Unchecked;
                                    for (int n = 0; n < values.Length; n++)
                                    {
                                        if (values[n].Trim() == String.Format(CultureInfo.InvariantCulture, "[{0}]", row[SchemaTableColumn.ColumnName]))
                                        {
                                            check = CheckState.Checked;
                                            break;
                                        }
                                    }
                                    _list.Items.Add(row[SchemaTableColumn.ColumnName].ToString(), check);
                                }
                            }
                    }
                }
                catch
                {
                }
            }
            _list.Height = Math.Min(300, (_list.Items.Count + 1) * _list.Font.Height);

            // show the list
            _cancel = false;
            _edSvc.DropDownControl(_list);

            // build return value from checked items on the list
            if (!_cancel)
            {
                // build a comma-delimited string with the checked items
                StringBuilder sb = new StringBuilder();
                foreach (object item in _list.CheckedItems)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.AppendFormat("[{0}]", item.ToString());
                }

                return(sb.ToString());
            }

            // done
            return(value);
        }
예제 #3
0
 internal ViewTrigger(ViewTableBase parent, DataRow row)
     : base(parent, row)
 {
     _triggerOccurs = (int)ViewTriggerOccurs.InsteadOf;
 }
예제 #4
0
 internal TriggerEditor(ViewTableBase parent)
     : base((parent is View) ? typeof(List <ViewTrigger>) :  typeof(List <Trigger>))
 {
     _table = parent;
 }
예제 #5
0
        internal Trigger(ViewTableBase parent, DataRow row)
        {
            _table = parent;
            if (row != null)
            {
                _name = row["TRIGGER_NAME"].ToString();

                string sql = row["TRIGGER_DEFINITION"].ToString();
                _origsql = sql;
                SimpleTokenizer.StringParts[] arr = SimpleTokenizer.BreakString(sql);

                int x = 3;
                switch (arr[x].keyword)
                {
                case "BEFORE":
                    _triggerOccurs = 0;
                    break;

                case "AFTER":
                    _triggerOccurs = 1;
                    break;

                case "INSTEAD":
                    _triggerOccurs = 2;
                    x++;
                    break;

                default:
                    x--;
                    break;
                }
                x++;

                switch (arr[x].keyword)
                {
                case "UPDATE":
                    _type = TriggerType.Update;
                    if (arr[x + 1].keyword == "OF")
                    {
                        x++;
                        StringBuilder builder   = new StringBuilder();
                        string        separator = String.Empty;
                        while (arr[x + 1].keyword != "ON")
                        {
                            builder.AppendFormat("{0}[{1}]", separator, arr[x + 1].value);
                            separator = ", ";
                            x++;
                        }
                        _columns = builder.ToString();
                    }
                    break;

                case "INSERT":
                    _type = TriggerType.Insert;
                    break;

                case "DELETE":
                    _type = TriggerType.Delete;
                    break;
                }
                x++;

                while (arr[x].keyword != "BEGIN")
                {
                    if (arr[x].keyword == "FOR" && arr[x + 1].keyword == "EACH" && arr[x + 1].keyword == "ROW")
                    {
                        //_eachRow = true;
                        x += 3;
                        continue;
                    }

                    if (arr[x].keyword == "WHEN")
                    {
                        x++;
                        int           depth   = 0;
                        StringBuilder builder = new StringBuilder();
                        while (arr[x].keyword != "BEGIN")
                        {
                            if (builder.Length > 0)
                            {
                                builder.Append(" ");
                            }
                            while (depth < arr[x].depth)
                            {
                                depth++;
                                builder.Append("(");
                            }
                            while (depth > arr[x].depth)
                            {
                                depth--;
                                builder.Append(")");
                            }

                            if (String.IsNullOrEmpty(arr[x].quote) == false)
                            {
                                builder.Append(arr[x].quote[0]);
                            }
                            builder.Append(arr[x].value);
                            if (String.IsNullOrEmpty(arr[x].quote) == false)
                            {
                                builder.Append(arr[x].quote[1]);
                            }
                            x++;
                        }
                        while (depth > 0)
                        {
                            depth--;
                            builder.Append(")");
                        }
                        _when = builder.ToString();
                        break;
                    }
                    x++;
                }

                int startpos = arr[x].position + arr[x].value.Length;

                x = arr.Length - 1;
                while (arr[x].keyword != "END")
                {
                    x--;
                }
                int endpos = arr[x].position;

                _action = sql.Substring(startpos, endpos - startpos);
                _action = _action.TrimStart('\r').TrimStart('\n').TrimEnd('\n').TrimEnd('\r').Trim();
            }
        }
예제 #6
0
 protected Trigger(Trigger source)
 {
   _triggerOccurs = source._triggerOccurs;
   _type = source._type;
   //_eachRow = source._eachRow;
   _when = source._when;
   _table = source._table;
   _name = source._name;
   _columns = source._columns;
   _action = source._action;
   _dirty = source._dirty;
 }
예제 #7
0
 internal TriggerEditor(ViewTableBase parent)
   : base((parent is View) ? typeof(List<ViewTrigger>) :  typeof(List<Trigger>))
 {
   _table = parent;
 }
예제 #8
0
 internal ViewTrigger(ViewTableBase parent, DataRow row)
   : base(parent, row)
 {
   _triggerOccurs = (int)ViewTriggerOccurs.InsteadOf;
 }
예제 #9
0
    internal Trigger(ViewTableBase parent, DataRow row)
    {
      _table = parent;
      if (row != null)
      {
        _name = row["TRIGGER_NAME"].ToString();

        string sql = row["TRIGGER_DEFINITION"].ToString();
        _origsql = sql;
        SimpleTokenizer.StringParts[] arr = SimpleTokenizer.BreakString(sql);

        int x = 3;
        switch (arr[x].keyword)
        {
          case "BEFORE":
            _triggerOccurs = 0;
            break;
          case "AFTER":
            _triggerOccurs = 1;
            break;
          case "INSTEAD":
            _triggerOccurs = 2;
            x++;
            break;
          default:
            x--;
            break;
        }
        x++;

        switch (arr[x].keyword)
        {
          case "UPDATE":
            _type = TriggerType.Update;
            if (arr[x + 1].keyword == "OF")
            {
              x++;
              StringBuilder builder = new StringBuilder();
              string separator = "";
              while (arr[x + 1].keyword != "ON")
              {
                builder.AppendFormat("{0}[{1}]", separator, arr[x + 1].value);
                separator = ", ";
                x++;
              }
              _columns = builder.ToString();
            }
            break;
          case "INSERT":
            _type = TriggerType.Insert;
            break;
          case "DELETE":
            _type = TriggerType.Delete;
            break;
        }
        x++;

        while (arr[x].keyword != "BEGIN")
        {
          if (arr[x].keyword == "FOR" && arr[x + 1].keyword == "EACH" && arr[x + 1].keyword == "ROW")
          {
            //_eachRow = true;
            x += 3;
            continue;
          }

          if (arr[x].keyword == "WHEN")
          {
            x++;
            int depth = 0;
            StringBuilder builder = new StringBuilder();
            while (arr[x].keyword != "BEGIN")
            {
              if (builder.Length > 0) builder.Append(" ");
              while (depth < arr[x].depth)
              {
                depth++;
                builder.Append("(");
              }
              while (depth > arr[x].depth)
              {
                depth--;
                builder.Append(")");
              }

              if (String.IsNullOrEmpty(arr[x].quote) == false)
                builder.Append(arr[x].quote[0]);
              builder.Append(arr[x].value);
              if (String.IsNullOrEmpty(arr[x].quote) == false)
                builder.Append(arr[x].quote[1]);
              x++;
            }
            while (depth > 0)
            {
              depth--;
              builder.Append(")");
            }
            _when = builder.ToString();
            break;
          }
          x++;
        }

        int startpos = arr[x].position + arr[x].value.Length;

        x = arr.Length - 1;
        while (arr[x].keyword != "END")
        {
          x--;
        }
        int endpos = arr[x].position;

        _action = sql.Substring(startpos, endpos - startpos);
        _action = _action.TrimStart('\r').TrimStart('\n').TrimEnd('\n').TrimEnd('\r').Trim();
      }
    }