Exemplo n.º 1
0
		public CranTaskInfo(CranTask tbl) {
			OrdersUser currentUser = OrdersUser.loadFromCache(HttpContext.Current.User.Identity.Name);
			CranNumber = tbl.CranNumber;
			Number = tbl.Number;
			NeedStartDate = tbl.NeedDateStart;
			NeedEndDate = tbl.NeedDateEnd;
			Comment = tbl.Comment;
			CranName = tbl.CranName;
			Author = OrdersUser.loadFromCache(tbl.Author).FullName;
			State = "Новая";
			StateDB = tbl.State;
			Allowed = tbl.Allowed;
			Denied = tbl.Denied;
			Cancelled = tbl.Cancelled;
			Finished = tbl.Finished;
			AgreeComments = tbl.AgreeComment;
			
			canChange = (!Cancelled)&&(!Allowed) && (!Denied) && (!Finished) && tbl.Author.ToLower() == currentUser.Name.ToLower();
			canCancel = (!Cancelled) && (!Denied) && (!Finished) && tbl.Author.ToLower() == currentUser.Name.ToLower();
			canFinish = Allowed && (tbl.Author.ToLower() == currentUser.Name.ToLower() || currentUser.CanReviewCranTask || currentUser.CanReviewCranMZTask);

			canCheck = (currentUser.CanReviewCranTask && CranNumber>2 || currentUser.CanReviewCranMZTask && CranNumber<=2) && (!Finished) &&(!Cancelled);
			canComment = true;
			Manager = tbl.Manager;
			if (Denied) {
				State = "Отклонена";
				canChange = false;
				AuthorAllow = OrdersUser.loadFromCache(tbl.AuthorAllow).FullName;
			}
			if (tbl.Allowed) {
				AuthorAllow = OrdersUser.loadFromCache(tbl.AuthorAllow).FullName;
				AllowDateStart = tbl.AllowedDateStart.Value;
				AllowDateEnd = tbl.AllowedDateEnd.Value;
				RealDateStart = tbl.RealDateStart.Value;
				RealDateEnd = tbl.RealDateEnd.Value;
				canChange = false;
				State = "Разрешена";
			}
			if (tbl.Cancelled) {
				State = "Снята";
			}
			if (tbl.Finished) {
				State = "Закрыта";
				Finished = tbl.Finished;
				if (!string.IsNullOrEmpty(tbl.AuthorFinish))
					AuthorFinish = OrdersUser.loadFromCache(tbl.AuthorFinish).FullName;
			}
			AgreeUsersIDS = tbl.AgreeUsersIDS;
			AgreeDict = getAgreeUsers(AgreeUsersIDS);
			AgreeUsersText = string.Join(", ", AgreeDict.Values);
			DateCreate = tbl.DateCreate;
		}
