コード例 #1
0
ファイル: GridInputTable.cs プロジェクト: ardud/ClassLibrary
        /// <summary>
        /// File|SaveFile
        /// Saves the content of the table stored in the control at the path selected by the user in the CSV
        /// format using a semicolon as a separator.
        /// All semicolons are replaced with the string SO+(int);+SI.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveToFileCSV(object sender, EventArgs e)
        {
            string DefaultDirectory = sender.ExtractTagInfo();

            if ((DefaultDirectory.Trim().Length > 0) && (System.IO.Directory.Exists(DefaultDirectory) == false))
            {
                throw new ArgumentException("There is no directory at the path " + DefaultDirectory);
            }

            MyTable ToCollect = TableInfo();///Puts into the variable ToCollect the content of the current instance

            ///Replace all semicolons
            for (int Iterator = 1; Iterator <= MyGridView2.RowCount; Iterator++)
            {
                for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.ColumnCount; ColumnIterator++)
                {
                    if (MyGridView2[ColumnIterator - 1, Iterator - 1].Value != null)
                    {
                        string Minu = MyGridView2[ColumnIterator - 1, Iterator - 1].Value.ToString();
                        if (MyStringOperations.AsciiSet3.Semicolon.Ist(Minu))
                        {
                            string ToReplace = MyStringOperations.C0Controls.SO.ToString() + Convert.ToString((int)MyStringOperations.AsciiSet3.Semicolon) +
                                               MyStringOperations.C0Controls.SI.ToString();
                            string ToPut = MyStringOperations.Replace(Minu, MyStringOperations.AsciiSet3.Semicolon.ToString(), ToReplace);
                            MyGridView2[ColumnIterator - 1, Iterator - 1].Value           = ToPut;
                            MyGridView2[ColumnIterator - 1, Iterator - 1].Style.BackColor = Color.Red;
                        }
                    }
                }
            }
            SaveFileDialog MyDialog = new SaveFileDialog();

            MyDialog.InitialDirectory = DefaultDirectory;
            DialogResult MyOutcome = MyDialog.ShowDialog();

            if (MyOutcome == DialogResult.OK)
            {
                ToCollect.SaveToCSV(MyDialog.FileName);
            }
            else
            {
                MessageBox.Show("Operation aborted");
            }

            CheckState();
        }