コード例 #1
0
ファイル: Main.cs プロジェクト: borisblizzard/classtools
        private void openMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = this.showSaveChangesDialog(SAVE_PROMPT_OPEN);

            if (result != DialogResult.Cancel)
            {
                this.ofdDatabase.FileName = string.Empty;
                result = this.ofdDatabase.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Stream stream = this.ofdDatabase.OpenFile();
                    this.repository = Serializer.Deserialize(stream, this.repository);
                    stream.Close();
                    this.lastFilename = this.ofdDatabase.FileName;
                    this.model        = repository.Model;
                    repository.Update(this.model);
                    this.lastRepository = Serializer.Clone(this.repository);
                    this.lastRepository.Update(this.model);
                    InternalClipboard.Clear();
                    this.listIndices.Clear();
                    this.lastSelectedClass = null;
                    this.RefreshData();
                }
            }
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: borisblizzard/classtools
        private void newMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = this.showSaveChangesDialog(SAVE_PROMPT_NEW);

            if (result != DialogResult.Cancel)
            {
                this.repository     = new Repository(this.model);
                this.lastRepository = new Repository(this.model);
                InternalClipboard.Clear();
                this.lastFilename = string.Empty;
                this.listIndices.Clear();
                this.lastSelectedClass = null;
                this.RefreshData();
            }
        }
コード例 #3
0
        private void copyRowToolStripMenuItem_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;

            var      tbl  = StaticReference.GetTableByFullName(fileName);
            GridView view = GetViewFromSelectedTabPage();

            if (view == null || tbl == null)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_SelectPageFirst"));
                return;
            }


            // MessageBox.Show("ctrlc");
            if (view.SelectedRowsCount == 0)
            {
                StaticReference.ShowWarning(this, LanguageManager.Get("Message_NoRowsSelected"));
                return;
            }
            List <DataRow> drList = new List <DataRow>();

            for (int i = 0; i < view.SelectedRowsCount; i++)
            {
                drList.Add(tbl.Table.Rows[view.GetSelectedRows()[i]]);
                //view.GetSelectedRows().cl
            }
            /* Copy the content of selected rows to the internal clipboard. */
            InternalClipboard.Copy(ref drList);
            view.ClearSelection();
            StaticReference.ShowInformation(this, string.Format(LanguageManager.Get("Message_NRowsCopied"), InternalClipboard.GetSize()));
        }
コード例 #4
0
ファイル: Main.cs プロジェクト: borisblizzard/classtools
        private void updateModelMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult result = this.showSaveChangesDialog(SAVE_PROMPT_OPEN);

            if (result != DialogResult.Cancel)
            {
                this.ofdModel.FileName = string.Empty;
                result = this.ofdModel.ShowDialog();
                if (result == DialogResult.OK)
                {
                    Stream stream   = this.ofdModel.OpenFile();
                    Model  newModel = Serializer.Deserialize(stream, this.model);
                    stream.Close();
                    if (!this.repository.Model.Equals(newModel))
                    {
                        Repository newRepository = Serializer.Clone(this.repository);
                        result = this.updateTypes(newRepository, newModel);
                        if (result == DialogResult.OK)
                        {
                            this.repository = newRepository;
                        }
                    }
                    if (result == DialogResult.OK)
                    {
                        this.model = newModel;
                        this.repository.Update(this.model);
                        this.lastRepository = Serializer.Clone(this.repository);
                        this.lastRepository.Update(this.model);
                        InternalClipboard.Clear();
                        this.listIndices.Clear();
                        this.lastSelectedClass = null;
                        this.RefreshData();
                    }
                }
            }
        }
コード例 #5
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"));
            }
        }