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

そして今回の本体部分「DailyReport.js」です。

やっぱり、テキストボックス描画やなんかのところをシンプルに
したい。おもいっきりさっきのコピペ感が漂っています。
ここでは細かい動き。時間再計算部分を自動で走らせたり
日付が変わったらボタンを押さずに再描画とかできないかなぁ。
と、後はレイアウトがガタガタなんでいつかは整えたほうがいいなぁ。


DailyReport.js
var EmpCd=location.search.substring(1);

onload = init;
onunload = dbClose;

//*
//* 追加ボタン押下時に入力項目を追加する。
//*
var ItemField = {
    //div要素の中で最大のitemNOを取得してcurrentNumberにセットする。
    currentNumber: 0,
    itemTemplate: '<table border="1"><tr><td>実績ID :<input type="text" name="txtReportCd__count__" id="txtReportCd__count__" style ="width:30px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="" \/>'
                 + '計画ID :<input type="text" name="txtPlanCd__count__" id="txtPlanCd__count__" style ="width:30px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="-" \/>'
                 + '案件:<span id="MatterCdDisplay__count__"></span>'
                 + '<span id="MatterDisplay__count__"></span>'
                 + '作業:<span id="TaskCdDisplay__count__"></span>'
                 + '<span id="TaskDisplay__count__"></span>'
                 + '<br/>作業予定:<textarea name="txtTaskMemo__count__" id="txtTaskMemo__count__" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'">-<\/textarea>'
                 + '実績・補足:<textarea name="txtReportMemo__count__" id="txtReportMemo__count__" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"><\/textarea>'
                 + '<input type="button" name="btnStart__count__" id="btnStart__count__" value="開始" onclick="startTimeUpdate(txtReportCd__count__.value,txtPlanCd__count__.value,txtReportMemo__count__.value,txtTime__count__.value,txtRefarence__count__.value,__count__)" \/>'
                 + '<input type="button" name="btnEnd__count__" id="btnEnd__count__" value="終了" onclick="endTimeUpdate(txtReportCd__count__.value,txtPlanCd__count__.value,txtReportMemo__count__.value,txtTime__count__.value,txtRefarence__count__.value,__count__)" \/>'
                 + '時間:<input type="text" name="txtTime__count__" id="txtTime__count__" style ="width:40px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="0" \/>'
                 + '関連資料:<input type="text" name="txtRefarence__count__" id="txtRefarence__count__" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="-" \/><\/td>'
                 + '<td><input type="button" name="btnInsert__count__" id="btnInsert__count__" value="登録" onclick="btnActionSelect(txtReportCd__count__.value,txtPlanCd__count__.value,txtReportMemo__count__.value,txtTime__count__.value,txtRefarence__count__.value,__count__,0)" \/>'
                 + '<input type="button" name="btnDelete__count__" id="btnDelete__count__" value="削除"  onclick="btnActionSelect(txtReportCd__count__.value,txtPlanCd__count__.value,txtReportMemo__count__.value,txtTime__count__.value,txtRefarence__count__.value,__count__,1)" \/><\/td><\/tr></table>',
    //項目追加
    add: function () {
        //テキストボックスの最後の要素番号取得
        var eleNumber = document.getElementsByTagName("div").length - 1;
        this.currentNumber = eleNumber;
        //テキストフィールド追加
        this.currentNumber++;
        var field = document.getElementById('item' + this.currentNumber);
        var newItem = this.itemTemplate.replace(/__count__/mg, this.currentNumber);
        field.innerHTML = newItem;
        var nextNumber = this.currentNumber + 1;
        var new_area = document.createElement("div");
        new_area.setAttribute("id", "item" + nextNumber);
        MatterCdDisplay(this.currentNumber,0);
        TaskCdDisplay(this.currentNumber,"0");
        field.appendChild(new_area);
        //テキストボックス追加時に計画IDにフォーカス
        var nxtfield = document.getElementById('txtReportCd' + this.currentNumber);
        //最新テキストボックスにテキストボックスに表示されているID+1の値を表示する。
        nxtfield.value = this.currentNumber;
        //案件セレクトボックスにフォーカス移動
        var nxtMatter = document.getElementById('selectMatter' + this.currentNumber);
        nxtMatter.focus();
    },
    //項目削除
    remove: function () {
        var chkPCdTxtbox = document.getElementById('txtReportCd' + this.currentNumber);
        var chkMCdTxtbox = document.getElementById('txtReportMemo' + this.currentNumber);
        if (this.currentNumber == 0) {
            return;
        }
        //入力データ存在時はテキストボックス削除不可
        if (chkPCdTxtbox.value == "" && chkMCdTxtbox.value == '') {
            //テキストフィールド削除
            var field = document.getElementById('item' + this.currentNumber);
            field.removeChild(field.lastChild);
            field.innerHTML = '';
            this.currentNumber--;
            //テキストボックス削除時に案件IDにフォーカス
            var beforefield = document.getElementById('txtReportCd' + this.currentNumber);
            if (this.currentNumber == 0) {
                return;
            } //最終行除外
            beforefield.focus();
        } else {
            alert("入力データが存在します");
            var currentfield = document.getElementById('txtReportCd' + this.currentNumber);
            currentfield.focus();
        }
    },
    clear: function () {
        var clNumber = document.getElementsByTagName("div").length - 1;
        this.currentNumber = clNumber;
        var clfield = document.getElementById('item' + this.currentNumber);
        clfield.removeChild(clfield.lastChild);
        clfield.innerHTML = '';
        this.currentNumber--;
        var clfield = document.getElementById('item' + this.currentNumber);
        if (this.currentNumber == 0) {
            return;
        } //最終行除外
        clfield.removeChild(clfield.lastChild);
    }
}

