JavaScriptとACCESSでちょこっとやってみたその6

さてDailyReportView.jsです。ここは、テーブルの動的変更部分で
結構ベタベタなことしてます。テーブル表示の部分をシンプルにしたいのと。
同一の案件ならセル結合させたいなぁと思っていますが、
そこまでスキルがついて来なかった。EXCELのセル結合みたいな感じに
したいと思いましたが断念

参考にさせてもらったサイト、ありがとうございます。
http://www.abe-tatsuya.com/web_prog/javascript/add_table_rows.php
http://www.yscjp.com/doc/table1.html

DailyReportView.js

var EmpCd=location.search.substring(1);     //ログイン画面から担当者CD取得

onload = init;
onunload = dbClose;

//*
//* 初期設定をする関数
//*
function init() {
    //実績日表示
    txtReportday = document.getElementById("txtReportday");
    var txtdate = new DateFormat("yyyy/MM/dd");
    txtdate = txtdate.format(new Date());
    txtReportday.value = txtdate;
    //計画日のテキストボックス制御
    txtReportday.onblur = function () {
        this.style.backgroundColor = "#ffffff";
    }
    document.getElementById("btnDaySearch").onclick = function() {
        txtDateUpdate(txtReportday);
    }
    //データベース接続
    dbConnect();
    // 担当者をセットして画面の初期表示
    EmpCdisplay(EmpCd);
    DisPlayChecker();
}

//*
//* 終了処理
//*
function OperateEnd() {
    dbClose();
    (window.open('', '_self').opener = window).close();
}

//*
//* 実績日更新時の処理
//*
function txtDateUpdate(obj) {
    DisPlayChecker();
    obj.style.backgroundColor = "#ffffff";
}

//*
//* 実績日にデータが存在するかを判別して表示する関数
//*
function DisPlayChecker() {
    //実績日チェック
    var Reportday = document.getElementById('txtReportday').value;
    var EmpID = EmpCd;
    if (ChckDate(Reportday)) {
    } else {
        return;
    }
    var mySql = " SELECT COUNT(WorkplanID) AS WIDCount" + " FROM t_workplan"
                     + " WHERE (PlanDate='" + Reportday + "') AND (Empid='" + EmpID + "') AND (DeleteFlg = '0' );";
    var recordSet = database.Execute(mySql);
    var wPlanCount = recordSet(0);

    var mySql = " SELECT COUNT(ReportID) AS RIDCount "
           + " FROM t_dailyreport "
           + " WHERE (Reportday>='" + Reportday + "') AND (Empid='" + EmpID + "') AND (DeleteFlg = '0' );";
    var recordSet = database.Execute(mySql);
    var ReportCount = recordSet(0);
    //登録がなければ画面をクリアする
    if (ReportCount == 0) {
        //0件の場合は画面をクリアする。
        TableClear();
    }
    //登録があればデータを表示する。   
    if (ReportCount != 0) {
        TableClear();
        dataDisplay();
    }
    recordSet.Close();
    recordSet = null;
}

