using System.Linq;
|
|
using System.Text;
|
|
using System.Web.UI;
|
|
using System.Web.UI.HtmlControls;
|
|
using TSingSoft.WebControls2;
|
|
using TSingSoft.WebControls2.BillReports;
|
|
using TSingSoft.WebPluginFramework;
|
|
using WebUnit = System.Web.UI.WebControls.Unit;
|
|
|
|
|
|
using Forks.EnterpriseServices.BusinessInterfaces;
|
|
using Forks.EnterpriseServices.DataForm;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
using Forks.EnterpriseServices.SqlDoms;
|
|
using Forks.Utils;
|
|
using Forks.Utils.IO;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using System.IO;
|
|
using BWP.B3QingDaoWanFu.BO;
|
|
using BWP.B3Sale.BO;
|
|
using BWP.B3Frameworks;
|
|
using BWP.B3Frameworks.Utils;
|
|
using System;
|
|
using BWP.B3UnitedInfos.BO;
|
|
using BWP.Web.Utils;
|
|
|
|
namespace BWP.Web.Pages.B3QingDaoWanFu.SaleOutStore_
|
|
{
|
|
|
|
|
|
|
|
|
|
class SaleOutStoreSimpleAnaysePrint : PrintPageBase
|
|
{
|
|
|
|
private Control CreateReport()
|
|
{
|
|
var result = new TemplateBillReport();
|
|
var parameters = new Dictionary<string, object>();
|
|
parameters.Add("$CurrentUserName", BLContext.User.Name);
|
|
AddParameters(parameters);
|
|
|
|
var autoAdd = new Dictionary<string, object>();
|
|
foreach (KeyValuePair<string, object> pair in parameters)
|
|
{
|
|
if (pair.Value != null && pair.Value is ICollection)
|
|
{
|
|
string newKey = pair.Key + "_RecordCount";
|
|
if (!parameters.ContainsKey(newKey))
|
|
autoAdd.Add(newKey, ((ICollection)pair.Value).Count);
|
|
}
|
|
else if (pair.Value != null && pair.Value is LoadArguments)
|
|
{
|
|
string newKey = pair.Key + "_RecordCount";
|
|
if (!parameters.ContainsKey(newKey))
|
|
{
|
|
var loadArguments = new LoadArguments(((LoadArguments)pair.Value).DQuery.Clone() as DQueryDom);
|
|
loadArguments.DQuery.Range = SelectRange.Top(0);
|
|
var adapater = new DFDataAdapter(loadArguments);
|
|
var table = adapater.PagedFill();
|
|
autoAdd.Add(newKey, table.TotalCount);
|
|
}
|
|
}
|
|
}
|
|
foreach (KeyValuePair<string, object> pair in autoAdd)
|
|
{
|
|
parameters.Add(pair.Key, pair.Value);
|
|
}
|
|
|
|
var printTemplateFile = Path.Combine(Wpf.Settings.ConfigFolder, GetTemplateFile());
|
|
result.ParseTemplate(FS.OpenRead(printTemplateFile), parameters);
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string GetTemplateFile()
|
|
{
|
|
|
|
var xmlFile = Path.Combine(Wpf.Settings.ConfigFolder, "BillReports/" + "B3QingDaoWanFu" + "/" + "SaleOutStoreSimpleAnaysePrint.xml");
|
|
var changedFile = Path.ChangeExtension(xmlFile, "chg");
|
|
var result = string.Empty;
|
|
if (FS.FileExists(changedFile))
|
|
{
|
|
result = changedFile;
|
|
}
|
|
else if (FS.FileExists(xmlFile))
|
|
{
|
|
result = xmlFile;
|
|
}
|
|
else
|
|
{
|
|
return string.Empty;
|
|
}
|
|
return result.Substring(Wpf.Settings.ConfigFolder.Length + 1);
|
|
}
|
|
|
|
private void AddParameters(Dictionary<string, object> parameters)
|
|
{
|
|
|
|
parameters.Add("$Details", GetList());
|
|
parameters.Add("$DetailsType", typeof(SaleOutStoreSimpleAnayseBo));
|
|
|
|
}
|
|
|
|
|
|
private List<SaleOutStoreSimpleAnayseBo> GetList()
|
|
{
|
|
var list = new List<SaleOutStoreSimpleAnayseBo>();
|
|
var query = GetQueryDom();
|
|
using (var context = new TransactionContext())
|
|
{
|
|
using (var reader = context.Session.ExecuteReader(query))
|
|
{
|
|
|
|
while (reader.Read())
|
|
{
|
|
int i = 0;
|
|
var item = new SaleOutStoreSimpleAnayseBo();
|
|
item.Customer_Name = (string)reader[i++];
|
|
item.DeliverGoodsLine_Name = (string)reader[i++];
|
|
|
|
item.Goods_Name = (string)reader[i++];
|
|
item.Goods_Spec = (string)reader[i++];
|
|
item.OrderNumber = (Money<decimal>?)reader[i++];
|
|
item.SecondNumber = (Money<decimal>?)reader[i++];
|
|
item.Goods_SecondUnit = (string)reader[i++];
|
|
list.Add(item);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
return list;
|
|
}
|
|
|
|
|
|
public SaleOutStorePrintInfo info { get; set; }
|
|
|
|
|
|
|
|
|
|
private string[] fieldInfo = new string[] { "DeliverGoodsLine_Name", "Customer_Name", "Goods_Name", "Goods_Spec", "UnitNum", "SecondNumber", "Goods_SecondUnit" };
|
|
|
|
private DQueryDom GetQueryDom()
|
|
{
|
|
|
|
var root = new JoinAlias("__main", typeof(SaleOutStore));
|
|
var detail = new JoinAlias("__detail", typeof(SaleOutStore_Detail));
|
|
var dom = new DQueryDom(root);
|
|
|
|
var goods = new JoinAlias(typeof(SaleGoods));
|
|
var goodsProperty = new JoinAlias(typeof(GoodsProperty));
|
|
var goodsPropertyCatalog = new JoinAlias(typeof(GoodsPropertyCatalog));
|
|
dom.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(root, "ID", detail, "SaleOutStore_ID"));
|
|
|
|
dom.From.AddJoin(JoinType.Left, new DQDmoSource(goods), DQCondition.EQ(detail, "SaleGoods_ID", goods, "ID"));
|
|
dom.From.AddJoin(JoinType.Left, new DQDmoSource(goodsProperty), DQCondition.EQ(goodsProperty, "ID", goods, "GoodsProperty_ID"));
|
|
dom.From.AddJoin(JoinType.Left, new DQDmoSource(goodsPropertyCatalog), DQCondition.EQ(goodsProperty, "GoodsPropertyCatalog_ID", goodsPropertyCatalog, "ID"));
|
|
dom.Where.Conditions.Add(DQCondition.EQ(root, "Domain_ID", DomainContext.Current.ID));
|
|
OrganizationUtil.AddOrganizationLimit(dom, typeof(SaleOutStore));
|
|
|
|
|
|
foreach (var item in fieldInfo)
|
|
{
|
|
switch (item)
|
|
{
|
|
case "Customer_Name":
|
|
case "DeliverGoodsLine_Name":
|
|
dom.Columns.Add(DQSelectColumn.Field(item, root));
|
|
dom.GroupBy.Expressions.Add(DQExpression.Field(root, item));
|
|
break;
|
|
case "Goods_Name":
|
|
case "Goods_Spec":
|
|
case "Goods_SecondUnit":
|
|
dom.Columns.Add(DQSelectColumn.Field(item, detail));
|
|
dom.GroupBy.Expressions.Add(DQExpression.Field(detail, item));
|
|
break;
|
|
case "SecondNumber":
|
|
case "UnitNum":
|
|
dom.Columns.Add(DQSelectColumn.Sum( detail, item));
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
if (info != null)
|
|
{
|
|
if (info.MaxLoadTime != null)
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(root, "LoadTime", info.MaxLoadTime));
|
|
}
|
|
if (info.MaxOrderDate != null)
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.LessThanOrEqual(root, "OrderDate", info.MaxOrderDate));
|
|
}
|
|
|
|
if (info.MinLoadTime != null)
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(root, "LoadTime", info.MinLoadTime));
|
|
}
|
|
if (info.MinOrderDate != null)
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.GreaterThanOrEqual(root, "OrderDate", info.MinOrderDate));
|
|
}
|
|
if (!string.IsNullOrEmpty(info.BillStates))
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(root, "BillState"), info.BillStates.Split('|').Select(x=>DQExpression.Value(x)).ToArray()));
|
|
}
|
|
if (!string.IsNullOrEmpty(info.DeliverGoodsLines))
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(root, "DeliverGoodsLine_ID"), info.DeliverGoodsLines.Split('|').Select(x => DQExpression.Value(x)).ToArray()));
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(info.GoodsPropertyCatalogs))
|
|
{
|
|
var strs = B3SaleWebUtil.GetDeepByTreeName(info.GoodsPropertyCatalogDisplayValue);
|
|
var conditions = new List<IDQExpression>();
|
|
var values = info.GoodsPropertyCatalogs.Split('|');
|
|
for (int index = 0; index < values.Length; index++)
|
|
{
|
|
var value = values[index];
|
|
if (string.IsNullOrEmpty(value))
|
|
continue;
|
|
conditions.Add(DQCondition.EQ(goodsPropertyCatalog, "TreeDeep" + strs[index] + "ID", value));
|
|
}
|
|
dom.Where.Conditions.Add(DQCondition.Or(conditions));
|
|
|
|
|
|
}
|
|
if (!string.IsNullOrEmpty(info.Customers))
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(root, "Customer_ID"), info.Customers.Split('|').Select(x => DQExpression.Value(x)).ToArray()));
|
|
}
|
|
if (!string.IsNullOrEmpty(info.TakeGoodsTypes))
|
|
{
|
|
dom.Where.Conditions.Add(DQCondition.InList(DQExpression.Field(root, "TakeGoods_Type"), info.TakeGoodsTypes.Split('|').Select(x => DQExpression.Value(x)).ToArray()));
|
|
}
|
|
|
|
|
|
}
|
|
dom.Where.Conditions.Add(DQCondition.EQ(root, "Domain_ID", DomainContext.Current.ID));
|
|
OrganizationUtil.AddOrganizationLimit(dom, typeof(SaleOutStore));
|
|
|
|
|
|
|
|
return dom;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
private bool Print
|
|
{
|
|
get { return Request.QueryString["Print"] == "1"; }
|
|
}
|
|
|
|
protected virtual bool SkipPrintBL
|
|
{
|
|
get
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
protected override void InitForm(HtmlForm form)
|
|
{
|
|
|
|
LoadQueryInfo();
|
|
var absoluteSet = false;
|
|
form.Controls.Add(new LiteralControl(PagerBand.PageBreak));
|
|
Control pageContainer = CreatePageContainer(CreateReport(), out absoluteSet);
|
|
form.Controls.Add(pageContainer);
|
|
|
|
}
|
|
|
|
private void LoadQueryInfo()
|
|
{
|
|
info = SaleOutStorePrintInfo.Load();
|
|
}
|
|
|
|
private int pagesCount;
|
|
private int slipPages;
|
|
private WebUnit pageHeight = WebUnit.Empty;
|
|
|
|
private Control CreatePageContainer(Control control, out bool absoluteSet)
|
|
{
|
|
absoluteSet = false;
|
|
foreach (Control ctrl in control.Controls)
|
|
{
|
|
BillReport r = ctrl as BillReport;
|
|
if (r != null)
|
|
{
|
|
pagesCount += r.PagesCount;
|
|
if (pageHeight == WebUnit.Empty)
|
|
pageHeight = r.PageHeight;
|
|
}
|
|
}
|
|
HtmlGenericControl result = new HtmlGenericControl("div");
|
|
result.Style[HtmlTextWriterStyle.Width] = "100%";
|
|
result.Style[HtmlTextWriterStyle.Padding] = "0cm";
|
|
result.Style[HtmlTextWriterStyle.BorderWidth] = "0cm";
|
|
result.Style[HtmlTextWriterStyle.Margin] = "0cm";
|
|
if (!pageHeight.IsEmpty)
|
|
{
|
|
result.Style[HtmlTextWriterStyle.Top] = new WebUnit((pageHeight.Value * slipPages), pageHeight.Type).ToString();
|
|
result.Style[HtmlTextWriterStyle.Position] = "absolute";
|
|
absoluteSet = true;
|
|
}
|
|
result.Controls.Add(control);
|
|
slipPages = pagesCount;
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
|
|
public string PrintName
|
|
{
|
|
get { return "万福销售分析"; }
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|