public ViewModelWindowWarnOnSubsetUpdate(int numFrags, int numToids, int numTotalFrags, int numTotToids, ViewModelWindowMain.GeometryTypes typeFeatures)
 {
     _numFrags = numFrags;
     _numToids = numToids;
     _numTotalFrags = numTotalFrags;
     _numTotToids = numTotToids;
     _gisFeaturesType = typeFeatures;
 }
 public ViewModelWindowWarnOnGISSelect(int numFeatures, int numIncids, ViewModelWindowMain.GeometryTypes typeFeatures, bool selectByjoin)
 {
     // Store the expected number of features to be selected in GIS.
     _gisFeaturesNum = numFeatures;
     //---------------------------------------------------------------------
     // CHANGED: CR12 (Select by attribute performance)
     // Store the expected number of incids to be selected in GIS.
     _gisIncidNum = numIncids;
     // If the type of feature is not known then just use 'feature'.
     if (typeFeatures != ViewModelWindowMain.GeometryTypes.Unknown)
         _gisFeaturesType = typeFeatures.ToString().ToLower();
     else
         _gisFeaturesType = "feature";
     // Store if a GIS table join will be used to perform the selection.
     _selectByjoin = selectByjoin;
     //---------------------------------------------------------------------
 }
Exemplo n.º 3
0
        internal void CopyValues(ViewModelWindowMain vmMain)
        {
            List <string> errorProps   = new List <string>();
            string        propertyName = null;
            object        copyValue    = null;

            foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy")))
            {
                try
                {
                    propertyName = pi.Name.Remove(0, 4);
                    PropertyInfo copyPI  = typeof(WindowMainCopySwitches).GetProperty(propertyName);
                    PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName);

                    if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType))
                    {
                        if ((bool)pi.GetValue(this, null))
                        {
                            copyValue = valuePI.GetValue(vmMain, null);
                        }
                        else
                        {
                            copyValue = GetDefault(copyPI.PropertyType);
                        }

                        copyPI.SetValue(this, copyValue, null);
                    }
                    else
                    {
                        errorProps.Add(propertyName);
                    }
                }
                catch { errorProps.Add(propertyName); }
            }

            if (errorProps.Count > 0)
            {
                MessageBox.Show(String.Format("Unable to copy {0}{1}.", errorProps.Count > 1 ?
                                              String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ",
                                              String.Join(", ", errorProps.ToArray())), "HLU: Copy Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }

            vmMain.OnPropertyChanged("CanPaste");
        }
Exemplo n.º 4
0
        internal void PasteValues(ViewModelWindowMain vmMain)
        {
            List <string> errorProps   = new List <string>();
            string        propertyName = null;

            foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy")))
            {
                try
                {
                    propertyName = pi.Name.Remove(0, 4);
                    PropertyInfo copyPI  = this.GetType().GetProperty(propertyName);
                    PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName);

                    if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType))
                    {
                        if ((bool)pi.GetValue(this, null))
                        {
                            vmMain.Pasting = true;
                            valuePI.SetValue(vmMain, copyPI.GetValue(this, null), null);
                            vmMain.Pasting = false;
                        }
                    }
                    else
                    {
                        errorProps.Add(propertyName);
                    }
                }
                catch { errorProps.Add(propertyName); }
                finally { vmMain.Pasting = false; }
            }

            if (errorProps.Count > 0)
            {
                MessageBox.Show(String.Format("Unable to paste {0}{1}", errorProps.Count > 1 ?
                                              String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ",
                                              String.Join(", ", errorProps.ToArray())), "HLU: Paste Error",
                                MessageBoxButton.OK, MessageBoxImage.Error);
            }

            vmMain.RefreshAll();
        }
 public ViewModelWindowMainMerge(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
 public ViewModelWindowMainUpdate(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
 /// <summary>
 /// Updates those columns of IncidCurrentRow in main view model that are not directly updated
 /// by properties (to enable undo if update cancelled).
 /// Called here and by bulk update.
 /// </summary>
 /// <param name="viewModelMain">Reference to main window view model.</param>
 internal static void IncidCurrentRowDerivedValuesUpdate(ViewModelWindowMain viewModelMain)
 {
     viewModelMain.IncidCurrentRow.ihs_habitat           = viewModelMain.IncidIhsHabitat;
     viewModelMain.IncidCurrentRow.last_modified_user_id = viewModelMain.IncidLastModifiedUserId;
     viewModelMain.IncidCurrentRow.last_modified_date    = viewModelMain.IncidLastModifiedDateVal;
 }
        internal void PasteValues(ViewModelWindowMain vmMain)
        {
            List<string> errorProps = new List<string>();
            string propertyName = null;

            foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy")))
            {
                try
                {
                    propertyName = pi.Name.Remove(0, 4);
                    PropertyInfo copyPI = this.GetType().GetProperty(propertyName);
                    PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName);

                    if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType))
                    {
                        if ((bool)pi.GetValue(this, null))
                        {
                            vmMain.Pasting = true;
                            valuePI.SetValue(vmMain, copyPI.GetValue(this, null), null);
                            vmMain.Pasting = false;
                        }
                    }
                    else
                    {
                        errorProps.Add(propertyName);
                    }
                }
                catch { errorProps.Add(propertyName); }
                finally { vmMain.Pasting = false; }
            }

            if (errorProps.Count > 0)
                MessageBox.Show(String.Format("Unable to paste {0}{1}", errorProps.Count > 1 ?
                    String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ",
                    String.Join(", ", errorProps.ToArray())), "HLU: Paste Error",
                    MessageBoxButton.OK, MessageBoxImage.Error);

            vmMain.RefreshAll();
        }
        internal void CopyValues(ViewModelWindowMain vmMain)
        {
            List<string> errorProps = new List<string>();
            string propertyName = null;
            object copyValue = null;

            foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy")))
            {
                try
                {
                    propertyName = pi.Name.Remove(0, 4);
                    PropertyInfo copyPI = typeof(WindowMainCopySwitches).GetProperty(propertyName);
                    PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName);

                    if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType))
                    {
                        if ((bool)pi.GetValue(this, null))
                            copyValue = valuePI.GetValue(vmMain, null);
                        else
                            copyValue = GetDefault(copyPI.PropertyType);

                        copyPI.SetValue(this, copyValue, null);
                    }
                    else
                    {
                        errorProps.Add(propertyName);
                    }
                }
                catch { errorProps.Add(propertyName); }
            }

            if (errorProps.Count > 0)
                MessageBox.Show(String.Format("Unable to copy {0}{1}.", errorProps.Count > 1 ?
                    String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ",
                    String.Join(", ", errorProps.ToArray())), "HLU: Copy Error",
                    MessageBoxButton.OK, MessageBoxImage.Error);

            vmMain.OnPropertyChanged("CanPaste");
        }
 public ViewModelWindowMainSplit(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
Exemplo n.º 11
0
 public ViewModelWindowMainMerge(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
 public ViewModelWindowMainExport(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
        /// <summary>
        /// Writes history records to DB.
        /// </summary>
        /// <param name="fixedValues">Dictionary of insert values that will be equal for all new rows.</param>
        /// <param name="newHistoryRecords">DataTable containing the new history rows to be inserted.</param>
        /// <param name="operation">One of the members of the Operations enum describing the operation 
        /// that created the new history records.</param>
        internal void HistoryWrite(Dictionary<int, string> fixedValues,
            DataTable newHistoryRecords, ViewModelWindowMain.Operations operation)
        {
            if ((newHistoryRecords == null) || (newHistoryRecords.Rows.Count == 0)) return;

            bool startTransaction = _viewModelMain.DataBase.Transaction == null;

            if (startTransaction) _viewModelMain.DataBase.BeginTransaction(true, IsolationLevel.ReadCommitted);

            try
            {
                // create dictionary of insert values that will be equal for all new rows
                Dictionary<int, object> fixedValueDict = new Dictionary<int, object>();
                if (fixedValues != null)
                {
                    foreach (KeyValuePair<int, string> kv in fixedValues)
                        fixedValueDict.Add(kv.Key, kv.Value);
                }
                if (!fixedValueDict.ContainsKey(_viewModelMain.HluDataset.history.modified_user_idColumn.Ordinal))
                    fixedValueDict.Add(_viewModelMain.HluDataset.history.modified_user_idColumn.Ordinal, _viewModelMain.UserID);
                if (!fixedValueDict.ContainsKey(_viewModelMain.HluDataset.history.modified_dateColumn.Ordinal))
                //---------------------------------------------------------------------
                // CHANGED: CR4 (Modified date)
                // Store the time with the date in the modified_date column to make the history more exact
                // and avoid separate updates with identical details (except the time) being merged together
                // when displayed by the tool.
                {
                    //---------------------------------------------------------------------
                    // FIX: 028 Only update DateTime fields to whole seconds
                    // Fractions of a second can cause rounding differences when
                    // comparing DateTime fields later in some databases.
                    DateTime currDtTm = DateTime.Now;
                    DateTime nowDtTm = new DateTime(currDtTm.Year, currDtTm.Month, currDtTm.Day, currDtTm.Hour, currDtTm.Minute, currDtTm.Second, DateTimeKind.Local);
                    //---------------------------------------------------------------------
                    fixedValueDict.Add(_viewModelMain.HluDataset.history.modified_dateColumn.Ordinal, nowDtTm);
                }
                //---------------------------------------------------------------------
                if (!fixedValueDict.ContainsKey(_viewModelMain.HluDataset.history.modified_reasonColumn.Ordinal))
                    fixedValueDict.Add(_viewModelMain.HluDataset.history.modified_reasonColumn.Ordinal, _viewModelMain.Reason);
                if (!fixedValueDict.ContainsKey(_viewModelMain.HluDataset.history.modified_processColumn.Ordinal))
                    fixedValueDict.Add(_viewModelMain.HluDataset.history.modified_processColumn.Ordinal, _viewModelMain.Process);
                if (!fixedValueDict.ContainsKey(_viewModelMain.HluDataset.history.modified_operationColumn.Ordinal))
                {
                    string operationCode = ViewModelWindowMainHelpers.GetOperationsCode(_viewModelMain.HluDataset, operation);
                    if (!String.IsNullOrEmpty(operationCode))
                        fixedValueDict.Add(_viewModelMain.HluDataset.history.modified_operationColumn.Ordinal,
                            operationCode);
                    else
                        throw new Exception(String.Format("Missing or indeterminate operation code for {0}.",
                            operation.ToString()));
                }

                // rename the generically named geom1 and geom2 fields according to layer type
                HistoryRenameGeometryPropertyColumns(_viewModelMain.HluDataset.history.modified_lengthColumn.ColumnName,
                    _viewModelMain.HluDataset.history.modified_areaColumn.ColumnName, ref newHistoryRecords);

                // get an array of column ordinals in the new history table as they match columns
                // in DB history table and are not among the fixed values (fixedValueDic)
                // a new history column named "<columnName>" will match both DB history columns named
                // "<columnName>" *and* "modified_<columnName>" as long as there is no column named
                // "modified_<columnName>" in the new history table
                int[] newHistoryColumns = (from t in _viewModelMain.HluDataset.history.Columns.Cast<DataColumn>()
                                           let gisCols = (from g in newHistoryRecords.Columns.Cast<DataColumn>()
                                                          select g.ColumnName).ToArray()
                                           let gisColsMod = (from g in newHistoryRecords.Columns.Cast<DataColumn>()
                                                             select !gisCols.Contains("modified_" + g.ColumnName) ?
                                                             "modified_" + g.ColumnName : String.Empty).ToArray()
                                           select new
                                           {
                                               gisPos = !fixedValueDict.ContainsKey(t.Ordinal) ?
                                                        Array.IndexOf(gisCols, t.ColumnName) : -1,
                                               gisModPos = !fixedValueDict.ContainsKey(t.Ordinal) ?
                                                        Array.IndexOf(gisColsMod, t.ColumnName) : -1
                                           })
                                           .Select(a => a.gisPos != -1 ? a.gisPos : a.gisModPos).ToArray();

                // get the next available history_id
                object objHistId = _viewModelMain.DataBase.ExecuteScalar(String.Format("SELECT MAX({0}) + 1 FROM {1}",
                    _viewModelMain.DataBase.QuoteIdentifier(_viewModelMain.HluDataset.history.history_idColumn.ColumnName),
                    _viewModelMain.DataBase.QualifyTableName(_viewModelMain.HluDataset.history.TableName)),
                    _viewModelMain.DataBase.Connection.ConnectionTimeout, CommandType.Text);
                int historyId = objHistId != DBNull.Value && objHistId != null ? (int)objHistId : 1;

                // append new history rows to a history table
                HluDataSet.historyDataTable historyTable = new HluDataSet.historyDataTable();
                foreach (DataRow r in newHistoryRecords.Rows)
                {
                    HluDataSet.historyRow newRow = historyTable.NewhistoryRow();
                    for (int i = 0; i < historyTable.Columns.Count; i++)
                    {
                        if (i == _viewModelMain.HluDataset.history.history_idColumn.Ordinal)
                        {
                            newRow[i] = historyId++;
                        }
                        else if (newHistoryColumns[i] != -1)
                        {
                            if (!r.IsNull(newHistoryColumns[i]))
                                newRow[i] = r[newHistoryColumns[i]];
                        }
                        else
                        {
                            object val;
                            if (fixedValueDict.TryGetValue(i, out val))
                                newRow[i] = val;
                        }
                    }
                    historyTable.AddhistoryRow(newRow);
                }

                // insert new rows
                if (_viewModelMain.HluTableAdapterManager.historyTableAdapter.Update(historyTable) == -1)
                    throw new Exception("Failed to update history table.");

                if (startTransaction) _viewModelMain.DataBase.CommitTransaction();
            }
            catch
            {
                if (startTransaction) _viewModelMain.DataBase.RollbackTransaction();
                throw;
            }
        }
 public ViewModelWindowMainHistory(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
 public ViewModelWindowMainExport(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
Exemplo n.º 16
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            StartupArguments = e.Args;

            try
            {
#if !THREADED
                WindowSplash splashWindow = new WindowSplash();
                _splashViewModel              = new ViewModelWindowSplash();
                splashWindow.DataContext      = _splashViewModel;
                _splashViewModel.ProgressText = "Initialising...";
                splashWindow.Show();

                _mainWindow    = new WindowMain();
                _mainViewModel = new ViewModelWindowMain();
#else
                UpgradeSettings();

                _threadSplashScreen = new Thread(ExecuteSplashScreen);
                _threadSplashScreen.SetApartmentState(ApartmentState.STA);
                _threadSplashScreen.Start();

                _mainWindow    = new WindowMain();
                _mainViewModel = new ViewModelWindowMain();

                bool          mainWinShowInTaskbar = _mainWindow.ShowInTaskbar;
                SizeToContent mainWinSizeToContent = _mainWindow.SizeToContent;
                _mainWindow.ShowInTaskbar = false;
                _mainWindow.SizeToContent = SizeToContent.Manual;

                _mainWindow.WindowState = WindowState.Minimized;
                _mainWindow.Show();
#endif

                DispatcherHelper.DoEvents();
                if (!_mainViewModel.Initialize())
                {
                    _mainWindow.Close();
                }
                else
                {
                    EventHandler handler = null;
                    handler = delegate
                    {
                        _mainViewModel.RequestClose -= handler;
                        _mainWindow.Close();
                    };
                    _mainViewModel.RequestClose += handler;

                    _mainWindow.DataContext = _mainViewModel;
                    App.Current.MainWindow  = _mainWindow;

#if !THREADED
                    _mainWindow.Cursor = Cursors.Arrow;
                    splashWindow.Close();
                    _mainWindow.Show();
#else
                    _mainWindow.ShowInTaskbar = mainWinShowInTaskbar;
                    _mainWindow.WindowState   = WindowState.Normal;
                    _mainWindow.SizeToContent = mainWinSizeToContent;
#endif

                    _mainWindow.Activate();
                }
            }
            finally
            {
                if ((_threadSplashScreen != null) && _threadSplashScreen.IsAlive)
                {
                    _threadSplashScreen.Abort();
                }
            }
        }
 public ViewModelWindowMainUpdate(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
 /// <summary>
 /// Updates those columns of IncidCurrentRow in main view model that are not directly updated 
 /// by properties (to enable undo if update cancelled).
 /// Called here and by bulk update.
 /// </summary>
 /// <param name="viewModelMain">Reference to main window view model.</param>
 internal static void IncidCurrentRowDerivedValuesUpdate(ViewModelWindowMain viewModelMain)
 {
     viewModelMain.IncidCurrentRow.ihs_habitat = viewModelMain.IncidIhsHabitat;
     viewModelMain.IncidCurrentRow.last_modified_user_id = viewModelMain.IncidLastModifiedUser;
     viewModelMain.IncidCurrentRow.last_modified_date = viewModelMain.IncidLastModifiedDateVal;
 }
Exemplo n.º 19
0
 public ViewModelWindowMainHistory(ViewModelWindowMain viewModelMain)
 {
     _viewModelMain = viewModelMain;
 }
Exemplo n.º 20
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            StartupArguments = e.Args;

            try
            {
#if !THREADED
                WindowSplash splashWindow = new WindowSplash();
                _splashViewModel = new ViewModelWindowSplash();
                splashWindow.DataContext = _splashViewModel;
                _splashViewModel.ProgressText = "Initialising...";
                splashWindow.Show();

                _mainWindow = new WindowMain();
                _mainViewModel = new ViewModelWindowMain();
#else

                UpgradeSettings();

                _threadSplashScreen = new Thread(ExecuteSplashScreen);
                _threadSplashScreen.SetApartmentState(ApartmentState.STA);
                _threadSplashScreen.Start();

                _mainWindow = new WindowMain();
                _mainViewModel = new ViewModelWindowMain();

                bool mainWinShowInTaskbar = _mainWindow.ShowInTaskbar;
                SizeToContent mainWinSizeToContent = _mainWindow.SizeToContent;
                _mainWindow.ShowInTaskbar = false;
                _mainWindow.SizeToContent = SizeToContent.Manual;

                _mainWindow.WindowState = WindowState.Minimized;
                _mainWindow.Show();
#endif

                DispatcherHelper.DoEvents();
                if (!_mainViewModel.Initialize())
                {
                    _mainWindow.Close();
                }
                else
                {
                    EventHandler handler = null;
                    handler = delegate
                    {
                        _mainViewModel.RequestClose -= handler;
                        _mainWindow.Close();
                    };
                    _mainViewModel.RequestClose += handler;

                    _mainWindow.DataContext = _mainViewModel;
                    App.Current.MainWindow = _mainWindow;

#if !THREADED
                    _mainWindow.Cursor = Cursors.Arrow;
                    splashWindow.Close();
                    _mainWindow.Show();
#else
                    _mainWindow.ShowInTaskbar = mainWinShowInTaskbar;
                    _mainWindow.WindowState = WindowState.Normal;
                    _mainWindow.SizeToContent = mainWinSizeToContent;
#endif

                    _mainWindow.Activate();
                }
            }
            finally
            {
                if ((_threadSplashScreen != null) && _threadSplashScreen.IsAlive)
                    _threadSplashScreen.Abort();
            }
        }