using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using TSingSoft.WebControls2;
|
|
|
|
namespace BWP.Web.Pages.Utils
|
|
{
|
|
public class Second_ConvertRatioRowManager
|
|
{
|
|
readonly DFEditGridColumn<DFTextBox> _unitNumInput;
|
|
readonly DFEditGridColumn<DFTextBox> _secondNumberInput;
|
|
|
|
readonly string _unitNumField;
|
|
readonly string _secondNumberField;
|
|
|
|
private const string ConvertDirection = "dfContainer.getValue('Goods_UnitConvertDirection')";
|
|
private const string MainUnitRatio = "dfContainer.getValue('Goods_MainUnitRatio')";
|
|
private const string SecondUnitRatio = "dfContainer.getValue('Goods_SecondUnitRatio')";
|
|
private const string LeftRatio = "dfContainer.getValue('LeftRatio')";
|
|
private const string RightRatio = "dfContainer.getValue('RightRatio')";
|
|
|
|
public Second_ConvertRatioRowManager(DFGridBase grid) : this(grid, "UnitNum", "SecondNumber")
|
|
{
|
|
|
|
}
|
|
|
|
public Second_ConvertRatioRowManager(DFGridBase grid, string unitNumfield, string secondfield)
|
|
{
|
|
_unitNumField = unitNumfield;
|
|
_secondNumberField = secondfield;
|
|
foreach (DFGridColumn column in grid.Columns)
|
|
{
|
|
if (column is DFEditGridColumn<DFTextBox>)
|
|
{
|
|
var c = (DFEditGridColumn<DFTextBox>)column;
|
|
if (c.Name == unitNumfield)
|
|
{
|
|
_unitNumInput = c;
|
|
}
|
|
|
|
else if (c.Name == secondfield)
|
|
_secondNumberInput = c;
|
|
}
|
|
}
|
|
SetClientScript();
|
|
}
|
|
|
|
private void SetClientScript()
|
|
{
|
|
SetUnitNumChanged();
|
|
// SetMainNumberChanged();
|
|
SetSecondNumberChanged();
|
|
}
|
|
|
|
private void SetSecondNumberChanged()//辅至主
|
|
{
|
|
if (_secondNumberInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
if (_unitNumInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由辅至主'){alert(1); if({ratioRight}>0 && {ratioLeft}>0 && {unitRatioLeft} > 0 && {unitRatioRight}>0)
|
|
{alert('1');{setUnitNum}}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{unitRatioLeft}", LeftRatio)
|
|
.Replace("{unitRatioRight}", RightRatio)
|
|
.Replace("{setUnitNum}", SetUnitNumBySecondNumber));
|
|
}
|
|
_secondNumberInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
private void SetUnitNumChanged()//主至辅
|
|
{
|
|
if (_unitNumInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
if (_secondNumberInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由主至辅'){if({unitRatioLeft} > 0 && {unitRatioRight}>0 && {ratioRight}>0 && {ratioLeft}>0){{SetSecondNumberByUnitNum}}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{unitRatioLeft}", LeftRatio)
|
|
.Replace("{unitRatioRight}", RightRatio)
|
|
.Replace("{SetSecondNumberByUnitNum}", SetSecondNumberByUnitNum)
|
|
);
|
|
}
|
|
|
|
_unitNumInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
string SetSecondNumberByUnitNum
|
|
{
|
|
get
|
|
{
|
|
return string.Format("var number = dfContainer.getValue('{0}')/{1}*{2}; dfContainer.setValue('{3}', (number /{4}*{5}).toFixed(6));", _unitNumField, LeftRatio, RightRatio, _secondNumberField, MainUnitRatio, SecondUnitRatio);
|
|
}
|
|
}
|
|
string SetUnitNumBySecondNumber
|
|
{
|
|
get
|
|
{
|
|
return string.Format("var number = dfContainer.getValue('{0}')*{1}/{2};dfContainer.setValue('{3}', (number/{4}*{5}).toFixed(2));", _secondNumberField, MainUnitRatio, SecondUnitRatio, _unitNumField, RightRatio, LeftRatio);
|
|
}
|
|
}
|
|
}
|
|
}
|