Esempio n. 1
0
        public void AddLabelContextMenu(Label element, DbAttribute att)
        {
            var menu = new ContextMenu();

            element.ContextMenu = menu;

            MenuItem item = new MenuItem();

            item.Header = "Search for this field [" + att.GetQueryName().Replace("_", "__") + "]";
            menu.Items.Add(item);

            item.Click += delegate {
                var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

                if (selected != null)
                {
                    selected._dbSearchPanel._searchTextBox.Text = _getTextSearch(att);
                }
            };

            item        = new MenuItem();
            item.Header = "Append search for this field [" + att.GetQueryName().Replace("_", "__") + "]";
            menu.Items.Add(item);

            item.Click += delegate {
                var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

                if (selected != null)
                {
                    if (selected._dbSearchPanel._searchTextBox.Text == "")
                    {
                        selected._dbSearchPanel._searchTextBox.Text = _getTextSearch(att);
                    }
                    else
                    {
                        selected._dbSearchPanel._searchTextBox.Text = "(" + selected._dbSearchPanel._searchTextBox.Text + ") && " + _getTextSearch(att);
                    }
                }
            };
        }
Esempio n. 2
0
        private string _getTextSearch(DbAttribute att)
        {
            var selected = SdeEditor.Instance.Tabs.FirstOrDefault(p => p.IsSelected);

            if (selected != null)
            {
                var tuple = selected._listView.SelectedItem as Database.Tuple;

                if (tuple != null)
                {
                    if (att.DataType == typeof(bool))
                    {
                        return("[" + att.GetQueryName() + "] == " + tuple.GetValue <string>(att));
                    }
                    else if (att.DataType.BaseType == typeof(Enum) || att.DataType == typeof(int))
                    {
                        return("[" + att.GetQueryName() + "] == " + tuple.GetValue <int>(att));
                    }
                    else
                    {
                        string value = tuple.GetRawValue <string>(att.Index);

                        if (FormatConverters.LongOrHexConverter(value) > 0 || value == "0x0" || value == "0")
                        {
                            return("[" + att.GetQueryName() + "] == " + value);
                        }
                        else
                        {
                            return("[" + att.GetQueryName() + "] contains \"" + value + "\"");
                        }
                    }
                }
                else
                {
                    if (att.DataType == typeof(bool))
                    {
                        return("[" + att.GetQueryName() + "] == true");
                    }
                    else
                    {
                        return("[" + att.GetQueryName() + "] == 0");
                    }
                }
            }

            return("");
        }
Esempio n. 3
0
        private static void _saveFile(SdeDatabase gdb, string filename, string output, DbAttribute attribute, RequiredCondition <ReadableTuple <int> > condition = null, bool allowReturns = true)
        {
            if (output == null && gdb.MetaGrf.GetData(filename) == null)
            {
                Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, filename, null, "Table not saved (" + attribute.GetQueryName() + ")."));
                return;
            }

            if (output == null)
            {
                BackupEngine.Instance.BackupClient(filename, gdb.MetaGrf);
            }

            string   tmpFilename = Path.Combine(SdeAppConfiguration.TempPath, Path.GetFileName(filename));
            Encoding encoder     = EncodingService.DisplayEncoding;

            byte[] tmpBuffer;
            byte[] lineFeedByte       = encoder.GetBytes(SdeStrings.LineFeed);
            byte[] doubleLineFeedByte = encoder.GetBytes(SdeStrings.LineFeed + SdeStrings.LineFeed);

            using (MemoryStream memStream = new MemoryStream()) {
                IEnumerable <ReadableTuple <int> > items = gdb.GetDb <int>(ServerDbs.CItems).Table.GetSortedItems();

                int  previousId = -1;
                bool firstItem  = true;

                foreach (ReadableTuple <int> item in items)
                {
                    if (condition == null || condition(item))
                    {
                        string itemProperty = attribute != null?item.GetRawValue(attribute.Index) as string : null;

                        if (itemProperty != null || attribute == null)
                        {
                            if (attribute == ClientItemAttributes.IdentifiedDisplayName || attribute == ClientItemAttributes.UnidentifiedDisplayName)
                            {
                                itemProperty = itemProperty.Replace(" ", "_");
                            }

                            if (!firstItem)
                            {
                                if (allowReturns)
                                {
                                    if (previousId == (item.GetValue <int>(ClientItemAttributes.Id) - 1))
                                    {
                                        memStream.Write(lineFeedByte, 0, lineFeedByte.Length);
                                    }
                                    else
                                    {
                                        memStream.Write(doubleLineFeedByte, 0, doubleLineFeedByte.Length);
                                    }
                                }
                                else
                                {
                                    memStream.Write(lineFeedByte, 0, lineFeedByte.Length);
                                }
                            }

                            if (attribute == null)
                            {
                                tmpBuffer = encoder.GetBytes(item.GetValue <int>(ClientItemAttributes.Id) + "#");
                            }
                            else
                            {
                                tmpBuffer = encoder.GetBytes(item.GetValue <int>(ClientItemAttributes.Id) + "#" + itemProperty + "#");
                            }

                            memStream.Write(tmpBuffer, 0, tmpBuffer.Length);

                            previousId = item.GetValue <int>(ClientItemAttributes.Id);
                            firstItem  = false;
                        }
                    }
                }

                memStream.Write(lineFeedByte, 0, lineFeedByte.Length);

                tmpBuffer = new byte[memStream.Length];
                Buffer.BlockCopy(memStream.GetBuffer(), 0, tmpBuffer, 0, tmpBuffer.Length);

                File.WriteAllBytes(tmpFilename, tmpBuffer);
            }

            if (output == null)
            {
                var data    = gdb.MetaGrf.GetData(filename);
                var toWrite = File.ReadAllBytes(tmpFilename);

                if (data != null && Methods.ByteArrayCompare(data, toWrite))
                {
                    return;
                }

                gdb.MetaGrf.SetData(filename, toWrite);
            }
            else
            {
                string copyPath = Path.Combine(output, Path.GetFileName(filename));

                try {
                    File.Delete(copyPath);
                    File.Copy(tmpFilename, copyPath);
                    File.Delete(tmpFilename);
                }
                catch (Exception err) {
                    ErrorHandler.HandleException(err);
                }
            }

            Debug.Ignore(() => DbDebugHelper.OnWriteStatusUpdate(ServerDbs.CItems, gdb.MetaGrf.FindTkPath(filename), null, "Saving client table (" + (attribute == null ? "" : attribute.GetQueryName()) + ")."));
        }