Beispiel #1
0
 public void OnColumnChanged(object sender, DataColumnChangeEventArgs e)
 {
     if (TableUtil.InConstraint(e.Row.Table))
     {
         RuleColumn column = TableUtil.GetRuleColumn(e.Column);
         if (column != null && column.HasConstraints)
         {
             string message = "";
             if (!DataUtil.CheckConstraints(e.Row[column.ColumnName], column, ref message))
             {
                 if (message != null && !message.Equals(""))
                 {
                     throw new RuleColumnConstraintException(this, e.Row, column, message);
                 }
                 //SendRuleExceptionEvent(sender, new RuleColumnConstraintException(this, e.Row, column, message));
                 else
                 {
                     throw new RuleColumnConstraintException(this, e.Row, column);
                 }
                 //SendRuleExceptionEvent(sender, new RuleColumnConstraintException(this, e.Row, column));
             }
         }
     }
 }
Beispiel #2
0
        public override string GetTranData()
        {
            DataTable table = this.Command as DataTable;

            if (table != null)
            {
                DataTable updatetable = table.GetChanges();
                if (updatetable != null && updatetable.Rows.Count > 0)
                {
                    DataColumnCollection columns = table.Columns;
                    DataRow    row;
                    RuleColumn rcolumn;

                    Object oldvalue, newvalue;
                    bool   haschange;

                    bool hasPK = TableUtil.BoolProperty(updatetable, "HasPK");

                    StringBuilder sb = new StringBuilder(String.Format("<item type=\"table\" dr=\"{0}\" ds=\"{1}\">", DS, TableUtil.StrProperty(table, "DataSource")));

                    string command = TableUtil.StrProperty(table, "Command");
                    if (!command.Equals(""))
                    {
                        sb.Append(string.Format("<command type=\"sql\">{0}</command>", command));
                    }

                    sb.Append("<rows>");

                    int count = updatetable.Rows.Count;
                    for (int i = 0; i < count; i++)
                    {
                        row = updatetable.Rows[i];

                        switch (row.RowState)
                        {
                        case DataRowState.Added:
                            sb.Append("<row state=\"ins\">");
                            foreach (DataColumn column in columns)
                            {
                                newvalue = row[column.ColumnName, DataRowVersion.Current];
                                if (newvalue != null)
                                {
                                    sb.Append(String.Format("<field name=\"{0}\">", column.ColumnName));
                                    sb.Append(DataUtil.FieldValueToString(newvalue, TableUtil.GetRuleColumn(column)));
                                    sb.Append("</field>");
                                }
                            }
                            sb.Append("</row>");
                            break;

                        case DataRowState.Modified:
                            row.EndEdit();
                            sb.Append("<row state=\"upd\">");
                            foreach (DataColumn column in columns)
                            {
                                rcolumn = TableUtil.GetRuleColumn(column);

                                oldvalue = row[column.ColumnName, DataRowVersion.Original];
                                newvalue = row[column.ColumnName, DataRowVersion.Current];

                                haschange = !DataUtil.CheckEquals(oldvalue, newvalue);

                                if (hasPK)
                                {
                                    if (haschange || TableUtil.BoolProperty(column, "PK"))
                                    {
                                        sb.Append(String.Format("<field name=\"{0}\">", column.ColumnName));
                                        sb.Append("<old>");
                                        sb.Append(DataUtil.FieldValueToString(oldvalue, rcolumn));
                                        sb.Append("</old>");
                                        if (haschange)
                                        {
                                            sb.Append("<cur>");
                                            sb.Append(DataUtil.FieldValueToString(newvalue, rcolumn));
                                            sb.Append("</cur>");
                                        }
                                        sb.Append("</field>");
                                    }
                                }
                                else
                                {
                                    if (rcolumn == null || haschange || rcolumn.IsForePrimaryKey)
                                    {
                                        sb.Append(String.Format("<field name=\"{0}\">", column.ColumnName));
                                        sb.Append("<old>");
                                        sb.Append(DataUtil.FieldValueToString(oldvalue, rcolumn));
                                        sb.Append("</old>");
                                        if (haschange)
                                        {
                                            sb.Append("<cur>");
                                            sb.Append(DataUtil.FieldValueToString(newvalue, rcolumn));
                                            sb.Append("</cur>");
                                        }
                                        sb.Append("</field>");
                                    }
                                }
                            }
                            sb.Append("</row>");
                            break;

                        case DataRowState.Deleted:
                            sb.Append("<row state=\"del\">");
                            foreach (DataColumn column in columns)
                            {
                                rcolumn = TableUtil.GetRuleColumn(column);
                                if (rcolumn == null || rcolumn.IsForePrimaryKey)
                                {
                                    oldvalue = row[column.ColumnName, DataRowVersion.Original];
                                    if (oldvalue != null)
                                    {
                                        sb.Append(String.Format("<field name=\"{0}\">", column.ColumnName));
                                        sb.Append(DataUtil.FieldValueToString(oldvalue, rcolumn));
                                        sb.Append("</field>");
                                    }
                                }
                            }
                            sb.Append("</row>");
                            break;
                        }
                    }
                    sb.Append("</rows>");
                    sb.Append("</item>");
                    return(sb.ToString());
                }
            }
            return("");
        }