public int GettblhmidetFornestingmachine(int hmiid) { int det = 0; tblhmiscreen ddldet = new tblhmiscreen(); Repository <tblhmiscreen> lista = new Repository <tblhmiscreen>(); try { string query = "SELECT * from [" + ConnectionFactory.DB + "].[dbo].tblhmiscreen WHERE HMIID =" + hmiid + ""; ddldet = lista.GetFirstOrDefault(query, _connectionFactory.GetConnection); det = (int)ddldet.SheetNoList; } catch (Exception ex) { det = 0; // MessageBox.Show(ex.ToString()); } return(det); }
public bool OEE(int machineID, string correctdate) { // string correctdate = DateTime.Now.ToString("yyyy-MM-dd"); DateTime correctedDate = Convert.ToDateTime(correctdate); int GetHour = System.DateTime.Now.Hour; DateTime StartModeTime = Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd " + GetHour + ":00:00")); double AvailabilityPercentage = 0; double PerformancePercentage = 0; double QualityPercentage = 0; double OEEPercentage = 0; decimal Utilization = 0; decimal DayOEEPercent = 0; int PerformanceFactor = 0; decimal Quality = 0; int TotlaQty = 0; decimal IdealCycleTimeVal = 0; OEECalModel OEECal = OEEDetails(machineID, correctedDate); decimal OperatingTime = OEECal.OperatingTime; decimal LossTime = OEECal.LossTime; decimal MinorLossTime = OEECal.MinorLossTime; decimal MntTime = OEECal.MntTime; decimal SetupTime = OEECal.SetupTime; //var scrap = new tblworkorderentry(); var scrap = new tblhmiscreen(); var scrapqty1 = new List <tblrejectqty>(); int YeildQty = 0; int rejQty = 0; int reject = 0; //decimal SetupMinorTime = 0; decimal PowerOffTime = OEECal.PowerOffTime; decimal PowerONTime = OEECal.PowerONTime; int cuttingTime = 0; #region Commented //var machinedet = db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.IsNormalWC == 0 && m.MachineID == machineID).FirstOrDefault(); //var GetModeDurations = db.tblmodes.Where(m => m.MachineID == machineID && m.CorrectedDate == correctedDate.Date && m.IsCompleted == 1 && m.ModeTypeEnd == 1).ToList(); //foreach (var ModeRow in GetModeDurations) //{ // //GetCorrectedDate = ModeRow.CorrectedDate; // if (ModeRow.ModeType == "PROD") // { // OperatingTime += (decimal)(ModeRow.DurationInSec / 60.00); // } // else if (ModeRow.ModeType == "IDLE" && ModeRow.DurationInSec > 600) // { // LossTime += (decimal)(ModeRow.DurationInSec / 60.00); // decimal LossDuration = (decimal)(ModeRow.DurationInSec / 60.00); // //if (ModeRow.LossCodeID != null) // // insertProdlosses(ProdRow.HMIID, (int)ModeRow.LossCodeID, LossDuration, CorrectedDate, MachineID); // } // else if (ModeRow.ModeType == "IDLE" && ModeRow.DurationInSec < 600) // { // MinorLossTime += (decimal)(ModeRow.DurationInSec / 60.00); // } // else if (ModeRow.ModeType == "MNT") // { // MntTime += (decimal)(ModeRow.DurationInSec / 60.00); // } // else if (ModeRow.ModeType == "POWEROFF") // { // PowerOffTime += (decimal)(ModeRow.DurationInSec / 60.00); // } // else if (ModeRow.ModeType == "SETUP") // { // try // { // SetupTime += (decimal)Convert.ToDateTime(ModeRow.LossCodeEnteredTime).Subtract(Convert.ToDateTime(ModeRow.StartTime)).TotalMinutes; // //SetupMinorTime += (decimal)(db.tblSetupMaints.Where(m => m.ModeId == ModeRow.ModeId).Select(m => m.MinorLossTime).First() / 60.00); // } // catch { } // } // else if (ModeRow.ModeType == "POWERON") // { // PowerONTime += (decimal)(ModeRow.DurationInSec / 60.00); // } //} #endregion //scrap = db.tblworkorderentries.Where(m => m.MachineID == machineID && m.CorrectedDate == correctedDate).OrderByDescending(m => m.HMIID).FirstOrDefault(); scrap = db.tblhmiscreens.Where(m => m.MachineID == machineID && m.CorrectedDate == correctdate).OrderByDescending(m => m.HMIID).FirstOrDefault(); TotlaQty = GetQuantiy(machineID, out YeildQty, correctedDate.ToString("yyyy-MM-dd"), out cuttingTime); var partsdet = db.tblparts.Where(m => m.MachineID == machineID).FirstOrDefault(); if (partsdet != null) { IdealCycleTimeVal += Math.Round((partsdet.IdealCycleTime / 60), 2); int qty = Convert.ToInt32(partsdet.PartsPerCycle); //TotlaQty = TotlaQty * qty; } decimal IdleTime = LossTime + MinorLossTime; decimal BDTime = MntTime; if (scrap != null) { using (i_facility_shaktiEntities1 db = new i_facility_shaktiEntities1()) { scrapqty1 = db.tblrejectqties.Where(m => m.WOID == scrap.HMIID && m.CorrectedDate == correctdate).ToList(); } foreach (var r1 in scrapqty1) { reject = reject + Convert.ToInt32(r1.RejectQty); } } int TotalTime = Convert.ToInt32(PowerONTime) + Convert.ToInt32(OperatingTime) + Convert.ToInt32(IdleTime) + Convert.ToInt32(BDTime) + Convert.ToInt32(PowerOffTime); if (TotalTime == 0) { TotalTime = 1; } if (TotlaQty == 0) { TotlaQty = 1; } Utilization = Convert.ToInt32(Convert.ToDouble(Convert.ToDouble(Convert.ToDouble(OperatingTime) / Convert.ToDouble(TotalTime)) * 100)); if (OperatingTime == 0) { OperatingTime = 1; } else { OperatingTime = Math.Round(OperatingTime, 2); } //double TotalTime1 = Convert.ToDouble(PowerONTime) + Convert.ToDouble(OperatingTime) + Convert.ToDouble(IdleTime) + Convert.ToDouble(BDTime) + Convert.ToDouble(PowerOffTime); if (YeildQty == 0) { YeildQty = 1; } //Quality = 100; Quality = Math.Round((decimal)((YeildQty - reject) / YeildQty), 2) * 100; decimal Performance = (decimal)Math.Round((((double)IdealCycleTimeVal * (double)TotlaQty) / (double)OperatingTime) * 100, 2); PerformanceFactor = (int)IdealCycleTimeVal * TotlaQty; if (PerformanceFactor == 0) { //PerformanceFactor = 100; } if (Quality > 0) { Quality = 100; } DayOEEPercent = (decimal)Math.Round((double)(Utilization / 100) * (double)(Performance / 100) * (double)(Quality / 100), 2) * 100; AvailabilityPercentage = (double)Utilization; QualityPercentage = (double)Quality; PerformancePercentage = (double)Performance; OEEPercentage = (double)DayOEEPercent; bool Res = InsertOEEDetails(correctdate, machineID, (decimal)AvailabilityPercentage, (decimal)QualityPercentage, (decimal)PerformancePercentage, (decimal)OEEPercentage, TotlaQty, OperatingTime, IdleTime, (decimal)PerformanceFactor); //} return(Res); }