多种方式收费解决方案

核心算法:

        /// <summary>
        /// 计算付款明细
        /// </summary>
        /// <param name="cpy_account"></param>
        /// <param name="tmp"></param>
        /// <param name="tmp_row"></param>
        /// <returns></returns>
        private decimal Settlement(decimal cpy_account, ref decimal tmp, ref decimal tmp_row)
        {
            decimal sy_account = 0;//剩余应付

            if (cpy_account > 0)
            {
                if (tmp >= cpy_account)
                {
                    tmp_row = cpy_account;
                    tmp -= cpy_account;
                }
                else
                {
                    tmp_row = tmp;
                    tmp = 0;
                    sy_account = cpy_account - tmp_row;
                }
            }
            return sy_account;
        }
        /// <summary>
        /// 执行结算
        /// </summary>
        /// <param name="cpy_account"></param>
        /// <param name="tmpList"></param>
        /// <returns></returns>
        private List<decimal> SettlementRun(decimal cpy_account, List<decimal> tmpList)
        {
            List<decimal> decList = new List<decimal>();

            decimal sy_account = cpy_account;
            for (int i = 0; i < tmpList.Count; i++)
            {
                decimal tmp = tmpList[i];
                decimal tmp_row = 0;
                sy_account = Settlement(sy_account, ref tmp, ref tmp_row);
                tmpList[i] = tmp;

                decList.Add(tmp_row);
            }

            return decList;
        }

调用执行:

        List<decimal> tmpList = new List<decimal>() { xj1, xj2, xj3, sk1, sk2, sk3, sk4, fq1, fq2, fq3, fq4, fq5, fq6, fq7, dsf1, dsf2, dsf3, dsf4, qt1, qt2, qt3 };
///收费明细循环 /// foreach (DataRow dataRow in ctmzpts.Rows) {
       //明细行应付金额
       decimal cpy_account = dataRow["cpy_account"].ToDecimal(); 
List<decimal> decList = SettlementRun(cpy_account, tmpList); decimal xj1_row = decList[0]; decimal xj2_row = decList[1]; decimal xj3_row = decList[2]; decimal sk1_row = decList[3]; decimal sk2_row = decList[4]; decimal sk3_row = decList[5]; decimal sk4_row = decList[6]; decimal fq1_row = decList[7]; decimal fq2_row = decList[8]; decimal fq3_row = decList[9]; decimal fq4_row = decList[10]; decimal fq5_row = decList[11]; decimal fq6_row = decList[12]; decimal fq7_row = decList[13]; decimal dsf1_row = decList[14]; decimal dsf2_row = decList[15]; decimal dsf3_row = decList[16]; decimal dsf4_row = decList[17]; decimal qt1_row = decList[18]; decimal qt2_row = decList[19]; decimal qt3_row = decList[20];

       //TODO...
     }

 看不懂说明用不到,用到了就能看懂了^-^

posted @ 2020-10-27 17:54  mapstar  阅读(140)  评论(0编辑  收藏  举报