1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="PaperInfoEdit.aspx.cs" Inherits="CY.WebForm.Pages.sysInquiry.PaperInfoEdit" enableEventValidation="false" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>新增/修改纸张</title>
    <uc:CMSHead ID="CMSHead1" runat="server" />
    <script type="text/javascript">
        //正数正则表达式
        var reg1 = /^\d+(?=\.{0,1}\d+$|$)/;
        //整数正则表达式
        var reg2 = /^-?\d+$/;
        $(
            function () {
                $("#hidResult").val($("#txtResultGramWeights").val());
 
                $("#btnAddGramWeight").click(
                    function () {
                        var txtGramWeights = $("#txtGramWeights").val();
                        var lblGramWeights = $("#txtResultGramWeights").val();
                        if (txtGramWeights == "") {
                            top.Dialog.alert("请输入要新增的克重", function () {
                            });
                            return;
                        }
                        else {
                            var msg = "";
                            var txtGramWeightArry = txtGramWeights.split('|');
                            for (var i = 0; i < txtGramWeightArry.length; i++) {
                                if (!reg2.test(txtGramWeightArry[i])) {
                                    msg = "新增的克重" + txtGramWeightArry[i] + "必须是整数";
                                    top.Dialog.alert(msg, function () {
                                    });
                                    return;
                                }
                                var lblGramWeightArry = lblGramWeights.split('|');
                                for (var j = 0; j < lblGramWeightArry.length; j++) {
                                    if (txtGramWeightArry[i] == lblGramWeightArry[j]) {
                                        msg = "新增的克重" + txtGramWeightArry[i] + "已存在";
                                        top.Dialog.alert(msg, function () {
                                        });
                                        return;
                                    }
                                }
                            }
                            if (lblGramWeights != "") {
                                $("#txtResultGramWeights").val(lblGramWeights + "|" + txtGramWeights);
                            }
                            else {
                                $("#txtResultGramWeights").val(txtGramWeights);
                            }
                            $("#txtGramWeights").val("");
                        }
                    }
                );
 
                $("#btnDeleteGramWeight").click(
                    function () {
                        var txtGramWeights = $("#txtGramWeights").val();
                        var lblGramWeights = $("#txtResultGramWeights").val();
                        if (txtGramWeights == "") {
                            top.Dialog.alert("请输入要删除的克重", function () {
                            });
                            return;
                        }
                        else {
                            var msg = "";
                            var leftValue = "";
                            var txtGramWeightArry = txtGramWeights.split('|');
                            var lblGramWeightArry = lblGramWeights.split('|');
                            for (var i = 0; i < lblGramWeightArry.length; i++) {
                                if (!IsExist(txtGramWeightArry, lblGramWeightArry[i]))
                                    leftValue += lblGramWeightArry[i] + "|";
                            }
                            if (leftValue != "") {
                                leftValue = leftValue.substring(0, leftValue.length - 1);
                            }
                            $("#txtResultGramWeights").val(leftValue);
                            $("#txtGramWeights").val("");
                        }
                    }
                );
 
                $("#txtResultGramWeights").blur(
                    function () {
                        var newValue = $(this).val();
                        if (newValue == "") {
                            top.Dialog.alert("克重不能为空", function () {
                            });
                            return;
                        }
                        var newValueArry = newValue.split('|');
                        for (var i = 0; i < newValueArry.length; i++) {
                            if (IsRepeat(newValueArry, newValueArry[i])) {
                                top.Dialog.alert("克重不能重复", function () {
                                });
                                $("#txtResultGramWeights").val($("#hidResult").val());
                                return;
                            }
                        }
                        $("#hidResult").val($("#txtResultGramWeights").val());
                    }
                );
 
                cbkAllSelChecked();
                var isChecked = true;
                $(":checkbox[id*=cbkAllSel]").click(
                    function () {
                        if (this.checked) {
                            isChecked = true;
                        }
                        else {
                            isChecked = false;
                        }
                        $("input:checkbox").each(
                            function () {
                                $(this).attr("checked", isChecked);
                            }
                        );
                        BindDefaultBrand();
                    }
                );
                $("input:checkbox[id!=cbkAllSel]").click(
                        function () {
                            cbkAllSelChecked();
                            BindDefaultBrand();
                        }
                );
 
                $("#ddlDefaultBrand").change(
                        function () {
                            $("#hidSelBrandId").val($(this).val());
                        }
                );
            }
        );
 
        //判断在数组中是否存在
        function IsExist(gramWeightArry,value)
        {
            for(var i=0;i<gramWeightArry.length;i++)
            {
                if(value==gramWeightArry[i])
                {
                    return true;
                }
            }
            return false;
        }
 
        //判断是否重复
        function IsRepeat(gramWeightArry, value) {
            var num=0;
            for(var i=0;i<gramWeightArry.length;i++)
            {
                if(value==gramWeightArry[i])
                {
                    num++;
                }
                if(num==2)
                {
                    return true;
                }
            }
            return false;
        }
 
        //控制全选状态
        function cbkAllSelChecked() {
            var isAllChecked = true;
            $("input:checkbox[id!=cbkAllSel]").each(
                            function () {
                                if (!this.checked) {
                                    isAllChecked = false;
                                }
                            }
            );
            $(":checkbox[id*=cbkAllSel]").attr("checked", isAllChecked);
        }
 
        //绑定默认品牌
        function BindDefaultBrand() {
            var selArry = [];
            var option = "";
            $("input:checkbox[id!=cbkAllSel]").each(
                function () {
                    if (this.checked) {
                        option += "<option value=\"" + $(this).val() + "\">" + $(this).next().text() + "</option>";
                        selArry.push($(this).val());
                    }
                }
            );
                $("#ddlDefaultBrand").html("");
                $("#ddlDefaultBrand").html(option);
                if (selArry.length > 0) {
                    var hidDefaultBrandId = $("#hidDefaultBrandId").val();
                    if (IsExist(selArry, hidDefaultBrandId)) {
                        $("#hidSelBrandId").val(hidDefaultBrandId);
                        $("#ddlDefaultBrand").val(hidDefaultBrandId);
                    }
                    else {
                        $("#hidSelBrandId").val(selArry[0]);
                    }
                }
            }
 
 
        function CanOpeate() {
            var isCanOpeate = false;
            $("input:checkbox[id!=cbkAllSel]").each(
                function () {
                    if (this.checked) {
                        isCanOpeate = true;
                    }
                }
            );
                if (!isCanOpeate) {
                    top.Dialog.alert("请至少选择一个品牌", function () {
                    });
                    return false;
                }
                else {
                    return true;
                }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server" class="form">
   <table class="tableStyle">
                <tr><td class="ali03">纸张类别:</td><td><asp:DropDownList ID="ddlPaperType" 
                        runat="server" CssClass="Sreq" msg="请选择纸张类别" keepdefaultstyle='true' 
                        AutoPostBack="true" onselectedindexchanged="ddlPaperType_SelectedIndexChanged"></asp:DropDownList></td></tr>
                <tr><td class="ali03">纸张名称:</td><td><input runat="server" id="txtPaperName" type="text" style="width:150px" class="req" msg="纸张名称不能为空"/></td></tr>
                <tr><td class="ali03">克重:</td><td><div>新增克重:<asp:TextBox ID="txtGramWeights" runat="server" style="width:200px"></asp:TextBox><input type="button" id="btnAddGramWeight" value="新增克重"/>&nbsp;&nbsp;<input type="button" id="btnDeleteGramWeight" value="删除克重"/></div><div style="color:Red">注:新增删除克重都可以以“|”间隔数字进行批量操作,如:70|80|90</div><div>已增克重:<asp:TextBox ID="txtResultGramWeights" runat="server" Width="300px"></asp:TextBox></div></td></tr>
                <%--<tr><td class="ali03">品牌列表:</td><td>
                      <asp:CheckBoxList ID="cbkBrandList" runat="server" RepeatColumns="5" RepeatDirection="Horizontal">
                      </asp:CheckBoxList>
                      &nbsp;&nbsp;<input type="checkbox" id="cbkAllSel" />全选
                </td></tr>
                <tr><td class="ali03">默认品牌:</td><td><asp:DropDownList ID="ddlDefaultBrand" runat="server" CssClass="Sreq" msg="请选择默认品牌" keepdefaultstyle='true'></asp:DropDownList></td></tr>--%>
                <tr><td class="ali03 ">是否有效:</td><td><asp:DropDownList ID="ddlStatus" runat="server"><asp:ListItem Value="True" Text="有效"></asp:ListItem><asp:ListItem Value="False" Text="无效"></asp:ListItem></asp:DropDownList></td></tr>
                <tr><td class="ali03 ">排序顺序:</td><td><input id="txtOrerNum" type="text" runat="server" class="req int" msg="排序不能为空" value="1" /></td></tr>
                <tr><td class="ali03"></td><td><asp:Button ID="btnSubmit" Text="提交" runat="server" OnClick="btnSubmit_Click"/>&nbsp;&nbsp;<input type="button" id="btnClose" value="关闭" onclick="RefreshDIVOpener();"/></td></tr>
     </table>
     <input type="hidden" id="hidResult" />
     <input type="hidden" id="hidDefaultBrandId" runat="server" />
     <input type="hidden" id="hidSelBrandId" runat="server" />
    </form>
</body>
</html>