Example #1
0
		/// <summary>
		/// Must save FPC before using this, also this always throws
		/// </summary>
		/// <param name="fpcId"></param>
		public static void AutoRouteCheck(int fpcId)
		{
			var sj = new SmartJob();
			sj._fpcModel = sj._fpcDs.GetSingleWithStates(fpcId);
			var stateDs = new DataServices.StateDataService();
			var fpcPRs = sj._fpcDs.GetProductReworks(sj._fpcModel, true);
			List<string> errors = new List<string>();
			bool shouldWarnUser = false;
			foreach (var pr in fpcPRs)
			{
				try
				{
					var state = stateDs.GetStartingState(fpcId, pr);
					if (state == null)
						errors.Add(string.Format("Rework {0} not found in {1}", pr.Rework.Name, pr.Product.Name));
					else if (!sj.buildLayers(state))
					{
						shouldWarnUser = true;
						throw new Exception(string.Format(
							"Cannot trace FPC for {0}.\n FPC contains too many layers or it has a loop.", pr.Product.Name));//???
					}
				}
				catch (SoheilExceptionBase exp)
				{
					errors.Add(exp.Message);
					if (exp.Level == ExceptionLevel.Warning) shouldWarnUser = true;
				}
				catch (Exception exp) { errors.Add(exp.Message); }
			}
			if (errors.Any())
			{
				string msg = string.Format("{0} States have errors:\n", errors.Count);
				foreach (var err in errors)
				{
					msg = string.Format("{0}\n{1}", msg, err);
				}
				throw new SoheilExceptionBase(
					msg,
					shouldWarnUser ? ExceptionLevel.Warning : ExceptionLevel.Info,
					"مسیریابی خودکار FPC");
			}
			throw new SoheilExceptionBase("ذخیره و مسیریابی با موفقیت انجام شد", ExceptionLevel.Info, "ذخیره FPC");
		}