Пример #1
0
        protected override void onSaving()
        {
            DataTable table = this.DataTable.GetChanges();

            if (table != null)
            {
                List <DataRow> deletedRow  = new List <DataRow>();
                List <DataRow> addedRow    = new List <DataRow>();
                List <DataRow> modifiedRow = new List <DataRow>();

                foreach (DataRow row in table.Rows)
                {
                    if (row.RowState == DataRowState.Deleted)
                    {
                        deletedRow.Add(row);
                    }
                    else if (row.RowState == DataRowState.Added)
                    {
                        addedRow.Add(row);
                    }
                    if (row.RowState == DataRowState.Modified)
                    {
                        modifiedRow.Add(row);
                    }
                }

                base.onSaving();

                foreach (DataRow row in deletedRow)
                {
                    QLMamNon.Dao.QLMamNonDs.KhoiRow khoiRow = row as QLMamNon.Dao.QLMamNonDs.KhoiRow;
                    this.khoiTruongTableAdapter.DeleteKhoiTruongByKhoiId(khoiRow.KhoiId);
                }

                foreach (DataRow row in modifiedRow)
                {
                    QLMamNon.Dao.QLMamNonDs.KhoiRow       khoiRow       = row as QLMamNon.Dao.QLMamNonDs.KhoiRow;
                    QLMamNon.Dao.QLMamNonDs.KhoiTruongRow khoiTruongRow = StaticDataUtil.GetKhoiTruongByKhoiId(this.khoiTruongTableAdapter, khoiRow.KhoiId);

                    if (khoiTruongRow != null)
                    {
                        this.khoiTruongTableAdapter.DeleteKhoiTruongByKhoiId(khoiRow.KhoiId);
                    }

                    if (!khoiRow.IsTruongIdNull())
                    {
                        this.khoiTruongTableAdapter.Insert(khoiRow.KhoiId, khoiRow.TruongId);
                    }
                }

                foreach (DataRow row in addedRow)
                {
                    QLMamNon.Dao.QLMamNonDs.KhoiRow khoiRow = row as QLMamNon.Dao.QLMamNonDs.KhoiRow;

                    if (!khoiRow.IsTruongIdNull())
                    {
                        this.khoiTruongTableAdapter.Insert(khoiRow.KhoiId, khoiRow.TruongId);
                    }
                }
            }
        }