Пример #1
0
        private ReportItemCollection CreateReportItem(string[] fields)
        {
            try
            {
                if (fields.Length != 6)                                                 // 各区切りフィールドの数の確認。
                {
                    throw new ExceptionImportData();                                    // 各区切りフィールドの数が規定値と異なっていた場合は例外をスローする。
                }
            }
            catch (ExceptionImportData ExcImp)
            {
                ShowMyDialog.ShowInfoMessageBox(ExcImp.Message, "デバッグ用");                        // 例外のキャッチ。
            }

            ReportItemCollection importItem = new ReportItemCollection();               // 戻り値用にReportItemCollectionインスタンスを作成。

            importItem.ItemTitle = fields[0].TrimEnd();                                 // パラメータの配列field[0]の末尾から空白を取り除き、一旦ReportItemCollectionインスタンスのItemTitleプロパティに格納。
            if (importItem.ItemTitle.Length == 0 || importItem.ItemTitle.Length > 32)   // ReportItemCollectionのItemTitleプロパティが0文字あるいは32文字より多いかを確認。
            {
                throw new ExceptionImportData();                                        // 0文字あるいは32文字より多い場合は例外をスローする。
            }

            DateTime _tmpDate;                                                          // パラメータの配列field[1]が日付に変換出来るか確認するためのDateTime構造体。
            if (!DateTime.TryParse(fields[1], out _tmpDate))                            // パラメータの配列field[1]が日付に変更出来るかを確認。
            {
                throw new ExceptionImportData();                                        // 日付に変更出来ない場合は例外をスローする。
            }
            importItem.ItemDate = _tmpDate;                                             // 日付に変更出来る場合は、ReportItemCollectionのItemDateプロパティに格納。

            importItem.ItemType = fields[2].TrimEnd();                                  // パラメータの配列field[2]の末尾から空白を取り除き、一旦ReportItemCollectionインスタンスのItemTypeプロパティに格納。
            if (!(importItem.ItemType.Equals("議事録") ||                               // ReportItemCollectionのItemTypeプロパティが"議事録"あるいは"業務案件"あるいは"業務知識"あるいは"提出物"の何れかであるかを確認。
                  importItem.ItemType.Equals("業務案件") ||
                  importItem.ItemType.Equals("業務知識") ||
                  importItem.ItemType.Equals("提出物") ||
                  importItem.ItemType.Equals("その他")))
            {
                throw new ExceptionImportData();                                        // "議事録"あるいは"業務案件"あるいは"業務知識"あるいは"提出物"の何れかでない場合は例外をスローする。
            }

            ConversionRegular convertString = new ConversionRegular();                  // ConversionRegularインスタンス(置き換え文字の置き換えを行う)作成。
            convertString.TextImportConvert(fields[3].TrimEnd());                       // 特殊な置き換え文字を改行文字変更する。
            importItem.ItemContent = convertString.ImportString;                        // パラメータの配列field[3]の末尾から空白を取り除き、一旦ReportItemCollectionインスタンスのItemContentプロパティに格納。
            if (importItem.ItemContent.Length == 0 ||                                   // 0文字あるいは1000文字より多い場合は例外をスローする。
                importItem.ItemContent.Length > ItemContent)
            {
                throw new ExceptionImportData();
            }

            bool _tmpBool;                                                              // パラメータの配列field[4]がbool値に変換出来るかを確認する為の変数。
            if (!bool.TryParse(fields[4], out _tmpBool))                                // パラメータの配列field[4]がbool値に変換出来るかを確認。
            {
                throw new ExceptionImportData();                                        // bool値に変換出来ない場合は例外をスローする。
            }
            importItem.AlarmOrNotFlag = _tmpBool;                                       // bool値に変換出来る場合は、ReportItemCollectionのAlarmOrNotFlagプロパティに格納。

            importItem.AlarmType = fields[5].TrimEnd();                                 // パラメータの配列field[5]の末尾から空白を取り除き、一旦ReportItemCollectionインスタンスのAlarmTypeプロパティに格納。
            if (!(importItem.AlarmType.Equals("アラームなし") ||                        // ReportItemCollectionのAlarmTypeプロパティがあるいは"アラーム1"あるいは"アラーム2"あるいは"アラーム3"あるいは"アラーム4"の何れかであるかを確認。
                  importItem.AlarmType.Equals("アラーム1") ||
                  importItem.AlarmType.Equals("アラーム2") ||
                  importItem.AlarmType.Equals("アラーム3") ||
                  importItem.AlarmType.Equals("アラーム4") ||
                  importItem.AlarmType.Equals("アラーム5") ||
                  importItem.AlarmType.Equals("アラーム6")))

            {
                throw new ExceptionImportData();                                         // "アラーム1"あるいは"アラーム2"あるいは"アラーム3"あるいは"アラーム4"の何れかでない場合は例外をスローする。
            }

            return importItem;                                                          // フォーマットの確認が完了し、各区切りフィールドの内容を格納したReportItemCollectionインスタンスを戻す。
        }