<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="InjectionDownRecord.aspx.cs" Inherits="MESWebSite.Manage.InjectionDownRecord" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="/CSS/Basics.css" rel="stylesheet" />
    <link href="/Scripts/jquery-easyui-1.4.3/themes/metro/easyui.css" rel="stylesheet" type="text/css" />
    <link href="/Scripts/jquery-easyui-1.4.3/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="/Scripts/jquery-easyui-1.4.3/themes/color.css" rel="stylesheet" type="text/css" />
    <script src="/Scripts/jquery-easyui-1.4.3/jquery.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-easyui-1.4.3/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="/Scripts/jquery-easyui-1.4.3/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
    <script src="/Scripts/MyJs.js" type="text/javascript"></script>
    <style>
        #w td {
            padding: 5px 5px;
            text-align: left;
            vertical-align: middle;
        }

        #w .title {
            vertical-align: middle;
            text-align: right;
            width: 80px;
            height: 40px;
            padding: 0px;
        }

        p {
            padding: 0px 5px;
            font-size: small;
            font-family: 微软雅黑;
            margin: 0px;
        }

        .tree-folder-open, .tree-folder, .tree-file {
            display: none;
        }

        .datagrid {
            text-align: center;
        }

        .ttb {
            width: 180px;
            display: block;
        }
    </style>
    <title>停机时间拆分</title>
    <script>


