public List <DefectRateData> GetListDefectRateReportFromTo(string Dept, string codeProcess, DateTime from, DateTime to)
        {
            List <DefectRateData> defectRates = new List <DefectRateData>();

            try
            {
                LoadDataSummary       loadData     = new LoadDataSummary();
                List <MQCItemSummary> ListmQCItems = loadData.GetMQCItemSummariesFromTo(from, to, Dept, "MQC");
                foreach (var mQCItems in ListmQCItems)
                {
                    DefectRateData defectRate = new DefectRateData();
                    defectRate.Lot            = mQCItems.Lot;
                    defectRate.Line           = mQCItems.Line;
                    defectRate.Product        = mQCItems.product;
                    defectRate.DateTime_from  = mQCItems.Time_from;
                    defectRate.DateTime_to    = mQCItems.Time_To;
                    defectRate.TotalQuantity  = mQCItems.QuantityTotal;
                    defectRate.ReworkQuantity = mQCItems.ReworkQty;
                    defectRate.ReworkRate     = mQCItems.ReworkRate;

                    defectRate.DefectQuantity = mQCItems.NGQty;
                    defectRate.OutputQuantity = mQCItems.OutputQty;
                    defectRate.DefectRate     = (defectRate.TotalQuantity != 0) ? (defectRate.DefectQuantity / defectRate.TotalQuantity) : 0;
                    LoadDefectMapping     loadDefectTop13 = new LoadDefectMapping();
                    List <NGItemsMapping> listTop13       = loadDefectTop13.listNGMappingGetReportTop13(Dept, "MQC");
                    List <DefectItem>     listDefectTop13 = new List <DefectItem>();
                    for (int i = 0; i < listTop13.Count; i++)
                    {
                        var getlist = mQCItems.defectItems.Where(d => d.DefectSFT == listTop13[i].NGCode_SFT).ToList();

                        DefectItem defect = new DefectItem();
                        if (getlist != null && getlist.Count > 0)
                        {
                            defect          = getlist[0];
                            defect.Quantity = getlist.Select(s => s.Quantity).Sum();
                        }
                        defect.Note = listTop13[i].Note;
                        listDefectTop13.Add(defect);
                    }
                    var listDefectTop13Groupby = listDefectTop13.OrderBy(d => d.Note).ToList();
                    defectRate.defectItems = listDefectTop13Groupby;
                    defectRate.ReworkItems = mQCItems.ReworkItems;

                    defectRate.TargetMQC = new TargetMQC();
                    LoadTargetProduction loadTarget = new LoadTargetProduction();
                    TimeSpan             timeSpan   = to - from;
                    defectRate.TargetMQC = loadTarget.GetArraystarget(defectRate.Product, from, from.AddDays(Math.Round(timeSpan.TotalDays - 1, 0)));
                    defectRates.Add(defectRate);
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetDefectRateReport(DateTime from, DateTime to, string Dept, string codeProcess)", ex.Message);
            }
            return(defectRates);
        }
Exemplo n.º 2
0
        public MQCItemSummary GetMQCItemSummary(DateTime from, DateTime to, string site, string process)
        {
            MQCItemSummary itemSummary = new MQCItemSummary();

            try
            {
                LoadDataMQC         dataMQC      = new LoadDataMQC();
                List <MQCDataItems> mQCDataItems = dataMQC.listMQCDataItemsbySite(from, to, site, process);
                //Nhom theo san pham
                var ListItemsData = mQCDataItems
                                    .GroupBy(u => u.item)
                                    .Select(grp => grp.ToList())
                                    .ToList();

                var ListItemsTime = mQCDataItems
                                    .GroupBy(u => u.inspecttime)
                                    .ToList();



                itemSummary.product     = "";
                itemSummary.defectItems = new List <DefectItem>();

                //Khi thay doi ngay can phai chinh lai thoi gian
                itemSummary.Time_from = mQCDataItems.Min(d => d.inspecttime).ToString();
                itemSummary.Time_To   = mQCDataItems.Max(d => d.inspecttime).ToString();

                foreach (var itemData in ListItemsData)
                {
                    if (itemData[0].remark == "OP")
                    {
                        itemSummary.OutputQty = itemData.Select(d => d.data).Sum();
                    }
                    else if (itemData[0].remark == "NG")
                    {
                        DefectItem item = new DefectItem();
                        item.DefectCode = itemData[0].item;
                        item.Quantity   = itemData.Select(d => d.data).Sum();
                        LoadDefectMapping defectMapping  = new LoadDefectMapping();
                        NGItemsMapping    nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode);
                        item.DefectSFT     = nGItemsMapping.NGCode_SFT;
                        item.DefectSFTName = nGItemsMapping.NGCodeName_SFT;
                        itemSummary.defectItems.Add(item);
                        itemSummary.NGQty += item.Quantity;
                    }
                }
                itemSummary.QuantityTotal = itemSummary.OutputQty + itemSummary.NGQty;
                itemSummary.DefectRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.NGQty / itemSummary.QuantityTotal) : 0;
            }
            catch (Exception ex)
            {
                Log.Logfile.Output(Log.StatusLog.Error, "GetMQCItemSummaries(DateTime from, DateTime to, string site, string process)", ex.Message);
            }
            return(itemSummary);
        }
        public DefectRateData GetDefectRateReportAmountOfTime(DateTime from, DateTime to, string Dept, string codeProcess)
        {
            DefectRateData defectRate = new DefectRateData();

            try
            {
                LoadDataSummary loadData = new LoadDataSummary();
                MQCItemSummary  mQCItems = loadData.GetMQCItemSummaryByAmountOfTime(from, to, Dept, "MQC");
                defectRate.TotalQuantity  = mQCItems.QuantityTotal;
                defectRate.DefectQuantity = mQCItems.NGQty;
                defectRate.OutputQuantity = mQCItems.OutputQty;
                defectRate.Line           = mQCItems.Line;
                defectRate.DefectRate     = (defectRate.TotalQuantity != 0) ? (defectRate.DefectQuantity / defectRate.TotalQuantity) : 0;
                LoadDefectMapping     loadDefectTop5 = new LoadDefectMapping();
                List <NGItemsMapping> listTop5       = loadDefectTop5.listNGMappingGetReport(Dept, "MQC");
                List <DefectItem>     listDefectTop5 = new List <DefectItem>();
                for (int i = 0; i < listTop5.Count; i++)
                {
                    var getlist = mQCItems.defectItems.Where(d => d.DefectSFT == listTop5[i].NGCode_SFT).ToList();

                    DefectItem defect = new DefectItem();
                    if (getlist != null && getlist.Count > 0)
                    {
                        defect          = getlist[0];
                        defect.Quantity = getlist.Select(s => s.Quantity).Sum();
                    }
                    defect.Note = listTop5[i].Note;
                    listDefectTop5.Add(defect);
                }
                var listDefectTop5Groupby = listDefectTop5.OrderBy(d => d.Note).ToList();
                defectRate.defectItems = listDefectTop5Groupby;
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetDefectRateReport(DateTime from, DateTime to, string Dept, string codeProcess)", ex.Message);
            }
            return(defectRate);
        }
        public DefectRateData GetDefectRateReportByLotTop13(DateTime from, TimeSpan time_From, DateTime to, TimeSpan time_to, string Dept, string codeProcess, string lot)
        {
            DefectRateData defectRate = new DefectRateData();

            try
            {
                //code lay tren ERP va SFT
                //     StringBuilder sql = new StringBuilder();
                //     sql.Append("select sum(TA011) as outputQty, sum(TA012) as DefectQTy, sum(TA011)+ sum(TA012) as TotalQty ");
                //     sql.Append("from SFCTA ");
                //     sql.Append("where 1=1 ");
                //     sql.Append("and TA004 = '" + Dept + "'");
                //     sql.Append("and TA003 = '" + codeProcess + "'");
                //     sql.Append("and CREATE_DATE >= '" + from.ToString("yyyyMMdd") + "'");
                //     sql.Append("and CREATE_DATE <= '" + to.ToString("yyyyMMdd") + "'");
                //     sqlERPCON sqlERPCON = new sqlERPCON();
                //     DataTable dt = new DataTable();
                //     sqlERPCON.sqlDataAdapterFillDatatable(sql.ToString(), ref dt);

                //var     defectItems = (from DataRow dr in dt.Rows
                //                        select new DefectRateData()
                //                        {
                //                           TotalQuantity  =double.Parse( dr["TotalQty"].ToString()),
                //                            DefectQuantity = double.Parse( dr["DefectQTy"].ToString()),
                //                            OutputQuantity = double.Parse(dr["outputQty"].ToString())

                //                        }).ToList();

                //     defectRate = defectItems[0];
                //     defectRate.DateTime_from = from;
                //     defectRate.DateTime_to = to;
                //     defectRate.DefectRate = (defectRate.TotalQuantity != 0) ? (defectRate.DefectQuantity / defectRate.TotalQuantity) : 0;


                LoadDataSummary loadData = new LoadDataSummary();
                MQCItemSummary  mQCItems = loadData.GetMQCItemSummarybyLot(from, time_From, to, time_to, Dept, "MQC", lot);
                defectRate.Product        = mQCItems.product;
                defectRate.Lot            = lot;
                defectRate.Line           = mQCItems.Line;
                defectRate.TotalQuantity  = mQCItems.QuantityTotal;
                defectRate.DefectQuantity = mQCItems.NGQty;
                defectRate.OutputQuantity = mQCItems.OutputQty;
                defectRate.DateTime_from  = mQCItems.Time_from;
                defectRate.DateTime_to    = mQCItems.Time_To;
                defectRate.DefectRate     = (defectRate.TotalQuantity != 0) ? (defectRate.DefectQuantity / defectRate.TotalQuantity) : 0;
                LoadDefectMapping     loadDefectTop16 = new LoadDefectMapping();
                List <NGItemsMapping> listTop16       = loadDefectTop16.listNGMappingGetReportTop13(Dept, "MQC");
                List <DefectItem>     listDefectTop16 = new List <DefectItem>();
                for (int i = 0; i < listTop16.Count; i++)
                {
                    var getlist = mQCItems.defectItems.Where(d => d.DefectSFT == listTop16[i].NGCode_SFT).ToList();

                    DefectItem defect = new DefectItem();
                    if (getlist != null && getlist.Count > 0)
                    {
                        defect          = getlist[0];
                        defect.Quantity = getlist.Select(s => s.Quantity).Sum();
                    }
                    defect.Note = listTop16[i].Note;
                    listDefectTop16.Add(defect);
                }
                var listDefectTop16Groupby = listDefectTop16.OrderBy(d => d.Note).ToList();
                defectRate.defectItems = listDefectTop16Groupby;
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetDefectRateReport(DateTime from, DateTime to, string Dept, string codeProcess)", ex.Message);
            }
            return(defectRate);
        }
        public List <DefectRateData> GetListDefectRateReportAmountOfTimeDaily(string Dept, string codeProcess, PeriodProduction period)
        {
            List <DefectRateData> defectRates = new List <DefectRateData>();

            try
            {
                LoadDataSummary       loadData     = new LoadDataSummary();
                List <MQCItemSummary> ListmQCItems = loadData.GetMQCItemSummaries(period, Dept, "MQC");
                foreach (var mQCItems in ListmQCItems)
                {
                    DefectRateData defectRate = new DefectRateData();
                    defectRate.Lot            = mQCItems.Lot;
                    defectRate.Line           = mQCItems.Line;
                    defectRate.Product        = mQCItems.product;
                    defectRate.DateTime_from  = mQCItems.Time_from;
                    defectRate.DateTime_to    = mQCItems.Time_To;
                    defectRate.TotalQuantity  = mQCItems.QuantityTotal;
                    defectRate.ReworkQuantity = mQCItems.ReworkQty;
                    defectRate.ReworkRate     = mQCItems.ReworkRate;

                    defectRate.DefectQuantity = mQCItems.NGQty;
                    defectRate.OutputQuantity = mQCItems.OutputQty;
                    defectRate.DefectRate     = (defectRate.TotalQuantity != 0) ? (defectRate.DefectQuantity / defectRate.TotalQuantity) : 0;
                    LoadDefectMapping     loadDefectTop13 = new LoadDefectMapping();
                    List <NGItemsMapping> listTop13       = loadDefectTop13.listNGMappingGetReportTop13(Dept, "MQC");
                    List <DefectItem>     listDefectTop13 = new List <DefectItem>();
                    for (int i = 0; i < listTop13.Count; i++)
                    {
                        var getlist = mQCItems.defectItems.Where(d => d.DefectSFT == listTop13[i].NGCode_SFT).ToList();

                        DefectItem defect = new DefectItem();
                        if (getlist != null && getlist.Count > 0)
                        {
                            defect          = getlist[0];
                            defect.Quantity = getlist.Select(s => s.Quantity).Sum();
                        }
                        defect.Note = listTop13[i].Note;
                        listDefectTop13.Add(defect);
                    }
                    var listDefectTop13Groupby = listDefectTop13.OrderBy(d => d.Note).ToList();
                    defectRate.defectItems = listDefectTop13Groupby;
                    DateTime dateTarget = DateTime.Now.Date;
                    if (period == PeriodProduction.AllDay)
                    {
                        dateTarget = DateTime.Now.Date.AddDays(-1);
                    }
                    else if (period == PeriodProduction.dayshift)
                    {
                        dateTarget = DateTime.Now.Date;
                    }
                    else if (period == PeriodProduction.nightshift)
                    {
                        dateTarget = DateTime.Now.Date.AddDays(-1);
                    }
                    defectRate.TargetMQC = new TargetMQC();
                    LoadTargetProduction loadTarget = new LoadTargetProduction();
                    defectRate.TargetMQC = loadTarget.GetTargetMQC(defectRate.Product, dateTarget.ToString("yyyyMMdd"));
                    defectRates.Add(defectRate);
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetDefectRateReport(DateTime from, DateTime to, string Dept, string codeProcess)", ex.Message);
            }
            return(defectRates);
        }
Exemplo n.º 6
0
        public void CreateDatagridview()
        {
            DataGridViewCell cell = new DataGridViewTextBoxCell();

            cell.Style.Font = new Font("Times New Roman", 12);
            DataGridViewColumn newCol = new DataGridViewColumn(); // add a column to the grid

            newCol.CellTemplate = cell;
            newCol.HeaderText   = @"
Tên sản phẩm
 品名";
            newCol.Name         = "col1";
            newCol.Visible      = true;
            newCol.Width        = 100;
            dtgv_summary.Columns.Add(newCol);

            DataGridViewColumn newCol2 = new DataGridViewColumn(); // add a column to the grid

            newCol2.CellTemplate = cell;
            newCol2.HeaderText   = @"
时间
Thời gian
";
            newCol2.Name         = "col2";
            newCol2.Visible      = true;
            newCol2.Width        = 100;
            dtgv_summary.Columns.Add(newCol2);


            DataGridViewColumn newCol3 = new DataGridViewColumn(); // add a column to the grid

            newCol3.CellTemplate = cell;
            newCol3.HeaderText   = @"
Số lượng nhận
数量
Quantity received
";
            newCol3.Name         = "col3";
            newCol3.Visible      = true;
            newCol3.Width        = 100;
            dtgv_summary.Columns.Add(newCol3);
            LoadDefectMapping     defectMapping   = new LoadDefectMapping();
            List <NGItemsMapping> nGItemsMappings = defectMapping.listNGMapping("B01", "MQC");

            foreach (var mQCItem in qCItemSummaries)
            {
                foreach (var defect in mQCItem.defectItems)
                {
                    if (listHeader.Contains(defect.DefectSFT) == false)
                    {
                        DataGridViewColumn col = new DataGridViewColumn(); // add a column to the grid

                        col.CellTemplate = cell;
                        col.HeaderText   = defect.DefectSFTName;
                        col.Name         = defect.DefectSFT;
                        col.Visible      = true;
                        col.Width        = 100;
                        dtgv_summary.Columns.Add(col);
                        listHeader.Add(defect.DefectSFT);
                    }
                }
            }

            DataGridViewColumn newCol4 = new DataGridViewColumn(); // add a column to the grid

            newCol4.CellTemplate = cell;
            newCol4.HeaderText   = @"
Số lượng đạt
合格数
Good part quantity
";
            newCol4.Name         = "col4";
            newCol4.Visible      = true;
            newCol4.Width        = 100;
            dtgv_summary.Columns.Add(newCol4);

            DataGridViewColumn newCol5 = new DataGridViewColumn(); // add a column to the grid

            newCol5.CellTemplate = cell;
            newCol5.HeaderText   = @"
Số lượng lỗi
不良数
Quantity of defect
";
            newCol5.Name         = "col5";
            newCol5.Visible      = true;
            newCol5.Width        = 100;
            dtgv_summary.Columns.Add(newCol5);

            DataGridViewColumn newCol6 = new DataGridViewColumn(); // add a column to the grid

            newCol6.CellTemplate = cell;
            newCol6.HeaderText   = @"
Tỷ lệ % lỗi
不良率(%)
Defect rate
(%)
";
            newCol6.Name         = "col6";
            newCol6.Visible      = true;
            newCol6.Width        = 100;
            dtgv_summary.Columns.Add(newCol6);

            DataGridViewColumn newCol7 = new DataGridViewColumn(); // add a column to the grid

            newCol7.CellTemplate = cell;
            newCol7.HeaderText   = @"
Ghi chú
备注
Remarks
";
            newCol7.Name         = "col7";
            newCol7.Visible      = true;
            newCol7.Width        = 100;
            dtgv_summary.Columns.Add(newCol7);
        }
Exemplo n.º 7
0
        public MQCItem1 GetQCCItemOK(DateTime from, DateTime to, string model, string lot, string site, string process)
        {
            MQCItem1 mQCItem = new MQCItem1();

            try
            {
                LoadDefectMapping     defectMapping   = new LoadDefectMapping();
                List <NGItemsMapping> nGItemsMappings = defectMapping.listNGMapping("B01", "MQC");
                mQCItem.TargetMQC = new TargetMQC();
                LoadTargetProduction loadTarget = new LoadTargetProduction();
                mQCItem.TargetMQC = loadTarget.GetTargetMQC(model, DateTime.Now.Date.ToString("yyyyMMdd"));
                List <MQCDataItems> listMQC = new List <MQCDataItems>();
                listMQC = listMQCDataItems(from, to, model, lot, process);
                //Load MQCItem to show
                mQCItem.process    = process;
                mQCItem.department = site;
                mQCItem.product    = model;

                mQCItem.PO = (listMQC != null && listMQC.Count > 0) ?   listMQC[0].lot: "";
                var TotalOutputQty = listMQC
                                     .Where(d => d.remark == "OP")
                                     .Select((s => s.data))
                                     .ToList();
                mQCItem.TotalOutput = TotalOutputQty.Sum();
                var TotalNGQty = listMQC
                                 .Where(d => d.remark == "NG")
                                 .Select((s => s.data))
                                 .ToList();
                mQCItem.TotalNG = TotalNGQty.Sum();
                var TotalRework = listMQC
                                  .Where(d => d.remark == "RW")
                                  .Select((s => s.data))
                                  .ToList();
                mQCItem.TotalRework   = TotalRework.Sum();
                mQCItem.percentNG     = (mQCItem.TotalOutput + mQCItem.TotalNG + mQCItem.TotalRework) != 0 ? mQCItem.TotalNG / (mQCItem.TotalOutput + mQCItem.TotalNG + mQCItem.TotalRework) :0;
                mQCItem.percentRework = (mQCItem.TotalOutput + mQCItem.TotalNG + mQCItem.TotalRework) != 0 ? mQCItem.TotalRework / (mQCItem.TotalOutput + mQCItem.TotalNG + mQCItem.TotalRework) : 0;
                var listNGItem = listMQC
                                 .Where(d => d.remark == "NG")
                                 .Select((s => new { s.item, s.data }))
                                 .ToList();
                mQCItem.listNGItems = new List <NGItems>();
                foreach (var item in listNGItem)
                {
                    NGItems nGItems = new NGItems();
                    var     _NG_SFT = nGItemsMappings.Where(d => d.NGCode_Process == item.item).Select(s => s.NGCode_SFT).ToArray();
                    string  NG_SFT  = (_NG_SFT != null && _NG_SFT.Count() > 0) ?_NG_SFT[0] : "";
                    nGItems.NGType = NG_SFT;
                    var    _NGName_SFT = nGItemsMappings.Where(d => d.NGCode_Process == item.item).Select(s => s.NGCodeName_SFT).ToArray();
                    string NGName_SFT  = (_NGName_SFT != null && _NGName_SFT.Count() > 0) ? _NGName_SFT[0] : "";
                    nGItems.NGName = NGName_SFT;

                    nGItems.NGKey      = item.item;
                    nGItems.NGQuantity = item.data;
                    mQCItem.listNGItems.Add(nGItems);
                }
                var listRWItem = listMQC
                                 .Where(d => d.item.Contains("RW"))
                                 .Select((s => new { s.item, s.data }))
                                 .ToList();
                mQCItem.listRWItems = new List <NGItems>();
                foreach (var item in listRWItem)
                {
                    NGItems nGItems    = new NGItems();
                    string  strReplace = item.item.Replace("RW", "NG");
                    var     _NG_SFT    = nGItemsMappings.Where(d => d.NGCode_Process == strReplace).Select(s => s.NGCode_SFT).ToArray();
                    string  NG_SFT     = (_NG_SFT != null && _NG_SFT.Count() > 0) ? _NG_SFT[0] : "";
                    nGItems.NGType = NG_SFT;
                    var    _NGName_SFT = nGItemsMappings.Where(d => d.NGCode_Process == strReplace).Select(s => s.NGCodeName_SFT).ToArray();
                    string NGName_SFT  = (_NGName_SFT != null && _NGName_SFT.Count() > 0) ? _NGName_SFT[0] : "";
                    nGItems.NGName     = NGName_SFT;
                    nGItems.NGKey      = item.item;
                    nGItems.NGQuantity = item.data;
                    mQCItem.listRWItems.Add(nGItems);
                }
                List <MQCDataItems> listMQC_Error = new List <MQCDataItems>();
                listMQC_Error = listMQCData_ErrorItems(from, to, model, lot, process);
                mQCItem.InputMaterialNotYet = listMQC_Error.Where(w => w.remark == "OP" || w.remark == "NG").Select(d => d.data).ToArray().Sum();
                double targetDefect = 0;
                if (mQCItem.TargetMQC.TargetOutput != 0)
                {
                    targetDefect = (mQCItem.TargetMQC.TargetDefect / (mQCItem.TargetMQC.TargetDefect + mQCItem.TargetMQC.TargetOutput));
                }

                if (mQCItem.InputMaterialNotYet > 0)
                {
                    mQCItem.Status  = ProductionStatus.ShortageMaterial.ToString();
                    mQCItem.Measage = "Please supply material for production";
                }
                else if (mQCItem.percentNG > targetDefect && targetDefect > 0)
                {
                    mQCItem.Status  = ProductionStatus.HighDefect.ToString();
                    mQCItem.Measage = "Defect is too much";
                }
                else
                {
                    mQCItem.Status = ProductionStatus.Normal.ToString();
                }
                mQCItem.InputSFT = (mQCItem.TotalOutput + mQCItem.TotalNG) - mQCItem.InputMaterialNotYet;
            }
            catch (Exception ex)
            {
                Log.Logfile.Output(Log.StatusLog.Error, "GetQCCItemOK", ex.Message);
            }
            // sql.Append()
            return(mQCItem);
        }
        public List <MQCItemSummary> GetMQCItemSummariesFromTo(DateTime from, DateTime to, string site, string process)
        {
            List <MQCItemSummary> qCItemSummaries = new List <MQCItemSummary>();

            try
            {
                LoadDataMQC         dataMQC      = new LoadDataMQC();
                List <MQCDataItems> mQCDataItems = dataMQC.listMQCDataItemsbySite(from, to, site, process);
                //Nhom theo san pham
                var ListMQCbyProduct = mQCDataItems
                                       .OrderBy(d => d.line)
                                       .GroupBy(u => u.lot)
                                       .Select(grp => grp.ToList())
                                       .ToList();
                foreach (var qCDataItems in ListMQCbyProduct)
                {
                    MQCItemSummary itemSummary = new MQCItemSummary();
                    itemSummary.product     = qCDataItems[0].model;
                    itemSummary.defectItems = new List <DefectItem>();
                    itemSummary.ReworkItems = new List <DefectItem>();
                    var ListItemsData = qCDataItems
                                        .GroupBy(u => u.item)
                                        .Select(grp => grp.ToList())
                                        .ToList();


                    itemSummary.Time_from = dataMQC.GetMinTimeProductionOfProduct(itemSummary.product, from, to);
                    itemSummary.Time_To   = dataMQC.GetMaxTimeProductionOfProduct(itemSummary.product, from, to);
                    //Khi thay doi ngay can phai chinh lai thoi gian

                    foreach (var itemData in ListItemsData)
                    {
                        itemSummary.product = itemData[0].model;
                        itemSummary.Line    = itemData[0].line;
                        itemSummary.Lot     = itemData[0].lot;

                        if (itemData[0].remark == "OP")
                        {
                            itemSummary.OutputQty = itemData.Select(d => d.data).Sum();
                        }
                        else if (itemData[0].remark == "NG")
                        {
                            DefectItem item = new DefectItem();
                            item.DefectCode = itemData[0].item;
                            item.Quantity   = itemData.Select(d => d.data).Sum();
                            LoadDefectMapping defectMapping  = new LoadDefectMapping();
                            NGItemsMapping    nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode);
                            item.DefectSFT     = nGItemsMapping.NGCode_SFT;
                            item.DefectSFTName = nGItemsMapping.NGCodeName_SFT;
                            itemSummary.defectItems.Add(item);
                            itemSummary.NGQty += item.Quantity;
                        }
                        else if (itemData[0].remark == "RW")
                        {
                            DefectItem item = new DefectItem();
                            item.DefectCode = itemData[0].item;
                            item.Quantity   = itemData.Select(d => d.data).Sum();
                            LoadDefectMapping defectMapping  = new LoadDefectMapping();
                            NGItemsMapping    nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode.Replace("RW", "NG"));
                            item.DefectSFT     = nGItemsMapping.NGCode_SFT;
                            item.DefectSFTName = nGItemsMapping.NGCodeName_SFT;
                            itemSummary.ReworkItems.Add(item);
                            itemSummary.ReworkQty += item.Quantity;
                        }
                    }

                    itemSummary.QuantityTotal = itemSummary.OutputQty + itemSummary.NGQty /*+ itemSummary.ReworkQty*/;
                    itemSummary.DefectRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.NGQty / itemSummary.QuantityTotal) : 0;
                    itemSummary.ReworkRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.ReworkQty / itemSummary.QuantityTotal) : 0;
                    qCItemSummaries.Add(itemSummary);
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetMQCItemSummaries(DateTime from, DateTime to, string site, string process)", ex.Message);
            }
            return(qCItemSummaries);
        }
        public MQCItemSummary GetMQCItemSummarybyLot(DateTime from, TimeSpan time_from, DateTime to, TimeSpan time_to, string site, string process, string lot)
        {
            MQCItemSummary itemSummary = new MQCItemSummary();

            try
            {
                LoadDataMQC         dataMQC      = new LoadDataMQC();
                List <MQCDataItems> mQCDataItems = dataMQC.listMQCDataItemsbylot(from, time_from, to, time_to, site, process, lot);
                //Nhom theo san pham
                var ListItemsData = mQCDataItems
                                    .GroupBy(u => u.remark)
                                    .Select(grp => grp.ToList())
                                    .ToList();

                var ListItemsTime = mQCDataItems
                                    .GroupBy(u => u.inspecttime)
                                    .ToList();

                itemSummary.defectItems = new List <DefectItem>();

                //Khi thay doi ngay can phai chinh lai thoi gian
                itemSummary.Time_from = (from + time_from).ToString("dd-MM-yyyy HH:mm:ss");
                itemSummary.Time_To   = (to + time_to).ToString("dd-MM-yyyy HH:mm:ss");

                foreach (var itemData in ListItemsData)
                {
                    itemSummary.product = itemData[0].model;
                    itemSummary.Line    = itemData[0].line;
                    if (itemData[0].remark == "OP")
                    {
                        itemSummary.OutputQty = itemData.Select(d => d.data).Sum();
                    }
                    else if (itemData[0].remark == "NG")
                    {
                        DefectItem item = new DefectItem();
                        item.DefectCode = itemData[0].item;
                        item.Quantity   = itemData.Select(d => d.data).Sum();
                        LoadDefectMapping defectMapping  = new LoadDefectMapping();
                        NGItemsMapping    nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode);
                        item.DefectSFT     = nGItemsMapping.NGCode_SFT;
                        item.DefectSFTName = nGItemsMapping.NGCodeName_SFT;
                        itemSummary.defectItems.Add(item);
                        itemSummary.NGQty += item.Quantity;
                    }
                    else if (itemData[0].remark == "RW")
                    {
                        DefectItem item = new DefectItem();
                        item.DefectCode = itemData[0].item;
                        item.Quantity   = itemData.Select(d => d.data).Sum();

                        itemSummary.ReworkQty += item.Quantity;
                    }
                }
                itemSummary.QuantityTotal = itemSummary.OutputQty + itemSummary.NGQty + itemSummary.ReworkQty;
                itemSummary.DefectRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.NGQty / itemSummary.QuantityTotal) : 0;
                itemSummary.ReworkRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.ReworkQty / itemSummary.QuantityTotal) : 0;
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetMQCItemSummaries(DateTime from, DateTime to, string site, string process)", ex.Message);
            }
            return(itemSummary);
        }
        public List <MQCItemSummary> GetMQCSummarybyYear(DateTime from, DateTime to, string site, string process)
        {
            //    DateTime from = new DateTime(); DateTime to = new DateTime();
            //    DateTimeControl.ReturnDateTimePeriodProduction(period, ref from, ref to);
            string date = from.ToString("yyyy-MM-dd");
            string time = from.ToString("HH:mm:ss");
            List <MQCItemSummary> qCItemSummaries = new List <MQCItemSummary>();

            try
            {
                LoadDataMQC         dataMQC      = new LoadDataMQC();
                List <MQCDataItems> mQCDataItems = dataMQC.listMQCDataItemsbySite(from, to, site, process);
                //Nhom theo san pham
                var ListMQCbyProduct = mQCDataItems
                                       .OrderBy(d => d.inspectdate)
                                       .GroupBy(u => u.inspectdate)
                                       .Select(grp => grp.ToList())
                                       .ToList();
                foreach (var qCDataItems in ListMQCbyProduct)
                {
                    MQCItemSummary itemSummary = new MQCItemSummary();
                    //DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
                    //Calendar cal = dfi.Calendar;
                    //int WeekNo = cal.GetWeekOfYear(qCDataItems[0].inspectdate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
                    itemSummary.Time_from   = qCDataItems[0].inspectdate.ToString("yyyy");
                    itemSummary.defectItems = new List <DefectItem>();
                    var ListItemsData = qCDataItems
                                        .GroupBy(u => u.item)
                                        .Select(grp => grp.ToList())
                                        .ToList();


                    //Khi thay doi ngay can phai chinh lai thoi gian

                    foreach (var itemData in ListItemsData)
                    {
                        itemSummary.product = itemData[0].model;
                        itemSummary.Line    = itemData[0].line;
                        itemSummary.Lot     = itemData[0].lot;

                        if (itemData[0].remark == "OP")
                        {
                            itemSummary.OutputQty = itemData.Select(d => d.data).Sum();
                        }
                        else if (itemData[0].remark == "NG")
                        {
                            DefectItem item = new DefectItem();
                            item.DefectCode = itemData[0].item;
                            item.Quantity   = itemData.Select(d => d.data).Sum();
                            LoadDefectMapping defectMapping  = new LoadDefectMapping();
                            NGItemsMapping    nGItemsMapping = defectMapping.GetNGMapping(site, process, item.DefectCode);
                            if (nGItemsMapping != null)
                            {
                                item.DefectSFT     = nGItemsMapping.NGCode_SFT;
                                item.DefectSFTName = nGItemsMapping.NGCodeName_SFT;
                                itemSummary.defectItems.Add(item);
                                itemSummary.NGQty += item.Quantity;
                            }
                        }
                        else if (itemData[0].remark == "RW")
                        {
                            DefectItem item = new DefectItem();
                            item.DefectCode = itemData[0].item;
                            item.Quantity   = itemData.Select(d => d.data).Sum();

                            itemSummary.ReworkQty += item.Quantity;
                        }
                    }
                    itemSummary.QuantityTotal = itemSummary.OutputQty + itemSummary.NGQty /*+ itemSummary.ReworkQty*/;
                    itemSummary.OutputRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.OutputQty / itemSummary.QuantityTotal) : 0;
                    itemSummary.DefectRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.NGQty / itemSummary.QuantityTotal) : 0;
                    itemSummary.ReworkRate    = (itemSummary.QuantityTotal != 0) ? (itemSummary.ReworkQty / itemSummary.QuantityTotal) : 0;
                    qCItemSummaries.Add(itemSummary);
                }
            }
            catch (Exception ex)
            {
                SystemLog.Output(SystemLog.MSG_TYPE.Err, "GetMQCItemSummaries(DateTime from, DateTime to, string site, string process)", ex.Message);
            }
            return(qCItemSummaries);
        }