<%@ page language="C#" masterpagefile="~/Admin/AdminIndexMaster.master" autoeventwireup="true" inherits="Admin_Admin_JXC_AccountSubject, WebApp_deploy" %>

<asp:Content ID="cphContent" runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
    <asp:ScriptManager ID="sm" runat="server">
    </asp:ScriptManager>
    <script src="Js/Jquery/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Js/Function.js" type="text/javascript"></script>
    <table class="nick" id="table_item" runat="server">
        <tr>
            <td class="tit left1">
                &nbsp;&nbsp;会计科目管理
            </td>
            <td class="tit" style="text-align: right;">
                <a href="Admin_JXC_AccountSubject.aspx?action=addinfo&MenuName=进销存管理&FileName=添加会计科目&ParentID=0">
                    <img style="border: 0px;" src="tpl/img/ico/add.gif" alt="添加" />新增 </a>&nbsp;&nbsp;
            </td>
        </tr>
    </table>
    <%--列表 begin--%>
    <asp:PlaceHolder ID="phManage" runat="server">
        <table class="nick" runat="server">
            <tr>
                <td class="tit" style="vertical-align: top;">
                    <asp:TreeView ID="TVAccountSubject" runat="server" ExpandDepth="1" 
                         CollapseImageUrl="~/Admin/Images/folderopen.gif" 
                        ExpandImageUrl="~/Admin/Images/folder_icon.gif" 
                        NoExpandImageUrl="~/Admin/Images/page.gif">
                        <HoverNodeStyle BackColor="Silver" />
                    </asp:TreeView>
                </td>
                <td style="vertical-align: top">
                    <span style="text-align: left; display: none">会计科目名称：<asp:Label ID="lblASTitle" runat="server"></asp:Label></span>
                    <div id="divAccountSubject" runat="server">
                    </div>                    
                </td>
            </tr>
        </table>
    </asp:PlaceHolder>
    <%--列表 end--%>
    <%--添加/修改 begin--%>
    <asp:PlaceHolder ID="phAddOrEdit" runat="server">
        <table class="nick" width="100%" id="AddTable" runat="server">
            <tr>
                <td class="tit" colspan="2">
                    &nbsp;&nbsp;<asp:Literal ID="ltrTitle" runat="server">添加会计科目</asp:Literal>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    上级科目 ：
                </td>
                <td class="rtd">
                    <asp:Label ID="lblParentName" runat="server"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp;<a
                        id="updateParent" style="cursor: pointer; color: Red; font-weight: bold;" runat="server"
                        visible="false"> 修改</a>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    科目编号 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtAccountSNumber" runat="server"></asp:TextBox>(由数字组成)
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    科目名称 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtAccountSName" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    拼音码 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtAccountSSpell" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    借贷方向 ：
                </td>
                <td class="rtd">
                    <asp:DropDownList ID="ddlAccountSLend" runat="server">
                        <asp:ListItem Value="借">借</asp:ListItem>
                        <asp:ListItem Value="贷">贷</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    辅助核算 ：
                </td>
                <td class="rtd">
                    <asp:DropDownList ID="ddlAccountSAuxiliaryCheck" runat="server">
                        <asp:ListItem Value="">—请选择—</asp:ListItem>
                        <asp:ListItem Value="供应商">供应商</asp:ListItem>
                        <asp:ListItem Value="客户">客户</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="ltd">
                    备注 ：
                </td>
                <td class="rtd">
                    <asp:TextBox ID="txtRemark" runat="server"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="btm">
                    <asp:HiddenField ID="hfAccountSRootID" runat="server" Value="" />
                    <%--hfAccountSRootID 科目根ID--%>
                    <asp:HiddenField ID="hfAccountSDepth" runat="server" Value="" />
                    <%--hfAccountSDepth 科目深度--%>
                    <asp:HiddenField ID="hfAccountSParentID" runat="server" Value="" />
                    <%--hfAccountSParentID 科目父ID--%>
                    <asp:Button ID="btnAdd" runat="server" Text="添 加" OnClientClick="return checkPass()"
                        OnClick="btnAdd_Click" />
                    <input type="button" onclick="location.href='Admin_JXC_AccountSubject.aspx'" value="返 回" />
                </td>
            </tr>
        </table>
    </asp:PlaceHolder>
    <%--添加/修改 end--%>
    <%--查看 begin--%>
    <asp:PlaceHolder ID="phCheck" runat="server"></asp:PlaceHolder>
    <%--查看 end--%>
    <br />
    <script type="text/javascript">
        //编号
        function checkNumber() {
            var txtNumber = $("#<%=txtAccountSNumber.ClientID %>"); //科目编号
            if (txtNumber.val().length == 0) {
                alert("科目编号不能为空!");
                txtNumber.focus();
                return false;
            }
            return true;
        }
        //名称
        function checkName() {
            var txtName = $("#<%=txtAccountSName.ClientID %>"); //科目名称
            if (txtName.val().length == 0) {
                alert("科目名称不能为空!");
                txtName.focus();
                return false;
            }
            return true;
        }
        function checkPass() {
            if (checkNumber() && checkName()) {
                return true;
            } else {
                return false;
            }
        }
    </script>
    <script type="text/javascript">
        function SelectAccountSubjectParentID(asparentid) {
            var arr = showModalDialog('Admin_JXC_AccountSubjectTV.aspx?DefaultValue=' + document.getElementById(asparentid).value, '', 'dialogWidth:400px; dialogHeight:450px; help: no; scroll: yes; status: no');
            if (arr != null) {
                document.getElementById(asparentid).value = arr; //ParentID
                GetDisplayParentName(arr);
            }
        }
        
        //会计科目信息
        function GetDisplayParentName(asparentid) {
            var lblParentName = $("#<%=lblParentName.ClientID %>"); //科目名称
            if (asparentid.toString()=="0") {
                lblParentName.text("顶级科目");
            }
            $.post("../WebService/Admin_JXCService.ashx", { 'Action': 'DisplayParentName', 'ASParentID': asparentid }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        lblParentName.text(data.toString());
                    }
                }
            });
        }
    </script>
    <script type="text/javascript">
        //选中的TreeView控件中的节点
        var backA_id = "";
        function GetAttribute(tvname, tvvalue) {
            var lblASTitle = $("#<%=lblASTitle.ClientID %>");
            lblASTitle.text(tvname);

            var id = "node" + tvvalue; //event.srcElement.id
            var a = document.getElementById(id);
            a.style.backgroundColor = "Silver";
            if (backA_id != "") {
                if (backA_id != id) {
                    var backa = document.getElementById(backA_id);
                    if (backa != undefined) {
                        backa.style.backgroundColor = ""; //恢复默认
                    }
                }
            }
            backA_id = id;
            GetAccountSubject(tvvalue);
        }
        //会计科目信息
        function GetAccountSubject(asparentid) {
            var prodcutStr = "";
            var before = "Admin_JXC_AccountSubject.aspx?MenuName=进销存管理";
            $("#<%=divAccountSubject.ClientID %>").html("");
            prodcutStr += "<table class='adminlist' width='auto'  id='tb_accountsubject'>" +
                           "<th style='text-align: center;'>行号</th>" +
                           "<th style='text-align: center;'>科目编号</th>" +
                          "<th style='text-align: center;'>科目名称</th>" +
                          "<th style='text-align: center;'>拼音码</th>" +
                          "<th style='text-align: center;'>借贷方向</th>" +
                          "<th style='text-align: center;'>辅助核算</th>" +
                          "<th style='text-align: center;'>备注</th>" +
                          "<th style='text-align: center;'>操作</th></tr>";
            $.post("../WebService/Admin_JXCService.ashx", { 'Action': 'GetAccountSubject', 'ASParentID': asparentid }, function (data, state) {
                if (state == "success") {
                    if (data.toString() != "") {
                        var d = eval(data);
                        $.each(d.table1, function (i) {
                            var asubjectID = d.table1[i].AccountSubjectID;
                            var accountsNumber = d.table1[i].AccountSNumber;
                            var accountsName = d.table1[i].AccountSName;
                            var accountsSpell = d.table1[i].AccountSSpell;
                            var accountsLend = d.table1[i].AccountSLend;
                            var accountsAuxiliaryCheck = d.table1[i].AccountSAuxiliaryCheck;
                            var Remark = d.table1[i].Remark;

                            prodcutStr += "<tr><td style='text-align: center;'>" + (i + 1) + "</td>" +
                                     "<td style='text-align: center;'>" + accountsNumber + "</td>" +
                                     "<td style='text-align: center;'>" + accountsName + "</td>" +
                                     "<td style='text-align: center;'>" + accountsSpell + "</td>" +
                                     "<td style='text-align: center;'>" + accountsLend + "</td>" +
                                     "<td style='text-align: center;'>" + accountsAuxiliaryCheck + "</td>" +
                                     "<td style='text-align: center;'>" + Remark + "</td>" +
                                     "<td style='text-align: center;'><a style='cursor:pointer;' href='" + before + "&FileName=添加子科目&action=addinfoChild&InfoID=" + asubjectID + "'>添加子科目</a>&nbsp;"
                                     + "<a style='cursor:pointer;' href='" + before + "&FileName=修改子科目&action=editinfo&InfoID=" + asubjectID + "'>修改</a>&nbsp;"
                                     + "<a style='cursor:pointer;' href='javascript:delAS(" + asubjectID + ',' + asparentid + ")'>删除</a></td></tr>";
                        });
                    } else {
                        prodcutStr += "<tr><td colspan='7' style='text-align: center;'>没有数据</td></tr>";
                    }
                    prodcutStr += "</table>";
                    $("#<%=divAccountSubject.ClientID %>").append(prodcutStr);
                }
            });
        }
        //删除
        function delAS(id, parentid) {
            if (confirm('删除栏目操作将删除此栏目中的所有子栏目,并且不能恢复!确定要删除此栏目吗?')) {
                $.post("../WebService/Admin_JXCService.ashx", { 'Action': 'DeleteAccountSubjectByID', 'ID': id }, function (data, state) {
                    if (state == "success") {
                        if (data.toString() == "2") {
                            alert("该科目还存在子科目，无法删除！");
                        } else if (data.toString() == "1") {
                            alert("删除成功！");
                            GetAccountSubject(parentid); //会计科目信息
                            window.location.href = "Admin_JXC_AccountSubject.aspx?MenuName=进销存管理&FileName=会计科目管理&ASParentID=" + parentid;
                        } else {
                            alert("删除失败！");
                        }
                    }
                });
            }
        }
        $(function () {
            var aspid = "<%=ASParentID %>";
            var actionInfo = "<%=ActionTab %>";
            if (actionInfo == "" || actionInfo == "null") {
                if (aspid != "" || aspid != null) {
                    GetAccountSubject(aspid);
                }
            }
        });
    </script>
</asp:Content>
