Пример #1
0
        } // OpenFileBTN END

        public int checkFileIsTextOrBinary(string strTmp, OpenFileRead_OR_Write file)       //檢查檔案為 Text 或是 Binary
        {
            int    intTmp;
            double doubleTmp;

            try
            {
                string[] strTmpArray = strTmp.Split(',');

                // TEXT //
                if ((int.TryParse(strTmpArray[0], out intTmp) && intTmp > 0) && (strTmpArray[1] != string.Empty) && (strTmpArray[2] != string.Empty) && (double.TryParse(strTmpArray[3], out doubleTmp)) && (double.TryParse(strTmpArray[4], out doubleTmp)) && (double.TryParse(strTmpArray[5], out doubleTmp)))
                {
                    checkFile = TEXT_FILE;
                    ToFile.FileReader.Close();
                }

                // BINARY //
                else
                {
                    file.input.Seek(0, SeekOrigin.Begin);
                    StudentRecord tmpRecord = (StudentRecord)binaryReader.Deserialize(file.input);
                    file.input.Seek(0, SeekOrigin.Begin);
                    checkFile = BINARY_FILE;
                    ToFile.FileReader.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(checkFile);
        } // checkFileIsTextOrBinary END