Beispiel #1
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();
            }));
        }