using FCOMMON;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FEQ0000
{
    public partial class rpt_equipmentAll : fBase
    {
        dsEQ.EETGW_EquipmentDataTable dt;
        public rpt_equipmentAll(dsEQ.EETGW_EquipmentDataTable dt_,string title)
        {
            //SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
            InitializeComponent();
            Properties.Settings.Default["gwcs"] = FCOMMON.info.CS;
            Properties.Settings.Default["EEEntities"] = FCOMMON.info.CS;

            this.dt = dt_;
            this.Text = "Equipment List(" + title + ")";
        }


      
        private void rpt_equipment_Load(object sender, EventArgs e)
        {
            EnsureVisibleAndUsableSize();
            this.Show();
            Application.DoEvents();

            //데이터를 집계해서 생성해준다.
            var dtSum = new dsEQ.vEquStockAllDataTable();
            var grpType = this.dt.GroupBy(t => t.type);
            foreach (var gItemType in grpType)
            {
                var grpManu = gItemType.GroupBy(t => t.manu);
                foreach (var gItemM in grpManu)
                {
                    var grpMod = gItemM.GroupBy(t => t.model);
                    foreach (var gItemMod in grpMod)
                    {
                        var grpLine = gItemMod.GroupBy(t => t.lineT + "-" + t.lineP);
                        foreach (var gItemLine in grpLine)
                        {
                            var grpP1 = gItemLine.GroupBy(t => t.param1);
                            foreach(var gItemP1 in grpP1)
                            {
                                var grpPlant = gItemP1.GroupBy(t => t.plant);
                                foreach (var gItemPlant in grpPlant)
                                {
                                    var grpGrp2 = gItemPlant.GroupBy(t => t.grp2);
                                    foreach (var gItemGrp2 in grpGrp2)
                                    {
                                        var dr = gItemGrp2.FirstOrDefault();
                                        var newdr = dtSum.NewvEquStockAllRow();
                                        newdr.pdate = DateTime.Now.ToString("yyyy-MM-dd");
                                        newdr.grp = dr.type;
                                        newdr.manu = dr.manu;
                                        newdr.model = dr.model;
                                        newdr.linecode = dr.linecode;
                                        newdr.lineT = dr.lineT;
                                        newdr.lineP = dr.lineP;
                                        newdr.cnt = gItemGrp2.Count();
                                        newdr.Remark = dr.memo;
                                        newdr.plant = dr.plant;
                                        newdr.grp2 = dr.grp2;
                                        newdr.gcode = FCOMMON.info.Login.gcode;
                                        dtSum.AddvEquStockAllRow(newdr);
                                    }
                                }
                            }
                        }
                    }
                }
            }


            this.rpv1.PageCountMode = Microsoft.Reporting.WinForms.PageCountMode.Actual;
            this.rpv1.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.PageWidth;

            //Set DataSource
            Microsoft.Reporting.WinForms.ReportDataSource DsEQ = new Microsoft.Reporting.WinForms.ReportDataSource();
            DsEQ.Name = "DataSet1";

            this.rpv1.LocalReport.ReportEmbeddedResource = "FEQ0000.Equipment.ReportB.rdlc";
            DsEQ.Value = dtSum;

            this.rpv1.LocalReport.DataSources.Add(DsEQ);
            this.rpv1.RefreshReport();
        }
    }
}
