You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

339 lines
11 KiB

using BWP.B3Sale.BO;
using Forks.EnterpriseServices.DataForm;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSingSoft.WebControls2;
using System.Web.UI.HtmlControls;
using TSingSoft.WebPluginFramework.Controls;
using BWP.Web.Utils;
using BWP.Web.Layout;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using BWP.B3Frameworks.BO.NamedValueTemplate;
using BWP.B3_YunKen;
using Forks.Utils;
using Forks.EnterpriseServices.BusinessInterfaces;
using System.Web.UI.WebControls;
using Forks.Utils.Collections;
using TSingSoft.WebPluginFramework.Pages;
using BWP.B3Frameworks.Utils;
using System.Globalization;
using BWP.B3Sale.BL;
using System.Web;
using TSingSoft.WebControls2.QBELinks;
using BWP.B3Sale.Utils;
using BWP.B3UnitedInfos;
using Forks.EnterpriseServices.DomainObjects2;
using TSingSoft.WebPluginFramework;
using Forks.EnterpriseServices.SqlDoms;
using BWP.B3Frameworks.BO;
namespace BWP.Web.Pages.B3YunKen.Bill
{
//class PriceBill_DetailAdjust
//{
//}
class PriceBill_DetailAdjust : AppBasePage
{
private DFBrowseGrid _grid;
private QueryContainer mQueryContainer;
private DFContainer dfContainer;
private DFBoolComboBox _sortType;
uint QueryID
{
get
{
return ViewState.EGetProp<uint>("QueryID", 0);
}
set
{
ViewState.ESetProp("QueryID", value);
}
}
long? GoodsClassID
{
get
{
long v;
if (long.TryParse(Request.QueryString["classID"], out v))
return v;
return null;
}
}
protected override void InitForm(HtmlForm form)
{
var vPanel = new VLayoutPanel();
form.Controls.Add(vPanel);
dfContainer = new DFContainer
{
ID = "DFContainer"
};
form.Controls.Add(dfContainer);
mQueryContainer = QueryContainer.FromResource(GetType().FullName + ".xml", GetType().Assembly);
form.Controls.Add(new PageTitle("定价单调整"));
AddQueryControls(vPanel);
CreateBrowseGrid(vPanel);
}
private ChoiceBox _goods, _goodsProperty, _priceClass;
readonly static DFInfo mDFInfo = DFInfo.Get(typeof(PriceBill));
readonly static DFInfo mDetailInfo = DFInfo.Get(typeof(PriceBill_Detail));
void AddQueryControls(VLayoutPanel vPanel)
{
var layoutManager = new LayoutManager("", mDFInfo, mQueryContainer);
_goods = QueryCreator.DFChoiceBoxEnableMultiSelection(mDetailInfo.Fields["SaleGoods_ID"], B3SaleDataSources.);
layoutManager.Add("SaleGoods_ID", new SimpleLabel("存货"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_goods, s => long.Parse(s)), "SaleGoods_ID"));
layoutManager["SaleGoods_ID"].NotAutoAddToContainer = true;
_goodsProperty = QueryCreator.DFChoiceBoxEnableMultiSelection(mDetailInfo.Fields["GoodsProperty_ID"], B3UnitedInfosConsts.DataSources.);
layoutManager.Add("GoodsProperty_ID", new SimpleLabel("存货属性"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_goodsProperty, s => long.Parse(s)), "GoodsProperty_ID"));
layoutManager["GoodsProperty_ID"].NotAutoAddToContainer = true;
_priceClass = QueryCreator.DFChoiceBoxEnableMultiSelection(mDFInfo.Fields["PriceClass_ID"], B3SaleDataSources.);
layoutManager.Add("PriceClass_ID", new SimpleLabel("价格分类"), mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(_priceClass, s => long.Parse(s)), "PriceClass_ID"));
layoutManager["PriceClass_ID"].NotAutoAddToContainer = true;
vPanel.Add(layoutManager.CreateLayout());
HLayoutPanel hPanel = new HLayoutPanel() { Align = HorizontalAlign.Center };
TSButton qButton = new TSButton("开始查询");
hPanel.Add(qButton);
qButton.Click += delegate
{
_grid.Query = CreateQueryGridQuery();
_grid.DataBind();
};
dfContainer.AddNonDFControl(qButton, "$btnsearch");
hPanel.Add(new RedirectTSButton("清除条件"));
vPanel.Add(hPanel);
}
class PriceBillTemp
{
public long ID { get; set; }
public long AccountingUnit_ID { get; set; }
public static void Regiester(DQueryDom query)
{
string[] field = { "ID" , "AccountingUnit_ID" };
query.RegisterQueryTable(typeof(PriceBillTemp), field, CreateQuery());
}
private static DQueryDom CreateQuery()
{
var main = new JoinAlias("__price_main", typeof(PriceBill));
var detail = new JoinAlias("__price_acc_detail", typeof(PriceBill_AccountingUnitDetail));
var query = new DQueryDom(main);
query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "PriceBill_ID"));
query.Columns.Add(DQSelectColumn.Field("ID", main));
query.Columns.Add(DQSelectColumn.Min(detail, "AccountingUnit_ID"));
query.GroupBy.Expressions.Add(DQExpression.Field(main, "ID"));
return query;
}
public static void AddJoin(DQueryDom query, JoinAlias joinAlias)
{
var root = query.From.RootSource.Alias;
query.From.AddJoin(JoinType.Left, new DQDmoSource(joinAlias), DQCondition.And(
DQCondition.EQ(joinAlias, "ID", root, "ID")
));
}
}
private DQueryDom CreateQueryGridQuery()
{
var detailFields = new[] {"ID", "Goods_Name", "GoodsProperty_Name", "SourcePrice", "Price" };
var dom = mQueryContainer.Build();
var main = dom.From.RootSource.Alias;
var detail = JoinAlias.Create("detail");
var priceTemp = new JoinAlias("priTemp", typeof(PriceBillTemp));
PriceBillTemp.Regiester(dom);
PriceBillTemp.AddJoin(dom, priceTemp);
var auu = new JoinAlias("auu", typeof(AccountingUnit));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(auu), DQCondition.EQ(priceTemp, "AccountingUnit_ID", auu, "ID"));
foreach (var field in detailFields)
{
dom.Columns.Add(DQSelectColumn.Field(field, detail));
}
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Snippet<string>("''"), "备注"));
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(main, "ID"), "MainID"));
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Field(auu, "Name"), "会计单位"));
QueryID = ViewStateUtil.Current.SaveToPersistenceMedium(dom.Where.Conditions);
dom.Where.Conditions.Add(DQCondition.EQ(main, "BillState", .));
var billFlowCataID = new B3YunKenOnlineConfiguration().PriceAdjustBillFlowState.Value;
if (billFlowCataID != 0)
{
dom.Where.Conditions.Add(DQCondition.EQ(main, "DepartmentWorkFlowStateCategory_ID", billFlowCataID));
}
dom.Where.Conditions.Add(DQExpression.Snippet(" (LEN(iSnull(detail.Remark,''))=0)"));
if (!_goods.IsEmpty)
{
dom.Where.Conditions.EFieldInList(DQExpression.Field(detail, "SaleGoods_ID"), _goods.GetValues());
}
if (!_goodsProperty.IsEmpty)
{
dom.Where.Conditions.EFieldInList(DQExpression.Field(detail, "GoodsProperty_ID"), _goodsProperty.GetValues());
}
if (!_priceClass.IsEmpty)
{
dom.Where.Conditions.EFieldInList(DQExpression.Field(main, "PriceClass_ID"), _priceClass.GetValues());
}
if (_sortType.Value != null)
dom.OrderBy.Expressions.Add(DQOrderByExpression.Create(detail, "Goods_Name", _sortType.Value == true ? false : true));
return dom;
}
private void CreateBrowseGrid(VLayoutPanel vPanel)
{
var hPanel = vPanel.Add(new HLayoutPanel(), new VLayoutOption(HorizontalAlign.Left));
hPanel.Add(new TSButton("通过", delegate {
_grid.GetFromUI();
using (var context = new TransactionContext())
{
var bl = BIFactory.Create<IPriceBillBL>(context);
foreach (var row in _grid.GetSelectedItems())
{
DoApproval(row, true, bl);
}
context.Commit();
}
AspUtil.Alert(this, "操作成功\n" + BIFactory.GetLastMessage());
_grid.DataBind();
}));
AddSortChoiceBox(hPanel);
_grid = vPanel.Add(new DFBrowseGrid(new DFDataTableEditor()));
_grid.Width = Unit.Percentage(100);
_grid.GridSubKey = "Grid";
_grid.DFGridSetEnabled = false;
_grid.MultiSelectionEnabled = true;
_grid.Columns.EAdd(new DFBrowseGridColumn("Goods_Name")).HeaderText = "标准件";
_grid.Columns.EAdd(new DFBrowseGridColumn("会计单位")).HeaderText = "会计单位"; ;
_grid.Columns.EAdd(new DFBrowseGridColumn( "GoodsProperty_Name")).HeaderText = "存货分类";
_grid.Columns.EAdd(new DFBrowseGridColumn("SourcePrice")).HeaderText = "原单价";
_grid.Columns.EAdd(new DFEditGridColumn<DFTextBox>("Price")).HeaderText = "调整单价";
_grid.Columns.EAdd(new DFBrowseGridCustomExtColumn((row, cell, rowIndex) => {
var lbt = new LinkButton
{
Text = "通过",
Width = Unit.Pixel(50)
};
var notlbt = new LinkButton
{
Text = "不通过",
Width = Unit.Pixel(50)
};
lbt.Command += (sender, e) => {
_grid.GetFromUI();
using (var context = new TransactionContext())
{
var bl = BIFactory.Create<IPriceBillBL>(context);
DoApproval(row, true, bl);
context.Commit();
}
AspUtil.Alert(this, "操作成功\n" + BIFactory.GetLastMessage());
_grid.DataBind();
};
notlbt.Command += (sender, e) => {
_grid.GetFromUI();
using (var context = new TransactionContext())
{
var bl = BIFactory.Create<IPriceBillBL>(context);
DoApproval(row, false, bl);
context.Commit();
}
AspUtil.Alert(this, "操作成功\n" + BIFactory.GetLastMessage());
_grid.DataBind();
};
cell.Controls.Add(lbt);
cell.Controls.Add(notlbt);
})).HeaderText = "是否通过";
_grid.Columns.EAdd(new DFEditGridColumn<DFMemoInfo>("备注")).InitEditControl += (sender, e) => {
e.Control.Width = 130;
e.Control.DataKind = "价格调整单备注";
};
}
private void AddSortChoiceBox(HLayoutPanel hPanel)
{
var label = new SimpleLabel {
Text = "排序方式"
};
hPanel.Add(label);
_sortType = new DFBoolComboBox("升序", "降序") {
AutoPostBack = true,
TrueIsFirst = true
};
hPanel.Add(_sortType);
_sortType.ValueChanged += delegate {
_grid.Query = CreateQueryGridQuery();
_grid.DataBind();
};
}
private void DoApproval(DFDataRow row, bool pass, IPriceBillBL bl)
{
var Price = (Money<decimal>?)row["Price"];
var detailID = (long?)row["ID"];
var mainID = (long?)row["MainID"];
var remark = pass ? "已审批通过" : (string)row["备注"];
if (string.IsNullOrEmpty(remark))
{
throw new Exception("备注不能为空");
}
bl.Approval(mainID, detailID, Price, remark);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
_grid.Query = CreateQueryGridQuery();
_grid.Reset();
_grid.DataBind();
}
}
}
}