| @ -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<string> ColumnNames | |||
| { | |||
| get | |||
| { | |||
| if (ViewState["ColumnNames"] == null) | |||
| ColumnNames = new List<string>(); | |||
| return (List<string>)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<TempData> 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<TempData>(); | |||
| 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<TempData> CombineList(List<TempData> list) | |||
| { | |||
| var combine = new List<TempData>(); | |||
| 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<TempData> 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; } | |||
| } | |||
| } | |||