<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/AppMaster.Master"
    Inherits="System.Web.Mvc.ViewPage<QMAPP.FJC.Web.Models.FeedInManage.InJectionRecorderModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    搪塑投料记录列表
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%=Html.QPSeach(100,true) %>
    <table id="condiTable">
        <tr>
            <th align="right">
                <%=Html.QV(p => p.MATERIALCODETXT)%>
            </th>
            <td>
                <%=Html.QC(p => p.MATERIALCODETXT)%>
            </td>
            <th align="right">
                <%=Html.QV(p=>p.MATERIALNAME) %>
            </th>
            <td>
                <%=Html.QC(p => p.MATERIALNAME)%>
            </td>
            <th align="right">
                粉料种类
            </th>
            <td>
                <input type="text" name="MATERIALTYPE" id="MATERIALTYPE"/>
            </td>
            <th align="right">
                <%=Html.QV(p => p.MATERIALBATCH)%>
            </th>
            <td>
                <%=Html.QC(p => p.MATERIALBATCH)%>
            </td>
        </tr>
        <tr>
            <th>
                <%=Html.QV(p => p.PRODUCESHIFTTCODE)%>
            </th>
            <td>
                <%=Html.QC(p => p.PRODUCESHIFTTCODE)%>
            </td>
            <th>
                <%=Html.QV(p => p.MACHINECODDE)%>
            </th>
            <td>
                <%=Html.QC(p => p.MACHINECODDE)%>
            </td>
            <th>
                <%=Html.QV(p => p.CreateDateStart)%>
            </th>
            <td>
                <%=Html.QC(p => p.CreateDateStart)%>
            </td>
            <th>
                <%=Html.QV(p => p.CreateDateEnd)%>
            </th>
            <td>
                <%=Html.QC(p => p.CreateDateEnd)%>
            </td>
        </tr>
    </table>
    <div style="left: 1px; position: relative;">
    </div>
    <%=Html.HiddenFor(p=>p.PROCESSTYPE)%>
    <%=Html.QPEnd()%>
    <%=Html.QPList() %>
    <%//=Html.QDateGrid<QMAPP.FJC.Web.Models.FeedInManage.InJectionRecorderModel>(Model)%>
    <table id="QDateGrid" cellspacing="0" cellpadding="0" data-options="pageNumber:1,pageSize:20">
    </table>
    <input id="pageNumber" name="pageNumber" type="hidden" value="" />
    <input id="pageSize" name="pageSize" type="hidden" value="" />
    <input id="pageSort" name="pageSort" type="hidden" value="" />
    <script>
        $(function () {
            $('#QDateGrid').datagrid({
                //IconCls:'icon-save', 
                width: 600,
                height: 350,
                fit: true,
                nowrap: false,
                striped: true,
                collapsible: false,
                onSortColumn: function (sort, order) {
                    $('#pageSort').attr('value', sort + ' ' + order);
                    if ($('#pageNumber').val() == '') { List(1); } else { List(parseInt($('#pageNumber').val())); }
                },
                pagination: true,
                rownumbers: false,
                remoteSort: false,
                idField: 'PID',
                frozenColumns: [[
	                    { field: 'ck', checkbox: true },
                        { field: 'MATERIALCODE', title: '物料号', sortable: 'true', align: 'center', width: 100 },
                        { field: 'MATERIALNAME', title: '物料名称', sortable: 'true', align: 'left', width: 300 },
                        { field: 'MATERIALTYPE', title: '粉料种类', sortable: 'true', align: 'left', width: 100 }
				    ]],
                columns: [[
                        { field: 'MATERIALBATCH', title: '批次号', sortable: 'true', align: 'center', width: 100 },
                        { field: 'PACKAGENO', title: '料包号', sortable: 'true', align: 'center', width: 100 },
                        { field: 'METERIALWEIGHT', title: '投料重量', sortable: 'true', align: 'left', width: 100 },
                        { field: 'MACHINENAME', title: '设备', sortable: 'true', align: 'left', width: 100 },
                        { field: 'INJECTIONTERMINAL', title: '料箱', sortable: 'true', align: 'left', width: 100 },
                        { field: 'CREATEDATE', title: '换料时间', sortable: 'true', align: 'center', width: 150 },
                        { field: 'CREATEUSERNAME', title: '操作用户', sortable: 'true', align: 'left', width: 100 },
                        { field: 'PRODUCESHIFTNAME', title: '班次', sortable: 'true', align: 'left', width: 100 },
                        { field: 'UPDATEDATE', title: '更新时间', sortable: 'true', align: 'center', width: 150 }
				    ]],
                toolbar: false,
                onLoadError: function () { MSI('error', '获取数据时出现异常。'); }
            });
            var p = $('#QDateGrid').datagrid('getPager');
            if (p) {
                $(p).pagination({
                    pageSize: 20,
                    pageList: [20, 40, 60],
                    pageNumber: 1,
                    onSelectPage: function (pageNumber) {
                        var ops = $('#QDateGrid').datagrid('options');
                        ops.url = ""
                        List(pageNumber);
                    }
                });
            }
            var ops = $('#QDateGrid').datagrid('options');
            ops.view.onBeforeRender = function () { $.tabPages.beginDraw(); }
            ops.view.onAfterRender = function () { $.tabPages.endDraw(); };
        })
        function List(pageNumber) {
            if (pageNumber == null) { pageNumber = 1; }
            $('#QDateGrid').datagrid('loading');
            $('#QDateGrid').datagrid('clearSelections');
            $('#pageNumber').attr('value', pageNumber);
            var p = $('#QDateGrid').datagrid('getPager');
            if (p) {
                var ipageSize = p.data("pagination").options.pageSize;
                $('#pageSize').attr('value', ipageSize);
            }
            $.ajax({
                type: "POST",
                url: "/InJectionRecorder/GetList",
                dataType: "json",
                data: $('#Mainform').serialize(),
                success: function (data) {

                    var arrSort = null;
                    var obj = null;
                    if ($('#pageSort').val() != '') {
                        arrSort = $('#pageSort').val().split(' ');
                        obj = $('#QDateGrid').datagrid('options');
                        obj.sortName = null;
                        obj.sortOrder = 'asc';
                    }

                    $("#QDateGrid").datagrid('loadData', data);
                    $('#QDateGrid').datagrid('loaded');

                    if (arrSort != null) {
                        obj.sortName = arrSort[0];
                        obj.sortOrder = arrSort[1];
                    }

                    var p = $('#QDateGrid').datagrid('getPager');
                    if (p) {
                        $(p).pagination({
                            pageNumber: pageNumber
                        });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $('#QDateGrid').datagrid('loaded');
                    MSI('error', '获取数据时出现异常。');
                }
            });
        }
        function getSelectKey() {
            var ids = [];
            var rows = $('#QDateGrid').datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                ids.push(rows[i].PID);
            }
            return ids.join(':');
        }
        function getSelectColumnValues(columnName) {
            var ids = [];
            var rows = $('#QDateGrid').datagrid('getSelections');
            for (var i = 0; i < rows.length; i++) {
                ids.push(rows[i][columnName]);
            }
            return ids.join(':');
        }
    </script>
    <%=Html.QPEnd() %>
    <%=Html.Hidden("selectKey")%>
    <script language="javascript" type="text/javascript">

        $(function () {
            var attriute = "3";
//            //获取物料下拉数据源
//            $('#MATERIALTYPE').combobox({
//                url: "/Dict/GetMaterialClassByAttributeComboxSource?attribute=" + attriute,
//                editable: 'false',
//                valueField: 'MATERIAL_TYPE_CODE',
//                textField: 'MATERIAL_TYPE_NAME'
//            });
//            $('#MATERIALTYPE').combobox("setValue", "");

            var type = "INJECT";
            //获取设备MACHINE下拉数据源
            $('#MACHINECODDE').combobox({
                url: "/Dict/GetMachineForOrder?ordertype=" + type,
                editable: 'false',
                valueField: 'MACHINECODDE',
                textField: 'MACHINENAME'
            });
            $('#MACHINECODDE').combobox("setValue", "");
            List(1);
        });

        //标记()的记录为红色
        //        $('#QDateGrid').datagrid({
        //            rowStyler: function (index, row) {
        //                if (row.USEDWEIGHTSUM == 0) {
        //                    return 'color:red;';
        //                }
        //            }
        //        });

        //修改
        function Update() {
            var ids = getSelectKey();
            if (ids == "") {
                MSI("提示", "请选择修改记录。");
                return;
            }
            if (ids.indexOf(":") > 0) {
                MSI("提示", "每次只能修改一条记录。");
                return;
            }
            var USEDWEIGHTSUM = $('#QDateGrid').datagrid('getSelections')[0].USEDWEIGHTSUM;
            if (USEDWEIGHTSUM != 0) {
                MSI("提示", "该零件已使用,不能修改!");
                return;
            }
            document.getElementById("selectKey").value = ids;
            openAppWindow1('注塑投料记录修改', 'Edit?PID=' + ids, '350', '360');
        }
        //删除
        function Delete() {
            var ids = getSelectKey();
            if (ids == "") {
                MSI("错误", "至少选择一条记录");
            }
            var USEDWEIGHTSUM = $('#QDateGrid').datagrid('getSelections')[0].USEDWEIGHTSUM;
            if (USEDWEIGHTSUM != 0) {
                MSI("提示", "该零件已使用,不能删除!");
                return;
            }
            document.getElementById("selectKey").value = ids;
            MSQ("提示", "确定要删除选中的记录吗?", function () {
                submitByButton("Delete");
            })
        }

        $(function () {

            $('#MACHINECODDE').combobox({
                panelWidth: '200'

            });

        });
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ToolContent" runat="server">
    <table cellpadding="0" cellspacing="0">
        <tr>
            <td align="center">
                <%=Html.QTButtonSearch("InJectionRecorder", "List", " List(1)")%>
                <%=Html.QTButtonUpdate("InJectionRecorder", "Update", "Update()")%>
                <%=Html.QTButtonDelete("InJectionRecorder", "Delete", "Delete()")%>
            </td>
        </tr>
    </table>
</asp:Content>