Esempio n. 1
0
        /// <summary>
        /// Sets the current code and updates the current version of the code.
        /// </summary>
        public static void SetCurrentCode(this IProjectEntry entry, string value, int buffer, int version)
        {
            lock (_currentCodeKey) {
                CurrentCode curCode = GetCurrentCode(entry, buffer);

                curCode.Text.Clear();
                curCode.Text.Append(value);
                curCode.Version = version;
            }
        }
Esempio n. 2
0
        public void TestMethodInsertCarta()
        {
            var da = new CartaDA();

            var cantidad = da.GetAll().ToList().Count(q => q.GerenciaId == 2) + 1;

            var carta = new Carta
            {
                Codigo        = CurrentCode.Codigo("GCO", cantidad),
                GerenciaId    = 2,
                Asunto        = "Este es otro asunto",
                Destinatario  = "Señor de Osinergmin",
                Usuario       = CurrentUser.GetUser(),
                FechaCreacion = DateTime.Now
            };

            Assert.AreEqual(1, da.AddCarta(carta));
        }
Esempio n. 3
0
        private static CurrentCode GetCurrentCode(IProjectEntry entry, int buffer)
        {
            object dictTmp;
            SortedDictionary <int, CurrentCode> dict;

            if (!entry.Properties.TryGetValue(_currentCodeKey, out dictTmp))
            {
                entry.Properties[_currentCodeKey] = dict = new SortedDictionary <int, CurrentCode>();
            }
            else
            {
                dict = (SortedDictionary <int, CurrentCode>)dictTmp;
            }

            CurrentCode curCode;

            if (!dict.TryGetValue(buffer, out curCode))
            {
                curCode = dict[buffer] = new CurrentCode();
            }

            return(curCode);
        }
Esempio n. 4
0
        /// <summary>
        /// Updates the code applying the changes to the existing text buffer and updates the version.
        /// </summary>
        public static string UpdateCode(this IProjectEntry entry, AP.VersionChanges[] versions, int buffer, int version)
        {
            lock (_currentCodeKey) {
                CurrentCode curCode   = GetCurrentCode(entry, buffer);
                var         strBuffer = curCode.Text;

                foreach (var versionChange in versions)
                {
                    int delta = 0;

                    foreach (var change in versionChange.changes)
                    {
                        strBuffer.Remove(change.start + delta, change.length);
                        strBuffer.Insert(change.start + delta, change.newText);

                        delta += change.newText.Length - change.length;
                    }
                }

                curCode.Version = version;
                return(strBuffer.ToString());
            }
        }
Esempio n. 5
0
        private static CurrentCode GetCurrentCode(IProjectEntry entry, int buffer) {
            object dictTmp;
            SortedDictionary<int, CurrentCode> dict;
            if (!entry.Properties.TryGetValue(_currentCodeKey, out dictTmp)) {
                entry.Properties[_currentCodeKey] = dict = new SortedDictionary<int, CurrentCode>();
            } else {
                dict = (SortedDictionary<int, CurrentCode>)dictTmp;
            }

            CurrentCode curCode;
            if (!dict.TryGetValue(buffer, out curCode)) {
                curCode = dict[buffer] = new CurrentCode();
            }

            return curCode;
        }
Esempio n. 6
0
        /// <summary>
        ///     Called when the pane is initialized.
        /// </summary>
        protected override async Task InitializeAsync()
        {
            await base.InitializeAsync();

            ShowCategory = new RelayCommand(SetActive, () => true);
            HasValue     = CurrentCode.Select(x => x.ToString().Length == 6).ToReactiveProperty();
            SetClipboard = HasValue.ToReactiveCommand()
                           .WithSubscribe(() => Clipboard.SetText(CurrentCode.Value.ToString()));
            Expanded     = CurrentCode.Select(x => x < 10).ToReactiveProperty();
            UpdateSearch = InputCode.Select(x => x)
                           .Throttle(TimeSpan.FromMilliseconds(200))
                           .ObserveOn(Application.Current.Dispatcher)
                           .Do(async x => await FilterNaicsByString(x))
                           .ToReactiveProperty();
            SetInputCode = new RelayCommand(x => { InputCode.Value = x.ToString(); }, () => true);

            var codeColumn  = 1;
            var titleColumn = 2;
            var skipRows    = 2;
            var currentRow  = 0;

            try {
                using (var stream = File.Open(_twoDigitCodesPath, FileMode.Open, FileAccess.Read)) {
                    using (var reader = ExcelReaderFactory.CreateReader(stream)) {
                        do
                        {
                            while (reader.Read())
                            {
                                currentRow += 1;
                                if (currentRow <= skipRows)
                                {
                                    continue;
                                }

                                try {
                                    NaicsCodes.Add(new NaicsModel(reader.GetDouble(codeColumn),
                                                                  reader.GetString(titleColumn)));
                                } catch (InvalidCastException) {
                                    NaicsCodes.AddRange(NaicsModel.CreateNaicsFromRange(reader.GetString(codeColumn),
                                                                                        reader.GetString(titleColumn)));
                                }
                            }
                        } while (reader.NextResult());
                    }
                }
            } catch (Exception) {
            }

            currentRow  = 0;
            skipRows    = 1;
            codeColumn  = 0;
            titleColumn = 1;

            try {
                using (var stream = File.Open(_allNaicsPath, FileMode.Open, FileAccess.Read)) {
                    using (var reader = ExcelReaderFactory.CreateReader(stream)) {
                        do
                        {
                            while (reader.Read())
                            {
                                currentRow += 1;
                                if (currentRow <= skipRows)
                                {
                                    continue;
                                }

                                AllNaicsCodes.Add(new NaicsModel(reader.GetDouble(codeColumn),
                                                                 reader.GetString(titleColumn)));
                            }
                        } while (reader.NextResult());
                    }
                }
            } catch (Exception) {
            }
        }