public WEDMSetting QueryByTaskID(int TaskID) { Task task = _context.Tasks.Where(t => t.TaskID == TaskID).FirstOrDefault() ?? new Task(); WEDMSetting wedmsetting = _context.WEDMSettings.Where(w => w.ID == task.ProgramID).FirstOrDefault() ?? new WEDMSetting(); return(wedmsetting); }
public int AddOrUpdateWEDMDrawing(WEDMSetting entity) { try { string _url = "/Task/SaveService_WEDMCAMSetting"; string _return = _server.SendObject(_url, "entity", entity); return(Convert.ToInt32(_return)); } catch { return(2); } }
public bool DeleteSettingByName(string partname, int rev) { WEDMSetting dbentity = _context.WEDMSettings.Where(m => m.DrawName == partname).Where(m => m.Rev == rev).FirstOrDefault() ?? new WEDMSetting(); if (dbentity.ID > 0) { dbentity.active = false; dbentity.DeleteDate = DateTime.Now; _context.SaveChanges(); return(true); } else { return(false); } }
/// <summary> /// 保存 /// </summary> /// <param name="entity"></param> /// <returns>return ID= 成功 -1--已发布 -2--失败 -3--已有更新版本 -4 上一版本没有发布</returns> public int Save(WEDMSetting entity) { bool IsNew = false; try { #region 返回错误代码 WEDMSetting ws = _context.WEDMSettings.Where(w => w.DrawName == entity.DrawName && w.Rev == entity.Rev && w.active).FirstOrDefault() ?? new WEDMSetting(); Task _task = _context.Tasks.Where(t => t.TaskType == 3 && t.ProgramID == ws.ID && t.ProgramID > 0).FirstOrDefault() ?? new Task(); if (_task.TaskID > 0 && _task.State != (int)TaskStatus.未发布) { return(-1); } WEDMSetting ws3 = _context.WEDMSettings.Where(w => w.DrawName == entity.DrawName && w.Rev == entity.Rev && w.Rev > entity.Rev && w.active).FirstOrDefault() ?? new WEDMSetting(); if (ws3.ID > 0) { return(-3); } WEDMSetting ws4 = _context.WEDMSettings.Where(w => w.DrawName == entity.DrawName && w.Rev == entity.Rev && w.Rev < entity.Rev && w.active && w.ReleaseFlag == false).FirstOrDefault() ?? new WEDMSetting(); if (ws4.ID > 0) { return(-4); } #endregion #region Add if (ws.ID == 0) { IsNew = true; entity.LastestFlag = true; entity.ReleaseFlag = false; entity.CreateDate = DateTime.Now; entity.active = true; entity.DeleteDate = DateTime.Parse("1900/1/1"); entity.ReleaseDate = DateTime.Parse("1900/1/1"); _context.WEDMSettings.Add(entity); } #endregion #region Update else { ws.Precision = entity.Precision; ws.Note = entity.Note; ws.FeatureCount = entity.FeatureCount; ws.Length = entity.Length; ws.Thickness = entity.Thickness; ws.LastestFlag = true; ws.active = true; ws.QcPoint = entity.QcPoint; ws.CADPartName = entity.CADPartName; ws.Time = entity.Time; ws.ThreeDPartName = entity.ThreeDPartName; _task.Time = Convert.ToDouble(entity.Time); _task.ProcessName = entity.Precision; } #endregion _context.SaveChanges(); if (IsNew) { if (entity.ID > 0) { ReleaseWEDMDrawing(entity.ID, "", 1); } return(entity.ID); } else { return(ws.ID); } } catch { return(-2); } }
/// <summary> /// 发布 /// </summary> /// <param name="DrawIndex"></param> /// <param name="ReleaseBy"></param> /// <param name="Qty"></param> /// <returns>0,成功;1,失败;2,已发布,无法保存;</returns> public int ReleaseWEDMDrawing(int DrawIndex, string ReleaseBy, int Qty = 1) { WEDMSetting ws = _context.WEDMSettings.Where(w => w.ID == DrawIndex && w.active == true).FirstOrDefault() ?? new WEDMSetting(); #region 返回错误代码 if (ws.ReleaseFlag) { return(2); } if (ws.ID == 0) { return(1); } #endregion var tran = _context.Database.BeginTransaction(); //开启事务 try { #region 版本 >0 string FullPartName = ""; User user = _context.Users.Where(u => u.FullName == ws.CreateBy && u.Enabled).FirstOrDefault() ?? new User(); if (ws.Rev > 0) { var mgtasks = from t in _context.Tasks join m in _context.WEDMSettings on t.ProgramID equals m.ID where m.DrawName == ws.DrawName && m.Rev < ws.Rev && t.TaskType == 3 && t.Enabled == true && t.State >= (int)TaskStatus.未发布 && t.State < (int)TaskStatus.完成 select t; if (mgtasks != null) { foreach (var mgt in mgtasks) { //任务状态设置为 完成 int _userID = (_context.Users.Where(u => u.FullName == user.FullName).FirstOrDefault() ?? new User()).UserID; mgt.FinishBy = _userID; mgt.FinishTime = DateTime.Now; mgt.State = (int)TaskStatus.完成; mgt.StateMemo = string.IsNullOrEmpty(mgt.StateMemo) ? "设定升版,低版本任务关闭。" : mgt.StateMemo + ";设定升版,低版本任务关闭。"; } } if (ws.Rev < 10) { FullPartName = ws.DrawName + "R0" + ws.Rev.ToString(); } else { FullPartName = ws.DrawName + "R" + ws.Rev.ToString(); } List <CAMDrawing> cds = _context.CAMDrawings.Where(c => c.DrawingName == FullPartName).ToList() ?? new List <CAMDrawing>(); if (cds.Count > 0) { foreach (var cd in cds) { cd.Lock = true; cd.ReleaseDate = DateTime.Now; cd.ReleaseBy = user.FullName; } } } #endregion #region 生成WEDM加工任务 DateTime PlanDate = new DateTime(1900, 1, 1); Project proj = _context.Projects.Where(p => p.MoldNumber == ws.MoldName && p.Enabled == true).FirstOrDefault() ?? new Project(); ProjectPhase ph10 = _context.ProjectPhases.Where(p => p.ProjectID == proj.ProjectID && p.PhaseID == 10).FirstOrDefault() ?? new ProjectPhase();//WEDM阶段 if (ph10.PlanFinish != null) { PlanDate = ph10.PlanFinish; } #region WEDMSetting 状态更新 ws.ReleaseFlag = true; ws.ReleaseDate = DateTime.Now; #endregion Task WEDMtask = new Task { TaskName = ws.DrawName, Version = ws.Rev, ProgramID = ws.ID, Creator = ws.CreateBy, CreateTime = DateTime.Now, Enabled = true, Priority = 0, State = (int)TaskStatus.未发布, PrevState = (int)TaskStatus.未发布, Memo = "Create by CAM", Quantity = Qty, PlanTime = PlanDate, StartTime = new DateTime(1900, 1, 1), ProjectID = proj.ProjectID, TaskType = 3, MoldNumber = ws.MoldName, ProcessName = ws.Precision, Time = Convert.ToDouble(ws.Time), CAMUser = user.UserID, Raw = "" }; //ws.DrawName.Substring(ws.DrawName.IndexOf('(') + 1, ws.DrawName.Length - ws.DrawName.IndexOf('(') - 2) _context.Tasks.Add(WEDMtask); #endregion _context.SaveChanges(); tran.Commit();//提交事务 return(0); } catch { tran.Rollback(); //回滚 return(1); } }
public TaskGridRowModel(Task Task, string CAD, string CAM, string Workshop, string QC, string FilePath, string PlanDate, SetupTaskStart _setupTask, CNCMachInfo Machinfo, WEDMSetting wedmsetting, MGSetting mgsetting, string taskType) { Helpers.TaskStatus _status = new Helpers.TaskStatus(); cell = new string[45]; //TaskID cell[0] = Task.TaskID.ToString(); //图纸 if (Task.DrawingFile != "") { cell[1] = "<a onclick='ShowElePDF(" + Task.TaskID.ToString() + ")'>Open</a>"; } //任务名 cell[2] = Task.TaskName; //版本 string _version = Task.Version.ToString(); cell[3] = _version.Length == 1 ? "V0" + _version : "V" + _version; //CAD文档 switch (Task.TaskType) { case 3: //CAD文档 cell[4] = wedmsetting.CADPartName ?? ""; break; case 6: cell[4] = mgsetting.CADNames ?? ""; break; default: cell[4] = ""; break; } //CAD人员FullName cell[5] = CAD; //备注 cell[6] = Task.Memo; switch (Task.TaskType) { case 3: //加工精度 cell[7] = wedmsetting.Precision ?? ""; //特征数量 cell[8] = wedmsetting.FeatureCount.ToString(); //长度 cell[9] = wedmsetting.Length.ToString(); //厚度 cell[10] = wedmsetting.Thickness.ToString(); break; case 6: cell[7] = ""; cell[8] = mgsetting.FeatureNote ?? ""; cell[9] = ""; cell[10] = ""; break; default: cell[7] = ""; cell[8] = ""; cell[9] = ""; cell[10] = ""; break; } //时间 cell[11] = Math.Round(Task.Time, 1).ToString(); //状态 string stateName; stateName = Enum.GetName(typeof(TechnikSys.MoldManager.Domain.Status.TaskStatus), Task.State); cell[12] = stateName; //状态备注 cell[13] = Task.StateMemo; //毛坯(规格) cell[14] = Task.Raw; //型号 cell[15] = Task.Model; if (Machinfo != null) { //表面 cell[16] = Machinfo.Surface; //平动 cell[17] = Machinfo.ObitType; //电极位置 cell[18] = Machinfo.Position; } else { cell[16] = ""; cell[17] = ""; cell[18] = ""; } //R cell[19] = Task.R.ToString(); //F cell[20] = Task.F.ToString(); //数量 cell[21] = Task.Quantity.ToString(); //备料 cell[22] = Task.Prepared.ToString(); //材料 cell[23] = Task.Material; //HRC cell[24] = Task.HRC; //工艺 cell[25] = Task.ProcessName; //实际工时 cell[26] = _setupTask.TotalTime.ToString(); //优先 cell[27] = Task.Priority.ToString(); //创建日期 _dateVal = Task.CreateTime.ToString("yyyy-MM-dd"); cell[28] = (_dateVal == "1900-01-01" || _dateVal == "0001-01-01") ? "-" : _dateVal; //计划日期 cell[29] = (PlanDate == "1900-01-01" || PlanDate == "0001-01-01") ? "-" : PlanDate; //接收日期 _dateVal = Task.AcceptTime.ToString("yyyy-MM-dd"); cell[30] = (_dateVal == "1900-01-01" || _dateVal == "0001-01-01") ? "-" : _dateVal; //发布日期 _dateVal = Task.ReleaseTime.ToString("yyyy-MM-dd"); cell[31] = (_dateVal == "1900-01-01" || _dateVal == "0001-01-01") ? "-" : _dateVal; //开始日期 _dateVal = Task.StartTime.ToString("yyyy-MM-dd"); cell[32] = (_dateVal == "1900-01-01" || _dateVal == "0001-01-01") ? "-" : _dateVal; //结束时间 _dateVal = Task.FinishTime.ToString("yyyy-MM-dd"); cell[33] = (_dateVal == "1900-01-01" || _dateVal == "0001-01-01") ? "-" : _dateVal; //预计日期 _dateVal = Task.ForecastTime.ToString("yyyy-MM-dd");; cell[34] = (_dateVal == "1900-01-01" || _dateVal == "0001-01-01") ? "-" : _dateVal; //CADM人员FullName cell[35] = CAM; //QC点 cell[36] = Task.QCInfoFinish.ToString(); //跑位检查 cell[37] = Task.PositionFinish.ToString(); //QC cell[38] = QC; //加工人员FullName cell[39] = Workshop; //机器号 cell[40] = _setupTask.MachinesName; //操作人员 cell[41] = _setupTask.UserName; cell[42] = taskType; cell[43] = Task.TaskType.ToString(); cell[44] = Task.Creator; }
public TaskGridViewModel(IEnumerable <Task> Tasks, IUserRepository UserRepository, string CAMDrawingPath, ICNCMachInfoRepository MachInfoRepository, IEDMDetailRepository EDMDetailRepository, ITaskRepository TaskRepository, IProjectPhaseRepository ProjectPhaseRepository, IMGSettingRepository MGSettingRepository, IWEDMSettingRepository WEDMSettingRepository, ITaskHourRepository TaskHourRepository , ISystemConfigRepository SystemConfigRepo , ITaskTypeRepository TasktypeRepo , IMachinesInfoRepository MachInfoRepo) { ProjectPhase _phase; string _cad, _cam, _workshop, _qc, _planDate; int _phaseID = 0; rows = new List <TaskGridRowModel>(); List <WEDMSetting> _wedmSettings = WEDMSettingRepository.WEDMSettings.ToList(); List <MGSetting> _mgSettings = MGSettingRepository.MGSettings.ToList(); List <User> _users = UserRepository.Users.ToList(); List <ProjectPhase> _pjPhases = ProjectPhaseRepository.ProjectPhases.ToList(); List <TaskHour> _taskhours = TaskHourRepository.TaskHours.ToList(); List <MachinesInfo> _machineInfos = MachInfoRepo.MachinesInfo.ToList(); List <TaskType> _tasktypes = TasktypeRepo.TaskTypes.ToList(); List <CNCMachInfo> _cncmachInfos = MachInfoRepository.CNCMachInfoes.ToList(); List <Task> _tasks = TaskRepository.Tasks.ToList(); List <EDMDetail> _edmDetails = EDMDetailRepository.EDMDetails.ToList(); foreach (Task _task in Tasks) { WEDMSetting wedmsetting = new WEDMSetting(); MGSetting mgsetting = new MGSetting(); switch (_task.TaskType) { case 1: _phaseID = 8; break; case 2: _phaseID = 9; break; case 3: wedmsetting = _wedmSettings.Where(s => s.ID == _task.ProgramID).FirstOrDefault() ?? new WEDMSetting(); //WEDMSettingRepository.QueryByTaskID(_task.TaskID); _phaseID = 10; break; case 4: _phaseID = 8; break; case 6: mgsetting = _mgSettings.Where(s => s.ID == _task.ProgramID).FirstOrDefault() ?? new MGSetting(); //MGSettingRepository.QueryByTaskID(_task.TaskID); _phaseID = 7; break; } _cad = _task.CADUser > 0 ? (_users.Where(u => u.UserID == _task.CADUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.CADUser).FullName : ""; _cam = _task.CAMUser > 0? (_users.Where(u => u.UserID == _task.CAMUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.CAMUser).FullName:""; _workshop = _task.WorkshopUser > 0? (_users.Where(u => u.UserID == _task.WorkshopUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.WorkshopUser).FullName:""; _qc = _task.QCUser > 0 ? (_users.Where(u => u.UserID == _task.QCUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.QCUser).FullName : ""; CNCMachInfo _machinfo = GetCNCMachinfo(_task, _cncmachInfos, _tasks, _edmDetails); //GetCNCMachinfo(_task,MachInfoRepository, TaskRepository, EDMDetailRepository); decimal TaskHour = 0; try { _phase = _pjPhases.Where(p => p.ProjectID == _task.ProjectID && p.PhaseID == _phaseID).FirstOrDefault() ?? new ProjectPhase();//ProjectPhaseRepository.GetProjectPhases(_task.ProjectID).Where(p => p.PhaseID == _phaseID).FirstOrDefault(); _planDate = _phase.PlanCFinish == new DateTime(1, 1, 1) ? _phase.PlanFinish.ToString("yyyy-MM-dd") : _phase.PlanCFinish.ToString("yyyy-MM-dd"); } catch { _planDate = "-"; } try { TaskHour = GetTotalHourByTaskID(_taskhours, _task.TaskID);//TaskHourRepository.GetTotalHourByTaskID(_task.TaskID); } catch { TaskHour = 0; } string _machineCode = GetMachineByTask(_taskhours, _machineInfos, _task.TaskID); //TaskHourRepository.GetMachineByTask(_task.TaskID) ?? ""; string Operater = GetOperaterByTaskID(_taskhours, _task.TaskID); //TaskHourRepository.GetOperaterByTaskID(_task.TaskID) ?? ""; SetupTaskStart _setupTask = new SetupTaskStart { TaskID = _task.TaskID, TaskName = _task.TaskName, State = Enum.GetName(typeof(TaskStatus), _task.State), MachinesCode = "", MachinesName = _machineCode, TotalTime = Convert.ToInt32(TaskHour), UserID = 0, UserName = Operater, }; //string _camDrawingPath = string.Empty; if (string.IsNullOrEmpty(CAMDrawingPath)) { if (_task.TaskType == 6) { CAMDrawingPath = SystemConfigRepo.GetTaskDrawingPath("CAD"); } else { CAMDrawingPath = SystemConfigRepo.GetTaskDrawingPath(); } } string taskType = string.Empty; int _mgtype = (_tasktypes.Where(t => t.ShortName == "MG" && t.Enable).FirstOrDefault() ?? new TaskType()).TaskID;//(TasktypeRepo.TaskTypes.Where(t => t.ShortName == "MG" && t.Enable).FirstOrDefault() ?? new TaskType()).TaskID;//6 if (_task.TaskType != _mgtype) { taskType = (_tasktypes.Where(t => t.TaskID == _task.TaskType && t.Enable).FirstOrDefault() ?? new TaskType()).Name;//TasktypeRepo.TaskTypes.Where(t => t.TaskID == _task.TaskType).Select(t => t.Name).FirstOrDefault(); } else { string _typeID = (_mgtype.ToString() + _task.OldID.ToString()); taskType = (_tasktypes.Where(t => t.TaskID == Convert.ToInt32(_typeID) && t.Enable).FirstOrDefault() ?? new TaskType()).Name;//TasktypeRepo.TaskTypes.ToList().Where(t => t.TaskID == Convert.ToInt32(_typeID)).Select(t => t.Name).FirstOrDefault(); } rows.Add(new TaskGridRowModel(_task, _cad, _cam, _workshop, _qc, CAMDrawingPath, _planDate, _setupTask, _machinfo, wedmsetting, mgsetting, taskType)); } }