Example #1
0
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (sender == MenuItem_String)
            {
                EditColumnDialog Dialog = new EditColumnDialog();
                if (DialogResult.OK == Dialog.ShowDialog())
                {
                    TableData.AddStringColumn(Dialog.TextBoxColumn.Text);
                }
            }
            else if (sender == MenuItem_Integer)
            {
                EditColumnDialog Dialog = new EditColumnDialog();
                if (DialogResult.OK == Dialog.ShowDialog())
                {
                    TableData.AddIntegerColumn(Dialog.TextBoxColumn.Text);
                }
            }
            else if (sender == MenuItem_Float)
            {
                EditColumnDialog Dialog = new EditColumnDialog();
                if (DialogResult.OK == Dialog.ShowDialog())
                {
                    TableData.AddFloatColumn(Dialog.TextBoxColumn.Text);
                }
            }
            else if (sender == MenuItem_Date)
            {
                EditColumnDialog Dialog = new EditColumnDialog();
                if (DialogResult.OK == Dialog.ShowDialog())
                {
                    TableData.AddDateColumn(Dialog.TextBoxColumn.Text);
                }
            }
            else if (sender == Button_RenameColumn)
            {
                String           Column = FpSpread_Panel.ActiveColumn.Tag.ToString();
                EditColumnDialog Dialog = new EditColumnDialog();
                Dialog.TextBoxColumn.Text = Column;
                if (DialogResult.OK == Dialog.ShowDialog())
                {
                    TableData.EditColumn(Column, Dialog.TextBoxColumn.Text);
                }
            }
            else if (sender == Button_DeleteColumn)
            {
                String Column = FpSpread_Panel.ActiveColumn.Tag.ToString();
                if (DialogResult.OK == MessageBox.Show("你确定要删除列‘" + Column + "’吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information))
                {
                    TableData.DeleteColumn(Column);
                }
            }
            else if (sender == Button_ColumnOrder)
            {
                DataTable         Table  = TableData.GetSchema();
                ColumnOrderDialog Dialog = new ColumnOrderDialog(Table.Columns);
                Dialog.ShowDialog();
            }
            else if (sender == Button_FieldSetting)
            {
                DataFieldSelector DataFieldSelector = new DataFieldSelector();
                Form Owner = Cache.CustomCache[SystemString.主窗口] as Form;
                DataFieldSelector.Location = Owner.PointToScreen(Owner.ClientRectangle.Location);
                DataFieldSelector.Size     = Owner.ClientRectangle.Size;
                if (DialogResult.OK == DataFieldSelector.ShowDialog())
                {
                    try
                    {
                        List <String> ModelFields = DataFieldSelector.ModelFields;

                        DataRow Row = TableData.AddRow();
                        Row.ItemArray = ModelFields.ToArray();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            else if (sender == Button_ImportData)
            {
                openFileDialog1.Filter           = "xml files (*.xml)|*.xml";
                openFileDialog1.FilterIndex      = 2;
                openFileDialog1.InitialDirectory = Application.StartupPath;
                openFileDialog1.RestoreDirectory = true;
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    using (TextReader tr = new StreamReader(openFileDialog1.FileName))
                    {
                        object obj = BinarySerializer.Deserialize(tr.ReadToEnd());
                        if (obj is JoinTableData)
                        {
                            TableData = obj as JoinTableData;
                        }
                        else
                        {
                            MessageBox.Show("选择的文件的数据格式有错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            else if (sender == Button_ExportData)
            {
                saveFileDialog1.Filter           = "xml files (*.xml)|*.xml";
                saveFileDialog1.FilterIndex      = 2;
                saveFileDialog1.InitialDirectory = Application.StartupPath;
                saveFileDialog1.RestoreDirectory = true;
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    using (TextWriter sw = new StreamWriter(saveFileDialog1.FileName))
                    {
                        sw.Write(BinarySerializer.Serialize(TableData));
                        sw.Close();
                    }
                }
            }

            ShowJoinTableData();
        }