Exemplo n.º 1
0
        private void View_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            GridView    view = GetViewFromSelectedTabPage();
            KOTableFile tbl  = StaticReference.GetTableByFullName(view.Tag as string);

            if (e.RowHandle < 0 || e.Column.AbsoluteIndex < 0)
            {
                return;
            }
            if (!(tbl == null))
            {
                /* New row highlight */
                if (NewRowHighlightEnabled(view, tbl.Table.Rows[e.RowHandle]))
                {
                    e.Appearance.BackColor = Color.FromArgb(128, Color.ForestGreen);
                }
            }
            if (_editedCells.ContainsKey(view))
            {
                /* Edited cell highlight */
                foreach (KeyValuePair <int, int> kvp in _editedCells[view])
                {
                    int cIndex = kvp.Value;
                    int rIndex = kvp.Key;
                    if (e.Column.AbsoluteIndex == cIndex && e.RowHandle == rIndex)
                    {
                        e.Appearance.BackColor = Color.FromArgb(128, Color.Gold);
                        break;
                    }
                }
            }
            //throw new NotImplementedException();
        }
Exemplo n.º 2
0
 private void frmExportAsSQL_Load(object sender, System.EventArgs e)
 {
     _tbl = StaticReference.GetTableByFullName(_tableName);
     if (_tbl == null)
     {
         StaticReference.ShowError(this, LanguageManager.Get("Message_NoFileOpen"));
         Close();
         return;
     }
     PopulateColumns();
     // meDescription.Text = StaticReference.GenerateKey(256);
 }
Exemplo n.º 3
0
 private void RedrawFileInformation(KOTableFile tbl)
 {
     Trace.Assert(tbl != null, "RedrawFileInformation() - Table is null."); ngFileInfo_Name.Text = string.Format("{0}", tbl.FileInformation.Name);
     ngFileInfo_Path.Text        = string.Format("{0}", tbl.FileInformation.DirectoryName);
     ngFileInfo_CreatedAt.Text   = string.Format("{0}", tbl.FileInformation.CreationTimeUtc.ToLocalTime());
     ngFileInfo_LastAccess.Text  = string.Format("{0}", tbl.FileInformation.LastAccessTimeUtc.ToLocalTime());
     ngFileInfo_LastModify.Text  = string.Format("{0}", tbl.FileInformation.LastWriteTimeUtc.ToLocalTime());
     ngFileInfo_ColumnCount.Text = tbl.Table.Columns.Count.ToString();
     ngFileInfo_RowCount.Text    = tbl.Table.Rows.Count.ToString();
     ngFileInfo_Size.Text        = string.Format("{0} kb", tbl.FileInformation.Length / 1024);
     ngFileInfo_Encryption.Text  = string.Format("{0}", tbl.Encryption.Name());
 }
Exemplo n.º 4
0
        private void frmColumnEditor_Load(object sender, EventArgs e)
        {
            _tbl = StaticReference.GetTableByFullName(_tableName);
            if (_tbl == null)
            {
                StaticReference.ShowError(this, LanguageManager.Get("Message_NoFileOpen"));
                Close();
                return;
            }
            PopulateColumns();

            foreach (var v in _dataTypeList)
            {
                cbColumnDataType_Add.Properties.Items.Add(v);
                cbColumnDataType_Update.Properties.Items.Add(v);
            }
        }
Exemplo n.º 5
0
        void tcMain_SelectedPageChanged(object sender, TabPageChangedEventArgs e)
        {
            var er = e as TabPageChangedEventArgs;

            if (er != null)
            {
                if (er.Page == null)
                {
                    return;
                }
                //Text = LanguageManager.Get("mainFrm_Menu_About_Program") + $" - {er.Page.Tag as string}";
                lblOpenFile.Caption = er.Page.Tag as string;
                KOTableFile tbl = StaticReference.GetTableByFullName(er.Page.Tag as string);
                RedrawFileInformation(tbl);
                //ngFile.Caption = $"File ({tbl.Name})";
            }
        }
Exemplo n.º 6
0
        private void ngEdit_NewRow_LinkPressed(object sender, NavBarLinkEventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }
            string      fileName = tcMain.SelectedTabPage.Tag as string;
            KOTableFile tbl      = StaticReference.GetTableByFullName(fileName);
            var         view     = GetViewFromSelectedTabPage();
            var         row      = tbl.Table.NewRow();

            tbl.Table.Rows.Add(row);
            AddNewRowHighlight(view, row);
            view.FocusedRowHandle = view.RowCount - 1;
            view.TopRowIndex      = view.RowCount - 1;
            view.RefreshData();
            view.Invalidate();
        }
Exemplo n.º 7
0
        private void LoadFolder(object state)
        {
            _loadedTables.Clear();
            lbLoadedTables.Items.Clear();

            meLog.Text += $"Populating and loading tables in {_sourceFolder}" + Environment.NewLine;
            string[] files = Directory.GetFiles(_sourceFolder);
            foreach (string path in files)
            {
                FileInfo fi = new FileInfo(path);
                if (!fi.Exists || fi.Extension != ".tbl")
                {
                    continue;
                }

                DataTable        table      = null;
                KOEncryptionBase encryption = null;
                /* Try to decrypt file. */
                foreach (var encryptionMethod in StaticReference.EncryptionMethods)
                {
                    table = encryptionMethod.GetDataTableFromFile(path, fi.Name);
                    if (table == null)
                    {
                        continue;
                    }
                    encryption = encryptionMethod;
                    break;
                }

                if (table == null)
                {
                    lbLoadedTables.Items.Add($"{fi.Name} - Load failed.");
                }
                else
                {
                    lbLoadedTables.Items.Add($"{fi.Name} [{encryption.Name()}] - OK");
                    var newTable = new KOTableFile(fi, table, encryption);
                    _loadedTables.Add(path, newTable);
                }
            }
        }
