Esempio n. 1
0
        public void TestWorkflow(string dearSirUID, string fromUserID, string userID, string dearSirPTitleId, string[] actionType, string[] workflowNo,
                                 string[] expectedToUserID, Boolean isReturn, string currentWorkflowReserveArea, DateTime replyDeadlineDate,
                                 Boolean isTurnBack, Boolean isForcedTermination, Boolean isTurnbackSlipIssuance, Boolean isSwitchPersonInCharge)
        {
            DataTable dt = null;

            try
            {
                string subSystemId;
                string workflowName = string.Empty;
                DataRow startWorkflow = null;
                DataRow selectedRow = null;

                workflowName = GetConfigParameter.GetConfigValue("WorkflowName");
                subSystemId = GetConfigParameter.GetConfigValue("SubSystemId");

                // GetUserInfoDelegateの設定
                if (Workflow.GetUserInfo == null)
                {
                    Workflow.GetUserInfo = new GetUserInfoDelegate(MyGetUserInfo);
                }

                dt = new DataTable();
                DataTable dt1 = null;
                DataTable dt2 = null;

                InitDam();

                // Creating instance of Workflow class
                Workflow wf = new Workflow(this._dam);

                int mailTemplateId = 0;
                if (workflowNo[0] == "1")
                {

                    HelperClass.WorkflowControlNumber = Guid.NewGuid().ToString();

                    dt1 = wf.PreStartWorkflow(
                     subSystemId, workflowName, 1);

                    dt2 = wf.PreStartWorkflow(
                        subSystemId, workflowName, 2);

                    //  開始可能なワークフローを表示
                    if (dt1 != null)
                    {
                        dt.Merge(dt1);
                    }
                    if (dt2 != null)
                    {
                        dt.Merge(dt2);
                    }

                    selectedRow = dt.Rows[0];
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (selectedRow != null)
                            if ((decimal)dr[0] == (decimal)selectedRow[0])
                            {
                                startWorkflow = dr;
                            }
                    }

                    mailTemplateId = wf.StartWorkflow(startWorkflow, HelperClass.WorkflowControlNumber, decimal.Parse(fromUserID), decimal.Parse(userID),
                                                      "ReserveArea", "CurrentWorkflowReserveArea", DateTime.Now);
                }

                dt = new DataTable();

                // 御中ID
                if (!string.IsNullOrEmpty(dearSirUID)
                    && !string.IsNullOrEmpty(dearSirPTitleId))
                {
                    // Calling GetWfRequest
                    dt1 = wf.GetWfRequest(subSystemId, workflowName, HelperClass.WorkflowControlNumber, decimal.Parse(dearSirUID), int.Parse(dearSirPTitleId));
                }
                // 個人ID
                if (!string.IsNullOrEmpty(userID))
                {
                    // Calling GetWfRequest
                    dt2 = wf.GetWfRequest(subSystemId, workflowName, HelperClass.WorkflowControlNumber, decimal.Parse(userID), null);
                }

                //  開始可能なワークフローを表示
                if (dt1 != null)
                {
                    dt.Merge(dt1);
                }
                if (dt2 != null)
                {
                    dt.Merge(dt2);
                }

                // Commit transactions
                this._dam.CommitTransaction();

                // Assert tests
                Assert.AreEqual(expectedToUserID[0], dt.Rows[0]["ToUserId"].ToString());
                Assert.AreEqual(fromUserID, dt.Rows[0]["FromUserId"].ToString());
                Assert.AreEqual(actionType[0], dt.Rows[0]["ActionType"].ToString());
                Assert.AreEqual(workflowNo[0], dt.Rows[0]["WorkflowNo"].ToString());
                Assert.AreEqual(subSystemId, dt.Rows[0]["SubSystemId"].ToString());
                Assert.AreEqual(workflowName, dt.Rows[0]["WorkflowName"].ToString());

                selectedRow = dt.Rows[0];
                DataRow workflowRequest = null;
                foreach (DataRow dr in dt.Rows)
                {
                    if ((string)dr[0] == (string)selectedRow[0])
                    {
                        workflowRequest = dr;
                    }
                }

                // Calling AcceptWfRequest                
                wf.AcceptWfRequest(workflowRequest, decimal.Parse(userID));

                // Commit transactions
                this._dam.CommitTransaction();

                // Assert tests
                Assert.AreEqual(expectedToUserID[0], dt.Rows[0]["ToUserId"].ToString());
                Assert.AreEqual(fromUserID, dt.Rows[0]["FromUserId"].ToString());
                Assert.AreEqual(actionType[0], dt.Rows[0]["ActionType"].ToString());
                Assert.AreEqual(workflowNo[0], dt.Rows[0]["WorkflowNo"].ToString());
                Assert.AreEqual(subSystemId, dt.Rows[0]["SubSystemId"].ToString());
                Assert.AreEqual(workflowName, dt.Rows[0]["WorkflowName"].ToString());

                // Calling GetProcessingWfRequest
                dt = wf.GetProcessingWfRequest(subSystemId, workflowName, HelperClass.WorkflowControlNumber, decimal.Parse(userID));

                // Commit transactions
                this._dam.CommitTransaction();

                // Assert tests
                Assert.AreEqual(expectedToUserID[0], dt.Rows[0]["ToUserId"].ToString());
                Assert.AreEqual(fromUserID, dt.Rows[0]["FromUserId"].ToString());
                Assert.AreEqual(actionType[0], dt.Rows[0]["ActionType"].ToString());
                Assert.AreEqual(workflowNo[0], dt.Rows[0]["WorkflowNo"].ToString());
                Assert.AreEqual(subSystemId, dt.Rows[0]["SubSystemId"].ToString());
                Assert.AreEqual(workflowName, dt.Rows[0]["WorkflowName"].ToString());

                selectedRow = dt.Rows[0];

                // 処理中ワークフロー依頼を取得
                DataRow processingWfReq = null;

                foreach (DataRow dr in dt.Rows)
                {
                    if ((string)dr[0] == (string)selectedRow[0])
                    {
                        processingWfReq = dr;
                    }
                }

                if (!string.IsNullOrEmpty(dearSirUID))
                {
                    dt1 = wf.GetNextWfRequest(processingWfReq, decimal.Parse(dearSirUID));
                }
                if (!string.IsNullOrEmpty(userID.ToString()))
                {
                    dt2 = wf.GetNextWfRequest(processingWfReq, decimal.Parse(userID));
                }

                //  次のワークフロー依頼を表示
                dt = new DataTable();

                if (dt1 != null)
                {
                    dt.Merge(dt1);
                }
                if (dt2 != null)
                {
                    dt.Merge(dt2);
                }

                // Commit transactions
                this._dam.CommitTransaction();

                // Assert tests
                Assert.AreEqual(expectedToUserID[1], dt.Rows[0]["ToUserId"].ToString());
                Assert.AreEqual(userID, dt.Rows[0]["FromUserId"].ToString());
                Assert.AreEqual(actionType[1], dt.Rows[0]["ActionType"].ToString());
                Assert.AreEqual(workflowNo[1], dt.Rows[0]["WorkflowNo"].ToString());
                Assert.AreEqual(subSystemId, dt.Rows[0]["SubSystemId"].ToString());
                Assert.AreEqual(workflowName, dt.Rows[0]["WorkflowName"].ToString());

                if (dt.Rows.Count > 3)
                {
                    // Assert tests
                    Assert.AreEqual(expectedToUserID[3], dt.Rows[1]["ToUserId"].ToString());
                    Assert.AreEqual(fromUserID, dt.Rows[1]["FromUserId"].ToString());
                    Assert.AreEqual(actionType[2], dt.Rows[1]["ActionType"].ToString());
                    Assert.AreEqual(workflowNo[1], dt.Rows[1]["WorkflowNo"].ToString());
                    Assert.AreEqual(subSystemId, dt.Rows[1]["SubSystemId"].ToString());
                    Assert.AreEqual(workflowName, dt.Rows[1]["WorkflowName"].ToString());
                }

                if (isTurnBack)
                {
                    selectedRow = dt.Rows[0];
                }
                else
                {
                    selectedRow = dt.Rows[1];
                }

                DataRow nextWorkflow = null;
                foreach (DataRow dr in dt.Rows)
                {
                    if ((decimal)dr[0] == (decimal)selectedRow[0])
                    {
                        nextWorkflow = dr;
                    }
                }

                // GetTurnBackToUser, StartWorkflow
                wf = new Workflow(this._dam);

                // fromUserIDを取得

                decimal? toUserId = null;

                if (isReturn
                    && (string)nextWorkflow["ActionType"] == "TurnBack")
                {
                    // TurnBack(送信元に差戻)
                    toUserId = wf.GetTurnBackToUser(nextWorkflow, HelperClass.WorkflowControlNumber);
                }
                else if (isReturn
                    && (string)nextWorkflow["ActionType"] == "Reply")
                {
                    // Reply(送信元に返信)
                    toUserId = wf.GetReplyToUser(nextWorkflow, HelperClass.WorkflowControlNumber);
                }
                else if ((string)nextWorkflow["ActionType"] == "End")
                {
                    // End
                    toUserId = null;
                }
                else
                {
                    // TurnBack, Reply, End以外
                    // nextWorkflow["ToUserId"]を使用する。
                }

                // Calling RequestWfApproval
                mailTemplateId = wf.RequestWfApproval(nextWorkflow, HelperClass.WorkflowControlNumber, decimal.Parse(fromUserID), toUserId, currentWorkflowReserveArea, replyDeadlineDate);

                // Calling TurnbackSlipIssuanceUserID based on flag
                if (isTurnbackSlipIssuance)
                {
                    wf.TurnbackSlipIssuanceUserID(subSystemId, HelperClass.WorkflowControlNumber, decimal.Parse(fromUserID), 1m, currentWorkflowReserveArea);
                }
                // Calling SwitchPersonInCharge based on flag
                if (isSwitchPersonInCharge)
                {
                    wf.SwitchPersonInCharge(nextWorkflow, HelperClass.WorkflowControlNumber);
                }
                //Calling ForcedTermination based on flag
                if (isForcedTermination)
                {
                    wf.ForcedTermination(nextWorkflow, HelperClass.WorkflowControlNumber, decimal.Parse(fromUserID), currentWorkflowReserveArea);
                }

                // Commit transactions
                this._dam.CommitTransaction();

                // Assert tests
                Assert.Greater(mailTemplateId, 0);
                Assert.AreEqual(workflowNo[1], dt.Rows[0]["WorkflowNo"].ToString());
                Assert.AreEqual(subSystemId, dt.Rows[0]["SubSystemId"].ToString());
                Assert.AreEqual(workflowName, dt.Rows[0]["WorkflowName"].ToString());
            }
            catch (Exception ex)
            {
                if (dt != null)
                {
                    // Rollback transactions
                    this._dam.RollbackTransaction();
                }
                Console.WriteLine(ex.ToString());
            }
        }
