C#根据公式计算结果

  [HttpPost]
        public JsonResult ScriptExpressions(string expL
            ,string expW,string expH,string expP,string expD
            , string L, string W, string H, string P)
        {
            ExpResult result = new ExpResult();
            try
            {
                MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
                sc.Language = "JavaScript";
                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("var L={0},W={1},H={2},P={3};", string.IsNullOrWhiteSpace(L) ? "0" : L, string.IsNullOrWhiteSpace(W) ? "0" : W, string.IsNullOrWhiteSpace(H) ? "0" : H, string.IsNullOrWhiteSpace(P) ? "0" : P);
                sc.ExecuteStatement(sb.ToString());
                
                if (!string.IsNullOrWhiteSpace(expL))
                    result.L = sc.Eval(expL);//长
                else
                    result.L = 0;
                if (!string.IsNullOrWhiteSpace(expW))
                    result.W = sc.Eval(expW);//宽
                else
                    result.W = 0;
                if (!string.IsNullOrWhiteSpace(expH))
                    result.H = sc.Eval(expH);//高
                else
                    result.H = 0;
                if (!string.IsNullOrWhiteSpace(expP))
                    result.P = sc.Eval(expP);//外箱单价
                else
                    result.P = 0;
                if (!string.IsNullOrWhiteSpace(expD))
                    result.D = sc.Eval(expD);//刀μ?卡¨单μ¥价?
                else
                    result.D = 0;
                result.flag = true;
                return Json(result);
            }
            catch
            {
                result.flag = false;
                return Json(result);
            }
            
        }
    }
    public class ExpResult
    {
        public double L { get; set; }
        public double W { get; set; }
        public double H { get; set; }
        public double P { get; set; }
        public double D { get; set; }
        public bool flag { get; set; }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值