Exemplo n.º 8
0
        private void OpenFile(object ofileName)
        {
            string fileName = ofileName as string;
            var    fi       = new FileInfo(fileName);

            if (!fi.Exists)
            {
                ;
                StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_FileOpenError"), fileName));
                return;
            }

            if (StaticReference.GetTableByFullName(fi.FullName) != null)
            {
                this.Invoke(new Action(() => { SwitchToTabpage(fi.FullName); }));

                return;
            }

            DataTable        table      = null;
            KOEncryptionBase encryption = null;

            /* Try to decrypt file. */
            foreach (var encryptionMethod in StaticReference.EncryptionMethods)
            {
                table = encryptionMethod.GetDataTableFromFile(fileName, fi.Name);
                if (table == null)
                {
                    continue;
                }
                encryption = encryptionMethod;
                break;
            }

            if (table == null)
            {
                this.Invoke(new Action(() => {
                    StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_FileEncryptionError"), fi.Name)); return;
                }));
                return;
            }
            var newTable = new KOTableFile(fi, table, encryption);

            /* Otherwise, we've succeeded to open file */
            StaticReference.AddNewTable(newTable);
            this.Invoke(new Action(() =>
            {
                CreateNewTabPage(newTable.Name, newTable.FullName);
                var grid         = GetTabPageGrid(newTable.FullName);
                grid.KeyPress   += Grid_KeyPress;
                grid.MouseClick += Grid_MouseClick;

                Trace.Assert(grid != null, "OpenFile() - Grid is null!");



                grid.BeginUpdate();
                grid.DataSource = table;
                var view        = grid.MainView as GridView;

                Trace.Assert(view != null, "OpenFile() - GridView is null!");

                view.Tag = newTable.FullName;

                foreach (var v in _itemTableHeaders.Where(v => newTable.Name.ToLowerInvariant().Contains(v.Key)))
                {
                    view.ColumnPanelRowHeight += 20;
                    for (var i = 0; i < view.Columns.Count; i++)
                    {
                        if (i < v.Value.Length)
                        {
                            view.Columns[i].Caption = string.Format("{0}\n{1}\n{2}", v.Value[i], i, ColumnTypes.GetColumnTypeNameFromFullName(view.Columns[i].ColumnType.FullName));
                        }
                    }
                }
                //view.
                foreach (GridColumn col in view.Columns)
                {
                    col.AppearanceCell.Options.UseTextOptions   = true;
                    col.AppearanceHeader.Options.UseTextOptions = true;

                    col.AppearanceCell.TextOptions.HAlignment   = HorzAlignment.Center;
                    col.AppearanceCell.TextOptions.VAlignment   = VertAlignment.Center;
                    col.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
                    col.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center;
                    col.MinWidth = col.ColumnType != typeof(string) ? 150 : 200;
                    col.OptionsColumn.FixedWidth = true;
                }

                grid.Refresh();
                grid.EndUpdate();
            }));
        }
Exemplo n.º 9
0
        private void pasteRowToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tcMain.SelectedTabPageIndex == -1 || tcMain.SelectedTabPage == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoFileOpen"));
                return;
            }

            string      fileName = tcMain.SelectedTabPage.Tag as string;
            KOTableFile tbl      = StaticReference.GetTableByFullName(fileName);
            GridView    view     = GetViewFromSelectedTabPage();

            if (null == tbl || null == view)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_PasteError"));
                return;
            }
            if (InternalClipboard.DataExists())
            {
                /*
                 * Let's check if copied datarow matches the column length of current table
                 * */
                int successfulRows = 0;
                foreach (var copiedRow in InternalClipboard.GetNext())
                {
                    /*
                     * 1. Column count of both tables should be same
                     * 2. Data types of columns for both tables should match
                     */
                    bool    column_ok = true;
                    DataRow newRow    = tbl.Table.NewRow();
                    if (tbl.Table.Columns.Count == copiedRow.Table.Columns.Count)
                    {
                        foreach (DataColumn cColumn in copiedRow.Table.Columns)
                        {
                            if (tbl.Table.Columns[cColumn.Ordinal].DataType != cColumn.DataType)
                            {
                                column_ok = false;
                                break;
                            }
                            else
                            {
                                newRow[cColumn.Ordinal] = copiedRow[cColumn];
                            }
                        }
                    }
                    else
                    {
                        column_ok = false;
                    }
                    if (column_ok)
                    {
                        successfulRows++;
                        /* Create a new row in table */
                        /* Insert the row.*/
                        tbl.Table.Rows.Add(newRow);
                        AddNewRowHighlight(view, newRow);
                    }
                }
                /* Scroll to bottom */
                view.FocusedRowHandle = view.RowCount - 1;
                view.TopRowIndex      = view.RowCount - 1;

                if (successfulRows == InternalClipboard.GetSize())
                {
                    StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_NRowsAddSuccess"), successfulRows));
                }
                else
                {
                    StaticReference.ShowWarning(this, string.Format(LanguageManager.Get("Message_CopyError"), successfulRows, InternalClipboard.GetSize()));
                }
            }
            else
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_PasteNoRows"));
            }
        }