Esempio n. 2
0
        /// <summary>ワークフロー承認を依頼します。</summary>
        private void button7_Click(object sender, EventArgs e)
        {
            // Damの初期化
            this.InitDam();

            try
            {
                // ワークフロー承認依頼を取得
                DataRow nextWorkflow = null;
                DataTable dt = (DataTable)this.dataGridView1.DataSource;

                DataGridViewRow dgvr = (this.dataGridView1.SelectedRows[0]);
                foreach (DataRow dr in dt.Rows)
                {
                    if ((decimal)dr[0] == (decimal)dgvr.Cells[0].Value)
                    {
                        nextWorkflow = dr;
                    }
                }

                // GetTurnBackToUser, StartWorkflow
                Workflow wf = new Workflow(this._dam);

                // fromUserIDを取得
                decimal fromUserId = decimal.Parse(this.txtUserID.Text);

                decimal? toUserId = null;

                // if ToUserId textbox value is not empty
                if (!string.IsNullOrEmpty(txtToUserID.Text))
                {
                    // if Action type is either TurnBack or Reply then set ToUserId otherwise check for DBNull
                    if (string.Equals(nextWorkflow["ActionType"].ToString(), "TurnBack") || string.Equals(nextWorkflow["ActionType"].ToString(), "Reply"))
                    {
                        toUserId = decimal.Parse(txtToUserID.Text);
                    }
                    else if (nextWorkflow["ToUserId"] == DBNull.Value)
                    {
                        toUserId = decimal.Parse(txtToUserID.Text);
                    }
                }

                if (this.checkBox1.Checked
                    && (string)nextWorkflow["ActionType"] == "TurnBack")
                {
                    // TurnBack(送信元に差戻)
                    toUserId = wf.GetTurnBackToUser(nextWorkflow, this.txtWorkflowControlNo.Text);
                }
                else if (this.checkBox1.Checked
                    && (string)nextWorkflow["ActionType"] == "Reply")
                {
                    // Reply(送信元に返信)
                    toUserId = wf.GetReplyToUser(nextWorkflow, this.txtWorkflowControlNo.Text);
                }
                else if ((string)nextWorkflow["ActionType"] == "End")
                {
                    // End
                    toUserId = null;
                }
                else
                {
                    // TurnBack, Reply, End以外
                    // nextWorkflow["ToUserId"]を使用する。                   
                }

                int mailTemplateId = 0;
                mailTemplateId = wf.RequestWfApproval(
                    nextWorkflow, this.txtWorkflowControlNo.Text, fromUserId, toUserId,
                    this.txtCurrentWorkflowReserveArea2.Text, this.dtpReplyDeadline2.Value);

                // ★ ココでメールを送信。

                this._dam.CommitTransaction();
            }
            catch (Exception ex)
            {
                this._dam.RollbackTransaction();

                MessageBox.Show(
                    "Message:" + ex.Message + "\n" + "StackTrace:" + ex.StackTrace,
                    ResourceMgr.GetString("E0001"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this._dam.ConnectionClose();
            }
        }