Exemplo n.º 2
0
		public static ReturnMessage AddComment(CranTaskInfo task, string comment) {
			Logger.info("Добавление комментария к заявке на работу крана", Logger.LoggerSource.server);
			try {
				string result = "";
				OrdersUser currentUser = OrdersUser.loadFromCache(HttpContext.Current.User.Identity.Name);
				VotGESOrdersEntities eni = new VotGESOrdersEntities();
				CranTask tbl = new CranTask();

				CranTask tsk = (from t in eni.CranTask where t.Number == task.Number select t).FirstOrDefault();
				if (tsk == null) {
					return new ReturnMessage(false, "Заявка не найдена");
				}
				tbl = tsk;

				if (!string.IsNullOrEmpty(task.AgreeComments))
					task.AgreeComments += "\r\n";
				task.AgreeComments += String.Format("{2} {0}:\r\n   {1}", currentUser.FullName, comment, DateTime.Now.ToString("dd.MM.yyyy HH:mm"));
				tbl.AgreeComment = task.AgreeComments;


				eni.SaveChanges();
				string message = String.Format("Заявка на работу крана \"{0}\" №{1}. Комментарий", task.CranName, task.CranNumber);
				MailContext.sendCranTask(message, new CranTaskInfo(tbl));
				if (Managers != null) {
					if (!Managers.Contains(task.Manager)) {
						Managers.Add(task.Manager);
					}
				}
				else
					ReadManagers();
				return new ReturnMessage(true, "Комментарий добавлен");
			}
			catch (Exception e) {
				Logger.info("Ошибка при создании/изменении заявки на работу крана " + e.ToString(), Logger.LoggerSource.server);
				return new ReturnMessage(false, "ошибка при добавлении комментария");
			}
		}
 /// <summary>
 /// Создание нового объекта CranTask.
 /// </summary>
 /// <param name="number">Исходное значение свойства Number.</param>
 /// <param name="cranNumber">Исходное значение свойства CranNumber.</param>
 /// <param name="author">Исходное значение свойства Author.</param>
 /// <param name="needDateStart">Исходное значение свойства NeedDateStart.</param>
 /// <param name="comment">Исходное значение свойства Comment.</param>
 /// <param name="allowed">Исходное значение свойства Allowed.</param>
 /// <param name="denied">Исходное значение свойства Denied.</param>
 /// <param name="needDateEnd">Исходное значение свойства NeedDateEnd.</param>
 /// <param name="manager">Исходное значение свойства Manager.</param>
 /// <param name="cranName">Исходное значение свойства CranName.</param>
 /// <param name="dateCreate">Исходное значение свойства DateCreate.</param>
 /// <param name="state">Исходное значение свойства State.</param>
 /// <param name="cancelled">Исходное значение свойства Cancelled.</param>
 /// <param name="finished">Исходное значение свойства Finished.</param>
 public static CranTask CreateCranTask(global::System.Int32 number, global::System.Int32 cranNumber, global::System.String author, global::System.DateTime needDateStart, global::System.String comment, global::System.Boolean allowed, global::System.Boolean denied, global::System.DateTime needDateEnd, global::System.String manager, global::System.String cranName, global::System.DateTime dateCreate, global::System.String state, global::System.Boolean cancelled, global::System.Boolean finished)
 {
     CranTask cranTask = new CranTask();
     cranTask.Number = number;
     cranTask.CranNumber = cranNumber;
     cranTask.Author = author;
     cranTask.NeedDateStart = needDateStart;
     cranTask.Comment = comment;
     cranTask.Allowed = allowed;
     cranTask.Denied = denied;
     cranTask.NeedDateEnd = needDateEnd;
     cranTask.Manager = manager;
     cranTask.CranName = cranName;
     cranTask.DateCreate = dateCreate;
     cranTask.State = state;
     cranTask.Cancelled = cancelled;
     cranTask.Finished = finished;
     return cranTask;
 }
