using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CY.Infrastructure.Common;
namespace CY.WebForm.Pages.sysInquiry
{
///
/// CalculatePaperPriceHandler 的摘要说明
///
public class CalculatePaperPriceHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string paperSize = string.Empty;
int? gramWeight = null;
decimal? tonsPrice = null;
decimal? reamPrice = null;
paperSize = context.Request.Params["paperSize"].ToString();
if (!string.IsNullOrEmpty(context.Request.Params["gramWeight"].ToString()))
{
gramWeight = int.Parse(context.Request.Params["gramWeight"].ToString());
}
if (!string.IsNullOrEmpty(context.Request.Params["tonsPrice"].ToString()))
{
tonsPrice = Convert.ToDecimal(context.Request.Params["tonsPrice"].ToString());
}
if (!string.IsNullOrEmpty(context.Request.Params["reamPrice"].ToString()))
{
reamPrice = Convert.ToDecimal(context.Request.Params["reamPrice"].ToString());
}
context.Response.Write(CalculatePaperPrice(paperSize, gramWeight, tonsPrice, reamPrice));
context.Response.End();
}
///
/// 纸价转换计算
///
/// 纸张尺寸
/// 克重
/// 吨价
/// 令价
/// 前台显示json字符串
public string CalculatePaperPrice(string paperSize, int? gramWeight, decimal? tonsPrice, decimal? reamPrice)
{
//纸张单价
decimal? price = 0;
//令重
decimal? reamWeight = 0;
//令数
double? reamNumber = 0;
string html = "";
if (gramWeight != null)
{
if (reamPrice == null)
{
if (!string.IsNullOrEmpty(paperSize) && gramWeight != null && tonsPrice != null)
{
string[] paperSizes = paperSize.Split('×');
double widht = paperSizes[0].ToDouble2().Value / 1000;
double height = paperSizes[1].ToDouble2().Value / 1000;
double _gramWeight = gramWeight.ToDouble2().Value / 1000;
double area = widht * height;
price = (area * _gramWeight * (tonsPrice.ToDouble2() / 1000)).ToDecimal2();
reamWeight = (widht * height * _gramWeight * 500).ToDecimal2();
reamWeight = reamWeight.ToDecimal2();
reamNumber = (1000 / reamWeight).ToDouble2().Value.ToString("0.00").ToDouble2();
reamPrice = price * 500;
}
}
else
{
if (!string.IsNullOrEmpty(paperSize) && gramWeight != null && reamPrice != null)
{
string[] paperSizes = paperSize.Split('×');
double widht = paperSizes[0].ToDouble2().Value / 1000;
double height = paperSizes[1].ToDouble2().Value / 1000;
double _gramWeight = gramWeight.ToDouble2().Value / 1000;
double area = (widht * height) / 2;
price = reamPrice / 500;
tonsPrice = (reamPrice.ToDouble2() / (area.ToDouble2() * (gramWeight.ToDouble2())) * 1000).ToDecimal2();
tonsPrice = tonsPrice.ToDecimal2();
reamWeight = (widht * height * _gramWeight * 500).ToDecimal2();
reamWeight = reamWeight.ToDecimal2();
reamNumber = (1000 / reamWeight).ToDouble2().Value.ToString("0.00").ToDouble2();
}
}
}
else
{
string[] paperSizes = paperSize.Split('×');
double widht = paperSizes[0].ToDouble2().Value / 1000;
double height = paperSizes[1].ToDouble2().Value / 1000;
double area = (widht * height) / 2;
price = reamPrice / 500;
gramWeight = ((reamPrice.ToDouble2() / (tonsPrice.ToDouble2() / 1000)) / area).ToInt32();
double _gramWeight = gramWeight.ToDouble2().Value / 1000;
reamWeight = (widht * height * _gramWeight * 500).ToDecimal2();
reamWeight = reamWeight.ToDecimal2();
reamNumber = (1000 / reamWeight).ToDouble2().Value.ToString("0.00").ToDouble2();
}
html = paperSize + "|" + gramWeight.ToDecimal2Yen() + "|" + reamWeight.ToDecimal2Yen() + "|" + reamNumber.ToDecimal2Yen() + "|" + tonsPrice.ToDecimal2Yen() + "|" + reamPrice.ToDecimal2Yen() + "|" + price.ToDecimal2Yen();
return html;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}