<%@ Page Title="" Language="C#" MasterPageFile="~/Car/car.Master" AutoEventWireup="true" CodeBehind="CarMaintain_Road.aspx.cs" Inherits="Car.Car.CarMaintain_Road" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    
     <ul class="nav nav-tabs">
  <li role="presentation" ><a href="CarMaintain.aspx">日常维护</a></li>
  <li role="presentation" class="active"><a href="CarMaintain_Road.aspx">行驶里程</a></li>
 
</ul>


    <div class="well">
        <b>行车里程数</b>：行政管理员或者司机可以每月编辑一下行车里程数。系统将使用此数据计算每月行车里程和耗油量。
    </div>
    <div style=" padding:10px; border:solid 1px #cccccc; margin-bottom:5px;">
  请选择年份  <asp:DropDownList ClientIDMode="Static"  runat="server" ID="ddl_year" AutoPostBack="true"  class="form-control" style="width:200px; display:inline-block" OnSelectedIndexChanged="ddl_year_SelectedIndexChanged">
       

    </asp:DropDownList>

        <input type="button" id="btnEdit" value="编辑"  class="btn btn-primary" onclick="edit(); return false;"/>
            <input type="button" id="btnSave" value="保存" style="display:none"  onclick="save(); return false;" class="btn  btn-danger"/>
          <input type="button" id="btnCancel" value="取消" style="display:none"  onclick="cancel(); return false;" class="btn  btn-success"/>

        </div>



    <table class="table table-hover table-bordered" id="tb_km">
        <tr>
            <th style="min-width:80px">
                车辆名称
            </th>
           <th style="min-width:80px">
                司机
            </th>
            <th class="hide" >
                CarID
            </th>

            <th width="80px" >
                1月
            </th>
              <th width="80px" >
                2月
            </th>
             <th width="80px" >
                3月
            </th>
           <th width="80px" >
                4月
            </th>
             <th width="80px" >
                5月
            </th>
            <th width="80px" >
                6月
            </th>
             <th width="80px" >
                7月
            </th>
             <th width="80px" >
                8月
            </th>
            <th width="80px" >
                9月
            </th>
             <th width="80px" >
                10月
            </th>
              <th width="80px" >
                11月
            </th>
             <th width="80px" >
                12月
            </th>
        </tr>
       
        <asp:Literal runat="server" ID="lbl_km"></asp:Literal>
    </table>


    <style>
        .kmvalue {
         width:80px;
        }
    </style>



    <script>

  

 
        function edit() {
            $("#btnEdit").hide();
            $("#btnCancel").show();
            $("#btnSave").show();

            $("td.tdedit").each(function () { 
                $(this).html("<input name=kmvalue type='text'class='kmvalue' value='" + ($(this).text() == "--" ? "" : $(this).text()) + "'>");
              });
        }
 
  
        function cancel() {
            window.location = "carmaintain_road.aspx?year="+$("#ddl_year").val();

            //$("#btnEdit").show();
            //$("#btnCancel").hide();
            //$("#btnSave").hide();
 

            //$("td.tdedit").each(function () {
            //    obj_text = $(this).find("input:text").val();
            //    $(this).html(obj_text == "" ? "--" : obj_text );
            //});

             
        }



        function save()
        {
            $("#btnEdit").show();
            $("#btnCancel").hide();
            $("#btnSave").hide();


            var kms = $(".kmvalue");
            var count = kms.length;

            

            var values = "";
            for (i = 0; i < count; i++)
            {
                v = $(kms[i]).val();
                if (v == "")
                {
                    v = "0";
                }
                values +=v+";"

            }

            var year = $("#ddl_year").val();

            $.post("ajax/savekm.aspx", { kms: values, year:year, rand:Math.random()});

            $("td.tdedit").each(function () {
                obj_text = $(this).find("input:text").val();
                $(this).html(obj_text == "" ? "--" : obj_text);
            });
        }

      </script>






</asp:Content>