Exemplo n.º 4
0
		public static ReturnMessage CreateCranTask(CranTaskInfo task) {
			Logger.info("Создание/изменение заявки на работу крана", Logger.LoggerSource.server);
			try {
				string result = "";
				string message = String.Format("Заявка на работу крана \"{0}\" №", task.CranName);
				OrdersUser currentUser = OrdersUser.loadFromCache(HttpContext.Current.User.Identity.Name);
				VotGESOrdersEntities eni = new VotGESOrdersEntities();
				CranTask tbl = new CranTask();
				if (task.init) {
					Logger.info("Определение номера заявки на кран", Logger.LoggerSource.server);
					tbl.State = "new";
					CranTask tsk = (from t in eni.CranTask orderby t.Number descending select t).FirstOrDefault();
					task.DateCreate = DateTime.Now;
					if (tsk != null) {
						task.Number = tsk.Number + 1;
					}
					else {
						task.Number = 1;
					}
					tbl.Allowed = false;
					tbl.Denied = false;
					tbl.Author = currentUser.Name;
					tbl.DateCreate = task.DateCreate;					
					task.Author = currentUser.FullName;
					eni.CranTask.AddObject(tbl);
					result = "Заявка на кран успешно создана";
				}
				else {
					CranTask tsk = (from t in eni.CranTask where t.Number == task.Number select t).FirstOrDefault();
					if (tsk == null) {
						return new ReturnMessage(false, "Заявка не найдена");
					}
					tbl = tsk;
					result = "Заявка на кран успешно изменена";
				}
				message += task.Number + ". ";

				if ((task.NeedEndDate <= task.NeedStartDate) || (task.Allowed && (task.AllowDateEnd <= task.AllowDateStart))) {
					return new ReturnMessage(false, "Дата окончания заявки больше чем дата начала");
				}

				tbl.Number = task.Number;
				tbl.CranName = task.CranName;
				tbl.AgreeComment = task.AgreeComments;
				tbl.NeedDateStart = task.NeedStartDate;
				tbl.NeedDateEnd = task.NeedEndDate;
				tbl.Comment = task.Comment;
				tbl.Manager = task.Manager;
				tbl.CranNumber = task.CranNumber;
				if (task.AgreeDict != null)
					tbl.AgreeUsersIDS = string.Join(";", task.AgreeDict.Keys);

				if (task.Finished) {
					tbl.State = "finished";
					result = "Заявка на кран завершена";
					tbl.RealDateStart = task.RealDateStart;
					tbl.RealDateEnd = task.RealDateEnd;
					tbl.AuthorFinish = currentUser.Name;
					tbl.Finished = true;
					message += " Заявка завершена";
				}
				else if (task.Allowed) {
					tbl.AllowedDateStart = task.AllowDateStart;
					tbl.AllowedDateEnd = task.AllowDateEnd;
					tbl.RealDateStart = task.AllowDateStart;
					tbl.RealDateEnd = task.AllowDateEnd;
					tbl.Denied = false;
					tbl.Allowed = true;
					tbl.Cancelled = false;
					tbl.State = "allowed";
					task.AuthorAllow = currentUser.FullName;
					result = "Заявка на кран разрешена";
					message += " Заявка разрешена";
				}
				else if (task.Denied) {
					tbl.AllowedDateStart = null;
					tbl.AllowedDateEnd = null;
					tbl.RealDateEnd = null;
					tbl.RealDateStart = null;
					tbl.Allowed = false;
					tbl.Denied = true;
					tbl.Cancelled = false;
					tbl.State = "denied";
					task.AuthorAllow = currentUser.FullName;
					result = "Заявка на кран отклонена";
					message += " Заявка отклонена";
				}
				else if (task.Cancelled) {
					tbl.State = "cancelled";
					tbl.Denied = false;
					tbl.Allowed = false;
					tbl.Cancelled = true;
					tbl.AuthorAllow = null;
					tbl.AllowedDateStart = null;
					tbl.AllowedDateEnd = null;
					tbl.RealDateEnd = null;
					tbl.RealDateStart = null;
					result = "Заявка на кран снята";
					message += " Заявка снята";
				}	else if (!task.init) {
					message += " Заявка изменена";
				}

				if (task.Allowed || task.Denied) {
					tbl.AuthorAllow = currentUser.Name;
				}

				eni.SaveChanges();
				MailContext.sendCranTask(message, new CranTaskInfo(tbl));
				if (Managers != null) {
					if (!Managers.Contains(task.Manager)) {
						Managers.Add(task.Manager);
					}
				}
				else
					ReadManagers();
				return new ReturnMessage(true, result);
			}
			catch (Exception e) {
				Logger.info("Ошибка при создании/изменении заявки на работу крана " + e.ToString(), Logger.LoggerSource.server);
				return new ReturnMessage(false, "Ошибка при создании/изменении заявки на работу крана");
			}
		}
 /// <summary>
 /// Устаревший метод для добавления новых объектов в набор EntitySet CranTask. Взамен можно использовать метод .Add связанного свойства ObjectSet&lt;T&gt;.
 /// </summary>
 public void AddToCranTask(CranTask cranTask)
 {
     base.AddObject("CranTask", cranTask);
 }