Beispiel #1
0
        /// <summary>
        ///     保存期間経過したデータの削除 </summary>
        private void dataDelete()
        {
            guideDataSet dts = new guideDataSet();

            guideDataSetTableAdapters.メール設定TableAdapter    adp  = new guideDataSetTableAdapters.メール設定TableAdapter();
            guideDataSetTableAdapters.ガイド依頼名TableAdapter   gAdp = new guideDataSetTableAdapters.ガイド依頼名TableAdapter();
            guideDataSetTableAdapters.ガイド依頼対象者TableAdapter mAdp = new guideDataSetTableAdapters.ガイド依頼対象者TableAdapter();

            this.Cursor = Cursors.WaitCursor;

            // データ読み込み
            adp.Fill(dts.メール設定);
            gAdp.Fill(dts.ガイド依頼名);
            mAdp.Fill(dts.ガイド依頼対象者);

            DateTime dt;

            if (dts.メール設定.Any(a => a.ID == guideRequest.common.global.mailKey))
            {
                var s = dts.メール設定.Single(a => a.ID == guideRequest.common.global.mailKey);

                if (s.データ保存月数 != 0)
                {
                    // 基準年月日
                    dt = DateTime.Today.AddMonths(-1 * s.データ保存月数);

                    // ガイド依頼対象者データ削除
                    foreach (var g in dts.ガイド依頼対象者
                             .Where(a => a.ガイド依頼名Row != null && a.ガイド依頼名Row.登録年月日 < dt))
                    {
                        g.Delete();
                    }

                    // ガイド依頼名データ削除
                    foreach (var t in dts.ガイド依頼名.Where(a => a.登録年月日 < dt))
                    {
                        // ガイド依頼データ削除
                        t.Delete();
                    }

                    // データベース更新
                    gAdp.Update(dts.ガイド依頼名);
                    mAdp.Update(dts.ガイド依頼対象者);
                }
            }

            this.Cursor = Cursors.Default;
        }
