Beispiel #1
0
        protected void NewActionLinkButton_Click(object sender, EventArgs e)
        {
            // 新しいIDを取得する(最大値+1)
            int newID = GetNewActionID();

            if (newID == -1)
            {
                // IDの取得に失敗したとき
                MessageLabel.Text = "IDの取得に失敗しました。データベースを確認してください。";
                return;
            }

            // 新規行挿入用のSQLステートメントを定義する
            string queryString = "INSERT INTO tbl_action" +
                                 " (ID, customerID, action_date, action_content, action_staffID) " +
                                 " VALUES (" + newID + "," + Request.QueryString["id"] + ",'" + DateTime.Today +
                                 "'," + "'★新規営業報告データ★'," + Session["StaffID"] + ")";

            try
            {
                // 接続文字列を取得する
                string connectionString = System.Configuration.ConfigurationManager.
                                          ConnectionStrings["customer_actionConnectionString"].ConnectionString;

                // コネクションを定義する
                using (SqlConnection connection = new SqlConnection(connectionString))
                {
                    // コマンドを定義する
                    SqlCommand command = new SqlCommand(queryString, connection);

                    // コネクションを開く
                    connection.Open();

                    // コマンドに定義したSQLステートメントを実行する
                    command.ExecuteNonQuery();

                    // グリッドビューを再バインドしてデータを読み込み直す
                    ActionListGridView.DataBind();

                    // 結果のメッセージを表示する
                    MessageLabel.Text = "新しいデータを追加しました。";
                }
            }
            catch (Exception ex)
            {
                // エラーが発生したとき
                MessageLabel.Text = "エラーが発生したため、処理を中止します。<br />" + ex.Message;
            }
        }
Beispiel #2
0
 private void btnDelete_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
 {
     try
     {
         if (ActionListGridView.GetFocusedRow() is ActionLists item)
         {
             UnitOfWork unitOfWork = new UnitOfWork();
             unitOfWork.ActionListsRepo.Delete(m => m.Id == item.Id);
             unitOfWork.Save();
             Init();
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }