// GET: MachineStatusReport public ActionResult DashboardStatus() { _conn = new ConnectionFactory(); obj1 = new Dao(_conn); obj2 = new Dao1(_conn); obj = new ReportsDao(_conn); if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; //var result = db.tblmachinedetails.Select(m=>m.ShopNo).Distinct(); ViewData["PlantID"] = new SelectList(obj2.GetPlantList(), "PlantID", "PlantName"); ViewData["ShopID"] = new SelectList(obj2.GetShopList1(), "ShopID", "ShopName"); ViewData["CellID"] = new SelectList(obj2.GetCellList(), "CellID", "CellName"); ViewData["WorkCenterID"] = new SelectList(obj2.GetmachineList1(), "MachineID", "MachineInvNo"); //ViewData["PlantID"] = new SelectList(db.tblplants.Where(m => m.IsDeleted == 0), "PlantID", "PlantName"); //ViewData["ShopID"] = new SelectList(db.tblshops.Where(m => m.IsDeleted == 0 && m.PlantID == 999), "ShopID", "ShopName"); //ViewData["CellID"] = new SelectList(db.tblcells.Where(m => m.IsDeleted == 0 && m.PlantID == 999), "CellID", "CellName"); //ViewData["WorkCenterID"] = new SelectList(db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.PlantID == 999), "MachineID", "MachineInvNo"); return(View()); }
// GET: /AllMachineStatus/ public ActionResult Index() { _conn = new ConnectionFactory(); obj = new Dao1(_conn); if ((Session["UserId"] == null) || (Session["UserId"].ToString() == String.Empty)) { return(RedirectToAction("Login", "Login", null)); } Session["colordata"] = null; ViewBag.Logout = Session["Username"]; ViewBag.roleid = Session["RoleID"]; //calculating Corrected Date TimeSpan currentHourMint = new TimeSpan(05, 59, 59); TimeSpan RealCurrntHour = System.DateTime.Now.TimeOfDay; string CorrectedDate = DateTime.Now.Date.ToString("yyyy-MM-dd"); if (RealCurrntHour < currentHourMint) { CorrectedDate = DateTime.Now.AddDays(-1).Date.ToString("yyyy-MM-dd"); } // getting all machine details and their count. var macData = obj.GettbMachineDetails(); // var macData = db.tblmachinedetails.Where(m => m.IsDeleted == 0 && m.IsNormalWC == 0); int mc = macData.Count(); ViewBag.macCount = mc; int[] macid = new int[mc]; int macidlooper = 0; foreach (var v in macData) { macid[macidlooper++] = v.MachineID; } Session["macid"] = macid; ViewBag.macCount = mc; int[,] maindata = new int[mc, 5]; //int[,] maindata = new int[mc, 6]; // write a raw query to get sum of powerOff, Operating, Idle, BreakDown, PlannedMaintenance. using (MsqlConnection mc1 = new MsqlConnection()) { mc1.open(); SqlCommand cmd1 = new SqlCommand("SELECT MachineID,sum(MachineOffTime) as op,sum(OperatingTime)as o,sum(IdleTime) as it,sum(BreakdownTime)as bt FROM i_facility_tsal.dbo.tblmimics where CorrectedDate='" + CorrectedDate + "'and MachineID IN (select distinct(MachineID) from tblmachinedetails where IsDeleted = 0 and IsNormalWC = 0) group by MachineID", mc1.msqlConnection); SqlDataReader datareader = cmd1.ExecuteReader(); int maindatalooper1 = 0; while (datareader.Read()) { int maindatalooper2 = 0; maindata[maindatalooper1, maindatalooper2++] = datareader.GetInt32(0); maindata[maindatalooper1, maindatalooper2++] = datareader.GetInt32(1); maindata[maindatalooper1, maindatalooper2++] = datareader.GetInt32(2); maindata[maindatalooper1, maindatalooper2++] = datareader.GetInt32(3); maindata[maindatalooper1, maindatalooper2++] = datareader.GetInt32(4); maindatalooper1++; } mc1.close(); } Session["colordata"] = maindata; var tblMainDT = obj.GetdailyprodstatusDetails(CorrectedDate); //var tblMainDT = db.tbllivedailyprodstatus.Include(t => t.tblmachinedetail).Where(m => m.CorrectedDate == CorrectedDate).OrderBy(m => m.StartTime); return(View(tblMainDT.ToList())); }