//*
//* データを表示する関数
//*
function dataDisplay() {
    try {
        //作業計画登録なし
        var cWork = "-";
        //日報部分
        var Reportday = document.getElementById('txtReportday').value;
        ChckDate(Reportday);
        var EmpId = EmpCd;
        var mySql = " SELECT ReportID,WorkplanID,AdministrationID,ActionplanID,MatterID,TaskID,Reportday,Dailymemo,Workinghours,Reference "
                     + " FROM t_dailyreport "
                     + " WHERE (Reportday='" + Reportday + "') AND (Empid='" + EmpId + "') AND (DeleteFlg = '0' ) ORDER BY  AdministrationID,ActionplanID,MatterID ;";
        var recordSet = database.Execute(mySql);
        //alert(mySql);
        //console.log(mySql);
        var counter = 1;
        while (!recordSet.EOF) {
            //テーブル設定用
            var table1 = document.getElementById("table1");
            var row1 = table1.insertRow(counter);
            var cell1 = row1.insertCell(0);
            var cell2 = row1.insertCell(1);
            var cell3 = row1.insertCell(2);
            var cell4 = row1.insertCell(3);
            var cell5 = row1.insertCell(4);
            // class の付与は UserAgent によって
            // 挙動が違うっぽいので念のため両方の方法で
            cell1.setAttribute("class", "ReportNo");
            cell2.setAttribute("class", "ActionPlan");
            cell3.setAttribute("class", "workPlan");
            cell4.setAttribute("class", "DailyReport");
            cell5.setAttribute("class", "Nextwork");
            cell1.className = 'ReportNo';
            cell2.className = 'ActionPlan';
            cell3.className = 'workPlan';
            cell4.className = 'DailyReport';
            cell5.className = 'Nextwork';
            //■NOと今日実施した作業表示:
            var ReportId = recordSet(0);
            var workPlanID = recordSet(1);
            var Mcd = Number(recordSet(2)) + '-' + Number(recordSet(3)) + '-' + Number(recordSet(4));
            var MatterCd = Number(recordSet(2))+recordSet(3)+recordSet(4);
            var Tcd = recordSet(5);
            var ReportMemo = recordSet(7);
            var TaskHour = recordSet(8);
            var Reference = recordSet(9);
            var tD = Date.parse(recordSet(6));
            var wkTime = new Date(tD);
            var bodydate = new DateFormat("MM/dd");
            bodydate = bodydate.format(wkTime);
            //案件が一致する場合はNO部分のセルを空白に
            if (Mcd == beforeMcd){
                var HTML1 = '<td rowspan = "2" ></td>';
            }else{
                var HTML1 = '<span id="ReportNo' + counter + '">'+ MatterCd + '</span>';
            }
            cell1.innerHTML = HTML1;
            var HTML4 = '<span id ="DailyReport' + counter + '">'+ReportMemo + '</span>';
            //作業名取得
            myTaskSql = "SELECT m_Task.TaskID, m_Task.taskName "
                        + " FROM m_Task"
                        + " WHERE (((m_Task.TaskID)=" + Tcd + ") AND ((m_Task.DeleteFlg) Is Null));"
            TrecordSet = database.Execute(myTaskSql);
            var TaskName = TrecordSet(1);
            var RepHtml = '<span id="DailyReport' + counter + '">' + bodydate + " " + TaskName + ":" + '</span>' + HTML4;
            TrecordSet.Close();
            TrecordSet = null;
            cell4.innerHTML = RepHtml;
            //■作業予定取得
            var WPMemo = "";
            if (workPlanID == cWork || workPlanID == null || workPlanID == undefined) {
                WPMemo = cWork;
                var HTML3 = '<span id="workPlan' + counter + '">' + WPMemo + '</span>';
            } else {
                mySubSql = " SELECT t_dailyreport.ReportID, t_workplan.WorkplanID, t_workplan.AdministrationID, t_workplan.ActionplanID, t_workplan.MatterID, t_workplan.TaskID,Planmemo "
                    + " FROM t_dailyreport INNER JOIN t_workplan ON (t_workplan.PlanDate = t_dailyreport.Reportday) "
                    + " AND (t_dailyreport.Empid = t_workplan.Empid) AND (t_dailyreport.WorkplanID = t_workplan.WorkplanID) "
                    + " WHERE (((t_dailyreport.Empid)='" + EmpId + "') AND ((t_dailyreport.Reportday)='" + Reportday + "') AND ((t_dailyreport.DeleteFlg)='0') AND ((t_workplan.DeleteFlg)='0')) "
                    + "AND ((t_workplan.WorkplanID)='" + workPlanID + "');";
                SubrecordSet = database.Execute(mySubSql);
                //alert(mySubSql);
                //console.log(mySubSql);
                var WPMemo = SubrecordSet(6);
                var HTML3 = '<span id="workPlan' + counter + '">' + WPMemo + '</span>';
                SubrecordSet.Close();
                SubrecordSet = null;
            }
            cell3.innerHTML = HTML3;
            //■案件名取得(案件ID分割後に案件名表示)
            var separator = "-";
            var allayworkCd = Mcd.split(separator);
            var AdministrationCd = allayworkCd[0];
            var ActionPlanCd = allayworkCd[1];
            var MatterCd = allayworkCd[2];
            myMatterSql = "SELECT m_Matter.AdministrationID, m_Matter.ActionplanID, m_Matter.MatterID, m_Matter.MatterName "
                        + " FROM m_Matter "
                        + "WHERE (((m_Matter.AdministrationID)='" + AdministrationCd + "') "
                        + " AND ((m_Matter.ActionplanID)='" + ActionPlanCd + "')"
                        + " AND ((m_Matter.MatterID)='" + MatterCd + "')"
                        + " AND ((m_Matter.DeleteFlg) Is Null));"
            MrecordSet = database.Execute(myMatterSql);
            //alert(myMatterSql);
            //console.log(myMatterSql);
            var MatterName = MrecordSet(3);
            //案件が一致する場合は計画部分のセルを空白
            if (Mcd == beforeMcd) {
                var HTML2 = '<td rowspan = "2" ></td>';
            } else {
                var HTML2 = '<span id="ActionPlan' + counter + '">' + MatterName + '</span>';
            }
            cell2.innerHTML = HTML2;
            MrecordSet.Close();
            MrecordSet = null;
            //案件ID比較用
            var beforeMcd = Mcd;
            //次レコード
            recordSet.MoveNext();
            counter++;
        }
        recordSet.Close();
        recordSet = null;
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* 登録されている担当者を表示する関数
//*
function EmpCdisplay(loginId) {
    var mySql = "SELECT * FROM m_Emp WHERE ( DeleteFlg Is Null) ORDER BY EmpID";
    var recordSet = database.Execute(mySql);
    //console.log(mySql);
    document.getElementById("EmpID").innerHTML = "";
    var tempHtml = "担当者ID: <select name=\"selectEmpId\" id=\"selectEmpId\">\n";
    tempHtml = tempHtml + "\t<option value=\"0\">選択してください。</option>\n";
    while (!recordSet.EOF) {
        var optionval = recordSet(0);
        //オプション値指定がある場合はそのオプションを選択状態にする。
        if (optionval == loginId) {
            tempHtml = tempHtml + '\t<option value="' + optionval + '" selected >' + recordSet(0) + ":" + recordSet(1) + '<\/option>\n';
        } else {
            tempHtml = tempHtml + '\t<option value="' + optionval + '"\">' + recordSet(0) + ":" + recordSet(1) + '<\/option>\n';
        }
        recordSet.MoveNext();
    }
    tempHtml = tempHtml + "</select>";
    //    console.log(tempHtml);
    document.getElementById("EmpID").innerHTML = tempHtml;
    selEmpid = document.getElementById("selectEmpId");
    selEmpid.onchange = function () {
        selectEmpIdCdchange(this);
    }
    recordSet.Close();
    recordSet = null;
}

//*
//* 担当者選択時の動作
//*
function selectEmpIdCdchange(obj) {
    var workCd = obj.value;
    if (obj.selectedIndex == 0) {
        var selEmp = document.getElementById("EmpIDdisPlay");
        alert("担当者を選択してください。");
        selEmp.focus();
        return;
    } else {
        EmpCd = workCd;
    }
}

//*
//* 実績日チェック
//*
function ChckDate(Reportday) {
    if (Reportday) {
    } else {
        txtReportday = document.getElementById("txtReportday");
        alert("実績日は必須です。");
        txtReportday.focus();
        return false;
    }
    return true;
}

//*
//* 担当者コードチェック
//*
function ChckEmp(Employ) {
    if (Employ) {
    } else {
        var selEmp = document.getElementById('selectEmpId');
            alert("担当者を選択してください。");
            selEmp.focus();
            return false;
    }
    return true;
}

//*
//* 案件の文字列分割用
//*
function StringSeparator(objString) {
    var sobj = objString;
    var separator = "-";
    var allayworkCd = sobj.split(separator);
    var robj = allayworkCd[1];
    return robj;
}

//*
//* テーブルの明細部分を削除する。
//*
function TableClear() {
    var targetTable = document.getElementById('table1');
    var allCount = targetTable.rows.length;
    var headerCount = 1;
    var footerCount = 0;
    if (targetTable.tHead) {
        headerCount = targetTable.tHead.rows.length;
    }
    for (var i = headerCount; i < allCount; i++) {
        targetTable.deleteRow(headerCount);
    }
}

コメント

このブログの人気の投稿

GASでGoogleDriveのサブフォルダとファイル一覧を出力する

証券外務員1種勉強(計算式暗記用メモ)

マクロ経済学(IS-LM分析)