コード例 #1
0
ファイル: SqlEditor.cs プロジェクト: fjiang2/sqlcon
 public void New()
 {
     link = FileLink.CreateLink(untitled);
     textBox.Document.Blocks.Clear();
     UpdateTitle();
     isDirty = false;
 }
コード例 #2
0
ファイル: SqlEditor.cs プロジェクト: fjiang2/sqlcon
        public SqlEditor(Configuration cfg, ConnectionProvider provider, FileLink link)
        {
            InitializeComponent(cfg);

            this.cfg = cfg;
            this.provider = provider;

            textBox.Document.Blocks.Clear();
            if (link != null)
            {
                this.link = link;
                string text = link.ReadAllText();
                textBox.Document.Blocks.Add(new Paragraph(new Run(text)));
            }
            else
            {
                this.link = FileLink.CreateLink(untitled);
            }
            UpdateTitle();

            tabControl.SelectionChanged += TabControl_SelectionChanged;
            textBox.SelectionChanged += TextBox_SelectionChanged;
            textBox.TextChanged += TextBox_TextChanged;
            textBox.Focus();
        }
コード例 #3
0
ファイル: XmlDbFile.cs プロジェクト: fjiang2/sqlcon
        public int Read(FileLink root, TableName tname, DataSet ds)
        {
            var file = root.PathCombine(tname.DatabaseName.Name, tname.ShortName);
            file = string.Format("{0}.{1}", file, EXT);

            var link = FileLink.CreateLink(file, tname.Provider.UserId, tname.Provider.Password);
            if (!link.Exists)
                throw new InvalidDataException($"table {tname.FormalName} data file \"{file}\" not exist");

            link.ReadXml(ds);
            
            if (ds.Tables.Count > 0)
                return ds.Tables[0].Rows.Count;
            else
                return -1;
        }
コード例 #4
0
ファイル: SqlEditor.cs プロジェクト: fjiang2/sqlcon
        public void Open()
        {
            var openFile = new Microsoft.Win32.OpenFileDialog
            {
                Filter = "Sql Script Files (*.sql)|*.sql|Text Files (*.txt)|*.txt|All Files (*.*)|*.*",
                FileName = link.Url
            };

            if (openFile.ShowDialog(this) == true)
            {
                link = FileLink.CreateLink(openFile.FileName);
                string text = link.ReadAllText();
                textBox.Document.Blocks.Clear();
                textBox.Document.Blocks.Add(new Paragraph(new Run(text)));
                UpdateTitle();
                isDirty = false;
            }
        }
コード例 #5
0
ファイル: SqlEditor.cs プロジェクト: fjiang2/sqlcon
        public void Save()
        {
            if (link.Url != untitled)
            {
                try
                {
                    link.Save(textBox.GetAllText());
                    lblMessage.Text = "saved successfully";
                    isDirty = false;
                }
                catch (Exception ex)
                {
                    lblMessage.Text = ex.Message;
                }
                return;
            }

            var saveFile = new Microsoft.Win32.SaveFileDialog
            {
                Filter = "Sql Script Files (*.sql)|*.sql|Text Files (*.txt)|*.txt|All Files (*.*)|*.*",
                FileName = link.Url
            };

            if (saveFile.ShowDialog(this) == true)
            {
                TextRange documentTextRange = new TextRange(textBox.Document.ContentStart, textBox.Document.ContentEnd);

                // If this file exists, it's overwritten.
                using (FileStream fs = File.Create(saveFile.FileName))
                {
                    if (Path.GetExtension(saveFile.FileName).ToLower() == ".rtf")
                    {
                        documentTextRange.Save(fs, DataFormats.Rtf);
                    }
                    else
                    {
                        documentTextRange.Save(fs, DataFormats.Text);
                    }

                    link = FileLink.CreateLink(saveFile.FileName);
                    UpdateTitle();
                    isDirty = false;
                }
            }

            return;
        }