const db=require('./function')


//顯示會議記錄 預設一頁10篇
//回傳 (JSON) ID、標題、會議時間、主席、記錄者
function SelectAllMeeting(){
    db.SelectAllMeeting()
}

//新增使用者，會去抓form表單的資料邏輯判斷，確定密碼一致沒問題就會進入到./db
function AddNewUser() {
    var username = document.getElementById("Add_Name");
    var userID=document.getElementById("Add_ID");
    var userpass1 = document.getElementById("Add_PW1");
    var userpass2 = document.getElementById("Add_PW2");
    if(userpass1.value==""||userpass2.value==""||username.value==""||userID.value==""){
        alert(`${userpass1.value},${userpass2.value}`);
        alert("請出入資料");
    }
    else if(userpass1.value!=userpass2.value){
        alert(`${userpass1.value},${userpass2.value}`);
        alert("密碼輸入錯誤");
    }
    else{
        db.addUser(username.value,userID.value,userpass1.value)
        console.log('成功')
    }
}

//刪除使用者須輸入要刪除的NAME
function DropUser(Name){
    db.DropUser(Name);
}

//修改使用者密碼
//需傳入(ID,就密碼,新密碼)
function UpdateUserPWD(UserID,UserPWD1,UserNewPWD){
    var UserPWD=db.UpdateUser(UserID)//讀取該用戶舊密碼
    if(UserPWD1==UserPWD){//判斷是否與密碼一致
        db.UpdateUserPWD(UserID,UserNewPWD)//修改密碼
    }
    else{
        return '帳密不一致'
    }
}

//新增會議記錄
function addmeeting(MEETING_TITLE, MEETING_DATE, MEETING_DATE_am,MEETING_DATE_H,MEETING_VENUE, MEETING_CHARPERSON, MEETING_PARTTICIPANT, MEETING_MINUTE, MEETING_DOC_String,MEETING_DOC_BLOB, MEETING_ATTACH, MEETING_TAGS)
{
    db.addmeeting(MEETING_TITLE, MEETING_DATE, MEETING_DATE_am,MEETING_DATE_H,MEETING_VENUE, MEETING_CHARPERSON, MEETING_PARTTICIPANT, MEETING_MINUTE, MEETING_DOC_String,MEETING_DOC_BLOB, MEETING_ATTACH, MEETING_TAGS)
}

function deletemeeting(UID,MeetingID){
    db.deletemeeting(UID,MeetingID)
}

//查詢關鍵字，會return (JSON) ID、標題、會議時間、主席、記錄者
function Inquiremeeting(inputString){
    db.Inquiremeeting(inputString)
}

function SelectMeetingSum(meetID){
    db.SelectMeetingSum(meetID)
}


//selectCountAllMeeting();

//SelectAllMeeting()

//AddNewUser();

//DropUser('master2');

//Inquiremeeting('國防')

/*addmeeting('測試新增紀錄', '2021-07-08', 'am','09','楊嘉翔家裡', '校長', '沒有人', 
    '楊嘉翔', '內文', '', '附件1','資管系')
*/

//deletemeeting('1','92')


//meeting_TITLE國字轉數字or數字轉國字
//SelectMeetingSum(MEETING_ID);
