Пример #1
0
        public virtual bool Delete()
        {
            bool       deleted = false;
            RowAdapter d       = new RowAdapter(this.fields, this.columns, this.TableName, this.Locator);

            foreach (DataRow dataRow in dataTable.Rows)
            {
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    dataRow.RejectChanges();
                    d.UpdateColumnValue(dataRow);

                    if (DataRowChangedHandler != null)
                    {
                        d.RowChanged += DataRowChangedHandler;
                    }

                    if (ValueChangedHandler != null)
                    {
                        d.ValueChangedHandler = ValueChangedHandler;
                    }

                    deleted = d.Delete();

                    if (deleted)
                    {
                        dataRow.Delete();
                    }
                }
            }

            dataTable.AcceptChanges();
            return(deleted);
        }
Пример #2
0
        public bool saved;    //RowChanged fired twice during Adding a record;
                              //true: after record saved
                              //false: before record saving, give a chance to deny saving


        public RowChangedEventArgs(RowAdapter adapter, ObjectState state, bool saved)
        {
            this.adapter   = adapter;
            this.state     = state;
            this.confirmed = true;
            this.saved     = saved;
        }
Пример #3
0
        public bool saved; //RowChanged fired twice during Adding a record;

        #endregion Fields

        #region Constructors

        //true: after record saved
        //false: before record saving, give a chance to deny saving
        public RowChangedEventArgs(RowAdapter adapter, ObjectState state, bool saved)
        {
            this.adapter = adapter;
            this.state = state;
            this.confirmed = true;
            this.saved = saved;
        }
Пример #4
0
        public virtual bool SaveOnly()
        {
            bool       saved = false;
            RowAdapter d     = GetPersistentRow();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                if (dataRow.RowState != DataRowState.Deleted)
                {
                    d.UpdateColumnValue(dataRow);

                    if (DataRowChangedHandler != null)
                    {
                        d.RowChanged += DataRowChangedHandler;
                    }

                    if (ValueChangedHandler != null)
                    {
                        d.ValueChangedHandler = ValueChangedHandler;
                    }

                    if (dataRow.RowState != DataRowState.Unchanged)
                    {
                        saved = d.Save();
                    }
                }
                else
                {
                    dataRow.RejectChanges();
                    d.UpdateColumnValue(dataRow);

                    if (DataRowChangedHandler != null)
                    {
                        d.RowChanged += DataRowChangedHandler;
                    }

                    if (ValueChangedHandler != null)
                    {
                        d.ValueChangedHandler = ValueChangedHandler;
                    }

                    d.Delete();
                    dataRow.Delete();
                }
            }


            return(saved);
        }
Пример #5
0
        private void Apply(RowAdapter d)
        {
            foreach (PropertyInfo propertyInfo in this.columnProperties)
            {
                ColumnAttribute a = Reflex.GetColumnAttribute(propertyInfo);
                if (a != null && d.Row.Table.Columns.Contains(a.ColumnNameSaved))
                {
                    if (propertyInfo.GetValue(this, null) == null)
                    {
                        d.Row[a.ColumnNameSaved] = System.DBNull.Value;
                    }
                    else
                    {
                        d.Row[a.ColumnNameSaved] = propertyInfo.GetValue(this, null);
                    }
                }
            }

            d.Fill();
        }
Пример #6
0
        public virtual bool Load()
        {
            RowAdapter d = GetPersistentRow();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    continue;
                }

                d.UpdateColumnValue(dataRow);
                d.Load();
                foreach (ColumnAdapter column in columns)
                {
                    dataRow[column.Field.Name] = d.Row[column.Field.Name];
                }
            }
            dataTable.AcceptChanges();

            return(true);
        }
Пример #7
0
 public void Add(RowAdapter row)
 {
     row.SetTransaction(this);
 }
Пример #8
0
        public virtual bool Delete()
        {
            bool deleted = false;
            RowAdapter d = new RowAdapter(this.fields, this.columns, this.TableName, this.Locator);

            foreach (DataRow dataRow in dataTable.Rows)
            {
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    dataRow.RejectChanges();
                    d.UpdateColumnValue(dataRow);

                    if (DataRowChangedHandler != null)
                        d.RowChanged += DataRowChangedHandler;

                    if (ValueChangedHandler != null)
                        d.ValueChangedHandler = ValueChangedHandler;

                    deleted = d.Delete();

                    if (deleted)
                        dataRow.Delete();
                }
            }

            dataTable.AcceptChanges();
            return deleted;
        }
Пример #9
0
        public virtual bool Save(Selector columnNames, RowChangedHandler rowHandler, ValueChangedHandler columnHandler)
        {
            if (dataTable == null || dataTable.Rows.Count == 0)
            {
                return(false);
            }

            //update this.dataTable
            // this.AcceptChanges();

            objectPermission = ObjectPermission.DenyUpdateObject;
            RowAdapter d = this.NewSqlRow(columnNames);

            d.RowChanged += RowChanged;

            if (rowHandler != null)
            {
                d.RowChanged += rowHandler;
            }

            if (columnHandler != null)
            {
                d.ValueChangedHandler = columnHandler;
            }
            else
            {
                d.ValueChangedHandler = ValueChanged;
            }

            int count = 0;

            foreach (DataRow dataRow in dataTable.Rows)
            {
                BeforeSave(dataRow);

                if (dataRow.RowState != DataRowState.Deleted)
                {
                    if (dataRow.RowState != DataRowState.Unchanged)
                    {
                        d.CopyFrom(dataRow);
                        d.Fill();
                        d.Save();
                        if (dataRow.RowState == DataRowState.Added)   //in case of existing identity columns
                        {
                            d.CopyTo(dataRow);
                            UpdateObject(dataRow);
                        }

                        //slow version
                        //T t = this[dataRow];
                        //t.Save(d);
                        count++;
                    }
                }
                else
                {
                    dataRow.RejectChanges();
                    d.CopyFrom(dataRow);
                    d.Fill();
                    d.Delete();

                    //slow version
                    //T t = this[dataRow];
                    //t.Delete();
                    dataRow.Delete();
                }

                AfterSave(dataRow);
            }

            dataTable.AcceptChanges();

            objectPermission = ObjectPermission.AllowUpdateObject;
            return(true);
        }
Пример #10
0
 public void Add(RowAdapter row)
 {
     row.SetTransaction(this);
 }