예제 #1
0
        private void registButton_Click(object sender, EventArgs e)
        {
            int      reportId    = 0;
            string   radioButton = "";
            DateTime dt          = DateTime.Now;
            DateTime startDate   = dt;
            DateTime endDate     = dt;

            //レポートIDをもらいます
            reportId = report.ReportId;

            //ラジオボックスでチェックされたものを確認
            if (tell.Checked == true)
            {
                radioButton = "電話";
            }
            else if (mail.Checked == true)
            {
                radioButton = "メール";
            }
            else if (opponentHouse.Checked == true)
            {
                radioButton = "相手宅";
            }
            else if (their.Checked == true)
            {
                radioButton = "自社";
            }
            else if (another.Checked == true)
            {
                radioButton = "その他";
            }
            else

            {
                radioButton = null;
            }

            DateTime startdt = report.VisitStratDate;
            DateTime enddt   = report.VisitEndDate;

            string fromdate = (startdt.Year).ToString() + "/" + (startdt.Month).ToString() + "/" + (startdt.Day).ToString();
            string todate   = (enddt.Year).ToString() + "/" + (enddt.Month).ToString() + "/" + (enddt.Day).ToString();



            CommonValidater validater = new CommonValidater(fromdate, (startdt.Hour).ToString(), (startdt.Minute).ToString(), todate, enddt.Hour.ToString(), enddt.Minute.ToString(), customer.Text, radioButton, reportText.Text);

            Boolean commonValidateCheck = validater.InputCheck();

            if (commonValidateCheck == true)
            {
                startDate = validater.StartDateAll;
                endDate   = validater.EndDateAll;

                ////入力されたfrom日付をデータ型に結合
                //string str = fromDate.Text + " " + fromHour.Text + ":" + fromMinute.Text + ":" + "00";
                //startDate = DateTime.Parse(str);


                ////入力されたto日付をデータ型に結合
                //string str2 = toDate.Text + " " + toHour.Text + ":" + toMinute.Text + ":" + "00";
                //endDate = DateTime.Parse(str);


                DialogResult finalCheck = MessageBox.Show("登録完了後は編集ができなくなります。修正を完了してよろしいですか?",
                                                          "最終確認",
                                                          MessageBoxButtons.OKCancel,
                                                          MessageBoxIcon.Exclamation,
                                                          MessageBoxDefaultButton.Button2);

                if (finalCheck == DialogResult.OK)
                {
                    // 接続用のクラス
                    SqlConnection con = new SqlConnection();

                    // DBへの接続文字列。
                    con.ConnectionString = "data source=localhost\\SQLEXPRESS;" + // 接続先のDBサーバーを指定
                                           "initial catalog=zebradb;" +           // 接続先のDBを指定
                                           "user id=sa;" +                        // ユーザー
                                           "password=p@ssw0rd;" +                 // パスワード
                                           "Connect Timeout=60;";

                    try
                    {
                        con.Open(); // DBに接続

                        string sql =
                            "UPDATE dbo.TM_DAILY_REPORT " +
                            "SET UPDATE_DATE = @UPDATE_DATE, VISIT_STRAT_DATE = @VISIT_STRAT_DATE, " +
                            "VISIT_END_DATE= @VISIT_END_DATE, VISIT_TYPE= @VISIT_TYPE, DETAILS = @DETAIL, " +
                            "APPROVAL_STATUS = @APPROVAL_STATUS " +
                            "WHERE REPORT_ID = @REPORT_ID";

                        // コネクションオブジェクトを使用して、SQLの発行準備
                        SqlCommand command = new SqlCommand(sql, con);

                        command.Parameters.Add(
                            new SqlParameter("@UPDATE_DATE", dt));
                        command.Parameters.Add(
                            new SqlParameter("@VISIT_STRAT_DATE", startDate));
                        command.Parameters.Add(
                            new SqlParameter("@VISIT_END_DATE", endDate));
                        command.Parameters.Add(
                            new SqlParameter("@VISIT_TYPE", radioButton));
                        command.Parameters.Add(
                            new SqlParameter("@DETAIL", reportText.Text));
                        command.Parameters.Add(
                            new SqlParameter("@APPROVAL_STATUS", 1));
                        command.Parameters.Add(
                            new SqlParameter("@REPORT_ID", reportId));


                        // 更新を実行する
                        int ret = command.ExecuteNonQuery();

                        // 更新が成功したらMessageBox
                        if (ret == 1)
                        {
                            DialogResult result = MessageBox.Show("更新が完了しました", "確認ダイアログ", MessageBoxButtons.OK);

                            if (result == DialogResult.OK)
                            {
                                //this.Close();
                                //NGList ng = new NGList();
                                //ng.Show();
                                Debug.WriteLine("画面を表示後。"); // 子画面が閉じてから、実行される。

                                this.Close();
                            }
                            else
                            {
                                MessageBox.Show("error");
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
                else if (finalCheck == DialogResult.Cancel)
                {
                    //戻る
                }
            }
            //バリデーションチェックで引っかかるfalse
            else
            {
                //CommonValidateクラスからエラーメッセージ用のリストを取得
                List <string> errorList = validater.ErrorList;

                string messageAll = "";

                foreach (string errorMessage in errorList)
                {
                    messageAll += errorMessage + Environment.NewLine;
                }
                MessageBox.Show(messageAll);
            }
        }
예제 #2
0
         /// <summary>
         /// 「登録」ボタンを押下されたら入力値のValidateを行い、正常ならば日報DBに追加をする
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
        private void registButton_Click(object sender, EventArgs e)
        {
            //入力された記入日を取得
            string _createDate = createDate.Text;

            //訪問日時を取得
            string _fromDate   = fromDate.Text;
            string _fromHour   = fromHour.Text;
            string _fromMinute = fromMinute.Text;

            string _toDate   = toDate.Text;
            string _toHour   = toHour.Text;
            string _toMinute = toMinute.Text;

            //顧客を取得
            _customerId = customerId.Text;

            string visitType = "";

            //訪問種別を取得
            if (tell.Checked == true)
            {
                visitType = "電話";
            }
            else if (mail.Checked == true)
            {
                visitType = "メール";
            }
            else if (opponentHouse.Checked == true)
            {
                visitType = "相手宅";
            }
            else if (their.Checked == true)
            {
                visitType = "自社";
            }
            else if (another.Checked == true)
            {
                visitType = "その他";
            }

            //内容を取得
            string _reportText = reportText.Text;


            //入力情報をチェック

            CommonValidater validate = new CommonValidater(_fromDate, _fromHour, _fromMinute,
                                                           _toDate, _toHour, _toMinute, _customerId, visitType, _reportText);


            //Validateが通った場合、Insert実行
            if (validate.InputCheck())
            {
                //DateTime型の訪問日時を取得する
                DateTime _visitStart = validate.StartDateAll;
                DateTime _visitEnd   = validate.EndDateAll;

                // DBへの接続文字列。
                con.ConnectionString = "data source=localhost\\SQLEXPRESS;" + // 接続先のDBサーバーを指定
                                       "initial catalog=zebradb;" +           // 接続先のDBを指定
                                       "user id=sa;" +                        // ユーザー
                                       "password=p@ssw0rd;" +                 // パスワード
                                       "Connect Timeout=60;";

                try
                {
                    con.Open();     // DBに接続

                    // 問い合わせのSQLを生成
                    string sql =
                        "INSERT INTO TM_DAILY_REPORT" +
                        "(VISIT_STRAT_DATE, VISIT_END_DATE, CUS_ID, VISIT_TYPE, DETAILS, AUTHOR_ID, AUTHOR_BOSS_ID, BOSS_COMMENT, APPROVAL_STATUS)" +
                        "VALUES" +
                        "(@VISIT_STRAT_DATE, @VISIT_END_DATE, @CUS_ID, @VISIT_TYPE, @DETAILS, @AUTHOR_ID, @AUTHOR_BOSS_ID, @BOSS_COMMENT, 1); ";

                    // コネクションオブジェクトを使用して、SQLの発行準備
                    SqlCommand command = new SqlCommand(sql, con);


                    // パラメタに値を設定
                    command.Parameters.Add(new SqlParameter("@VISIT_STRAT_DATE", _visitStart));
                    command.Parameters.Add(new SqlParameter("@VISIT_END_DATE", _visitEnd));
                    command.Parameters.Add(new SqlParameter("@CUS_ID", _customerId));
                    command.Parameters.Add(new SqlParameter("@VISIT_TYPE", visitType));
                    command.Parameters.Add(new SqlParameter("@DETAILS", _reportText));
                    command.Parameters.Add(new SqlParameter("@AUTHOR_ID", userId));
                    command.Parameters.Add(new SqlParameter("@AUTHOR_BOSS_ID", bossId));
                    command.Parameters.Add(new SqlParameter("@BOSS_COMMENT", ""));

                    // 登録を実行する
                    int ret = command.ExecuteNonQuery();

                    // 登録が成功したら、完了メールを表示させてメインメニューへ遷移する
                    if (ret == 1)
                    {
                        MessageBox.Show("登録が完了しました。");

                        //Hide();
                        //MainMenu mainMenu = new MainMenu();
                        //mainMenu.Show(this);
                        this.Close();
                        Debug.WriteLine("トップページに飛びました");
                    }
                }
                catch (SqlException ex)
                {
                    Debug.WriteLine(ex.Message);
                }
                finally
                {
                    con.Close();
                }
            }
            //入力値が正常でなければ、エラーメッセージを表示させる
            else
            {
                //CommonValidateクラスからエラーメッセージ用のリストを取得
                List <string> errorList = validate.ErrorList;

                string messageAll = "";

                foreach (string errorMessage in errorList)
                {
                    messageAll += errorMessage + Environment.NewLine;
                }

                MessageBox.Show(messageAll);
            }
        }