Example #1
0
 internal NanoDBLine(NanoDBFile parent, byte flag, int line, string key, object[] content, string sortKey = null)
 {
     this.parent     = parent;
     this.LineFlag   = flag;
     this.LineNumber = line;
     this.Key        = key;
     this.Content    = content;
     this.SortKey    = sortKey;
 }
Example #2
0
        private void OpenFile(string path)
        {
            this.editMode = false;

            if (this.dbFile != null)
            {
                this.dbFile.Unbind();
            }

            this.dbFile = new NanoDBFile(path);

            if (this.dbFile.Initialize() == InitializeResult.Success)
            {
                this.dbFile.Load(this.dbFile.RecommendedIndex);

                this.dbFile.Bind();

                this.uiDbGridView.Rows.Clear();
                this.uiGridEdit.Rows.Clear();

                this.uiDbGridView.ColumnCount = this.dbFile.Layout.LayoutSize;
                this.uiGridEdit.ColumnCount   = this.dbFile.Layout.LayoutSize;

                for (int i = 0; i < this.dbFile.Layout.LayoutSize; i++)
                {
                    if (i == this.dbFile.RecommendedIndex)
                    {
                        this.uiDbGridView.Columns[i].Name = ">> " + this.dbFile.Layout.Elements[i].GetName();
                    }
                    else
                    {
                        this.uiDbGridView.Columns[i].Name = this.dbFile.Layout.Elements[i].GetName();
                    }

                    this.uiDbGridView.Columns[i].Width = 150;
                }

                foreach (string key in this.dbFile.GetAllKeys())
                {
                    this.uiDbGridView.Rows.Add(this.Serialize(this.dbFile.GetLine(key)));
                }

                this.uiGridEdit.Rows.Add();

                this.uiResetButton.Enabled = true;
                this.editMode = true;

                // Workaround to reset the selection when started with a parameter
                new Thread(() => { Thread.Sleep(50); this.Invoke((MethodInvoker)(() => this.HandleResetButtonClicked(null, null))); }).Start();
            }
            else
            {
                this.dbFile = null;
                MessageBox.Show(this, "Database doesn't have a proper format!");
            }
        }
Example #3
0
        public DbCleaner(NanoDBFile dbFile)
        {
            this.InitializeComponent();

            this.textBox1.Text = dbFile.TotalLines.ToString();
            this.textBox2.Text = (dbFile.TotalLines - dbFile.EmptyLines).ToString();
            this.textBox3.Text = (int)(dbFile.StorageEfficiency * 100 + 0.5) + "%";

            this.dbFile = dbFile;
        }
Example #4
0
        private void HandleNewToolStripMenuItemClick(object sender, EventArgs e)
        {
            if (this.dbFile != null)
            {
                this.dbFile.Unbind();
            }

            this.saveFileDialog.FileName = "";

            if (this.saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                this.editMode = false;

                this.dbFile = new NanoDBFile(this.saveFileDialog.FileName);

                this.dbFile.Initialize();

                List <NanoDBElement> list = new List <NanoDBElement>();

                int curLayoutId = 0;

                while (true)
                {
                    ElementDialog dialog = new ElementDialog(curLayoutId);
                    dialog.ShowDialog();


                    list.Add(dialog.ReturnValue);
                    curLayoutId++;

                    if (dialog.Finish || curLayoutId == 256)
                    {
                        break;
                    }
                }

                this.dbFile.CreateNew(new NanoDBLayout(list.ToArray()), 0);

                this.dbFile.Bind();

                this.uiDbGridView.Rows.Clear();
                this.uiGridEdit.Rows.Clear();

                this.uiDbGridView.ColumnCount = this.dbFile.Layout.LayoutSize;
                this.uiGridEdit.ColumnCount   = this.dbFile.Layout.LayoutSize;

                for (int i = 0; i < this.dbFile.Layout.LayoutSize; i++)
                {
                    if (i == this.dbFile.RecommendedIndex)
                    {
                        this.uiDbGridView.Columns[i].Name = ">> " + this.dbFile.Layout.Elements[i].GetName();
                    }
                    else
                    {
                        this.uiDbGridView.Columns[i].Name = this.dbFile.Layout.Elements[i].GetName();
                    }

                    this.uiDbGridView.Columns[i].Width = 150;
                }

                this.uiGridEdit.Rows.Add();

                this.uiResetButton.Enabled = true;

                this.HandleResetButtonClicked(null, null);

                this.editMode = true;
            }
        }