Beispiel #2
0
        ///----------------------------------------------------------------------------------
        /// <summary>
        ///     ガイド依頼対象者抽出処理 </summary>
        /// <param name="pFile">
        ///     ピックアップリストパス</param>
        /// <param name="iDt">
        ///     依頼日</param>
        ///----------------------------------------------------------------------------------
        private void searchData(string pFile, DateTime iDt, DateTime iDt2)
        {
            // 依頼番号(ID)を取得
            DateTime dt = DateTime.Now;

            selNum = long.Parse((dt.Year - 2000).ToString() + dt.Month.ToString().PadLeft(2, '0') + dt.Day.ToString().PadLeft(2, '0') + dt.Hour.ToString().PadLeft(2, '0') + dt.Minute.ToString().PadLeft(2, '0') + dt.Second.ToString().PadLeft(2, '0'));

            // 依頼日(期間) : 2016/02/25
            DateTime sDt  = DateTime.Parse(iDt.ToShortDateString());
            DateTime sDt2 = DateTime.Parse(iDt2.ToShortDateString());

            //マウスポインタを待機にする
            this.Cursor = Cursors.WaitCursor;

            Excel.Application oXls = new Excel.Application();

            Excel.Workbook oXlsBook = (Excel.Workbook)(oXls.Workbooks.Open(pFile, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                           Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                           Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                                           Type.Missing, Type.Missing));

            Excel.Worksheet oxlsSheet = (Excel.Worksheet)oXlsBook.Sheets[1];

            Excel.Range   dRng;
            Excel.Range[] rng = new Microsoft.Office.Interop.Excel.Range[2];

            int dCnt = 0;

            // 列番号
            const int colHotel   = 9;
            const int colSonota1 = 10;
            const int colSonota2 = 11;
            const int colNum     = 1;
            const int colMail    = 8;

            try
            {
                // 読み込み開始行
                int fromRow = 2;

                // 利用領域行数を取得
                int toRow = oxlsSheet.UsedRange.Rows.Count;

                // エクセルシートの行を順次読み込む
                for (int i = fromRow; i <= toRow; i++)
                {
                    string hCode = string.Empty;

                    // 2016/02/02
                    //dRng = (Excel.Range)oxlsSheet.Cells[i, colHotel];
                    //hCode = dRng.Text.ToString().Trim();

                    //// 対象者か?
                    //if (hCode == string.Empty)
                    //{
                    //    continue;
                    //}

                    if (cmbKbn.SelectedIndex == 0)  // 依頼区分:ホテル 2016/02/01
                    {
                        // ホテル業務列の値を取得します
                        dRng  = (Excel.Range)oxlsSheet.Cells[i, colHotel];
                        hCode = dRng.Text.ToString().Trim();

                        // 対象者か?
                        if (hCode == string.Empty)
                        {
                            continue;
                        }
                    }
                    else if (cmbKbn.SelectedIndex == 1)  // 依頼区分:その他 2016/02/01
                    {
                        // 団体インセンティブ列の値を取得します
                        dRng  = (Excel.Range)oxlsSheet.Cells[i, colSonota1];
                        hCode = dRng.Text.ToString().Trim();

                        // 対象者か?
                        if (hCode == string.Empty)
                        {
                            // 普通の観光列の値を取得します
                            dRng  = (Excel.Range)oxlsSheet.Cells[i, colSonota2];
                            hCode = dRng.Text.ToString().Trim();

                            // 対象者か?
                            if (hCode == string.Empty)
                            {
                                continue;
                            }
                        }
                    }


                    // カード番号を取得します
                    dRng = (Excel.Range)oxlsSheet.Cells[i, colNum];
                    string sNum = dRng.Text.ToString().Trim();

                    // メールアドレスを取得します
                    dRng = (Excel.Range)oxlsSheet.Cells[i, colMail];
                    string sMail = dRng.Text.ToString().Trim();

                    // 会員稼働予定テーブルを参照
                    if (getSchedule(double.Parse(sNum), iDt, iDt2))
                    {
                        // 稼働可能のときガイド依頼対象者テーブルに追加
                        guideDataUpdate(double.Parse(sNum), sMail, selNum);
                        dCnt++;
                    }
                }

                if (dCnt > 0)
                {
                    // ガイド依頼名テーブル登録
                    guideNameUpdate(selNum);

                    // データベース更新
                    gAdp.Update(dts.ガイド依頼対象者);
                    adp.Update(dts.ガイド依頼名);

                    // 抽出者一覧表示
                    pickUpDataList(selNum);
                }
                else
                {
                    dg1.Rows.Clear();
                }

                //マウスポインタを元に戻す
                this.Cursor = Cursors.Default;

                //保存処理
                oXls.DisplayAlerts = false;

                // 終了メッセージ
                MessageBox.Show("ガイド依頼対象者の抽出が終了しました。" + Environment.NewLine + Environment.NewLine + dCnt.ToString() + "件のデータを抽出しました。", "結果", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            catch (Exception e)
            {
                MessageBox.Show(e.Message, "エクセルシートオープンエラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            finally
            {
                //Bookをクローズ
                oXlsBook.Close(Type.Missing, Type.Missing, Type.Missing);

                //Excelを終了
                oXls.Quit();

                // COM オブジェクトの参照カウントを解放する
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oxlsSheet);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oXlsBook);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(oXls);

                //マウスポインタを元に戻す
                this.Cursor = Cursors.Default;
            }
        }
Beispiel #3
0
        ///-----------------------------------------------------------------------------
        /// <summary>
        ///     依頼メールを送信する </summary>
        /// <param name="toAddress">
        ///     </param>
        /// <param name="sSubject">
        ///     メール件名</param>
        /// <param name="sMailText">
        ///     メール本文</param>
        /// <param name="SubjectOp">
        ///     </param>
        /// <param name="toStatus">
        ///     true:宛名差し込みする、false:宛名差し込みしない</param>
        /// <param name="reStatus">
        ///     結果 1:選考、0:お断り</param>
        /// <param name="testFlg">
        ///     0:本送信、1:テスト送信</param>
        ///-----------------------------------------------------------------------------
        private void sendRequestMail(string toAddress, string sSubject, string sMailText, string SubjectOp, bool toStatus, int reStatus, int testFlg)
        {
            // メール設定情報
            guideDataSet.メール設定Row r = dts.メール設定.Single(a => a.ID == global.mailKey);

            // smtpサーバーを指定する
            SmtpClient client = new SmtpClient();

            client.Host        = r.SMTPサーバー;
            client.Port        = r.SMTPポート番号;
            client.Credentials = new System.Net.NetworkCredential(r.ログイン名, r.パスワード);
            client.EnableSsl   = false;
            client.Timeout     = 10000;

            //メッセージインスタンス生成
            MailMessage message = new MailMessage();

            //送信元
            message.From = new MailAddress(r.メールアドレス, r.メール名称);

            //件名
            message.Subject = sSubject;

            // Cc
            if (txtCc.Text != string.Empty)
            {
                message.CC.Add(new MailAddress(txtCc.Text));
            }

            // Bcc
            if (txtBcc.Text != string.Empty)
            {
                message.Bcc.Add(new MailAddress(txtBcc.Text));
            }

            // 送信メールカウント
            int mCnt = 0;

            try
            {
                // 送信先テストモード
                if (Properties.Settings.Default.mailTest == global.FLGON)
                {
                    // テスト送信先
                    string[] toAdd = { "*****@*****.**", "*****@*****.**", "*****@*****.**" };

                    for (int i = 0; i < toAdd.Length; i++)
                    {
                        // 宛先
                        message.To.Clear();
                        message.To.Add(new MailAddress(toAdd[i]));

                        // 複数送信の時、2件目以降のCc/Bcc設定はクリアする
                        if (mCnt > 0)
                        {
                            message.CC.Clear();
                            message.Bcc.Clear();
                        }

                        // 本文
                        if (toStatus)
                        {
                            // 宛名氏名を差し込む
                            string toSama = dg1[C_Name, i].Value.ToString() + "様" + Environment.NewLine + Environment.NewLine;
                            message.Body = toSama + sMailText;
                        }
                        else
                        {
                            message.Body = sMailText;
                        }

                        // 送信する
                        client.Send(message);

                        // 送信ログ書き込み
                        DateTime nDt = DateTime.Now;
                        mllogUpdate("", toAdd[i], r.メール名称, r.メールアドレス, sSubject, sMailText, nDt);

                        // カウント
                        mCnt++;
                    }
                }
                else if (Properties.Settings.Default.mailTest == global.FLGOFF)
                {
                    // 本番用:グリッドから送付先を読み込む
                    for (int i = 0; i < dg1.RowCount; i++)
                    {
                        // メールアドレスの記入あり
                        if (dg1[C_MailAddress, i].Value != null)
                        {
                            string toAdd  = "";
                            string toName = "";

                            // テスト?本送信?
                            if (testFlg == global.FLGOFF)
                            {
                                // 本送信
                                toAdd  = dg1[C_MailAddress, i].Value.ToString();
                                toName = utility.NulltoStr(dg1[C_Name, i].Value);
                            }
                            else if (testFlg == global.FLGON)
                            {
                                // テスト送信
                                toAdd  = r.メールアドレス;
                                toName = r.メール名称;
                            }

                            //宛先
                            message.To.Clear();
                            message.To.Add(new MailAddress(toAdd, toName));

                            // 複数送信の時、2件目以降のCc/Bcc設定はクリアする
                            if (mCnt > 0)
                            {
                                message.CC.Clear();
                                message.Bcc.Clear();
                            }

                            // 本文
                            if (toStatus)
                            {
                                // 宛名氏名を差し込む
                                string toSama = dg1[C_Name, i].Value.ToString() + " 様" + Environment.NewLine + Environment.NewLine;
                                message.Body = toSama + sMailText;
                            }
                            else
                            {
                                message.Body = sMailText;
                            }

                            // 送信する
                            client.Send(message);

                            // 本送信の時
                            if (testFlg == global.FLGOFF)
                            {
                                DateTime nDt = DateTime.Now;

                                // ガイド依頼名テーブルに選考、断り送信日時を書き込む
                                iraiMLSendDateUpdate(nDt, reStatus);

                                // 対象者データに結果送信日時を書き込む
                                guideSendUpdate(int.Parse(dg1[C_reqID, i].Value.ToString()), reStatus, nDt);

                                // 送信ログ書き込み
                                mllogUpdate(toName, toAdd, r.メール名称, r.メールアドレス, sSubject, sMailText, nDt);
                            }

                            // カウント
                            mCnt++;
                        }
                    }
                }
            }
            catch (SmtpException ex)
            {
                //エラーメッセージ
                MessageBox.Show(ex.Message, "メール送信エラー", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            finally
            {
                // 送信あり
                if (mCnt > 0)
                {
                    MessageBox.Show(mCnt.ToString() + "件の" + comboBox2.Text + "メールを送信しました");

                    // 本送信の時
                    if (testFlg == global.FLGOFF)
                    {
                        // データベース更新
                        lAdp.Update(dts.メール送受信記録);
                        gAdp.Update(dts.ガイド依頼対象者);
                        adp.Update(dts.ガイド依頼名);
                    }
                }

                message.Dispose();
            }
        }