From de22d46bc23d08c89d42b3140d46df231e0bd716 Mon Sep 17 00:00:00 2001
From: yibo <361071264@qq.com>
Date: Wed, 18 Apr 2018 15:43:08 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=99=BD=E6=9D=A1=E7=BA=A7?=
=?UTF-8?q?=E5=88=AB=E6=B1=87=E6=80=BB=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../B3ClientService.Web.csproj | 3 +
.../CarcassGradeAnalyse.cs | 319 ++++++++++++++++++
.../config/plugins/B3ClientService.plugin | 2 +
3 files changed, 324 insertions(+)
create mode 100644 B3ClientService.Web/Pages/B3ClientService/Reports/CarcassGradeAnalyse_/CarcassGradeAnalyse.cs
diff --git a/B3ClientService.Web/B3ClientService.Web.csproj b/B3ClientService.Web/B3ClientService.Web.csproj
index 656c2f0..79135ff 100644
--- a/B3ClientService.Web/B3ClientService.Web.csproj
+++ b/B3ClientService.Web/B3ClientService.Web.csproj
@@ -110,6 +110,9 @@
ASPXCodeBehind
+
+ ASPXCodeBehind
+
ASPXCodeBehind
diff --git a/B3ClientService.Web/Pages/B3ClientService/Reports/CarcassGradeAnalyse_/CarcassGradeAnalyse.cs b/B3ClientService.Web/Pages/B3ClientService/Reports/CarcassGradeAnalyse_/CarcassGradeAnalyse.cs
new file mode 100644
index 0000000..317a164
--- /dev/null
+++ b/B3ClientService.Web/Pages/B3ClientService/Reports/CarcassGradeAnalyse_/CarcassGradeAnalyse.cs
@@ -0,0 +1,319 @@
+using BWP.Web.WebControls;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security;
+using System.Text;
+using System.Web.UI;
+using System.Web.UI.HtmlControls;
+using System.Web.UI.WebControls;
+using TSingSoft.WebPluginFramework.Controls;
+using TSingSoft.WebPluginFramework.Pages;
+using TSingSoft.WebControls2;
+using TSingSoft.WebControls2.DFGrids;
+using Forks.EnterpriseServices.DataForm;
+using System.Collections;
+using BWP.B3Frameworks.Utils;
+using Forks.EnterpriseServices.DomainObjects2;
+using BWP.B3ClientService.BO;
+using Forks.EnterpriseServices.DomainObjects2.DQuery;
+using Forks.EnterpriseServices.SqlDoms;
+using BWP.B3ClientService.NamedValueTemplate;
+using Forks.Utils;
+
+namespace BWP.Web.Pages.B3ClientService.Reports.CarcassGradeAnalyse_
+{
+ class CarcassGradeAnalyse : ServerPage, IDFGridService
+ {
+ protected override void OnInit(EventArgs e)
+ {
+ if (!User.IsInRole("B3ClientService.报表展示.白条级别汇总"))
+ throw new SecurityException();
+ base.OnInit(e);
+ }
+
+ protected override void InitForm(HtmlForm form)
+ {
+ form.EAdd(new PageTitle("白条级别汇总"));
+
+ var queryPanel = new Panel();
+ queryPanel.Style.Add(HtmlTextWriterStyle.BackgroundColor, "white");
+ queryPanel.CssClass = "QueryPanel PrintInVisible";
+ form.Controls.Add(queryPanel);
+
+ AddQueryControl(queryPanel);
+
+ var mZone = new TitlePanelZone();
+ form.Controls.Add(mZone);
+
+ mZone.Add(CreateResultTab());
+ }
+
+ DateInput butcherDate;
+ private void AddQueryControl(Panel queryPanel)
+ {
+ var hp = queryPanel.EAdd(new Panel());
+ hp.Style.Add("float", "right");
+ hp.EAdd(new SimpleLabel("屠宰日期"));
+ butcherDate = hp.EAdd(new DateInput() { Date = DateTime.Today, Width = Unit.Pixel(100) });
+ butcherDate.Style.Add("margin-right", "30px");
+ hp.EAdd(new TSButton("查询", delegate
+ {
+ StartQuery();
+ }) { Width = Unit.Pixel(80) });
+ }
+
+ protected List ColumnNames
+ {
+ get
+ {
+ if (ViewState["ColumnNames"] == null)
+ ColumnNames = new List();
+ return (List)ViewState["ColumnNames"];
+ }
+ set
+ {
+ ViewState["ColumnNames"] = value;
+ }
+ }
+
+ DFGrid mDFGrid;
+ private TitlePanel CreateResultTab()
+ {
+ var result = new TitlePanel("查询结果");
+ mDFGrid = new DFGrid(this, columns =>
+ {
+ foreach (string name in ColumnNames)
+ {
+ columns.Add(new DFBoundColumn(name));
+ }
+ })
+ {
+ Width = Unit.Percentage(100),
+ IgnoreItemsCount = true,
+ AllowColGroup = true,
+ AllowSorting = true
+ };
+ result.EAdd(mDFGrid);
+ return result;
+ }
+
+ void StartQuery()
+ {
+ mDFGrid.CurrentPage = 0;
+ mDFGrid.DataBind();
+ }
+
+ protected override void OnLoad(EventArgs e)
+ {
+ base.OnLoad(e);
+ if (!IsPostBack)
+ StartQuery();
+ }
+
+ public QueryResult GetData(QuerySettings settings)
+ {
+ ColumnNames.Clear();
+ DFDataTable table = GetDFDataTable(settings);
+
+ IList list = table.Rows;
+ if (!string.IsNullOrEmpty(settings.SortField))
+ {
+ int columnIndex = -1;
+ for (int i = 0; i < table.Columns.Count; i++)
+ {
+ if (table.Columns[i].Name == settings.SortField)
+ {
+ columnIndex = i;
+ break;
+ }
+ }
+ DFDataRow[] rows = new DFDataRow[table.Rows.Count];
+ for (int i = 0; i < rows.Length; i++)
+ rows[i] = table.Rows[i];
+
+ DFDataRowComparer comparer = new DFDataRowComparer(columnIndex, settings.SortDirection == SortDirection.Descending ? true : false);
+ Array.Sort(rows, comparer);
+ list = rows;
+ }
+
+ //var gridSet = mDFGrid.Set == null ? null : mDFGrid.Set.Sets;
+
+ var result = new QueryResult(table.Rows.Count, list, table.Columns, table.SumRow, null);
+
+ return result;
+ }
+
+ List GetAllData()
+ {
+ var main = new JoinAlias(typeof(CarcassFullInfo));
+ var livestock = new JoinAlias(typeof(Livestock));
+ var inGoods = new JoinAlias("iGoods", typeof(Goods));
+ var outGoods = new JoinAlias("oGoods", typeof(Goods));
+ var query = new DQueryDom(main);
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(livestock), DQCondition.EQ(main, "Livestock_ID", livestock, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(inGoods), DQCondition.EQ(main, "InStoreGoods_ID", inGoods, "ID"));
+ query.From.AddJoin(JoinType.Left, new DQDmoSource(outGoods), DQCondition.EQ(main, "SaleGoods_ID", outGoods, "ID"));
+ query.Columns.Add(DQSelectColumn.Field("Livestock_ID"));
+ query.Columns.Add(DQSelectColumn.Field("Name", livestock));
+ query.Columns.Add(DQSelectColumn.Field("GradeWeight"));
+
+ query.Columns.Add(DQSelectColumn.Field("InStoreGoods_ID"));
+ query.Columns.Add(DQSelectColumn.Field("Name", inGoods));
+ query.Columns.Add(DQSelectColumn.Field("InStoreWeight"));
+
+ query.Columns.Add(DQSelectColumn.Field("SaleGoods_ID"));
+ query.Columns.Add(DQSelectColumn.Field("Name", outGoods));
+ query.Columns.Add(DQSelectColumn.Field("PickWeight"));
+
+ if (butcherDate.Value.HasValue)
+ query.Where.Conditions.Add(DQCondition.EQ("ButcherDate", butcherDate.Date));
+
+ var list = new List();
+ using (var session = Dmo.NewSession())
+ {
+ using (var reader = session.ExecuteReader(query))
+ {
+ while (reader.Read())
+ {
+ var entity = new TempData();
+ entity.Livestock_ID = (long?)reader[0];
+ entity.Livestock_Name = (string)reader[1];
+ entity.LWeight = (decimal?)reader[2];
+
+ entity.IGoods_ID = (long?)reader[3];
+ entity.IGoods_Name = (string)reader[4];
+ entity.IWeight = (decimal?)reader[5];
+
+ entity.OGoods_ID = (long?)reader[6];
+ entity.OGoods_Name = (string)reader[7];
+ entity.OWeight = (decimal?)reader[8];
+ list.Add(entity);
+ }
+ }
+ }
+ return list;
+ }
+
+ DFDataTable GetDFDataTable(QuerySettings settings)
+ {
+ var table = new DFDataTable();
+ AddTableHead(table);
+ var list = GetAllData();
+ var combine = CombineList(list);
+ FillTable(table, combine);
+ return table;
+ }
+
+ private List CombineList(List list)
+ {
+ var combine = new List();
+ var l = list.Where(x => x.Livestock_ID.HasValue).GroupBy(x => x.Livestock_ID).OrderBy(x => x.Key);
+ foreach (var g in l)
+ {
+ var e = new TempData();
+ e.Livestock_Name = g.First().Livestock_Name;
+ e.LNumber = g.Count();
+ e.LWeight = g.Sum(x => x.LWeight ?? 0);
+ combine.Add(e);
+ }
+
+ var i = list.Where(x => x.IGoods_ID.HasValue).GroupBy(x => x.IGoods_ID).OrderBy(x => x.Key);
+ var n = 0;
+ foreach (var g in i)
+ {
+ if (n > combine.Count() - 1)
+ combine.Add(new TempData());
+ var tag = combine[n];
+ tag.IGoods_Name = g.First().IGoods_Name;
+ tag.INumber = g.Count();
+ tag.IWeight = g.Sum(x => x.IWeight ?? 0);
+ n++;
+ }
+
+ var o = list.Where(x => x.OGoods_ID.HasValue).GroupBy(x => x.OGoods_ID).OrderBy(x => x.Key);
+ n = 0;
+ foreach (var g in o)
+ {
+ if (n > combine.Count() - 1)
+ combine.Add(new TempData());
+ var tag = combine[n];
+ tag.OGoods_Name = g.First().OGoods_Name;
+ tag.ONumber = g.Count();
+ tag.OWeight = g.Sum(x => x.OWeight ?? 0);
+ n++;
+ }
+ return combine;
+ }
+
+ private void AddTableHead(DFDataTable table)
+ {
+ table.Columns.Add(new DFCustomDataColumn("屠宰级别|级别", typeof(string)));
+ table.Columns.Add(new DFCustomDataColumn("屠宰级别|头数", typeof(int)));
+ table.Columns.Add(new DFCustomDataColumn("屠宰级别|重量", typeof(decimal)));
+ ColumnNames.Add("屠宰级别|级别");
+ ColumnNames.Add("屠宰级别|头数");
+ ColumnNames.Add("屠宰级别|重量");
+
+ table.Columns.Add(new DFCustomDataColumn("入库级别|存货名称", typeof(string)));
+ table.Columns.Add(new DFCustomDataColumn("入库级别|头数", typeof(int)));
+ table.Columns.Add(new DFCustomDataColumn("入库级别|重量", typeof(decimal)));
+ ColumnNames.Add("入库级别|存货名称");
+ ColumnNames.Add("入库级别|头数");
+ ColumnNames.Add("入库级别|重量");
+
+
+ table.Columns.Add(new DFCustomDataColumn("销售级别|存货名称", typeof(string)));
+ table.Columns.Add(new DFCustomDataColumn("销售级别|头数", typeof(int)));
+ table.Columns.Add(new DFCustomDataColumn("销售级别|重量", typeof(decimal)));
+ ColumnNames.Add("销售级别|存货名称");
+ ColumnNames.Add("销售级别|头数");
+ ColumnNames.Add("销售级别|重量");
+ }
+
+ private void FillTable(DFDataTable table, List list)
+ {
+ foreach (var item in list)
+ {
+ var row = table.Rows.NewRow();
+ row[0] = item.Livestock_Name;
+ row[1] = item.LNumber;
+ row[2] = item.LWeight;
+
+ row[3] = item.IGoods_Name;
+ row[4] = item.INumber;
+ row[5] = item.IWeight;
+
+ row[6] = item.OGoods_Name;
+ row[7] = item.ONumber;
+ row[8] = item.OWeight;
+ }
+ table.SumRow[1] = list.Sum(x => x.LNumber);
+ table.SumRow[2] = list.Sum(x => x.LWeight ?? 0);
+
+ table.SumRow[4] = list.Sum(x => x.INumber);
+ table.SumRow[5] = list.Sum(x => x.IWeight ?? 0);
+
+ table.SumRow[7] = list.Sum(x => x.ONumber);
+ table.SumRow[8] = list.Sum(x => x.OWeight ?? 0);
+ }
+ }
+
+ class TempData
+ {
+ public long? Livestock_ID { get; set; }
+ public string Livestock_Name { get; set; }
+ public int LNumber { get; set; }
+ public decimal? LWeight { get; set; }
+
+ public long? IGoods_ID { get; set; }
+ public string IGoods_Name { get; set; }
+ public int INumber { get; set; }
+ public decimal? IWeight { get; set; }
+
+ public long? OGoods_ID { get; set; }
+ public string OGoods_Name { get; set; }
+ public int ONumber { get; set; }
+ public decimal? OWeight { get; set; }
+ }
+}
diff --git a/WebFolder/config/plugins/B3ClientService.plugin b/WebFolder/config/plugins/B3ClientService.plugin
index e5463ec..7d340ac 100644
--- a/WebFolder/config/plugins/B3ClientService.plugin
+++ b/WebFolder/config/plugins/B3ClientService.plugin
@@ -43,6 +43,7 @@
+
@@ -109,6 +110,7 @@
+