东方万旗模块
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.
 

258 lines
11 KiB

using System.Collections.Generic;
using System.Web.UI.WebControls;
using BWP.B3Frameworks;
using BWP.B3Frameworks.BO.NamedValueTemplate;
using BWP.B3Frameworks.Utils;
using BWP.Web.Layout;
using BWP.Web.Utils;
using BWP.Web.WebControls;
using Forks.EnterpriseServices;
using Forks.EnterpriseServices.DataForm;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.SqlDoms;
using Forks.Utils;
using TSingSoft.WebControls2;
using TSingSoft.WebControls2.QBELinks;
using BWP.B3Sale.BO;
using BWP.B3Sale.Utils;
using BWP.B3Frameworks.BO;
using TSingSoft.WebPluginFramework;
using System;
using BWP.B3Sale;
using Sale = BWP.Web.Pages.B3Sale.Reports.CarLoadingAnalyse_;
namespace BWP.Web.Overlays.CarLoadingAnalyse_
{
public class CarLoadingAnalyse: DFBrowseGridReportPage
{
protected override string Caption
{
get { return "装车单分析"; }
}
protected override string AccessRoleName
{
get { return "B3Sale.装车单.访问"; }
}
protected override bool EnableQueryPanel
{
get
{
return true;
}
}
readonly DFInfo _mainInfo = DFInfo.Get(typeof(CarLoading));
readonly DFInfo _detailInfo = DFInfo.Get(typeof(CarLoading_BillDetail));
protected virtual void AddShowFields(List<Tuple<string, string>> showFields)
{
}
CheckBoxListWithReverseSelect _checkbox;
readonly Dictionary<string, DFInfo> _fileInfo = new Dictionary<string, DFInfo>();
protected override void InitQueryPanel(QueryPanel queryPanel)
{
base.InitQueryPanel(queryPanel);
var panel = queryPanel.CreateTab("显示字段");
_fileInfo.Add("Date", _mainInfo);
_fileInfo.Add("ID", _mainInfo);
_fileInfo.Add("Car_Name", _mainInfo);
_fileInfo.Add("Employee_Name", _mainInfo);
_fileInfo.Add("Deliveryman_Name", _mainInfo);
_fileInfo.Add("AccountingUnit_Name", _mainInfo);
_fileInfo.Add("DeliverGoodsLine_Name", _mainInfo);
_fileInfo.Add("Remark", _mainInfo);
_fileInfo.Add("总数量", _mainInfo);
_fileInfo.Add("金额", _mainInfo);
_checkbox = new CheckBoxListWithReverseSelect { RepeatColumns = 6, RepeatDirection = RepeatDirection.Horizontal };
var showFields = new List<Tuple<string, string>>();
foreach (var item in _fileInfo)
{
if (item.Key == "总数量" || item.Key == "金额")
showFields.Add(new Tuple<string, string>(item.Key, item.Key));
else
showFields.Add(new Tuple<string, string>(item.Key, item.Value.Fields[item.Key].Prompt));
}
AddShowFields(showFields);
var section = mPageLayoutManager.AddSection("显示字段", "显示字段");
section.ApplyLayout(showFields, mPageLayoutManager);
foreach (var item in showFields)
{
_checkbox.Items.Add(new ListItem(item.Item2, item.Item1));
}
panel.EAdd(_checkbox);
var hPanel = new HLayoutPanel();
CreateDataRangePanel(hPanel);
queryPanel.ConditonPanel.EAdd(hPanel);
mQueryControls.Add("显示字段", _checkbox);
mQueryControls.EnableHoldLastControlNames.Add("显示字段");
}
void CreateDataRangePanel(HLayoutPanel hPanel)
{
hPanel.Add(new SimpleLabel(_mainInfo.Fields["Date"].Prompt));
hPanel.Add(QueryCreator.TimeRange(_mainInfo.Fields["Date"], mQueryContainer, "MinDate", "MaxDate"));
}
private ChoiceBox departmentSelect, custoemrSelect;
protected override void AddQueryControls(VLayoutPanel vPanel)
{
var layout = new LayoutManager("Main", _mainInfo);
layout.Add("ID", mQueryContainer.Add(new DFTextBox(_mainInfo.Fields["ID"]), "ID"));
layout.Add("Car_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(_mainInfo.Fields["Car_ID"], B3SaleDataSources.), s => long.Parse(s)), "Car_ID"));
layout.Add("Employee_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(_mainInfo.Fields["Employee_ID"], B3FrameworksConsts.DataSources.), s => long.Parse(s)), "Employee_ID"));
layout.Add("Deliveryman_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(_mainInfo.Fields["Deliveryman_ID"], B3FrameworksConsts.DataSources.), s => long.Parse(s)), "Deliveryman_ID"));
layout.Add("AccountingUnit_ID", mQueryContainer.AddLink(new ChoiceBoxMultiSelectLink(QueryCreator.DFChoiceBoxEnableMultiSelection(_mainInfo.Fields["AccountingUnit_ID"], B3FrameworksConsts.DataSources.), s => long.Parse(s)), "AccountingUnit_ID"));
layout.Add("Customer_ID", new SimpleLabel("购货客户"), custoemrSelect = new ChoiceBox() { DataKind = B3SaleDataSources., Width = Unit.Empty, EnableTopItem = true, EnableMultiSelection = false, EnableMultiSelectionViewer = false, EnableInputArgument = true });
layout.Add("Department_ID", new SimpleLabel("销售部门"), departmentSelect = new ChoiceBox() { DataKind = B3FrameworksConsts.DataSources., Width = Unit.Empty, EnableTopItem = true, EnableMultiSelection = true, EnableMultiSelectionViewer = true, EnableInputArgument = true });
var state = mQueryContainer.Add(CustomInputCreator_WQ.(_mainInfo.Fields["BillState"], true, false, true, true), "BillState");
((ChoiceBox)state).Value = ..Value.ToString() + "|";
state.DisplayValue = "已审核;";
state.EnableInputArgument = true;
layout.Add("BillState", state);
layout.Add("Remark", mQueryContainer.Add(new DFTextBox(_mainInfo.Fields["Remark"]), "Remark"));
var config = layout.CreateDefaultConfig(4);
config.Expand = false;
var section = mPageLayoutManager.AddSection("查询条件", "查询条件");
section.ApplyLayout(layout, config, mPageLayoutManager, _mainInfo);
section.SetDisplayName("ID", "单号");
section.SetDisplayName("Car_ID", "运输车辆");
section.SetDisplayName("Employee_ID", "经办人");
section.SetDisplayName("Deliveryman_ID", "送货人员");
section.SetDisplayName("AccountingUnit_ID", "会计单位");
section.SetDisplayName("Department_ID", "部门");
section.SetDisplayName("Customer_ID", "客户");
section.SetDisplayName("BillState", "单据状态");
section.SetDisplayName("Remark", "摘要");
vPanel.Add(layout.CreateLayout(), new VLayoutOption(HorizontalAlign.Left));
}
protected override DQueryDom GetQueryDom()
{
var dom = base.GetQueryDom();
var alias = dom.From.RootSource.Alias;
var department = new JoinAlias(typeof(Department));
dom.From.AddJoin(JoinType.Left, new DQDmoSource(department), DQCondition.EQ(alias, "Department_ID", department, "ID"));
foreach (ListItem field in _checkbox.Items)
{
if (field.Selected)
{
switch (field.Value)
{
case "ExtendField3":
case "ExtendField2":
case "ExtendField1":
dom.Columns.Add(DQSelectColumn.Field(field.Value, alias, field.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(field.Value));
break;
case "总数量":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(JoinDetail(dom, alias), "Number")), field.Value));
break;
case "金额":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(JoinDetail(dom, alias), "Money")), field.Value));
break;
case "BillTypeID":
dom.Columns.Add(DQSelectColumn.Create(DQExpression.LogicCase(DQCondition.EQ(JoinDetail(dom, alias), "BillTypeID", 777), DQExpression.Value("销售出库"), DQExpression.Value("调拨出库")), field.Text));
dom.GroupBy.Expressions.Add(DQExpression.Field(JoinDetail(dom, alias), "BillTypeID"));
break;
default:
dom.Columns.Add(DQSelectColumn.Field(field.Value, alias));
dom.GroupBy.Expressions.Add(DQExpression.Field(alias, field.Value));
break;
}
}
}
var _sd2 = mQueryContainer.GetControl<DFDateTimeInput>("MinDate");
if (_sd2.Value.HasValue)
{
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("Date", _sd2.Value.Value));
}
var _ed2 = mQueryContainer.GetControl<DFDateTimeInput>("MaxDate");
if (_ed2.Value.HasValue)
{
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual("Date", _ed2.Value.Value));
}
if (!custoemrSelect.IsEmpty)
{
dom.Where.Conditions.Add(DQCondition.Like("ExtendField2", custoemrSelect.DisplayValue));
}
if (!departmentSelect.IsEmpty)
{
var strs = B3SaleWebUtil.GetDeepByTreeName(departmentSelect.DisplayValue);
var conditions = new List<IDQExpression>();
var values = departmentSelect.GetValues();
for (int index = 0; index < values.Length; index++)
{
var value = values[index];
conditions.Add(DQCondition.EQ(department, "TreeDeep" + strs[index] + "ID", value));
}
dom.Where.Conditions.Add(DQCondition.Or(conditions));
}
dom.Where.Conditions.Add(DQCondition.EQ("Domain_ID", DomainContext.Current.ID));
OrganizationUtil.AddOrganizationLimit(dom, typeof(AcceptDiff));
return dom;
}
JoinAlias _detailAlias;
JoinAlias JoinDetail(DQueryDom query, JoinAlias alias)
{
if (_detailAlias != null)
return _detailAlias;
_detailAlias = new JoinAlias(typeof(DetailTmp));
query.RegisterQueryTable(typeof(DetailTmp), new[] { "CarLoading_ID", "BillTypeID", "Number", "Money" }, GetDetailDom());
query.From.AddJoin(JoinType.Left, new DQDmoSource(_detailAlias), DQCondition.EQ(alias, "ID", _detailAlias, "CarLoading_ID"));
return _detailAlias;
}
private DQueryDom GetDetailDom()
{
var detail = new JoinAlias(typeof(CarLoading_BillDetail));
var outdetail = new JoinAlias(typeof(SaleOutStore_Detail));
var query = new DQueryDom(detail);
query.From.AddJoin(JoinType.Left, new DQDmoSource(outdetail), DQCondition.EQ(detail, "BillID", outdetail, "SaleOutStore_ID"));
query.Columns.Add(DQSelectColumn.Field("CarLoading_ID", detail));
query.Columns.Add(DQSelectColumn.Field("BillTypeID", detail));
query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(detail, "Number")), "Number"));
query.Columns.Add(DQSelectColumn.Create(DQExpression.Sum(DQExpression.Field(outdetail, "Money")), "Money"));
query.GroupBy.Expressions.Add(DQExpression.Field(detail, "CarLoading_ID"));
query.GroupBy.Expressions.Add(DQExpression.Field(detail, "BillTypeID"));
return query;
}
class DetailTmp
{
public long CarLoading_ID { get; set; }
[LogicName("单据类型")]
public short BillTypeID { get; set; }
[LogicName("数量")]
public Money<decimal>? Number { get; set; }
[LogicName("金额")]
public Money<decimal>? Money { get; set; }
}
}
}