//*
//* 初期設定をする関数
//*
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);
    }
    document.getElementById("btnDailyPlan").onclick = function () {
        winOpen("DailyPlanInput.html");
    }
    document.getElementById("btnSumWorkTime").onclick = function () {
        txtTimeUpdate();
    }
    //データベース接続
    dbConnect();
    //登録用日時取得
    var dateFormat = new DateFormat("yyyy/MM/dd HH:mm:ss");
    OperateDate = dateFormat.format(new Date());
    // 担当者をセットして画面の初期表示
    EmpCdisplay(EmpCd);
    DisPlayChecker();
}

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

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


//*
//* データベースへの追加・削除・更新判断
//*
function btnActionSelect(ReportID,WorkplanID, Memo, whour ,Refar,txtCount,selectMode) {
    var sCount=txtCount;        //項目位置取得用
    //実績日を選択していない場合のチェック
    var Reportday = document.getElementById('txtReportday').value;
    if (ChckDate(Reportday)) {
    } else {
        return;
    }
    //担当を選択していない場合のチェック
    var selEmp = document.getElementById('selectEmpId');
    if(ChckEmp(selEmp)){
    } else {
        return;
    }
    //案件と作業を選択していない場合のチェック
    var selMatter = document.getElementById('selectMatter' + sCount);
    if (ChckMatter(selMatter, sCount)){
    } else {
        return;
    }
    var selTask = document.getElementById('selectTask' + sCount);
    if (ChckTask(selTask, sCount)) {
    } else {
        return;
    }

    //    必要項目類セット
    var rId = ReportID;                                                                     //実績ID
    var wId = WorkplanID;
    var reMemo = Memo;                                                                      //実績・補足
    var Reportday = document.getElementById('txtReportday').value;                          //実績日
    var EmpID = EmpCd;                                                                      //担当者
    var AdminID = document.getElementById('AdministrationCd' + sCount).innerText;           //方針
    var ActionID = document.getElementById('ActionPlanCd' + sCount).innerText;              //計画
    var MatterID = document.getElementById('MatterCd' + sCount).innerText;                  //案件ID
    var TaskID = document.getElementById('TaskCd' + sCount).innerText;                      //作業ID
    var Whour = whour;                                                                      //作業時間
    var Refe = Refar;                                                                       //関連資料
    //DB登録状況確認
    var mySql = " SELECT Count(ReportID) AS CountRid "
                + " FROM t_dailyreport "
                + " WHERE ( ReportID ='" + rId + "') AND ( Empid ='" + EmpID + "') AND (Reportday ='" + Reportday + "') AND (DeleteFlg = '0' ) ;";
    var recordSet = database.Execute(mySql);
    var idcount = recordSet(0);
    if (selectMode == 1) {
        //削除
        dataDelete(rId, EmpID, Reportday, sCount);
        return;
    }
    if (selectMode == 0 && idcount == 0) {
        //追加
        dataInsert(rId, wId, AdminID, ActionID, MatterID, TaskID, Reportday,reMemo,Refe, EmpID,Whour, sCount);
    } else {
        //更新
        dataUpdate(rId, wId, AdminID, ActionID, MatterID, TaskID, Reportday, reMemo, Refe, EmpID, Whour, sCount);
    }

}

//*
//* 実績日に実績登録が存在するかを判別して表示する関数
//*
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);
    //実績IDの登録がなければ計画のみ表示
    if (ReportCount == 0 && wPlanCount==0 ) {
        //0件の場合は画面をクリアする。
        var clfield = document.getElementById('item1');
        //子オブジェクトが取得可能な場合は子ツリーを削除してテキストボックス追加
        if (clfield.lastchild) {
            ItemField.clear()
            clfield.removeChild(clfield.lastChild);
            clfield.innerHTML = '';
            ItemField.add();
        }
        //子オブジェクト取得不可の場合は子オブジェクトを無視してテキストボックス追加
        clfield.innerHTML = '';
        ItemField.add();
        return;
    }
    //実績IDが存在しない場合は計画のみを表示する。   
    if (ReportCount == 0) {
        workPlanView();
    } else {
        dataDisplay();
    }
    recordSet.Close();
    recordSet = null;
}