</script>
</head>
<body>
    <form id="form1" runat="server">
        <div class="top">
            <table cellpadding="0" cellspacing="0" style="width: 100%">
                <thead>
                    <tr>
                        <td><span class="title">停机时间拆分</span></td>
                    </tr>
                </thead>

                <tbody>
                    <tr>
                        <td style="width: 415px;">注塑机台:<select id="fl_id_m_s" class="easyui-combobox" style="width: 100px;"
                            data-options="valueField: 'StationID',textField: 'StationNo'">
                        </select>
                            &nbsp;&nbsp;
                            时间:
                            <input id="StartTime" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />&nbsp;至&nbsp;
                            <input id="EndTime" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','23:59:59');}" />
                            &nbsp;&nbsp;
                            <a class="topsearchBtn">查询</a>
                            <%--   &nbsp;&nbsp;
                             <a class="topaddBtn">新增</a>--%>
                            &nbsp;&nbsp;
                          <a class="toppenBtn">编辑</a>
                            <%--  &nbsp;&nbsp;
                             <a class="topdelBtn">删除</a>--%>
                            &nbsp;&nbsp;
                          <a class="toppenBtn" id="UpdateBtn">更改</a>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <table id="tb" title="停机时间拆分" style="width: 99%;">
        </table>
        <!-- 编辑窗口 -->
        <div id="w" style="padding: 10px; visibility: hidden" title="编辑">
            <table cellpadding="0" cellspacing="0">
                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            机台:
                        </p>
                    </td>
                    <td colspan="2">
                        <input id="StationNo" type="text" style="width: 234px; height: 36px;" value="0" />
                    </td>
                </tr>

                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            开始时间:
                        </p>
                    </td>
                    <td colspan="2">
                        <input id="StartTime_U" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                    </td>
                </tr>
                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            结束时间:
                        </p>
                    </td>
                    <td colspan="2">
                        <input id="EndTime_U" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                    </td>
                </tr>
                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            停机类型:
                        </p>
                    </td>
                    <td colspan="2">
                        <select id="DownType" class="easyui-combobox" style="width: 234px; height: 36px;"
                            data-options="valueField: 'ID',textField: 'DownTypeName'">
                        </select><span style="color: red; font-size: 18px; vertical-align: middle;">*</span>
                    </td>
                </tr>

                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            停机原因:
                        </p>
                    </td>
                    <td colspan="2">
                        <select id="DownReason" class="easyui-combobox" style="width: 234px; height: 36px;"
                            data-options="valueField: 'ID',textField: 'Reason'">
                        </select><span style="color: red; font-size: 18px; vertical-align: middle;">*</span>
                    </td>
                </tr>
                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            描述:
                        </p>
                    </td>
                    <td colspan="2">
                        <input id="Des" type="text" style="width: 234px; height: 36px;" value="0" />
                    </td>
                </tr>
                <tr>
                    <td class="title" style="width: 110px;">
                        <p>
                            操作人:
                        </p>
                    </td>
                    <td colspan="2">
                        <input id="Remark1" type="text" class="text" style="width: 230px; height: 30px;" value="0" />
                    </td>
                </tr>
            </table>
        </div>
        <!-- 编辑窗口 - footer -->
        <div id="ft" style="padding: 10px; text-align: center; background-color: #f9f9f9; visibility: hidden">
            <a class="saveBtn" id="saveBtn">保存</a>
        </div>

        <div id="u" style="padding: 10px; visibility: hidden" title="拆分">
            <div class="top">
                <table cellpadding="0" cellspacing="0" style="width: 100%">
                    <tr>
                        <td style="width: 100px;">停机类型:
                            <select id="DownType_1" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'DownTypeName'">
                            </select>
                        </td>
                        <td style="width: 100px;">停机原因:
                            <select id="DownReason_1" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'Reason'">
                            </select>
                        </td>
                        <td style="width: 100px;">开始时间:
                            <input id="StartTime_1" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">结束时间:
                            <input id="EndTime_1" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">操作人:
                             <input id="Remark1_1" type="text" class="text" style="width: 150px; height: 30px;" value="" />
                        </td>
                        <td style="width: 80px">
                            <a class="topaddBtn" id="saveUBtn">保存</a>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">停机类型:
                            <select id="DownType_2" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'DownTypeName'">
                            </select>
                        </td>
                        <td style="width: 100px;">停机原因:
                            <select id="DownReason_2" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'Reason'">
                            </select>
                        </td>
                        <td style="width: 100px;">开始时间:
                            <input id="StartTime_2" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">结束时间:
                            <input id="EndTime_2" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">操作人:
                             <input id="Remark1_2" type="text" class="text" style="width: 150px; height: 30px;" value="" />
                        </td>
                        <td style="width: 80px"></td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">停机类型:
                            <select id="DownType_3" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'DownTypeName'">
                            </select>
                        </td>
                        <td style="width: 100px;">停机原因:
                            <select id="DownReason_3" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'Reason'">
                            </select>
                        </td>
                        <td style="width: 100px;">开始时间:
                            <input id="StartTime_3" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">结束时间:
                            <input id="EndTime_3" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">操作人:
                             <input id="Remark1_3" type="text" class="text" style="width: 150px; height: 30px;" value="" />
                        </td>
                        <td style="width: 80px"></td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">停机类型:
                            <select id="DownType_4" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'DownTypeName'">
                            </select>
                        </td>
                        <td style="width: 100px;">停机原因:
                            <select id="DownReason_4" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'Reason'">
                            </select>
                        </td>
                        <td style="width: 100px;">开始时间:
                            <input id="StartTime_4" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">结束时间:
                            <input id="EndTime_4" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">操作人:
                             <input id="Remark1_4" type="text" class="text" style="width: 150px; height: 30px;" value="" />
                        </td>
                        <td style="width: 80px"></td>
                    </tr>
                    <tr>
                        <td style="width: 100px;">停机类型:
                            <select id="DownType_5" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'DownTypeName'">
                            </select>
                        </td>
                        <td style="width: 100px;">停机原因:
                            <select id="DownReason_5" class="easyui-combobox" style="width: 234px; height: 36px;"
                                data-options="valueField: 'ID',textField: 'Reason'">
                            </select>
                        </td>
                        <td style="width: 100px;">开始时间:
                            <input id="StartTime_5" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">结束时间:
                            <input id="EndTime_5" class="easyui-datetimebox" data-options="onShowPanel:function(){ $(this).datetimebox('spinner').timespinner('setValue','00:00:00');}" />
                        </td>
                        <td style="width: 100px;">操作人:
                             <input id="Remark1_5" type="text" class="text" style="width: 150px; height: 30px;" value="" />
                        </td>
                        <td style="width: 80px"></td>
                    </tr>
                </table>
            </div>
        </div>


        <div hidden="hidden">
            <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label>
        </div>
        <input id="DownRecordID" type="text" hidden="hidden" runat="server" />
        <input id="UserID" type="text" hidden="hidden" runat="server" />
        <input id="StationID" type="text" hidden="hidden" runat="server" />
        <input id="StartTime_B" type="text" hidden="hidden" runat="server" />
        <input id="EndTime_B" type="text" hidden="hidden" runat="server" />
        <input id="PlanID" type="text" hidden="hidden" runat="server" />
        <script>
            /****************       全局变量          ***************/
            var PrimaryID;               //要编辑的id
            var dg = $('#tb');      //表格
            var isEdit = false;     //是否为编辑状态

            /****************       DOM加载          ***************/
            $(function () {

                var curr_time = new Date();
                var str = curr_time.getFullYear() + "-";
                str += curr_time.getMonth() + 1 + "-";
                str += curr_time.getDate()

                $('#StartTime').datetimebox('setValue', str + " 00:00:00");
                $('#EndTime').datetimebox('setValue', str + " 23:59:59");

                $.ajaxSetup({
                    cache: false //关闭AJAX缓存
                });

                $("#EndTime_1").datetimebox({
                    stopFirstChangeEvent: true,
                    onChange: function () {
                        var options = $(this).datebox('options');
                        if (options.stopFirstChangeEvent) {
                            options.stopFirstChangeEvent = false;
                            return;
                        }
                        //onchange的逻辑
                        var EndTime = $('#EndTime_1').datetimebox('getValue');
                        $('#StartTime_2').datetimebox('setValue', EndTime);
                    }
                });

                $("#EndTime_2").datetimebox({
                    stopFirstChangeEvent: true,
                    onChange: function () {
                        var options = $(this).datebox('options');
                        if (options.stopFirstChangeEvent) {
                            options.stopFirstChangeEvent = false;
                            return;
                        }
                        //onchange的逻辑
                        var EndTime = $('#EndTime_2').datetimebox('getValue');
                        $('#StartTime_3').datetimebox('setValue', EndTime);
                    }
                });

                $("#EndTime_3").datetimebox({
                    stopFirstChangeEvent: true,
                    onChange: function () {
                        var options = $(this).datebox('options');
                        if (options.stopFirstChangeEvent) {
                            options.stopFirstChangeEvent = false;
                            return;
                        }
                        //onchange的逻辑
                        var EndTime = $('#EndTime_3').datetimebox('getValue');
                        $('#StartTime_4').datetimebox('setValue', EndTime);
                    }
                });

                $("#EndTime_4").datetimebox({
                    stopFirstChangeEvent: true,
                    onChange: function () {
                        var options = $(this).datebox('options');
                        if (options.stopFirstChangeEvent) {
                            options.stopFirstChangeEvent = false;
                            return;
                        }
                        //onchange的逻辑
                        var EndTime = $('#EndTime_4').datetimebox('getValue');
                        $('#StartTime_5').datetimebox('setValue', EndTime);
                    }
                });

                $("#EndTime_5").datetimebox({
                    stopFirstChangeEvent: true,
                    onChange: function () {
                        var options = $(this).datebox('options');
                        if (options.stopFirstChangeEvent) {
                            options.stopFirstChangeEvent = false;
                            return;
                        }
                        //onchange的逻辑
                        var EndTime = $('#EndTime_5').datetimebox('getValue');

                    }
                });



                //编辑窗口加载
                $('#w').window({
                    modal: true,
                    closed: true,
                    minimizable: false,
                    maximizable: false,
                    collapsible: false,
                    width: 460,
                    height: 620,
                    footer: '#ft',
                    top: 20,
                    onBeforeClose: function () { clearw(); },
                    onBeforeOpen: function () {
                        $('#w').css('visibility', 'visible'); $('#ft').css('visibility', 'visible');
                        reloadfl_id();
                    }

                });

                //编辑窗口加载
                $('#u').window({
                    modal: true,
                    closed: true,
                    minimizable: false,
                    maximizable: false,
                    collapsible: false,
                    width: 1200,
                    height: 700,
                    footer: '',
                    top: 20,
                    onBeforeClose: function () {

                    },
                    onBeforeOpen: function () {
                        $('#u').css('visibility', 'visible');
                        reload_u();
                    }
                });


                //新增按钮点击
                //$('.topaddBtn').first().click(function () {
                //    isEdit = false;
                //    $('#w').window('open');
                //});

                //编辑按钮点击
                $('.toppenBtn').first().click(function () {
                    isEdit = true;
                    initEidtWidget();
                });

                //拆分
                $('#UpdateBtn').first().click(function () {
                    initUpdateWidget();
                });
                //拆分保存按钮
                $('#saveUBtn').bind('click', function () {
                    SaveUpdateInfo();
                });

                //保存按钮
                $('#saveBtn').bind('click', function () {
                    SaveInfo(isEdit);
                });


                //删除按钮
                $('.topdelBtn').first().click(function () {
                    $.messager.confirm('提示框', '你确定要删除吗?', function (r) {
                        if (r) {
                            deleteInfos();
                        }
                    });

                });

                //搜索按钮
                $('.topsearchBtn').first().click(function () {
                    SearchInfo();
                });

                //下拉框加载
                reloadfl_ids();

                //排序
                function sorts(obj, sortName, sortOrder) {
                    var queryParams = $('#' + obj).datagrid('options').queryParams;
                    queryParams.sortName = sortName;
                    queryParams.sortOrder = sortOrder;
                    console.log(queryParams.sortOrder)
                    $('#' + obj).datagrid('reload');
                }

                var StationID = $('#fl_id_m_s').combobox('getValue');
                var StartTime = $('#StartTime').datetimebox('getValue');
                var EndTime = $('#EndTime').datetimebox('getValue');

                var queryParams = {
                    StationID: StationID,
                    StartTime: StartTime,
                    EndTime: EndTime
                };


                dg = $('#tb').datagrid({
                    fitColumns: true,
                    nowrap: false,
                    striped: true,
                    collapsible: true,
                    url: "/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryList",
                    queryParams: queryParams,
                    remoteSort: false,
                    columns: [[
                        { field: 'ID', title: 'ID', hidden: true },
                        { field: 'PlanID', title: 'PlanID', hidden: true },
                        { field: 'StationNo', title: '注塑机台', sortable: 'true', width: 30 },
                        {
                            field: 'StartTime', title: '开始时间', sortable: 'true', width: 20,
                            formatter: function (date) {
                                var pa = /.*\((.*)\)/;
                                var unixtime = date.match(pa)[1].substring(0, 10);
                                return getTime(unixtime).substring(0, 19);
                            }
                        },
                        {
                            field: 'EndTime', title: '结束', sortable: 'true', width: 20,
                            formatter: function (date) {
                                var pa = /.*\((.*)\)/;
                                var unixtime = date.match(pa)[1].substring(0, 10);
                                return getTime(unixtime).substring(0, 19);
                            }
                        },
                        { field: 'DownTime', title: '停机时间', sortable: 'true', width: 20 },
                        { field: 'DownTypeName', title: '停机类型', sortable: 'true', width: 50 },
                        { field: 'DownReasonName', title: '停机原因', sortable: 'true', width: 50 },
                        { field: 'Des', title: '描述', sortable: 'true', width: 50 },
                        { field: 'Remark1', title: '操作人', sortable: 'true', width: 50 }
                    ]],
                    onSortColumn: function (sort, order) {
                        sorts('tb', sort, order);//调用排序方法。
                    },
                    pagination: true,//表示在datagrid设置分页              
                    rownumbers: true,
                    singleSelect: true
                });

                dg.datagrid('getPager').pagination({
                    pageSize: 10,
                    pageNumber: 1,
                    pageList: [10, 20, 30, 40, 50, 100],
                    beforePageText: '第',//页数文本框前显示的汉字   
                    afterPageText: '页    共 {pages} 页',
                    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
                });
            });

            /****************       主要业务程序          ***************/
            //新增 / 编辑  
            function SaveInfo(isEdit) {

                var ID = isEdit == true ? PrimaryID : 0;
                var StationID = $('#StationID').val();
                var StartTime = $('#StartTime_U').datetimebox('getValue');
                var EndTime = $('#EndTime_U').datetimebox('getValue');

                var DownType = $('#DownType').combobox('getValue');
                var DownReason = $('#DownReason').combobox('getValue');

                var Des = $('#Des').val();
                var Remark1 = $('#Remark1').val();

                if (StationID == "") {
                    $.messager.alert('提示', '机号不能为空,请重新输入', 'warning');
                    return;
                }

                if (DownType == "") {
                    $.messager.alert('提示', '日期不能为空,请重新输入', 'warning');
                    return;
                }
                if (DownReason == "") {
                    $.messager.alert('提示', '班次不能为空,请重新输入', 'warning');
                    return;
                }

                var model = {
                    ID: ID,
                    StationID: StationID,
                    StartTime: StartTime,
                    EndTime: EndTime,
                    DownType: DownType,
                    DownReason: DownReason,
                    Des: Des,
                    Remark1: Remark1,
                    method: 'SaveInfo'
                };
                SaveModel(model);
            }
            function SaveModel(model) {
                $.ajax({
                    type: "POST",
                    async: false,
                    url: "/HttpHandlers/InjectionDownRecordHandler.ashx",
                    data: model,
                    success: function (data) {
                        if (data == 'true') {
                            $.messager.alert('提示', '已保存', 'info');
                            dg.datagrid('reload');
                            $('#w').window('close');
                        }
                        else {
                            $.messager.alert('提示', '保存失败,请查看是否重复', 'warning');
                        }

                    },
                    error: function () {
                    }
                });
            }
            //查询方法
            function SearchInfo() {

                var StationID = $('#fl_id_m_s').combobox('getValue');
                var StartTime = $('#StartTime').datetimebox('getValue');
                var EndTime = $('#EndTime').datetimebox('getValue');

                var queryParams = {
                    StationID: StationID,
                    StartTime: StartTime,
                    EndTime: EndTime
                };
                dg.datagrid({
                    queryParams: queryParams
                });

            }
            function post(url, PARAMS) {
                var temp_form = document.createElement("form");
                temp_form.action = url;
                temp_form.target = "_blank";
                temp_form.method = "post";
                temp_form.style.display = "none"; for (var x in PARAMS) {
                    var opt = document.createElement("textarea");
                    opt.name = x;
                    opt.value = PARAMS[x];
                    temp_form.appendChild(opt);
                }
                document.body.appendChild(temp_form);
                temp_form.submit();
            }

            //编辑时加载窗体数据
            function initEidtWidget() {
                var selRows = dg.datagrid('getSelections');
                if (selRows.length > 1) {
                    $.messager.alert('提示', '每次只能编辑一条记录,请重新选取', 'warning');
                    return;
                } else if (selRows.length == 0) {
                    $.messager.alert('提示', '请选择一条记录进行编辑', 'warning');
                    return;
                }

                //窗体数据初始化              
                var row = selRows[0];
                PrimaryID = row.ID;
                $('#StationID').val(row.StationID);
                $('#StationNo').val(row.StationNo);
                $('#DownType').combobox('select', row.DownType);
                $('#DownReason').combobox('select', row.DownReason);
                $('#Des').val(row.Des);
                $('#Remark1').val(row.Remark1);

                var pa = /.*\((.*)\)/;
                var unixtime = row.StartTime.match(pa)[1].substring(0, 10);

                $('#StartTime_U').datetimebox('setValue', getTime(unixtime).substring(0, 19));


                var unixtime2 = row.EndTime.match(pa)[1].substring(0, 10);

                $('#EndTime_U').datetimebox('setValue', getTime(unixtime2).substring(0, 19));



                $('#w').window('open');

            }
            //删除方法
            function deleteInfos() {
                var selRows = dg.datagrid('getSelections');
                if (selRows.length > 1) {
                    $.messager.alert('提示', '每次只能删除一条记录,请重新选取', 'warning');
                    return;
                } else if (selRows.length == 0) {
                    $.messager.alert('提示', '请选择一条记录进行删除', 'warning');
                    return;
                }
                var row = selRows[0];

                var model = {
                    ID: row.ID,
                    method: 'DelInfo'
                };

                $.ajax({
                    url: "/HttpHandlers/InjectionDownRecordHandler.ashx",
                    data: model,
                    async: false,
                    success: function (data) {
                        if (data == 'true') {
                            $.messager.alert('提示', '已删除', 'info');
                            dg.datagrid('reload');
                        }
                        else {
                            $.messager.alert('提示', '由于有关联数据,删除失败', 'warning');
                        }
                    },
                    error: function () {
                    }
                });
            }


            function initUpdateWidget() {
                var selRows = dg.datagrid('getSelections');
                if (selRows.length > 1) {
                    $.messager.alert('提示', '每次只能编辑一条记录,请重新选取', 'warning');
                    return;
                } else if (selRows.length == 0) {
                    $.messager.alert('提示', '请选择一条记录进行编辑', 'warning');
                    return;
                }

                //窗体数据初始化              
                var row = selRows[0];

                if (row.Remark2 == "1") {
                    $.messager.alert('提示', '已拆分', 'warning');
                    return;
                }

                $('#DownRecordID').val(row.ID);
                $('#StationID').val(row.StationID);
                $('#PlanID').val(row.PlanID);
                
                var pa = /.*\((.*)\)/;
                var unixtime = row.StartTime.match(pa)[1].substring(0, 10);

                $('#StartTime_1').datetimebox('setValue', getTime(unixtime).substring(0, 19));
                $('#StartTime_B').val(getTime(unixtime).substring(0, 19));

                var unixtime2 = row.EndTime.match(pa)[1].substring(0, 10);

                $('#EndTime_1').datetimebox('setValue', getTime(unixtime2).substring(0, 19));
                $('#EndTime_B').val(getTime(unixtime2).substring(0, 19));
                $('#u').window('open');
            }

            function SaveUpdateInfo() {

                var datalistBill = new Array();

                var ID = $('#DownRecordID').val();
                var StationID = $('#StationID').val();
                var PlanID = $('#PlanID').val();

                var StartTime_B = $('#StartTime_B').val();
                var EndTime_B = $('#EndTime_B').val();

                var start = new Date(StartTime_B.replace("-", "/").replace("-", "/"));
                var end = new Date(EndTime_B.replace("-", "/").replace("-", "/"));

                var DownType_1 = $('#DownType_1').combobox('getValue');
                var DownReason_1 = $('#DownReason_1').combobox('getValue');
                var StartTime_1 = $('#StartTime_1').datetimebox('getValue');
                var EndTime_1 = $('#EndTime_1').datetimebox('getValue');
                var Remark1_1 = $('#Remark1_1').val();

                if (DownType_1 != "" || DownReason_1 != "" || StartTime_1 != "" || EndTime_1 != "") {

                    if (DownType_1 == "") {
                        $.messager.alert('提示', '1.停机类型不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (DownReason_1 == "") {
                        $.messager.alert('提示', '1.停机原因不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (StartTime_1 == "") {
                        $.messager.alert('提示', '1.开始时间不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (EndTime_1 == "") {
                        $.messager.alert('提示', '1.结束时间不能为空,请重新输入', 'warning');
                        return;
                    }


                    var start_1 = new Date(StartTime_1.replace("-", "/").replace("-", "/"));
                    var end_1 = new Date(EndTime_1.replace("-", "/").replace("-", "/"));


                    if (start_1 < start) {
                        $.messager.alert('提示', '1.开始时间:' + StartTime_1 + '小于拆分的开始时间:' + StartTime_B + ',请重新输入', 'warning');
                        return;
                    }
                    if (end < end_1) {
                        $.messager.alert('提示', '1.结束时间:' + EndTime_1 + '大于拆分的结束时间:' + EndTime_B + ',请重新输入', 'warning');
                        return;
                    }

                    var DownRecordVO = {
                        ID: ID,
                        StationID: StationID,
                        PlanID: PlanID,
                        StartTime: StartTime_1,
                        EndTime: EndTime_1,
                        DownType: DownType_1,
                        DownReason: DownReason_1,
                        Remark1: Remark1_1
                    };

                    datalistBill.push(DownRecordVO);

                }

                var DownType_2 = $('#DownType_2').combobox('getValue');
                var DownReason_2 = $('#DownReason_2').combobox('getValue');
                var StartTime_2 = $('#StartTime_2').datetimebox('getValue');
                var EndTime_2 = $('#EndTime_2').datetimebox('getValue');
                var Remark1_2 = $('#Remark1_2').val();

                if (DownType_2 != "" || DownReason_2 != "" || StartTime_2 != "" || EndTime_2 != "") {

                    if (DownType_2 == "") {
                        $.messager.alert('提示', '2.停机类型不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (DownReason_2 == "") {
                        $.messager.alert('提示', '2.停机原因不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (StartTime_2 == "") {
                        $.messager.alert('提示', '2.开始时间不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (EndTime_2 == "") {
                        $.messager.alert('提示', '2.结束时间不能为空,请重新输入', 'warning');
                        return;
                    }

                    var start_1 = new Date(StartTime_2.replace("-", "/").replace("-", "/"));
                    var end_1 = new Date(EndTime_2.replace("-", "/").replace("-", "/"));


                    if (start_1 < start) {
                        $.messager.alert('提示', '2.开始时间:' + StartTime_2 + '小于拆分的开始时间:' + StartTime_B + ',请重新输入', 'warning');
                        return;
                    }
                    if (end < end_1) {
                        $.messager.alert('提示', '2.结束时间:' + EndTime_2 + '大于拆分的结束时间:' + EndTime_B + ',请重新输入', 'warning');
                        return;
                    }



                    var DownRecordVO = {
                        ID: ID,
                        StationID: StationID,
                        PlanID: PlanID,
                        StartTime: StartTime_2,
                        EndTime: EndTime_2,
                        DownType: DownType_2,
                        DownReason: DownReason_2,
                        Remark1: Remark1_2
                    };

                    datalistBill.push(DownRecordVO);

                }


                var DownType_3 = $('#DownType_3').combobox('getValue');
                var DownReason_3 = $('#DownReason_3').combobox('getValue');
                var StartTime_3 = $('#StartTime_3').datetimebox('getValue');
                var EndTime_3 = $('#EndTime_3').datetimebox('getValue');
                var Remark1_3 = $('#Remark1_3').val();

                if (DownType_3 != "" || DownReason_3 != "" || StartTime_3 != "" || EndTime_3 != "") {

                    if (DownType_3 == "") {
                        $.messager.alert('提示', '3.停机类型不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (DownReason_3 == "") {
                        $.messager.alert('提示', '3.停机原因不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (StartTime_3 == "") {
                        $.messager.alert('提示', '3.开始时间不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (EndTime_3 == "") {
                        $.messager.alert('提示', '3.结束时间不能为空,请重新输入', 'warning');
                        return;
                    }

                    var start_1 = new Date(StartTime_3.replace("-", "/").replace("-", "/"));
                    var end_1 = new Date(EndTime_3.replace("-", "/").replace("-", "/"));


                    if (start_1 < start) {
                        $.messager.alert('提示', '3.开始时间:' + StartTime_3 + '小于拆分的开始时间:' + StartTime_B + ',请重新输入', 'warning');
                        return;
                    }
                    if (end < end_1) {
                        $.messager.alert('提示', '3.结束时间:' + EndTime_3 + '大于拆分的结束时间:' + EndTime_B + ',请重新输入', 'warning');
                        return;
                    }

                    var DownRecordVO = {
                        ID: ID,
                        StationID: StationID,
                        PlanID: PlanID,
                        StartTime: StartTime_3,
                        EndTime: EndTime_3,
                        DownType: DownType_3,
                        DownReason: DownReason_3,
                        Remark1: Remark1_3
                    };

                    datalistBill.push(DownRecordVO);

                }

                var DownType_4 = $('#DownType_4').combobox('getValue');
                var DownReason_4 = $('#DownReason_4').combobox('getValue');
                var StartTime_4 = $('#StartTime_4').datetimebox('getValue');
                var EndTime_4 = $('#EndTime_4').datetimebox('getValue');
                var Remark1_4 = $('#Remark1_4').val();

                if (DownType_4 != "" || DownReason_4 != "" || StartTime_4 != "" || EndTime_4 != "") {

                    if (DownType_4 == "") {
                        $.messager.alert('提示', '4.停机类型不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (DownReason_4 == "") {
                        $.messager.alert('提示', '4.停机原因不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (StartTime_4 == "") {
                        $.messager.alert('提示', '4.开始时间不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (EndTime_4 == "") {
                        $.messager.alert('提示', '4.结束时间不能为空,请重新输入', 'warning');
                        return;
                    }
                    var start_1 = new Date(StartTime_4.replace("-", "/").replace("-", "/"));
                    var end_1 = new Date(EndTime_4.replace("-", "/").replace("-", "/"));


                    if (start_1 < start) {
                        $.messager.alert('提示', '4.开始时间:' + StartTime_4 + '小于拆分的开始时间:' + StartTime_B + ',请重新输入', 'warning');
                        return;
                    }
                    if (end < end_1) {
                        $.messager.alert('提示', '4.结束时间:' + EndTime_4 + '大于拆分的结束时间:' + EndTime_B + ',请重新输入', 'warning');
                        return;
                    }

                    var DownRecordVO = {
                        ID: ID,
                        StationID: StationID,
                        PlanID: PlanID,
                        StartTime: StartTime_4,
                        EndTime: EndTime_4,
                        DownType: DownType_4,
                        DownReason: DownReason_4,
                        Remark1: Remark1_4
                    };

                    datalistBill.push(DownRecordVO);

                }

                var DownType_5 = $('#DownType_5').combobox('getValue');
                var DownReason_5 = $('#DownReason_5').combobox('getValue');
                var StartTime_5 = $('#StartTime_5').datetimebox('getValue');
                var EndTime_5 = $('#EndTime_5').datetimebox('getValue');
                var Remark1_5 = $('#Remark1_5').val();

                if (DownType_5 != "" || DownReason_5 != "" || StartTime_5 != "" || EndTime_5 != "") {

                    if (DownType_5 == "") {
                        $.messager.alert('提示', '5.停机类型不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (DownReason_5 == "") {
                        $.messager.alert('提示', '5.停机原因不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (StartTime_5 == "") {
                        $.messager.alert('提示', '5.开始时间不能为空,请重新输入', 'warning');
                        return;
                    }
                    if (EndTime_5 == "") {
                        $.messager.alert('提示', '5.结束时间不能为空,请重新输入', 'warning');
                        return;
                    }


                    var start_1 = new Date(StartTime_5.replace("-", "/").replace("-", "/"));
                    var end_1 = new Date(EndTime_5.replace("-", "/").replace("-", "/"));


                    if (start_1 < start) {
                        $.messager.alert('提示', '5.开始时间:' + StartTime_5 + '小于拆分的开始时间:' + StartTime_B + ',请重新输入', 'warning');
                        return;
                    }
                    if (end < end_1) {
                        $.messager.alert('提示', '5.结束时间:' + EndTime_5 + '大于拆分的结束时间:' + EndTime_B + ',请重新输入', 'warning');
                        return;
                    }

                    var DownRecordVO = {
                        ID: ID,
                        StationID: StationID,
                        PlanID: PlanID,
                        StartTime: StartTime_5,
                        EndTime: EndTime_5,
                        DownType: DownType_5,
                        DownReason: DownReason_5,
                        Remark1: Remark1_5
                    };

                    datalistBill.push(DownRecordVO);

                }

                SaveUpdateModel(datalistBill, ID);
            }

            function SaveUpdateModel(model, DownRecordID) {

                $.ajax({
                    type: "POST",
                    async: false,
                    url: "/HttpHandlers/InjectionDownRecordHandler.ashx?method=updateRecord",
                    data: { 'datalistBill': JSON.stringify(model), 'DownRecordID': DownRecordID },
                    success: function (data) {
                        if (data == 'True') {
                            $.messager.alert('提示', '已保存', 'info');
                            dg.datagrid('reload');
                            $('#u').window('close');
                        }
                        else {
                            $.messager.alert('提示', '保存失败,请查看是否编号重复', 'warning');
                        }

                    },
                    error: function () {
                    }
                });
            }


            /****************       辅助业务程序          ***************/
            /**********************************************/
            /*****************   窗体程序 *******************/
            /**********************************************/

            //编辑窗口关闭清空数据
            function clearw() {

                $('#StationID').val('');
                $('#StationNo').val('');
                $('#DownType').combobox('clear');
                $('#DownReason').combobox('clear');
                $('#Des').val('');
                $('#Remark1').val('');
                $('#StartTime_U').datetimebox('setValue', '');
                $('#EndTime_U').datetimebox('setValue', '');

            }

            function reloadfl_ids() {
                $('#fl_id_m_s').combobox('reload', '/HttpHandlers/StationHandler.ashx?method=QueryForCombobox&StationNo=IM');
            }

            function reloadfl_id() {
                $('#DownType').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

                $('#DownType_1').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason_1').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

            }

            function reload_u() {
                $('#DownType_1').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason_1').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

                $('#DownType_2').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason_2').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

                $('#DownType_3').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason_3').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

                $('#DownType_4').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason_4').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

                $('#DownType_5').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownType');
                $('#DownReason_5').combobox('reload', '/HttpHandlers/InjectionDownRecordHandler.ashx?method=QueryForComboboxByDownReason');

            }



        </script>
    </form>
</body>
</html>