Exemple #1
0
        public static List <FactoryStatus> GetListFactoryStatusFilter(int companyId, string factoryName, string fromDate, string toDate)
        {
            DateTime dtFrom = new DateTime(2000, 1, 1);
            DateTime dtTo   = new DateTime(2200, 1, 1);

            if (!string.IsNullOrWhiteSpace(fromDate))
            {
                dtFrom = Convert.ToDateTime(fromDate);
            }
            if (!string.IsNullOrWhiteSpace(toDate))
            {
                dtTo = Convert.ToDateTime(toDate);
            }
            if (string.IsNullOrWhiteSpace(factoryName))
            {
                factoryName = "";
            }

            var context = new DBContext();

            var query =
                (from w in context.GetTable <WorkZone>()
                 join
                 f in context.GetTable <Factory>() on new { w.FactoryId } equals new { f.FactoryId }
                 where
                 (
                     f.CompanyId == companyId &&
                     w.CompanyId == companyId &&
                     f.Name.ToLower().Contains(factoryName.ToLower()) &&
                     (w.ProgramDate != null && dtFrom.Date <= w.ProgramDate.Value.Date && w.ProgramDate.Value.Date <= dtTo.Date) &&
                     f.isDeleted == false
                 )
                 select new
            {
                ImageFile = f.ImageFile,
                Status = WorkZoneDetail.GetStatusForWorkZone(w.WorkZoneId),
                FactoryId = w.FactoryId,
                FactoryName = f.Name
            }
                ).GroupBy(p => new { p.FactoryId, p.FactoryName }).ToList();

            List <FactoryStatus> list = new List <FactoryStatus>();
            string companyPath        = string.Format(Constant.PATH_COMPANY, companyId, Company.GetCompanyName(companyId));

            foreach (var i in query)
            {
                FactoryStatus s = new FactoryStatus();
                s.FactoryId   = i.First().FactoryId;
                s.FactoryName = i.First().FactoryName;
                string factoryPath = string.Format(Constant.PATH_FACTORY, s.FactoryId, s.FactoryName);
                s.ImageFile = string.IsNullOrEmpty(i.First().ImageFile) ? "" : string.Format(@"{0}{1}{2}/{3}", Common.AppSettingKey(Constant.PORTAL_CONFIG), companyPath, factoryPath, i.First().ImageFile.Replace(" ", "%20"));//Ima

                s.InProcess   = i.Where(p => p.Status == 0).Count();
                s.HaveProblem = i.Where(p => p.Status == 1).Count();
                s.Finished    = i.Where(p => p.Status == 2).Count();

                list.Add(s);
            }
            return(list);
        }
Exemple #2
0
        public static List <WorkZoneStatus> GetListWorkZoneStatusFromFactory(int FactoryId)
        {
            List <WorkZoneStatus> list = new List <WorkZoneStatus>();
            var context = new DBContext();

            list =
                (from w in context.GetTable <WorkZone>()
                 join m in context.GetTable <Machine>() on new { w.MachineId } equals new { m.MachineId }
                 where
                 (
                     w.FactoryId == FactoryId &&
                     m.isDeleted == false
                 )
                 select new WorkZoneStatus()
            {
                WorkZoneId = w.WorkZoneId,
                WorkZoneName = w.Name,
                CompanyId = w.CompanyId,
                ImageFile = w.ImageFile,
                Upload = string.Format("{0:yyyy-MM-dd}", w.ModifiedDate),
                Machine = m.Name,
                Operator = w.NCDataProgramer,
                StatusId = WorkZoneDetail.GetStatusForWorkZone(w.WorkZoneId),            //w.Status,
                Date = !w.ProgramDate.HasValue ? "" : w.ProgramDate.Value.ToString(),
            }
                ).ToList();

            foreach (WorkZoneStatus i in list)
            {
                i.Status = Common.GetResourceString(string.Format("STATUS_{0}", i.StatusId));

                if (i.Date != "")
                {
                    i.Date = DateTime.Parse(i.Date).ToString("yyyy-MM-dd");
                }
                if (string.IsNullOrEmpty(i.ImageFile))
                {
                    i.ImageFile = "";     //no image
                }
                else
                {
                    string pathWorkZone = Common.GetFolderWorkZone(i.CompanyId, Company.GetCompanyName(i.CompanyId), FactoryId, Factory.GetFactoryName(FactoryId), i.WorkZoneId, i.WorkZoneName);
                    pathWorkZone = pathWorkZone.Replace("Portal", "");
                    i.ImageFile  = string.Format(@"{0}{1}/{2}", Common.AppSettingKey(Constant.PORTAL_CONFIG), pathWorkZone, i.ImageFile).Replace(" ", "%20");
                }
            }
            return(list);
        }