/// <summary>
        /// Returns TRUE if the next DataSetMessage is a delta frame.
        /// </summary>
        public bool HasMetaDataChanged(DataSetWriterDataType writer, DataSetMetaDataType metadata)
        {
            if (metadata == null)
            {
                return(false);
            }

            lock (m_dataSetStates)
            {
                DataSetState state = GetState(writer);

                ConfigurationVersionDataType version = state.ConfigurationVersion;
                // no matter what the TransportSettings.MetaDataUpdateTime is the ConfigurationVersion is checked
                if (version == null)
                {
                    // keep a copy of ConfigurationVersion
                    state.ConfigurationVersion = metadata.ConfigurationVersion.MemberwiseClone() as ConfigurationVersionDataType;
                    state.LastMetaDataUpdate   = DateTime.UtcNow;
                    return(true);
                }

                if (version.MajorVersion != metadata.ConfigurationVersion.MajorVersion ||
                    version.MinorVersion != metadata.ConfigurationVersion.MinorVersion)
                {
                    // keep a copy of ConfigurationVersion
                    state.ConfigurationVersion = metadata.ConfigurationVersion.MemberwiseClone() as ConfigurationVersionDataType;
                    state.LastMetaDataUpdate   = DateTime.UtcNow;
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary> Activates the DataView, with the specification of the initial state. </summary>
        /// <remarks> If the DataView is already active, then this method has no effect. </remarks>
        public void Open(DataSetState openState)
        {
            if (State == DataSetState.Inactive)
            {
                _openState = openState == DataSetState.Inactive ? DataSetState.Browse : openState;
                Open();

                try
                {
                    switch (_openState)
                    {
                    case DataSetState.Insert: Insert(); break;

                    case DataSetState.Edit: Edit(); break;
                    }
                }
                catch
                {
                    try
                    {
                        Close();
                    }
                    catch
                    {
                        // Ignore close errors here
                    }

                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        // - koniec edycji
        public bool PostEdit()
        {
            bool res = false;

            if ((this.State == DataSetState.dsEdit) && (this.Row != null))
            {
                try {
                    // - uzupełnij parametry
                    if (this.Adapter.UpdateCommand != null)
                    {
                        foreach (OleDbParameter param in this.Adapter.UpdateCommand.Parameters)
                        {
                            param.Value = this.Row[param.SourceColumn];
                        }
                        //
                        res = (this.Adapter.UpdateCommand.ExecuteNonQuery() == 1);
                        if (res)
                        {
                            this.Refresh();
                        }
                    }
                    this.State = DataSetState.dsUnknown;
                } catch (Exception ex) {
                    MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
                }
            }
            return(res);
        }
        /// <summary>
        /// Increments the message counter.
        /// </summary>
        public void MessagePublished(DataSetWriterDataType writer, DataSet dataset)
        {
            if (writer.KeyFrameCount > 1)
            {
                lock (DataSets)
                {
                    DataSetState state = GetState(writer);
                    state.MessageCount++;
                    state.ConfigurationVersion = dataset.DataSetMetaData.ConfigurationVersion;

                    if (state.LastDataSet == null)
                    {
                        state.LastDataSet = Copy(dataset);
                        return;
                    }

                    for (int ii = 0; ii < dataset.Fields.Length && ii < state.LastDataSet.Fields.Length; ii++)
                    {
                        var field = dataset.Fields[ii];

                        if (field != null)
                        {
                            state.LastDataSet.Fields[ii] = field;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        // - zatwierdz dane
        public bool Post()
        {
            try
            {
                // - zatwierdz zmiany
                switch (this.State)
                {
                case DataSetState.dsUnknown:
                    this.Adapter.Update(this.Query.Tables[this.TableName]);
                    this.State = DataSetState.dsUnknown;
                    break;

                case DataSetState.dsInsert:
                    this.PostInsert();
                    break;

                case DataSetState.dsEdit:
                    this.PostEdit();
                    break;
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
            }
            return(false);
        }
        /// <summary>
        /// Increments the message counter.
        /// </summary>
        public void OnMessagePublished(DataSetWriterDataType writer, DataSet dataset)
        {
            lock (m_dataSetStates)
            {
                DataSetState state = GetState(writer);
                state.MessageCount++;

                if (writer.KeyFrameCount > 1)
                {
                    state.ConfigurationVersion =
                        dataset.DataSetMetaData.ConfigurationVersion.MemberwiseClone() as ConfigurationVersionDataType;

                    if (state.LastDataSet == null)
                    {
                        state.LastDataSet = dataset.MemberwiseClone() as DataSet;
                        return;
                    }

                    for (int ii = 0; ii < dataset.Fields.Length && ii < state.LastDataSet.Fields.Length; ii++)
                    {
                        var field = dataset.Fields[ii];

                        if (field != null)
                        {
                            state.LastDataSet.Fields[ii] = field.MemberwiseClone() as Field;
                        }
                    }
                }
            }
        }
        private DataSetState GetState(DataSetWriterDataType writer)
        {
            DataSetState state;

            if (!m_dataSetStates.TryGetValue(writer.DataSetWriterId, out state))
            {
                m_dataSetStates[writer.DataSetWriterId] = state = new DataSetState();
            }

            return(state);
        }
        /// <summary>
        /// Checks if the DataSet has changed and null
        /// </summary>
        public DataSet ExcludeUnchangedFields(DataSetWriterDataType writer, DataSet dataset)
        {
            lock (m_dataSetStates)
            {
                DataSetState state = GetState(writer);

                DataSet lastDataSet = state.LastDataSet;

                if (lastDataSet == null)
                {
                    state.LastDataSet = dataset.MemberwiseClone() as DataSet;
                    return(dataset);
                }

                bool changed = false;

                for (int ii = 0; ii < dataset.Fields.Length && ii < lastDataSet.Fields.Length; ii++)
                {
                    var field1 = dataset.Fields[ii];
                    var field2 = lastDataSet.Fields[ii];

                    if (field1 == null || field2 == null)
                    {
                        changed = true;
                        continue;
                    }

                    if (field1.Value.StatusCode != field2.Value.StatusCode)
                    {
                        changed = true;
                        continue;
                    }

                    if (!Utils.IsEqual(field1.Value.WrappedValue, field2.Value.WrappedValue))
                    {
                        changed = true;
                        continue;
                    }

                    dataset.Fields[ii] = null;
                }

                if (!changed)
                {
                    return(null);
                }
            }

            return(dataset);
        }
Ejemplo n.º 9
0
 // - anuluj zmiany
 public bool Cancel()
 {
     try
     {
         this.Query.RejectChanges();
         this.State = DataSetState.dsUnknown;
         return(true);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
     }
     return(false);
 }
        /// <summary>
        /// Returns TRUE if the next DataSetMessage is a delta frame.
        /// </summary>
        public bool IsDeltaFrame(DataSetWriterDataType writer, out uint sequenceNumber)
        {
            lock (m_dataSetStates)
            {
                DataSetState state = GetState(writer);
                sequenceNumber = state.MessageCount + 1;

                if (state.MessageCount % writer.KeyFrameCount != 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 11
0
 // - odśwież dane
 public bool Refresh()
 {
     if (this.ParentMenager.IsConnected)
     {
         try
         {
             this.Adapter.SelectCommand.CommandText = PrepareSQLCommand();
             // - przypisz klucz obcy jeżeli jest na liście parametrów
             if (this.Owner != null)
             {
                 DataRow row = this.Owner.GetDataRow();
                 if (row != null)
                 {
                     try
                     {
                         foreach (OleDbParameter param in this.Adapter.SelectCommand.Parameters)
                         {
                             param.Value = row[param.SourceColumn];
                         }
                     }
                     catch { }
                 }
             }
             if (this.PrimaryKeyColumns.Length == 0)
             {
                 this.Query.Clear();
             }
             if (this.Table != null)
             {
                 Cursor.Current = Cursors.WaitCursor;
                 this.Query.RejectChanges();
                 this.Adapter.Fill(this.Query, this.TableName);
                 this.State     = DataSetState.dsUnknown;
                 Cursor.Current = Cursors.Default;
                 return(true);
             }
             else
             {
                 return(this.Open());
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
         }
     }
     return(false);
 }
Ejemplo n.º 12
0
        private DataView OpenDataView(string expression, DataSetState initialState, bool isReadOnly)
        {
            DataView dataView = new DataView();

            try
            {
                dataView.Session    = this;
                dataView.Expression = expression;
                dataView.IsReadOnly = isReadOnly;
                dataView.Open(initialState);
                return(dataView);
            }
            catch
            {
                dataView.Dispose();
                throw;
            }
        }
Ejemplo n.º 13
0
        // - początek edycji
        public DataRow BeginEdit()
        {
            // duplikat wiersza
            this.Row           = this.Table.NewRow();
            this.Row.ItemArray = this.GetDataRow().ItemArray.Clone() as object[];

            if (this.Row != null)
            {
                try  {
                    this.Row.BeginEdit();
                    this.State = DataSetState.dsEdit;
                    return(this.Row);
                } catch (Exception ex) {
                    MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
                }
            }
            return(null);
        }
        /// <summary>
        /// Returns TRUE if the next DataSetMessage is a delta frame.
        /// </summary>
        public bool HasMetaDataChanged(DataSetWriterDataType writer, DataSetMetaDataType metadata, double updateTime)
        {
            if (metadata == null)
            {
                return(false);
            }

            lock (DataSets)
            {
                DataSetState state = GetState(writer);

                ConfigurationVersionDataType version = state.ConfigurationVersion;

                if (version == null)
                {
                    state.ConfigurationVersion = metadata.ConfigurationVersion;
                    state.LastMetaDataUpdate   = DateTime.UtcNow;
                    return(true);
                }

                if (version.MajorVersion != metadata.ConfigurationVersion.MajorVersion ||
                    version.MinorVersion != metadata.ConfigurationVersion.MinorVersion)
                {
                    state.ConfigurationVersion = metadata.ConfigurationVersion;
                    state.LastMetaDataUpdate   = DateTime.UtcNow;
                    return(true);
                }

                if (updateTime > 0)
                {
                    if (state.LastMetaDataUpdate.AddMilliseconds(updateTime) <= DateTime.UtcNow)
                    {
                        state.LastMetaDataUpdate = DateTime.UtcNow;
                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 15
0
        // - usuń bieżący rekord
        public bool Delete()
        {
            bool    res = false;
            DataRow row = this.GetDataRow();

            if (row != null)
            {
                try
                {
                    // - uzupełnij parametry
                    if (this.Adapter.DeleteCommand != null)
                    {
                        foreach (OleDbParameter param in this.Adapter.DeleteCommand.Parameters)
                        {
                            param.Value = row[param.SourceColumn];
                        }
                        res = (this.Adapter.DeleteCommand.ExecuteNonQuery() == 1);
                        if (res)
                        {
                            this.Query.Clear();
                            this.Refresh();
                            if ((this.BindSource.Count == 0) && (OnEmptyDataSet != null))
                            {
                                OnEmptyDataSet();
                            }
                        }
                    }
                    this.State = DataSetState.dsUnknown;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
                }
            }
            return(res);
        }
Ejemplo n.º 16
0
        /// <summary> Creates and opens a new DataView detailed to this one. </summary>
        public DataView OpenDetail(string expression, string masterKeyNames, string detailKeyNames, DataSetState initialState, bool isReadOnly)
        {
            DataView dataView = new DataView();

            try
            {
                dataView.Session        = this.Session;
                dataView.Expression     = expression;
                dataView.IsReadOnly     = isReadOnly;
                dataView.MasterSource   = DataSource;
                dataView.MasterKeyNames = masterKeyNames;
                dataView.DetailKeyNames = detailKeyNames;
                dataView.Open(initialState);
                return(dataView);
            }
            catch
            {
                dataView.Dispose();
                throw;
            }
        }
Ejemplo n.º 17
0
        // - początek dopisania
        public DataRow BeginInsert()
        {
            if ((this.ParentMenager.IsConnected) && (this.Table != null))
            {
                try
                {
                    this.Row = this.Table.NewRow();
                    // przypisz wartości domyślne
                    foreach (ItemTableColumn Item in this.ListColumn)
                    {
                        // jeżeli bieżąca tabela zawiera dane pole przypisz jego wartość domyślną
                        if (this.Row.Table.Columns.Contains(Item.ColumnName))
                        {
                            try
                            {
                                switch (Item.DataType)
                                {
                                case DbType.String:
                                    this.Row[Item.ColumnName] = Item.DefaultValue.Trim('"');
                                    break;

                                case DbType.UInt16:
                                case DbType.Int16:
                                    this.Row[Item.ColumnName] = Convert.ToInt16(Item.DefaultValue);
                                    break;

                                case DbType.UInt32:
                                case DbType.Int32:
                                    this.Row[Item.ColumnName] = Convert.ToInt32(Item.DefaultValue);
                                    break;

                                case DbType.Single:
                                case DbType.Double:
                                case DbType.Currency:
                                case DbType.Decimal:
                                    this.Row[Item.ColumnName] = decimal.Parse(Item.DefaultValue.Trim().Replace(".", this.ParentMenager.NumberDecimalSeparator));
                                    break;

                                case DbType.Date:
                                case DbType.DateTime:
                                    if (Item.DefaultValue.Trim().ToLower().Equals("=now()"))
                                    {
                                        this.Row[Item.ColumnName] = DateTime.Now;
                                    }
                                    else
                                    {
                                        this.Row[Item.ColumnName] = Convert.ToDateTime(Item.DefaultValue);
                                    }
                                    break;

                                case DbType.Boolean:
                                    this.Row[Item.ColumnName] = Convert.ToBoolean(Item.DefaultValue);
                                    break;
                                }
                            }
                            catch { }
                        }
                    }

                    // - przypisz klucz rodzica jeżeli takie powiązanie istnieje
                    if ((this.Owner != null) && (this.Owner.PrimaryKeyColumns != null))
                    {
                        foreach (ItemTableColumn col in this.Owner.PrimaryKeyColumns)
                        {
                            try
                            {
                                this.Owner.GetDataRow();
                                this.Row[col.ColumnName] = this.Owner.Row[col.ColumnName];
                            }
                            catch { }
                        }
                    }
                    this.State = DataSetState.dsInsert;
                    return(this.Row);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error:" + Environment.NewLine + ex.ToString(), "exception class" + this.ToString());
                }
            }
            return(null);
        }
Ejemplo n.º 18
0
 /// <summary> Creates and opens a new DataView detailed to this one. </summary>
 /// <remarks> The ReadOnly property for this overload will be false (read/write). </remarks>
 public DataView OpenDetail(string expression, string masterKeyNames, string detailKeyNames, DataSetState initialState)
 {
     return(OpenDetail(expression, masterKeyNames, detailKeyNames, initialState, false));
 }
Ejemplo n.º 19
0
 /// <summary> Opens a DataView on this session using the specified expression and opened in the specified state. </summary>
 /// <param name="expression"></param>
 /// <param name="initialState"></param>
 /// <returns></returns>
 public DataView OpenDataView(string expression, DataSetState initialState)
 {
     return(OpenDataView(expression, initialState, false));
 }