【问题标题】:Calculate the amounts in table (td)计算表中的金额 (td)
【发布时间】:2016-12-06 19:54:31
【问题描述】:

我正在创建一个网络应用程序,我在其中获取数据(员工的费用)。

我想计算所有td的金额并打印出来。

我正在使用 angularjs 来获取数据。

这是我的桌子:

<tr>
                <th colspan="2" style="border:1px solid black">Payment Id</th>
                <th colspan="2" style="border:1px solid black">Date Of Issue</th>
                <th colspan="2" style="border:1px solid black">Date Of Trainer</th>
                <th colspan="1" style="border:1px solid black">Training Id</th>
                <th colspan="2" style="border:1px solid black">Payment Mode</th>
                <th colspan="2" style="border:1px solid black">Cheque/ UTR no</th>
                <th style="border:1px solid black">Amount</th>
            </tr>
            <tr ng-repeat="i in getexpenseinfo">
                <td colspan="2" style="border:1px solid black">{{i.paymentid}}</td>
                <td colspan="2" style="border:1px solid black">{{i.dateofissue}}</td>
                <td colspan="2" style="border:1px solid black">{{i.dateoftransfer}}</td>
                <td colspan="1" style="border:1px solid black">{{i.trainingid}}</td>
                <td colspan="2" style="border:1px solid black">{{i.paymentmode}}</td>
                <td colspan="2" style="border:1px solid black">{{i.chequeno}}</td>
                <td style="border:1px solid black">{{i.amount}}</td>
            </tr>

{{i.amount}} 列正在获取花费在费用上的金额,这里是我的控制器

$http.get('/paymentrpt.asmx/expenseinforpt', {
                params: {
                    datefrm: $scope.datefrm,
                    dateto: $scope.dateto,
                    empname: $scope.emp
                }
            }).then(function (response) {

                $scope.getexpenseinfo = response.data.info;
                $scope.pageload = false;
            });

以及我正在获取数据的网络服务:

[WebMethod]
        [ScriptMethod(UseHttpGet = true)]
        public void expenseinforpt(string datefrm, string dateto, string empname)
        {
            List<object> expenseinfo = new List<object>();
            SqlCommand cmd = new SqlCommand("prolltexpense", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Connection = con;
            con.Open();
            SqlParameter[] param = {
                new SqlParameter("@from",datefrm),
                new SqlParameter("@to",dateto),
                new SqlParameter("@trainer",empname)
            };
            cmd.Parameters.AddRange(param);
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                expenseinfo.Add(new
                {
                    trainingno = dr["trainingno"].ToString(),
                    expenseno=dr["expenseno"].ToString(),
                    expensehead=dr["expensehead"].ToString(),
                    amount=dr["amt"].ToString(),
                    remark=dr["remark"].ToString(),
                    claim=dr["gigeraccount1"].ToString()
                });
            }
            var json = js.Serialize(expenseinfo);
            Context.Response.Write("{" + '"' + "info" + '"' + ":" + json + "}");
            con.Close();
        }

这是我从中获取金额的存储过程:

CREATE PROCEDURE prolltexpense (@from varchar(50),@to varchar(50),@trainer varchar(50))  

AS  
BEGIN  
select expense.trainingno,expense.expenseno,expense.expensehead,expense.amt,expense.remark,(case when expense.gigeraccount=1 then 'YES' when expense.gigeraccount=0 then 'NO' end) as gigeraccount1 from instructoreexpense left outer join sonvininsert on son
vininsert.sonvinid=instructoreexpense.sonvinid left outer join finalinstructoreexpense on finalinstructoreexpense.sonvinid=instructoreexpense.sonvinid join expense on sonvininsert.trainingno=expense.trainingno  where sonvininsert.date between convert(date
time,@from,105) and convert(datetime,@to,105) and sonvininsert.trainer=@trainer  order by sonvininsert.date  

END

如果要计算桌子的金额,我需要做什么?

这就是我的桌子的样子:

Training Id Expense No. Expense Head    Amount  Remark  Claim
16100800002 16100800002001  Conveyance  20  Kurla to Mumbra Return by train NO
16100800002 16100800002002  Conveyance  80  Mumbra stn. to School by auto Patrick, Kishan & me  NO
16100800002 16100800002003  Conveyance  45  School to Mumbra stn. by auto Patrick, Kisan & me   NO
16111800006 16111800006001  F&B 110 Dinner in train on 17th NO
16111800006 16111800006002  Conveyance  18  Residence to Vile parle stn. by auto on 17th    NO
16111800006 16111800006003  Travelling  150 Hotel to Guru Nanak school by auto  NO
16111800006 16111800006004  Travelling  30  Guru nanak school to hotel by sharing auto and bus  NO
16111800006 16111800006006  Conveyance  18  Vile parle to residence by auto on 19th NO
16111800006 16111800006005  F&B 287 Breakfast, Lunch & dinner   NO



(B) Payable
0

【问题讨论】:

    标签: angularjs sql-server web-services html-table


    【解决方案1】:

    我不知道 angularjs,但你可以从 sql-server 轻松完成

    select sum (expense.amt) as totalamt
     from instructoreexpense left outer join sonvininsert on 
    sonvininsert.sonvinid=instructoreexpense.sonvinid left outer join finalinstructoreexpense on 
    finalinstructoreexpense.sonvinid=instructoreexpense.sonvinid join expense 
    on sonvininsert.trainingno=expense.trainingno   where sonvininsert.date 
    between convert(datetime,@from,105) 
    and convert(datetime,@to,105) and sonvininsert.trainer=@trainer
    

    如果它给你错误,请告诉我,因为我使用你给定的代码,我不知道你的 sql 中的费用是 int 还是 varchar

    【讨论】:

      猜你喜欢
      • 2023-04-07
      • 2014-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多