using BWP.B3Sale.BL;
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using TSingSoft.WebControls2;
|
|
|
|
namespace BWP.Web.Pages
|
|
{
|
|
public class MainToSecondConvertRowManger
|
|
{
|
|
readonly DFEditGridColumn<DFTextBox> _unitNumInput;
|
|
readonly DFEditGridColumn<DFTextBox> _mainNumberInput;
|
|
readonly DFEditGridColumn<DFTextBox> _secondNumberInput;
|
|
readonly DFEditGridColumn<DFTextBox> _priceInput;
|
|
readonly DFEditGridColumn<DFTextBox> _willOutStoreSecondNumberInput;
|
|
readonly DFEditGridColumn<DFTextBox> _willOutStoreUnitNumInput;
|
|
readonly DFEditGridColumn<DFTextBox> _invoicedUnitNumInput;
|
|
readonly DFEditGridColumn<DFTextBox> _invoicedMoneyInput;
|
|
readonly DFEditGridColumn<DFTextBox> _moneyInput;
|
|
readonly DFEditGridColumn<DFTextBox> NetPriceInput;
|
|
readonly DFEditGridColumn<DFTextBox> PriceCostInput;
|
|
|
|
readonly string _unitNumField;
|
|
readonly string _mainNumberField;
|
|
readonly string _secondNumberField;
|
|
readonly string _moneyField;
|
|
readonly string _rebateField;
|
|
readonly string _rebateMoneyField;
|
|
readonly string _willOutStoreUnitNumField;
|
|
readonly string _willOutStoreSecondNumberField;
|
|
readonly string _invoicedUnitNumField;
|
|
readonly string _invoicedMoneyField;
|
|
readonly string _discountMoneyfield;
|
|
bool _hasPrice;
|
|
bool _hasMoney;
|
|
bool _hasRebate;
|
|
bool _hasRebateMoney;
|
|
bool _hasDiscountMoney;
|
|
bool _hasUnitNum;
|
|
public MainToSecondConvertRowManger(DFGridBase grid)
|
|
: this(grid, "UnitNum", "Number", "SecondNumber", "Money", "Rebate", "RebateMoney", "WillOutStoreUnitNum", "WillOutStoreSecondNumber", "InvoicedUnitNum", "InvoicedMoney", "DiscountMoney")
|
|
{
|
|
|
|
}
|
|
|
|
public MainToSecondConvertRowManger(DFGridBase grid, string unitNumfield, string mainfield, string secondfield, string moneyfield, string rebatefield, string rebateMoneyfield, string willOutStoreUnitNumfield, string willOutStoreSecondNumberfield, string invoicedUnitNumfield, string invoicedMoneyfield, string discountMoneyfield)
|
|
{
|
|
_unitNumField = unitNumfield;
|
|
_mainNumberField = mainfield;
|
|
_secondNumberField = secondfield;
|
|
_moneyField = moneyfield;
|
|
_rebateField = rebatefield;
|
|
_rebateMoneyField = rebateMoneyfield;
|
|
_willOutStoreUnitNumField = willOutStoreUnitNumfield;
|
|
_willOutStoreSecondNumberField = willOutStoreSecondNumberfield;
|
|
_discountMoneyfield = discountMoneyfield;
|
|
_invoicedUnitNumField = invoicedUnitNumfield;
|
|
_invoicedMoneyField = invoicedMoneyfield;
|
|
_discountMoneyfield = discountMoneyfield;
|
|
_hasMoney = _hasPrice = _hasRebate = _hasRebateMoney = _hasDiscountMoney = false;
|
|
foreach (DFGridColumn column in grid.Columns)
|
|
{
|
|
if (column is DFEditGridColumn<DFTextBox>)
|
|
{
|
|
var c = (DFEditGridColumn<DFTextBox>)column;
|
|
if (c.Name == unitNumfield)
|
|
{
|
|
_unitNumInput = c;
|
|
_hasUnitNum = true;
|
|
}
|
|
else if (c.Name == mainfield)
|
|
_mainNumberInput = c;
|
|
else if (c.Name == secondfield)
|
|
_secondNumberInput = c;
|
|
else if (c.Name == "Price")
|
|
{
|
|
_priceInput = c;
|
|
_hasPrice = true;
|
|
}
|
|
else if (c.Name == moneyfield)
|
|
{
|
|
_moneyInput = c;
|
|
_hasMoney = true;
|
|
}
|
|
else if (c.Name == "NetPrice")
|
|
NetPriceInput = c;
|
|
else if (c.Name == "PriceCost")
|
|
PriceCostInput = c;
|
|
else if (c.Name == willOutStoreUnitNumfield)
|
|
_willOutStoreUnitNumInput = c;
|
|
else if (c.Name == willOutStoreSecondNumberfield)
|
|
_willOutStoreSecondNumberInput = c;
|
|
else if (c.Name == invoicedUnitNumfield)
|
|
_invoicedUnitNumInput = c;
|
|
else if (c.Name == invoicedMoneyfield)
|
|
_invoicedMoneyInput = c;
|
|
}
|
|
else if (column is DFEditGridColumn)
|
|
{
|
|
var c1 = (DFEditGridColumn)column;
|
|
if (c1.Name == _moneyField)
|
|
{
|
|
_hasMoney = true;
|
|
}
|
|
else if (c1.Name == "Price")
|
|
{
|
|
_hasPrice = true;
|
|
}
|
|
else if (c1.Name == _rebateField)
|
|
{
|
|
_hasRebate = true;
|
|
}
|
|
else if (c1.Name == _rebateMoneyField)
|
|
{
|
|
_hasRebateMoney = true;
|
|
}
|
|
else if (c1.Name == _discountMoneyfield)
|
|
{
|
|
_hasDiscountMoney = true;
|
|
}
|
|
else if (c1.Name == _unitNumField)
|
|
{
|
|
_hasUnitNum = true;
|
|
}
|
|
}
|
|
}
|
|
SetClientScript();
|
|
}
|
|
|
|
string SetMainNumber
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('{0}', (dfContainer.getValue('{1}')*{2}/{3}).toFixed(6));", _mainNumberField, _secondNumberField, MainUnitRatio, SecondUnitRatio);
|
|
}
|
|
}
|
|
|
|
string SetSecondNumber
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('{0}', (dfContainer.getValue('{1}')*{2}/{3}).toFixed(6));", _secondNumberField, _mainNumberField, SecondUnitRatio, MainUnitRatio);
|
|
}
|
|
}
|
|
|
|
string SetMoney
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('{0}', (dfContainer.getValue('Price')*dfContainer.getValue('{1}')).toFixed(2));", _moneyField, _unitNumField);
|
|
}
|
|
}
|
|
|
|
string SetRebateMoney
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('RebateMoney', (dfContainer.getValue('Money')*dfContainer.getValue('Rebate')/100).toFixed(2));");
|
|
}
|
|
}
|
|
|
|
string SetDiscountMoney
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('DiscountMoney', dfContainer.getValue('Money')-dfContainer.getValue('RebateMoney'));");
|
|
}
|
|
}
|
|
|
|
|
|
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')";
|
|
|
|
private void SetClientScript()
|
|
{
|
|
SetUnitNumChanged();
|
|
SetMainNumberChanged();
|
|
SetSecondNumberChanged();
|
|
SetPriceChanged();
|
|
SetWillOutStoreUnitNumChanged();
|
|
SetWillOutStoreSecondNumberChanged();
|
|
SetinvoicedUnitNumChanged();
|
|
SetinvoicedMoneyChanged();
|
|
SetMoneyChanged();
|
|
SetNetPriceChanged();
|
|
SetPriceCostChanged();
|
|
}
|
|
|
|
private void SetinvoicedUnitNumChanged()
|
|
{
|
|
if (_invoicedUnitNumInput == null || _invoicedMoneyInput == null)
|
|
return;
|
|
if (_hasPrice && _hasRebate)
|
|
{
|
|
_invoicedUnitNumInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] =
|
|
"if(dfContainer.getValue('Price')!=0){dfContainer.setValue('InvoicedMoney', (dfContainer.getValue('InvoicedUnitNum')*dfContainer.getValue('Price')*dfContainer.getValue('Rebate')/100).toFixed(2));}";
|
|
};
|
|
}
|
|
}
|
|
|
|
private void SetMoneyChanged()
|
|
{
|
|
if (_moneyInput == null)
|
|
return;
|
|
if (_hasPrice && _hasUnitNum)
|
|
{
|
|
|
|
var str = @" var number = dfContainer.getValue('" + _unitNumField + @"');
|
|
if(number==''|| number=='0'){
|
|
number = 1;
|
|
dfContainer.setValue('" + _unitNumField + @"','1' )
|
|
};
|
|
dfContainer.setValue('Price', (dfContainer.getValue('" + _moneyField + "')/ number).toFixed(6));";
|
|
_moneyInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e) {
|
|
e.Control.Attributes["onchange"] = str;
|
|
};
|
|
}
|
|
}
|
|
|
|
private void SetinvoicedMoneyChanged()
|
|
{
|
|
if (_invoicedUnitNumInput == null && _invoicedMoneyInput == null)
|
|
return;
|
|
if (_hasPrice)
|
|
{
|
|
_invoicedMoneyInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = string.Format("dfContainer.setValue('{0}', (dfContainer.getValue('{1}')*100/dfContainer.getValue('Rebate')/dfContainer.getValue('Price')).toFixed(2));", _invoicedUnitNumField, _invoicedMoneyField);
|
|
};
|
|
}
|
|
}
|
|
|
|
string SetWillOutStoreSecondNumberByUnitNum
|
|
{
|
|
get
|
|
{
|
|
return string.Format("var number = dfContainer.getValue('{0}')/{1}*{2}; dfContainer.setValue('{3}', (number /{4}*{5}).toFixed(6));", _willOutStoreUnitNumField, LeftRatio, RightRatio, _willOutStoreSecondNumberField, MainUnitRatio, SecondUnitRatio);
|
|
}
|
|
}
|
|
|
|
private void SetWillOutStoreUnitNumChanged()
|
|
{
|
|
if (_willOutStoreUnitNumInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
if (_willOutStoreSecondNumberInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由主至辅'){if({unitRatioLeft} > 0 && {unitRatioRight}>0 && {ratioRight}>0 && {ratioLeft}>0){SetWillOutStoreSecondNumberByUnitNum}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{unitRatioLeft}", LeftRatio)
|
|
.Replace("{unitRatioRight}", RightRatio)
|
|
.Replace("{SetWillOutStoreSecondNumberByUnitNum}", SetWillOutStoreSecondNumberByUnitNum)
|
|
);
|
|
}
|
|
|
|
_willOutStoreUnitNumInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
string SetWillOutStoreUnitNumBySecondNumber
|
|
{
|
|
get
|
|
{
|
|
return string.Format("var number = dfContainer.getValue('{0}')*{1}/{2};dfContainer.setValue('{3}', (number/{4}*{5}).toFixed(2));", _willOutStoreSecondNumberField, MainUnitRatio, SecondUnitRatio, _willOutStoreUnitNumField, RightRatio, LeftRatio);
|
|
}
|
|
}
|
|
|
|
private void SetWillOutStoreSecondNumberChanged()
|
|
{
|
|
if (_willOutStoreSecondNumberInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
if (_willOutStoreUnitNumInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由辅至主'){ if({ratioRight}>0 && {ratioLeft}>0 && {unitRatioLeft} > 0 && {unitRatioRight}>0)
|
|
{SetWillOutStoreUnitNumBySecondNumber}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{unitRatioLeft}", LeftRatio)
|
|
.Replace("{unitRatioRight}", RightRatio)
|
|
.Replace("{SetWillOutStoreUnitNumBySecondNumber}", SetWillOutStoreUnitNumBySecondNumber));
|
|
}
|
|
|
|
_willOutStoreSecondNumberInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
string SetNumberByUnitNum
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('{0}', (dfContainer.getValue('{1}')/{2}*{3}).toFixed(6));", _mainNumberField, _unitNumField, LeftRatio, RightRatio);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
private void SetUnitNumChanged()
|
|
{
|
|
if (_unitNumInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
if (_mainNumberInput != null)
|
|
{
|
|
builder.Append(@"if({unitRatioLeft} > 0 && {unitRatioRight}>0){
|
|
{SetNumberByUnitNum}}".Replace("{unitRatioLeft}", LeftRatio)
|
|
.Replace("{unitRatioRight}", RightRatio)
|
|
.Replace("{SetNumberByUnitNum}", SetNumberByUnitNum)
|
|
);
|
|
}
|
|
|
|
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)
|
|
);
|
|
}
|
|
|
|
if (_hasPrice && _hasMoney)
|
|
{
|
|
builder.Append(SetMoney);
|
|
if (_hasRebate && _hasRebateMoney)
|
|
{
|
|
builder.Append(SetRebateMoney);
|
|
}
|
|
if (_hasRebate && _hasDiscountMoney)
|
|
{
|
|
builder.Append(SetDiscountMoney);
|
|
}
|
|
}
|
|
|
|
_unitNumInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
private void SetSecondNumberChanged()
|
|
{
|
|
if (_secondNumberInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
if (_mainNumberInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由辅至主'){ if({ratioRight}>0 && {ratioLeft}>0)
|
|
{setMainNumber}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{setMainNumber}", SetMainNumber));
|
|
}
|
|
if (_unitNumInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由辅至主'){ if({ratioRight}>0 && {ratioLeft}>0 && {unitRatioLeft} > 0 && {unitRatioRight}>0)
|
|
{{setUnitNum}}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{unitRatioLeft}", LeftRatio)
|
|
.Replace("{unitRatioRight}", RightRatio)
|
|
.Replace("{setUnitNum}", SetUnitNumBySecondNumber));
|
|
}
|
|
if (_hasPrice && _hasMoney)
|
|
{
|
|
builder.Append(SetMoney);
|
|
if (_hasRebate && _hasRebateMoney)
|
|
{
|
|
builder.Append(SetRebateMoney);
|
|
}
|
|
if (_hasRebate && _hasDiscountMoney)
|
|
{
|
|
builder.Append(SetDiscountMoney);
|
|
}
|
|
}
|
|
_secondNumberInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e) {
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
|
|
string SetUnitNumByNumber
|
|
{
|
|
get
|
|
{
|
|
return string.Format("dfContainer.setValue('{0}', (dfContainer.getValue('{1}')/{2}*{3}).toFixed(2));", _unitNumField, _mainNumberField, RightRatio, LeftRatio);
|
|
}
|
|
}
|
|
|
|
private void SetMainNumberChanged()
|
|
{
|
|
if (_mainNumberInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
if (_secondNumberInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由主至辅'){ if({ratioLeft}>0 && {ratioRight}>0){setSecondNumber}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{ratioLeft}", MainUnitRatio)
|
|
.Replace("{ratioRight}", SecondUnitRatio)
|
|
.Replace("{setSecondNumber}", SetSecondNumber)
|
|
);
|
|
}
|
|
if (_unitNumInput != null)
|
|
{
|
|
builder.Append(@"if({convertDirection}=='双向转换'||{convertDirection}=='由主至辅'){if({unitRatioLeft} > 0 && {unitRatioRight}>0){setUnitNum}}"
|
|
.Replace("{convertDirection}", ConvertDirection)
|
|
.Replace("{unitRatioLeft}", MainUnitRatio)
|
|
.Replace("{unitRatioRight}", SecondUnitRatio)
|
|
.Replace("{setUnitNum}", SetUnitNumByNumber)
|
|
);
|
|
}
|
|
if (_hasPrice && _hasMoney)
|
|
{
|
|
builder.Append(SetMoney);
|
|
if (_hasRebate && _hasRebateMoney)
|
|
{
|
|
builder.Append(SetRebateMoney);
|
|
}
|
|
if (_hasRebate && _hasDiscountMoney)
|
|
{
|
|
builder.Append(SetDiscountMoney);
|
|
}
|
|
}
|
|
_mainNumberInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e) {
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
ISaleForecastBL bl = BIFactory.Create<ISaleForecastBL>();
|
|
private void SetPriceChanged()
|
|
{
|
|
if (_priceInput == null)
|
|
return;
|
|
|
|
var builder = new StringBuilder();
|
|
|
|
if (_hasMoney && _unitNumInput != null)
|
|
{
|
|
builder.Append(SetMoney);
|
|
if (_hasRebate && _hasRebateMoney)
|
|
{
|
|
builder.Append(SetRebateMoney);
|
|
}
|
|
if (_hasRebate && _hasDiscountMoney)
|
|
{
|
|
builder.Append(SetDiscountMoney);
|
|
}
|
|
}
|
|
string SetPriceCost = "dfContainer.setValue('PriceCost',(dfContainer.getValue('Price')*1.00-dfContainer.getValue('NetPrice')*1.00));";
|
|
if (NetPriceInput != null && PriceCostInput != null && !bl.LockCostPrice)
|
|
builder.Append(SetPriceCost);
|
|
_priceInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e) {
|
|
e.Control.Attributes["onchange"] = builder.ToString();
|
|
};
|
|
}
|
|
|
|
private void SetNetPriceChanged()
|
|
{
|
|
if (_priceInput == null)
|
|
return;
|
|
if (PriceCostInput == null)
|
|
return;
|
|
string SetPriceByNetPrice = "dfContainer.setValue('Price',(dfContainer.getValue('NetPrice')*1.00+dfContainer.getValue('PriceCost')*1.00));";
|
|
if (NetPriceInput != null)
|
|
{
|
|
NetPriceInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = SetPriceByNetPrice;
|
|
};
|
|
}
|
|
}
|
|
|
|
private void SetPriceCostChanged()
|
|
{
|
|
if (_priceInput == null)
|
|
return;
|
|
if (NetPriceInput == null)
|
|
return;
|
|
string SetPriceByNetPrice = "dfContainer.setValue('Price',(dfContainer.getValue('NetPrice')*1.00+dfContainer.getValue('PriceCost')*1.00));";
|
|
|
|
if (PriceCostInput != null)
|
|
{
|
|
PriceCostInput.InitEditControl += delegate (object sender, InitEditControlEventArgs<DFTextBox> e)
|
|
{
|
|
e.Control.Attributes["onchange"] = SetPriceByNetPrice;
|
|
};
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|