//*
//* 該当日の計画を呼出して画面に表示する。
//*
function workPlanView() {
    var Reportday = document.getElementById('txtReportday').value;
    if (ChckDate(Reportday)) {
    } else {
        return;
    }
    try {
        var EmpID = EmpCd;
        var mySql = " SELECT WorkplanID, AdministrationID, ActionplanID, MatterID, TaskID ,Planmemo " + " FROM t_workplan"
                         + " WHERE (PlanDate='" + Reportday + "') AND (Empid='" + EmpID + "') AND (DeleteFlg = '0' ) ORDER BY  WorkplanID ;";
        var recordSet = database.Execute(mySql);
        var counter = 1;
        var tempHtml = "";
        while (!recordSet.EOF) {
            tempHtml = '<table border="1"><tr><td>実績ID :<input type="text" name="txtReportCd' + counter + '" id="txtReportCd' + counter + '"  style ="width:30px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="' + counter + '" \/>'
                    + '計画ID :<input type="text" name="txtPlanCd' + counter + '" id="txtPlanCd' + counter + '" style ="width:30px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="' + recordSet(0) + '" \/>'
                    + '案件:<span id="MatterCdDisplay' + counter + '"></span>'
                    + '<span id="MatterDisplay' + counter + '"></span>'
                    + '作業:<span id="TaskCdDisplay' + counter + '"></span>'
                    + '<span id="TaskDisplay' + counter + '"></span>'
                    + '<br/>作業予定:<textarea name="txtTaskMemo' + counter + '" id="txtTaskMemo' + counter + '" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'">' + recordSet(5) + '<\/textarea>'
                    + '実績・補足:<textarea name="txtReportMemo' + counter + '" id="txtReportMemo' + counter + '" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"><\/textarea>'
                    + '<input type="button" name="btnStart' + counter + '" id="btnStart' + counter + '" value="開始" onclick="startTimeUpdate(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ')" \/>'
                    + '<input type="button" name="btnEnd' + counter + '" id="btnEnd' + counter + '" value="終了" onclick="endTimeUpdate(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ')" \/>'
                    + '時間:<input type="text" name="txtTime' + counter + '" id="txtTime' + counter + '"  style ="width:40px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="0" \/>'
                    + '関連資料:<input type="text" name="txtRefarence' + counter + '" id="txtRefarence' + counter + '" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="-" \/><\/td>'
                    + '<td><input type="button" name="btnInsert' + counter + '" id="btnInsert' + counter + '" value="登録" onclick="btnActionSelect(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ',0)" \/>'
                    + '<input type="button" name="btnDelete' + counter + '" id="btnDelete' + counter + '" value="削除" onclick="btnActionSelect(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ',1)" \/><\/td><\/tr><\/table>';
            var field = document.getElementById('item' + counter);
            var workPlanID = recordSet(0);
            var newItem = tempHtml;
            field.innerHTML = newItem;
            var nextNumber = counter + 1;
            var new_area = document.createElement("div");
            new_area.setAttribute("id", "item" + nextNumber);
            field.appendChild(new_area);
            //案件ID表示
            var Mcd = Number(recordSet(1)) + '-' + Number(recordSet(2)) + '-' + Number(recordSet(3));
            MatterCdDisplay(counter, Mcd);
            var mdSelect = document.getElementById('MatterCdDisplay' + counter)
            mdSelect.innerHTML = "";
            var tempHtml = '<span id="AdministrationCd' + counter + '"\">' + recordSet(1) + '<\/span>' + '-' + '<span id=\"ActionPlanCd' + counter + '\">' + recordSet(2) + '<\/span>' + '-' + '<span id="MatterCd' + counter + '"\">' + recordSet(3) + '<\/span>';
            mdSelect.innerHTML = tempHtml;
            //作業ID表示表示用
            var Tcd = recordSet(4);
            TaskCdDisplay(counter, Tcd);
            var mtSelect = document.getElementById('TaskCdDisplay' + counter);
            mtSelect.innerHTML = "";
            var tempHtml = '<span id="TaskCd' + counter + '"\">' + Tcd + '<\/span>';
            mtSelect.innerHTML = tempHtml;
            recordSet.MoveNext();
            counter++;
        }
        recordSet.Close();
        recordSet = null;
        ItemField.add();
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* 実績データを表示する関数
//*
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  ReportID ;";
        var recordSet = database.Execute(mySql);
        var counter = 1;
        var tempHtml = "";
        while (!recordSet.EOF) {
            tempHtml = '<table border="1"><tr><td>実績ID :<input type="text" name="txtReportCd' + counter + '" id="txtReportCd' + counter + '" style ="width:30px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="' + recordSet(0) + '" \/>'
                    + '計画ID :<input type="text" name="txtPlanCd' + counter + '" id="txtPlanCd' + counter + '" style ="width:30px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="' + recordSet(1) + '" \/>'
                    + '案件:<span id="MatterCdDisplay' + counter + '"></span>'
                    + '<span id="MatterDisplay' + counter + '"></span>'
                    + '作業:<span id="TaskCdDisplay' + counter + '"></span>'
                    + '<span id="TaskDisplay' + counter + '"></span>'
                    + '<br/>作業予定:<textarea name="txtTaskMemo' + counter + '" id="txtTaskMemo' + counter + '" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"><\/textarea>'
                    + '実績・補足:<textarea name="txtReportMemo' + counter + '" id="txtReportMemo' + counter + '" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'">' + recordSet(7) + '<\/textarea>'
                    + '<input type="button" name="btnStart' + counter + '" id="btnStart' + counter + '" value="開始" onclick="startTimeUpdate(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ')" \/>'
                    + '<input type="button" name="btnEnd' + counter + '" id="btnEnd' + counter + '" value="終了" onclick="endTimeUpdate(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ')" \/>'
                    + '時間:<input type="text" name="txtTime' + counter + '" id="txtTime' + counter + '" style ="width:40px" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="' + recordSet(8) + '" \/>'
                    + '関連資料:<input type="text" name="txtRefarence' + counter + '" id="txtRefarence' + counter + '" onFocus="this.style.backgroundColor=\'#ffff00\'" onBlur="this.style.backgroundColor=\'#ffffff\'"  value="' + recordSet(9) + '" \/><\/td>'
                    + '<td><input type="button" name="btnInsert' + counter + '" id="btnInsert' + counter + '" value="登録" onclick="btnActionSelect(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ',0)" \/>'
                    + '<input type="button" name="btnDelete' + counter + '" id="btnDelete' + counter + '" value="削除" onclick="btnActionSelect(txtReportCd' + counter + '.value,txtPlanCd' + counter + '.value,txtReportMemo' + counter + '.value,txtTime' + counter + '.value,txtRefarence' + counter + '.value,' + counter + ',1)" \/><\/td><\/tr><\/table>';
            var field = document.getElementById('item' + counter);
            var workPlanID = recordSet(1);
            var newItem = tempHtml;
            field.innerHTML = newItem;
            var nextNumber = counter + 1;
            var new_area = document.createElement("div");
            new_area.setAttribute("id", "item" + nextNumber);
            field.appendChild(new_area);
            //作業予定表示
            if (workPlanID == cWork || workPlanID == null || workPlanID == undefined) {
                var TaskMemo = document.getElementById('txtTaskMemo' + counter);
                TaskMemo.value = cWork;
            } 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);
                var WPMemo = SubrecordSet(6);
                var TaskMemo = document.getElementById('txtTaskMemo' + counter);
                TaskMemo.value = WPMemo;
                SubrecordSet.Close();
                SubrecordSet = null;
            }
            //案件ID表示
            var Mcd = Number(recordSet(2)) + '-' + Number(recordSet(3)) + '-' + Number(recordSet(4));
            MatterCdDisplay(counter, Mcd);
            var mdSelect = document.getElementById('MatterCdDisplay' + counter)
            mdSelect.innerHTML = "";
            var tempHtml = '<span id="AdministrationCd' + counter + '"\">' + recordSet(2) + '<\/span>' + '-' + '<span id=\"ActionPlanCd' + counter + '\">' + recordSet(3) + '<\/span>' + '-' + '<span id="MatterCd' + counter + '"\">' + recordSet(4) + '<\/span>';
            mdSelect.innerHTML = tempHtml;
            //作業ID表示表示用
            var Tcd = recordSet(5);
            TaskCdDisplay(counter, Tcd);
            var mtSelect = document.getElementById('TaskCdDisplay' + counter);
            mtSelect.innerHTML = "";
            var tempHtml = '<span id="TaskCd' + counter + '"\">' + Tcd + '<\/span>';
            mtSelect.innerHTML = tempHtml;
            recordSet.MoveNext();
            counter++;
        }
        recordSet.Close();
        recordSet = null;
        ItemField.add();
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* データを追加する関数
//*
function dataInsert(ReportID, WorkplanID, AdminID, ActionID, MatterID, TaskID, Reportday, ReportMemo, Reference,EmpID, Workinghours, Chkcount) {
    try {
        if (dataCheck(ReportID, 0, Chkcount) && dataCheck(ReportMemo, 1, Chkcount)) {
            var mySql = " INSERT INTO t_dailyreport (ReportID,WorkplanID,AdministrationID,ActionplanID,MatterID,TaskID,Reportday,Dailymemo,Reference,Empid,Workinghours,Creationdate,DeleteFlg ) "
                         + " VALUES ('" + ReportID + "','" + WorkplanID + "','" + AdminID + "','" + ActionID + "','" + MatterID + "','" + TaskID + "','" + Reportday + "','" + ReportMemo + "','" + Reference + "','" + EmpID + "','" + Workinghours + "','" + OperateDate + "','0');";
            database.Execute(mySql);
            alert("追加しました。");
            //追加後に追加した実績・補足を表示する
            var cWork = "-";
            var WkplanId = document.getElementById('txtPlanCd' + Chkcount);
            var ckWk = WkplanId.value;
            var Report = document.getElementById('txtReportMemo' + Chkcount).value;
            var Report = ReportMemo;
            var Refer = document.getElementById('txtRefarence' + Chkcount).value;
            var Refer = Reference;
            var nextnum = Chkcount + 1;
            var nxtMatter = document.getElementById('selectMatter' + nextnum);
            //次の案件セレクトボックスがある場合はフォーカス移動
            if (nxtMatter) {
                nxtMatter.focus();
            }
            //実績IDで新規追加した場合のみ画面全体を更新
            if (ckWk == cWork) {
                dataDisplay();
            }
        }
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* データを更新する関数
//*
function dataUpdate(ReportID, WorkplanID, AdminID, ActionID, MatterID, TaskID, Reportday, ReportMemo, Reference, EmpID, Workinghours, Chkcount) {
    try {
        if (dataCheck(ReportID, 0, Chkcount) && dataCheck(ReportMemo, 1, Chkcount)) {
            var mySql = " UPDATE t_dailyreport SET WorkplanID = '" + WorkplanID + "', AdministrationID = '" + AdminID + "', ActionplanID = '" + ActionID
                        + "', MatterID = '" + MatterID + "', TaskID = '" + TaskID + "', Reportday = '" + Reportday + "', Dailymemo = '" + ReportMemo
                        + "', Reference = '" + Reference + " ', EmpID = '" + EmpID + " ', Workinghours = '" + Workinghours + " ', UpdateDate = '" + OperateDate + "',"
                        + " DeleteFlg ='0' WHERE ( ReportID = '" + ReportID + "' ) AND ( Empid = '" + EmpID + "' )  AND ( Reportday = '" + Reportday + "' );";
            database.Execute(mySql);
            alert("更新しました。");
            //追加後に追加した実績・補足を表示する
            var cWork = "-";
            var WkplanId = document.getElementById('txtPlanCd' + Chkcount);
            var ckWk = WkplanId.value;
            var Report = document.getElementById('txtReportMemo' + Chkcount).value;
            var Report = ReportMemo;
            var Refer = document.getElementById('txtRefarence' + Chkcount).value;
            var Refer = Reference;
            var nextnum = Chkcount + 1;
            var nxtMatter = document.getElementById('selectMatter' + nextnum);
            //次の案件セレクトボックスがある場合はフォーカス移動
            if (nxtMatter) {
                nxtMatter.focus();
            }
            //実績IDで新規追加した場合のみ画面を更新
            if (ckWk == cWork) {
                dataDisplay();
            }
        }
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* データを削除する関数
//*
function dataDelete(ReportID, EmpID, Reportday, Chkcount) {
    try {
        if (dataCheck(ReportID, 0, Chkcount)) {
            var mySql = " UPDATE t_dailyreport SET DeleteFlg ='1', DeleteDate = '" + OperateDate + "'"
                        + " WHERE ( ReportID = '" + ReportID + "' ) AND ( Empid = '" + EmpID + "' )  AND ( Reportday = '" + Reportday + "' );";
            database.Execute(mySql);
            alert("削除しました。");
            ItemField.clear();
            dataDisplay();
        }
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* 案件をセレクトボックスに表示する関数
//*
function MatterCdDisplay(Mcounter,MatterCd) {
    var labCounter = Mcounter;
    var mySql = " SELECT m_Administration.AdministrationID, m_ActionPlan.ActionplanID, m_Matter.MatterID, m_Matter.MatterName "
                + " FROM (m_ActionPlan INNER JOIN m_Matter ON m_ActionPlan.ActionplanID = m_Matter.ActionplanID) "
                + " INNER JOIN (m_Administration INNER JOIN m_Businessyear ON m_Administration.Businessyear = m_Businessyear.BusinessYear) "
                + " ON (m_ActionPlan.AdministrationID = m_Administration.AdministrationID) "
                + " AND (m_Matter.AdministrationID = m_Administration.AdministrationID) "
                + " WHERE (m_ActionPlan.DeleteFlg Is Null) AND (m_Businessyear.ShowFlg='0'); ";
    var recordSet = database.Execute(mySql);
    var MatterBox = document.getElementById('MatterDisplay' + labCounter);
    MatterBox.innerHTML = "";
    var tempHtml = '<select name="selectMatter' + labCounter + '" id="selectMatter' + labCounter + '" onchange="MatterCdchange(this,' + labCounter + ')" \">\n';
    tempHtml = tempHtml + '\t<option value="0">選択してください。<\/option>\n';
    while (!recordSet.EOF) {
        var optionval = Number(recordSet(0))+'-'+Number(recordSet(1))+'-'+Number(recordSet(2));
        //オプション値指定がある場合はそのオプションを選択状態にする。
        if (optionval == MatterCd) {
            tempHtml = tempHtml + '\t<option value="' + optionval + '" selected >' + recordSet(3) + '<\/option>\n';
        } else {
            tempHtml = tempHtml + '\t<option value="' + optionval + '"\">' + recordSet(3) + '<\/option>\n';
        }
        recordSet.MoveNext();
    }
    tempHtml = tempHtml + '</select>';
    MatterBox.innerHTML = tempHtml;
    recordSet.Close();
    recordSet = null;
}

//*
//* 案件セレクトボックス更新時の画面制御
//*
function MatterCdchange(obj, Mcounter) {
//案件CDを分割する。。
    var laMcounter = Mcounter;
    var workCd = obj.value;
    var separator = "-";
    var allayworkCd = workCd.split(separator);
    if (obj.selectedIndex == 0) {
        var selmatter = document.getElementById("selectMatter");
        alert("案件を選択してください。");
        obj.focus();
        return;
    }
    var AdministrationCd = allayworkCd[0];
    var ActionPlanCd = allayworkCd[1];
    var MatterCd = allayworkCd[2];
    var mySql = " SELECT m_Matter.AdministrationID, m_Matter.ActionplanID, m_Matter.MatterID"
                + " FROM m_ActionPlan INNER JOIN (m_Matter INNER JOIN (m_Administration INNER JOIN m_Businessyear"
                + " ON m_Administration.Businessyear = m_Businessyear.BusinessYear)"
                + " ON m_Matter.AdministrationID = m_Administration.AdministrationID)"
                + " ON (m_ActionPlan.ActionplanID = m_Matter.ActionplanID)"
                + " AND (m_ActionPlan.AdministrationID = m_Administration.AdministrationID)"
                + " WHERE ( m_Matter.AdministrationID ='" + AdministrationCd + "')"
                + " AND ( m_Matter.ActionplanID ='" + ActionPlanCd + "')"
                + " AND ( m_Matter.MatterID ='" + MatterCd + "')"
                + " AND (m_ActionPlan.DeleteFlg Is Null)"
                + " AND (m_Businessyear.ShowFlg = '0');"
    var recordSet = database.Execute(mySql);
    var sk1 = recordSet(0); //基本方針ID
    var sk2 = recordSet(1); //行動計画ID
    var sk3 = recordSet(2); //案件ID
    var mdSelect = document.getElementById('MatterCdDisplay' + Mcounter)
    mdSelect.innerHTML = "";
    var tempHtml = '<span id="AdministrationCd' + laMcounter + '"\">' + recordSet(0) + '<\/span>' + '-' + '<span id=\"ActionPlanCd' + laMcounter + '\">' + recordSet(1) + '<\/span>' + '-' + '<span id="MatterCd' + laMcounter + '"\">' + recordSet(2) + '<\/span>';
    mdSelect.innerHTML = tempHtml;
}

//*
//* 作業をセレクトボックスに表示する関数
//*
function TaskCdDisplay(Mcounter, TaskCd) {
    var labCounter = Mcounter;
    var mySql = " SELECT m_Task.* FROM m_Task;";
    var recordSet = database.Execute(mySql);
    var TaskBox = document.getElementById('TaskDisplay' + labCounter);
    TaskBox.innerHTML = "";
    var tempHtml = '<select name="selectTask' + labCounter + '" id="selectTask' + labCounter + '" onchange="TaskCdchange(this,' + labCounter + ')" \">\n';
    tempHtml = tempHtml + '\t<option value="0">選択してください。<\/option>\n';
    while (!recordSet.EOF) {
        //オプション値指定がある場合はそのオプションを選択状態にする。
        if (recordSet(0) == Number(TaskCd)) {
            tempHtml = tempHtml + '\t<option value=" ' + TaskCd + '" selected \">' + recordSet(1) + '<\/option>\n';
        } else {
            tempHtml = tempHtml + '\t<option value=" ' + recordSet(0) + '"\">' + recordSet(1) + '<\/option>\n';
        }
        recordSet.MoveNext();
    }
    tempHtml = tempHtml + '</select>';
    TaskBox.innerHTML = tempHtml;
    recordSet.Close();
    recordSet = null;
}

//*
//* 作業セレクトボックス更新時の画面制御
//*
function TaskCdchange(obj, Mcounter) {
    var laMcounter = Mcounter;
    var workCd = obj.value;
    if (obj.selectedIndex == 0) {
        var seltask = document.getElementById("selectTask");
        alert("作業を選択してください。");
        obj.focus();
        return;
    }
    var mtSelect = document.getElementById('TaskCdDisplay' + laMcounter)
    mtSelect.innerHTML = "";
    var tempHtml = '<span id="TaskCd' + laMcounter + '"\">' + workCd + '<\/span>';
    mtSelect.innerHTML = tempHtml;
}

//*
//* 登録されている社員を表示する関数
//*
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>";
    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 startTimeUpdate(ReportID, WorkplanID, Memo, whour, Refar, txtCount) {
    var Chkcount = txtCount;        //項目位置取得用
    //実績日および担当を選択していない場合のチェック
    var Reportday = document.getElementById('txtReportday').value;
    var selEmp = document.getElementById('selectEmpId');
    if (ChckDate(Reportday) && ChckEmp(selEmp)) {
    }else{
        return;
    }
    //案件と作業を選択していない場合のチェック
    var selMatter = document.getElementById('selectMatter' + Chkcount);
    var selTask = document.getElementById('selectTask' + Chkcount);
    if (ChckMatter(selMatter, Chkcount) && ChckTask(selTask, Chkcount)) {
    } else {
        return;
    }
    //必要項目類セット
    var rId = ReportID;                                                                     //実績ID
    var wId = WorkplanID;
    var ReportMemo = Memo;                                                                  //実績・補足
    var Reportday = document.getElementById('txtReportday').value;                          //実績日
    var EmpID = EmpCd;                                                                      //担当者
    var AdminID = document.getElementById('AdministrationCd' + Chkcount).innerText;         //基本方針
    var ActionID = document.getElementById('ActionPlanCd' + Chkcount).innerText;            //行動計画
    var MatterID = document.getElementById('MatterCd' + Chkcount).innerText;                  //案件ID
    var TaskID = document.getElementById('TaskCd' + Chkcount).innerText;                      //作業ID
    var Workinghours = whour;                                                                 //作業時間
    var Reference = Refar;                                                                    //関連資料
  try {
        var mySql = " SELECT Count(ReportID) AS CountRid "
                    + " FROM t_dailyreport "
                    + " WHERE ( Empid ='" + EmpID + "') AND (Reportday ='" + Reportday + "') AND (ReportID='" + ReportID + "');";
    var recordSet = database.Execute(mySql);
    var idcount = recordSet(0);
    if (idcount == 0) {
            if (dataCheck(ReportID, 0, Chkcount) && dataCheck(ReportMemo, 1, Chkcount)) {
                var mySql = " INSERT INTO t_dailyreport (ReportID,WorkplanID,AdministrationID,ActionplanID,MatterID,TaskID,Reportday,Dailymemo,Reference,Empid,Workinghours,Taskstart,Creationdate,DeleteFlg ) "
                            + " VALUES ('" + ReportID + "','" + WorkplanID + "','" + AdminID + "','" + ActionID + "','" + MatterID + "','" + TaskID + "','" + Reportday + "','" + ReportMemo + "','" + Reference + "','" + EmpID + "','" + Workinghours + "','" + OperateDate + "','" + OperateDate + "','0');";
                database.Execute(mySql);
                //console.log(mySql);
                alert("追加しました。");
                var cWork = "-";
                var WkplanId = document.getElementById('txtPlanCd' + Chkcount);
                var ckWk = WkplanId.value;
                var nextnum = Chkcount + 1;
                var nxtMatter = document.getElementById('selectMatter' + nextnum);
                //次の案件セレクトボックスがある場合はフォーカス移動
                if (nxtMatter) {
                    nxtMatter.focus();
                }
                //実績IDで新規追加した場合のみ画面を更新
                if (ckWk == cWork) {
                    dataDisplay();
                }
            }
    } else {
            if (dataCheck(ReportID, 0, Chkcount) && dataCheck(ReportMemo, 1, Chkcount)) {
                var mySql = " UPDATE t_dailyreport SET Taskstart = '" + OperateDate + " ', UpdateDate = '" + OperateDate + "'"
                        + " WHERE ( ReportID = '" + ReportID + "' ) AND ( Empid = '" + EmpID + "' )  AND ( Reportday = '" + Reportday + "' ) AND DeleteFlg ='0' ;";
                //alert(mySql);
                //console.log(mySql);
                database.Execute(mySql);
                var nextnum = Chkcount + 1;
                var nxtMatter = document.getElementById('selectMatter' + nextnum);
                //次の案件セレクトボックスがある場合はフォーカス移動
                if (nxtMatter) {
                    nxtMatter.focus();
                }
                alert("更新しました。");
            }
    }
    recordSet.Close();
    recordSet = null;
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* 終了時間をデータベースに登録し、作業時間を計算する。
//*
function endTimeUpdate(ReportID, WorkplanID, Memo, whour, Refar, txtCount) {
    var Chkcount = txtCount;        //項目位置取得用
    //実績日および担当を選択していない場合のチェック
    var Reportday = document.getElementById('txtReportday').value;
    var selEmp = document.getElementById('selectEmpId');
    if (ChckDate(Reportday) && ChckEmp(selEmp)) {
    } else {
        return;
    }
    //案件と作業を選択していない場合のチェック
    var selMatter = document.getElementById('selectMatter' + Chkcount);
    var selTask = document.getElementById('selectTask' + Chkcount);
    if (ChckMatter(selMatter, Chkcount) && ChckTask(selTask, Chkcount)) {
    } else {
        return;
    }
    //必要項目類セット
    var rId = ReportID;                                                                     //実績ID
    var wId = WorkplanID;
    var ReportMemo = Memo;                                                                  //実績・補足
    var Reportday = document.getElementById('txtReportday').value;                          //実績日
    var EmpID = EmpCd;                                                                      //担当者
    var AdminID = document.getElementById('AdministrationCd' + Chkcount).innerText;         //基本方針
    var ActionID = document.getElementById('ActionPlanCd' + Chkcount).innerText;            //行動計画
    var MatterID = document.getElementById('MatterCd' + Chkcount).innerText;                  //案件ID
    var TaskID = document.getElementById('TaskCd' + Chkcount).innerText;                      //作業ID
    var Workinghours = whour;                                                                 //作業時間
    var Reference = Refar;                                                                    //関連資料
    try {
        var mySql = " SELECT Count(ReportID) AS CountRid "
                    + " FROM t_dailyreport "
                    + " WHERE ( Empid ='" + EmpID + "') AND (Reportday ='" + Reportday + "') AND (ReportID='" + ReportID + "');";
        var recordSet = database.Execute(mySql);
        var idcount = recordSet(0);
        //alert(mySql);
        //console.log(mySql);
        if (idcount == 0) {
            alert("先に開始ボタンを押してください。")
            return;
        }   
        if (dataCheck(ReportID, 0, Chkcount) && dataCheck(ReportMemo, 1, Chkcount)) {
                //開始時刻取得
                var mySql = " SELECT Taskstart  FROM t_dailyreport "
                            +" WHERE (ReportID = '" + ReportID + "') AND (Reportday ='" + Reportday + "') AND "
                            + " (Empid='" + EmpID + "') AND (DeleteFlg='0');";
                //alert(mySql);
                //console.log(mySql);
                var recordSet = database.Execute(mySql);
                var startTime = recordSet(0);
                //終了時刻-開始時刻で作業時間を算出
                WorkTime = DateCalculate(startTime, OperateDate);
                var mySql = " UPDATE t_dailyreport SET Taskend = '" + OperateDate + " ', UpdateDate = '" + OperateDate + " ', Workinghours = '"+WorkTime + "' WHERE ( ReportID = '" + ReportID + "' )"
                            +" AND ( Empid = '" + EmpID + "' )  AND ( Reportday = '" + Reportday + "' ) AND DeleteFlg ='0' ;";
                //alert(mySql);
                //console.log(mySql);
                database.Execute(mySql);
                var wkTime = document.getElementById('txtTime' + Chkcount);
                wkTime.value = WorkTime;
                alert("更新しました。");
                var nextnum = Chkcount + 1;
                var nxtMatter = document.getElementById('selectMatter' + nextnum);
                //次の案件セレクトボックスがある場合はフォーカス移動
                if (nxtMatter) {
                    nxtMatter.focus();
                }
            }
        recordSet.Close();
        recordSet = null;
    } catch (error) {
        alert(error.number + "\n" + error.description);
    }
}

//*
//* データをチェックする関数
//*
function dataCheck(CheckValue, Chckflg, Chkcount) {
    var focucCnt = Chkcount;
    var tempStr = "は必ず入力してください。";
    var txtCd = document.getElementById('txtReportCd'+Chkcount);
    var txtDetail = document.getElementById('txtReportMemo'+Chkcount);

    if (Chckflg == 0 && CheckValue == "") {
        alert("実績ID" + tempStr);
        txtCd.focus();
        return false;
    }
    if (Chckflg == 1 && CheckValue == "") {
        alert("実績・補足" + tempStr);
        txtDetail.focus();
        return false;
    }
    return true;
}

//*
//* 実績日チェック
//*
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 ChckMatter(Matter,Chkcount) {
    var selMatter = document.getElementById('selectMatter' + Chkcount);
    if (selMatter.value == 0) {
        alert("案件を選択してください。");
        selMatter.focus();
        return false;
    }
    return true;
}

//*
//* 作業チェック
//*
function ChckTask(Task, Chkcount) {
    var selTask = document.getElementById('selectTask' + Chkcount);
    if (selTask.value == 0) {
        alert("作業を選択してください。");
        selTask.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 DateCalculate(StartTime, EndTime) {

    //時間差を求めて時間、分単位に変換する。
    var s = Date.parse(StartTime);
    var e = Date.parse(EndTime);
    var wkTime = e - s;
    var CTime = wkTime / 3600000;
    var rtn = CTime.toFixed(2)
    return rtn;
}

//*
//* 計画呼出
//*
function winOpen(target_site) {
    //社員コードを渡して計画画面に遷移
    var selEmp = document.getElementById('selectEmpId');
    var EmpCd = selEmp.value;
    if (ChckEmp(EmpCd)) {
        var child = target_site + "?" + EmpCd;
        subwin = window.open(child, "ChildWin", "top=50,left=500,width=1280,height=800");
    }
}

//*
//* 作業時間再計算
//*
function txtTimeUpdate(){
    //テキストボックスの値取得
    var eleNumber = document.getElementsByTagName("div").length - 1;
    var sumTime = 0;
    //テキストボックス内の時間を集計
    for(var i = 1; i < eleNumber ; i++){
        var Timefield = document.getElementById('txtTime'+ i);
        var wktime = parseFloat(Timefield.value);
        sumTime = parseFloat(sumTime) + wktime;
    }
    var sumTimeField = document.getElementById('txtSumWorkTime');
    sumTimeField.value = sumTime;
}

コメント

このブログの人気の投稿

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

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

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