Exemplo n.º 1
0
        // QAのスーパーユーザーに限って、複数トレーの一括キャンセルができる(パック後は不可)
        private void btnCancelMultiTray_Click(object sender, EventArgs e)
        {
            if (dgvTray.Rows.Count <= 0)
            {
                return;
            }

            // セルの選択範囲が2列以上の場合は、メッセージの表示のみでプロシージャを抜ける
            if (dgvTray.Columns.GetColumnCount(DataGridViewElementStates.Selected) >= 2)
            {
                MessageBox.Show("Please select only tray id column.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                return;
            }
            // 列名が正しい場合のみ、処理を行う
            if (dgvTray.Columns[dgvTray.CurrentCell.ColumnIndex].Name != "tray_id")
            {
                MessageBox.Show("Please select only tray id column.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);
                return;
            }

            // パック済みトレーがないか、確認する
            foreach (DataGridViewCell cell in dgvTray.SelectedCells)
            {
                if (dgvTray["pack_id", cell.RowIndex].Value.ToString() != string.Empty ||
                    dgvTray["cl_dept", cell.RowIndex].Value.ToString() != string.Empty)
                {
                    MessageBox.Show(cell.Value.ToString() + " has been packed or canceled already.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                    return;
                }
            }

            // 本当に削除してよいか、2重で確認する。
            DialogResult result1 = MessageBox.Show("Do you really want to cancel this tray?", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (result1 == DialogResult.No)
            {
                return;
            }
            DialogResult result2 = MessageBox.Show("Are you really sure? Please select NO if you are not sure.", "Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (result2 == DialogResult.No)
            {
                return;
            }

            // 選択セルを配列に格納、およびメッセージ用文字列を生成し、一括キャンセルSQLコマンドを実行
            string[] traylist = { };
            string   message  = string.Empty;
            int      i        = 0;

            foreach (DataGridViewCell cell in dgvTray.SelectedCells)
            {
                if (dgvTray["cl_dept", cell.RowIndex].Value.ToString() == string.Empty)
                {
                    i += 1;
                    Array.Resize(ref traylist, i);
                    traylist[i - 1] = cell.Value.ToString();
                    message         = message + Environment.NewLine + cell.Value.ToString();
                }
            }
            if (message == string.Empty)
            {
                MessageBox.Show("No tray ID was selected.", "Notice", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            TfSQL tf  = new TfSQL();
            bool  res = tf.sqlMultipleCancelModuleInTray(traylist, txtLoginDept.Text, txtLoginName.Text);

            if (res)
            {
                //本フォームのデータグリットビュー更新
                dtTray.Clear();
                updateDataGridViews(dtTray, ref dgvTray, false);
                MessageBox.Show("The following " + i + " tray IDs were canceled: " + message, "Process Result", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Cancel process was not successful.", "Process Result", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }