public ProjectApplication ApplyProject(long studentId, long projectId) { if (session == null || !session.IsOpen) { session = hibernate.getSession(); } Student student = session.CreateCriteria<Student>() .Add(Restrictions.Eq("USER_ID", studentId)) .UniqueResult<Student>(); //Check if both entities exists if (student == null) throw new ProjectApplicationException("Student ID " + studentId + " cannot be found."); Project project = this.getProjectById(projectId); if (project == null) throw new ProjectApplicationException("Project ID " + projectId + " cannot be found."); //Check student already has an application to the project IList<ProjectApplication> existingAppls = student.PROJECTS_APPLIED; foreach(ProjectApplication existingAppl in existingAppls){ if (existingAppl.PROJECT.PROJECT_ID == projectId) { throw new ProjectApplicationException("Student ID " + studentId + " already has application to project " + existingAppl.PROJECT.PROJECT_TITLE + " (" + existingAppl.PROJECT.PROJECT_ID + ")."); } } ProjectApplication appl = new ProjectApplication(); appl.APPLICANT = student; appl.PROJECT = project; appl.APPLICATION_STATUS = APPLICATION_STATUS.PENDING; student.PROJECTS_APPLIED.Add(appl); project.APPLICATIONS.Add(appl); session.BeginTransaction(); session.Save(appl); session.Transaction.Commit(); return appl; }
public async void ApplyForPosition() { CollaboratorProfileOverview profile = null; if (SelectedFacultyMemberProfileOverview != null) { profile = SelectedFacultyMemberProfileOverview; } else if (SelectedStudentProfileOverview != null) { profile = SelectedStudentProfileOverview; } if (profile != null) { ProjectApplication application = new ProjectApplication { ApplicantId = User.CurrentUserId, ApplicantComment = "" }; // searching for selected collaborator profile if (selectedFacultyMemberProfileIndex != -1) { application.CollaboratorProfileId = SelectedProject.CollaboratorProfiles.Where(p => p is FacultyMemberProfile).ElementAt(selectedFacultyMemberProfileIndex).CollaboratorProfileId; } else if (selectedStudentProfileIndex != -1) { application.CollaboratorProfileId = SelectedProject.CollaboratorProfiles.Where(p => p is StudentProfile).ElementAt(selectedStudentProfileIndex).CollaboratorProfileId; } Project project = await((App)App.Current).projects.GetByCollaboratorProfileAsync(application.CollaboratorProfileId); if (project.ProjectStatus != ProjectStatus.Closed) { await((App)App.Current).applications.AddAsync(application); } } }
protected void Page_Load(object sender, EventArgs e) { projApp = new ProjectApplication(); if (!Page.IsPostBack) { List <ProjectDetailDTO> list = projApp.GetUserProjects(UserInfo); switch (UserInfo.Role) { case RolesEnum.Leader: case RolesEnum.DEV: case RolesEnum.QA: list = list.FindAll(r => r.CompanyID == Config.SunnetCompany); break; } list.BindDropdown <ProjectDetailDTO>(ddlProjects, "Title", "ProjectID", "ALL", "-1"); ddlYears.SelectedValue = DateTime.Now.Year.ToString(); ddlMonths.SelectedValue = DateTime.Now.Month.ToString(); List <UsersEntity> userList = new App.ProjectApplication().GetProjectUsersByUserId(UserInfo); userList = userList.Distinct(new CompareUser()).ToList(); hiUserIds.Value = string.Join(",", userList.Select(r => r.UserID).ToArray()); ddlUser.DataSource = userList.OrderBy(r => r.FirstName); ddlUser.DataBind(); ddlUser.Items.Insert(0, new ListItem() { Text = "ALL", Value = "0" }); } if (ddlProjects.Items.Count <= 0) { ddlProjects.Items.Add(new ListItem() { Selected = true, Text = "None", Value = "0" }); } DateTitle = DateTime.Now.ToString("MMMM yyyy", System.Globalization.DateTimeFormatInfo.InvariantInfo); }
protected void Page_Load(object sender, EventArgs e) { ((Pop)this.Master).Width = 800; tsApp = new TimeSheetApplication(); if (!IsPostBack) { string headStr = ""; ProjectApplication projApp = new ProjectApplication(); TicketsApplication ticketApp = new TicketsApplication(); ProjectsEntity project = projApp.Get(QS("project", 0)); TicketsEntity ticket = ticketApp.GetTickets(QS("ticket", 0)); if (project != null) { headStr += project.Title; } if (ticket != null) { headStr += " - " + ticket.Title; } litHead.Text = headStr; InitControl(); } }
protected void Page_Load(object sender, EventArgs e) { int userID = QS("user", 0); int projectID = QS("project", 0); if (userID == 0 || projectID == 0) { this.Alert("Current Page get an error,please check your argument!", "/Report/Consuming.aspx?viewmodel=detailmodel"); } UserApplication userApp = new UserApplication(); this.SelectedUser = userApp.GetUser(userID); ProjectApplication projApp = new ProjectApplication(); this.SelectedProject = projApp.Get(projectID); DateTime startDate = DateTime.MinValue; DateTime endDate = DateTime.MinValue; DateTime.TryParse(Request.QueryString["startdate"], out startDate); DateTime.TryParse(Request.QueryString["enddate"], out endDate); TimeSheetApplication tsApp = new TimeSheetApplication(); DataTable dt = tsApp.GetSheetDateByProjectUser(projectID, userID, startDate, endDate); if (dt != null && dt.Rows.Count > 0) { this.rptDateView.DataSource = dt; this.rptDateView.DataBind(); } else { ShowFailMessageToClient("There is no records "); } litUserName.Text = SelectedUser.FirstName + " " + SelectedUser.LastName; litTotalhours.Text = totalHours.ToString("#0.00") + " h"; }
/// <summary> /// 下拉框 改变时 的做法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void ddlProject_SelectedIndexChanged(object sender, EventArgs e) { ProjectApplication projectApplication = new ProjectApplication(); List <ProjectDetailDTO> list = projectApplication.GetUserProjectsForCreateObject(UserInfo); ProjectDetailDTO projectDetailDto = list.FirstOrDefault(c => c.Title == ddlProject.SelectedItem.Text); List <UsersEntity> users = new List <UsersEntity>(); if (projectDetailDto != null) { var sunnetUser = projectApplication.GetProjectSunnetUserList(projectDetailDto.ProjectID); users.AddRange(sunnetUser.Select(t => userApp.GetUser(t.UserID)).Where(user => user != null && user.Status.Trim() != "INACTIVE")); list.Remove(projectDetailDto); list.BindDropdown <ProjectDetailDTO>(ddlProject, "Title", "ProjectID", projectDetailDto.Title, projectDetailDto.ProjectID.ToString(), "", false); ddlProject.Attributes.Add("onchange", "fnDisplayUsers();ChangeProject();check();"); UsersEntity myselef = users.FirstOrDefault(c => c.UserID == UserInfo.UserID); if (myselef != null) { users.Remove(myselef); users.Add(new UsersEntity() { FirstName = "System", UserID = -1 }); users.BindDropdown <UsersEntity>(ddlRes, "FirstAndLastName", "UserID", myselef.FirstAndLastName, myselef.UserID.ToString(), "", true); } else { users.Add(new UsersEntity() { FirstName = "System", UserID = -1 }); users.BindDropdown <UsersEntity>(ddlRes, "FirstAndLastName", "UserID"); } } }
public void ProcessRequest(HttpContext context) { HttpResponse response = context.Response; HttpRequest request = context.Request; int projectID = QS(request.QueryString["projectID"], 0); if (projectID != 0) { ProjectApplication projectApplication = new ProjectApplication(); List <UsersEntity> clientUsers = projectApplication.GetPojectClientUsers(projectID, projectApplication.Get(projectID).CompanyID); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("["); foreach (UsersEntity user in clientUsers) { stringBuilder.Append("{"); stringBuilder.AppendFormat("\"name\":\"{0}\",\"value\":\"{1}\"", user.FirstAndLastName, user.UserID); stringBuilder.Append("},"); } response.Write(stringBuilder.ToString().TrimEnd(',') + "]"); } }
private void SaveTicket(bool save) { #region add ticket TicketsEntity ticketsEntity = new TicketsApplication().GetTickets(QS("tid", 0)); ticketsEntity.Title = txtTitle.Text.NoHTML(); ticketsEntity.FullDescription = txtDesc.Value.NoHTML(); ticketsEntity.URL = txtUrl.Text; ticketsEntity.ProjectID = int.Parse(ddlProject.SelectedValue); ticketsEntity.TicketType = (TicketsType)int.Parse(rdoType.SelectedValue); ticketsEntity.Priority = (PriorityState)int.Parse(this.rdoPriority.SelectedValue); ProjectsEntity projectsEntity = new ProjectApplication().Get(ticketsEntity.ProjectID); ticketsEntity.CompanyID = projectsEntity.CompanyID; ticketsEntity.IsEstimates = chkEN.Checked; ticketsEntity.TicketCode = new TicketsApplication().ConvertTicketTypeToTicketCode(ticketsEntity.TicketType); ticketsEntity.IsInternal = false; ticketsEntity.CreatedBy = UserInfo.UserID; ticketsEntity.CreatedOn = DateTime.Now; ticketsEntity.ModifiedBy = UserInfo.UserID; ticketsEntity.ModifiedOn = DateTime.Now; ticketsEntity.PublishDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); ticketsEntity.ConvertDelete = CovertDeleteState.Normal; ticketsEntity.StartDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); ticketsEntity.DeliveryDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); if (save) { ticketsEntity.Status = TicketsState.Submitted; } else { ticketsEntity.Status = TicketsState.Draft; } if (new TicketsApplication().UpdateTickets(ticketsEntity)) { if (save) { new TicketStatusManagerApplication().SendEmailToPMWhenTicketAdd(ticketsEntity, UserInfo); } } #endregion #region add file string fileName = hidUploadFile.Value; if (fileName.Trim() != string.Empty) { string[] files = fileName.Split('|'); foreach (string str in files) { InsertFile(str, ticketsEntity.ProjectID, ticketsEntity.TicketID, ticketsEntity.CompanyID); } } #endregion ShowMessageToClient("The ticket has been updated.", 0, true, true); if (save) { Redirect("/Ticket/Ongoing.aspx", true); } else { Redirect("/Ticket/Draft.aspx", true); } }
protected void Page_Load(object sender, EventArgs e) { projApp = new ProjectApplication(); if (!Page.IsPostBack) { NotEnoughPTOHour = CurrentPTOHoursNotEnough(); int id = QS("ID", 0); EventEntity eventEntity = new EventsApplication().GetEventInfo(id); if (eventEntity != null) { FromDay = eventEntity.FromDay; var projectEntity = new ProjectApplication().Get(eventEntity.ProjectID); if (eventEntity.CreatedBy != UserInfo.UserID && projectEntity.Title != "0_PTO") { OnlyRead = true; Response.Redirect("/Event/View.aspx?ID=" + eventEntity.ID); } var ptoAdmin = Config.PtoAdmin; if (ptoAdmin == null) { if (projectEntity.Title == "0_PTO" && eventEntity.FromDay < DateTime.Now && eventEntity.CreatedBy == UserInfo.UserID) { OnlyRead = true; Response.Redirect("/Event/View.aspx?ID=" + eventEntity.ID); } } else { var ptoAdmins = ptoAdmin.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (!ptoAdmins.Contains(UserInfo.UserName)) { if (projectEntity.Title == "0_PTO" && eventEntity.FromDay < DateTime.Now && eventEntity.CreatedBy == UserInfo.UserID) { OnlyRead = true; Response.Redirect("/Event/View.aspx?ID=" + eventEntity.ID); } if (projectEntity.Title == "0_PTO" && eventEntity.CreatedBy != UserInfo.UserID) { OnlyRead = true; Response.Redirect("/Event/View.aspx?ID=" + eventEntity.ID); } } } Times = eventEntity.Times; txtName.Text = eventEntity.Name; //txtName.Enabled = projectEntity.ProjectCode != "PTO";取消不能编辑pto txtDetails.Text = eventEntity.Details; txtWhere.Text = eventEntity.Where; chkAllDay.Checked = eventEntity.AllDay; if (chkAllDay.Checked) { txtFromTime.Style.Add("display", "none"); txtToTime.Style.Add("display", "none"); } txtFrom.Enabled = eventEntity.FromDay >= DateTime.Today ? true : false; txtFrom.Text = eventEntity.FromDay.ToString("MM/dd/yyyy"); TxtFromHide.Text = DateTime.Now.ToString("MM/dd/yyyy"); txtFromTime.Text = eventEntity.FromTime + (eventEntity.FromTimeType == 1 ? "am" : "pm"); txtTo.Enabled = eventEntity.ToDay >= DateTime.Today ? true : false; txtTo.Text = eventEntity.ToDay.ToString("MM/dd/yyyy"); txtToTime.Text = eventEntity.ToTime + (eventEntity.ToTimeType == 1 ? "am" : "pm"); ddlAlert.SelectedValue = ((int)eventEntity.Alert).ToString(); imgIcon.ImageUrl = eventEntity.IconPath; List <ProjectDetailDTO> projectList = projApp.GetUserProjectsForCreateObject(UserInfo, eventEntity.ProjectID); switch (UserInfo.Role) { case RolesEnum.Leader: case RolesEnum.DEV: case RolesEnum.QA: projectList = projectList.FindAll(r => r.CompanyID == Config.SunnetCompany); break; } List <EventInviteEntity> list = GetInviteData(eventEntity); rptInviteUser.DataSource = list.FindAll(r => r.UserID > 0).OrderBy(r => r.LastName); rptInviteUser.DataBind(); if (rptInviteUser.Items.Count == 0) { rptInviteUser.Visible = false; litNoUser.Text = " <li>No Users</li>"; } if (eventEntity.ProjectID.ToString() == Config.HRProjectID) { chkOff.Checked = eventEntity.IsOff; } else { div_off.Attributes.Add("style", "display:none"); } rptOtherUser.DataSource = list.FindAll(r => r.UserID == 0).OrderBy(r => r.FirstName).OrderBy(r => r.LastName); rptOtherUser.DataBind(); } } else { if (chkAllDay.Checked) { txtFromTime.Style.Add("display", "none"); txtToTime.Style.Add("display", "none"); } else { txtFromTime.Style.Add("display", ""); txtToTime.Style.Add("display", ""); } } ((Pop)(this.Master)).Width = 780; }
protected void Page_Load(object sender, EventArgs e) { projApp = new ProjectApplication(); if (!Page.IsPostBack) { int id = QS("ID", 0); int canEdit = QS("c", 0); EventEntity eventEntity = new EventsApplication().GetEventInfo(id); ltrlName.Text = eventEntity.Name; ltrlDetail.Text = eventEntity.Details; ltrlWhere.Text = eventEntity.Where; chkAllDay.Checked = eventEntity.AllDay; chkAllDay.Enabled = false; string fromTime = string.Empty; string toTime = string.Empty; if (!chkAllDay.Checked) { fromTime = eventEntity.FromDayString + " " + eventEntity.FromTime + " " + (eventEntity.FromTimeType == 1 ? "AM" : "PM"); toTime = eventEntity.ToDayString + " " + eventEntity.ToTime + " " + (eventEntity.ToTimeType == 1 ? "AM" : "PM"); } else { fromTime = eventEntity.FromDayString; toTime = eventEntity.ToDayString; } ltrlFrom.Text = fromTime; ltrlTo.Text = toTime; ltrlAlert.Text = eventEntity.Alert.GetName <AlertType>(); imgIcon.ImageUrl = eventEntity.IconPath; if (eventEntity.ProjectID != -1) { ProjectsEntity projectsEntity = projApp.Get(eventEntity.ProjectID); ltrlProject.Text = projectsEntity.Title; } else { ltrlProject.Text = string.Empty; } litCreated.Text = new App.UserApplication().GetUser(eventEntity.CreatedBy).GetClientUserName(UserInfo); List <EventInviteEntity> list = new App.EventsApplication().GetEventInvites(eventEntity.ID); UsersEntity userEntity; foreach (EventInviteEntity tmpItem in list) { if (tmpItem.UserID > 0) { userEntity = new App.UserApplication().GetUser(tmpItem.UserID); tmpItem.FirstName = userEntity.FirstName; tmpItem.LastName = userEntity.LastName; } } if (eventEntity.ProjectID.ToString() == Config.HRProjectID) { chkOff.Checked = eventEntity.IsOff; } else { div_off.Attributes.Add("style", "display:none"); } rptInvite.DataSource = list.OrderBy(r => r.LastName); rptInvite.DataBind(); } ((Pop)(this.Master)).Width = 425; }
private void SaveTicket(bool save) { #region add ticket TicketsEntity ticketsEntity = new TicketsApplication().GetTickets(QS("tid", 0)); ticketsEntity.Title = txtTitle.Value.NoHTML(); ticketsEntity.FullDescription = txtDesc.Value.NoHTML(); ticketsEntity.URL = txtUrl.Value; ticketsEntity.ProjectID = int.Parse(ddlProject.SelectedValue); ticketsEntity.TicketType = (TicketsType)int.Parse(ddlTicketType.SelectedValue); ticketsEntity.Priority = (PriorityState)int.Parse(this.radioPriority.SelectedValue); ProjectsEntity projectsEntity = new ProjectApplication().Get(ticketsEntity.ProjectID); ticketsEntity.CompanyID = projectsEntity.CompanyID; ticketsEntity.IsEstimates = chkEN.Checked; ticketsEntity.TicketCode = new TicketsApplication().ConvertTicketTypeToTicketCode(ticketsEntity.TicketType); ticketsEntity.IsInternal = false; ticketsEntity.CreatedBy = UserInfo.UserID; ticketsEntity.CreatedOn = DateTime.Now; ticketsEntity.ModifiedBy = UserInfo.UserID; ticketsEntity.ModifiedOn = DateTime.Now; ticketsEntity.PublishDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); ticketsEntity.ConvertDelete = CovertDeleteState.Normal; ticketsEntity.StartDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); ticketsEntity.DeliveryDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); if (save) { ticketsEntity.Status = TicketsState.Submitted; } else { ticketsEntity.Status = TicketsState.Draft; } if (new TicketsApplication().UpdateTickets(ticketsEntity)) { if (save) { new TicketStatusManagerApplication().SendEmailToPMWhenTicketAdd(ticketsEntity.TicketID, ticketsEntity.TicketType); } } #endregion #region add file if (fileupload.PostedFile.ContentLength > 0) { string FolderName = string.Empty; if (null != projectsEntity) { FolderName = projectsEntity.ProjectID.ToString(); } string filderPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; //~/path string savepath = Server.MapPath(filderPath) + FolderName; string filename = fileupload.PostedFile.FileName; string fileExtension = Path.GetExtension(filename); if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } string sNewFileName = string.Format("{0}_{1}{2}", ticketsEntity.TicketID, DateTime.Now.ToString("yyMMddssmm"), fileExtension); fileupload.PostedFile.SaveAs(savepath + @"\" + sNewFileName); FilesEntity fileEntity = new FilesEntity(); fileEntity.ContentType = fileExtension.ToLower(); fileEntity.CreatedBy = ticketsEntity.CreatedBy; fileEntity.FilePath = filderPath.Substring(2) + FolderName + @"/" + sNewFileName; fileEntity.FileSize = fileupload.PostedFile.ContentLength; fileEntity.FileTitle = filename.Substring(0, filename.LastIndexOf('.')); fileEntity.IsPublic = !ticketsEntity.IsInternal; fileEntity.ProjectId = ticketsEntity.ProjectID; fileEntity.TicketId = ticketsEntity.TicketID; fileEntity.CreatedOn = DateTime.Now.Date; fileEntity.FeedbackId = 0; fileEntity.SourceType = (int)FileSourceType.Ticket; fileEntity.ThumbPath = ""; fileEntity.CompanyID = ticketsEntity.CompanyID; int response = new FileApplication().AddFile(fileEntity); } #endregion ShowMessageToClient("The ticket has been updated.", 0, true, true); }
public ActionResult InitiatesProjects(ProjectApplication application) { string userValidateCode = Request["txt-code"].ToString(); string seesionVCode = Session["VCode"] as string; Session["VCode"] = null; if (string.IsNullOrEmpty(seesionVCode) || userValidateCode != seesionVCode) { ViewBag.Message = "<script>alert('验证码错误!');</script>"; return(View()); } application.ApplicationID = Guid.NewGuid(); application.ProjectName = Request["project-name"].ToString(); application.Email = Request["email"].ToString(); application.ProjectSite = Request.Form["province-site"].ToString() + Request.Form["city-site"].ToString(); application.TargetFigure = Convert.ToInt32(Request["target-figure"]); application.ProjectBriefIntroduction = Request["txt-BriefIntroduction"].ToString(); application.ProjectIntroductionTitle = Request["txt-title"].ToString(); application.ProjectIntroduction = Request["txt-introduction"].ToString(); Users user = Session["Users"] as Users; application.UserName = user.UserName; string fullDirMain; string fullDirIllustrating; HttpPostedFileBase file1 = Request.Files["imgMainPicture"]; string fileName = Path.GetFileName(file1.FileName); string ext = Path.GetExtension(fileName); if (!(ext == ".jpeg" || ext == ".jpg" || ext == ".png" || ext == ".gif" || ext == ".bmp")) { ViewBag.Message = "<script>alert('图片格式不正确!');</script>"; return(View()); } else { string dir = "/Upload/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; Directory.CreateDirectory(Path.GetDirectoryName(Server.MapPath(dir)));//创建文件夹 fullDirMain = dir + MD5.GetStreamMD5(file1.InputStream) + ext; file1.SaveAs(Request.MapPath(fullDirMain)); } HttpPostedFileBase file2 = Request.Files["imgIllustratingPicture"]; string fileName2 = Path.GetFileName(file2.FileName); string ext2 = Path.GetExtension(fileName2); if (!(ext2 == ".jpeg" || ext2 == ".jpg" || ext2 == ".png" || ext2 == ".gif" || ext2 == ".bmp")) { ViewBag.Message = "<script>alert('图片格式不正确!');</script>"; return(View()); } else { string dir = "/Upload/" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + "/"; fullDirIllustrating = dir + MD5.GetStreamMD5(file2.InputStream) + ext2; file2.SaveAs(Request.MapPath(fullDirIllustrating)); } application.ImportantImageAddress = fullDirMain; application.BasicImageAddress = fullDirIllustrating; sun.ProjectApplication.Add(application); sun.SaveChanges(); return(RedirectToAction("PersonalCenter", "Home")); }
/// <summary> /// save : 1:save ; 2:draft ;3 save and new /// </summary> /// <param name="save"></param> private void SaveTicket(int save) { #region add ticket TicketsEntity ticketsEntity = new TicketsEntity(); ticketsEntity.Title = txtTitle.Value.NoHTML(); ticketsEntity.FullDescription = txtDesc.Value.NoHTML(); ticketsEntity.URL = txtUrl.Value; ticketsEntity.ProjectID = int.Parse(ddlProject.SelectedValue); ticketsEntity.TicketType = (TicketsType)int.Parse(ddlType.SelectedValue); ticketsEntity.TicketCode = new TicketsApplication().ConvertTicketTypeToTicketCode(ticketsEntity.TicketType); ticketsEntity.Priority = (PriorityState)int.Parse(this.radioPriority.SelectedValue); ProjectsEntity projectsEntity = new ProjectApplication().Get(ticketsEntity.ProjectID); ticketsEntity.CompanyID = projectsEntity.CompanyID; ticketsEntity.IsEstimates = chkEN.Checked; ticketsEntity.IsInternal = false; ticketsEntity.CreatedBy = UserInfo.UserID; ticketsEntity.CreatedOn = DateTime.Now; ticketsEntity.ModifiedBy = UserInfo.UserID; ticketsEntity.ModifiedOn = DateTime.Now; ticketsEntity.PublishDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); ticketsEntity.ConvertDelete = CovertDeleteState.Normal; ticketsEntity.StartDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); ticketsEntity.DeliveryDate = UtilFactory.Helpers.CommonHelper.GetDefaultMinDate(); if (UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.ADMIN) { ticketsEntity.Source = (RolesEnum)Enum.Parse(typeof(RolesEnum), ddlSource.SelectedValue); } else { ticketsEntity.Source = UserInfo.Role; } if (save == 2) { ticketsEntity.Status = TicketsState.Draft; } else { if (UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.ADMIN) { ticketsEntity.Status = TicketsState.PM_Reviewed; } else { ticketsEntity.Status = TicketsState.Submitted; } } int result = new TicketsApplication().AddTickets(ticketsEntity); if (result > 0) { TicketUsersEntity ticketUserEntity = new TicketUsersEntity(); //add pm user ticketUserEntity.Type = TicketUsersType.PM; ticketUserEntity.TicketID = result; ProjectsEntity projectEntity = new ProjectApplication().Get(ticketsEntity.ProjectID); if (projectEntity != null) { ticketUserEntity.UserID = projectEntity.PMID; new TicketsApplication().AddTicketUser(ticketUserEntity); } else { WebLogAgent.Write(string.Format("Add Pm To Ticket User Error:Project :{0},Ticket:{1},CreateDate:{2}", ticketsEntity.ProjectID, ticketsEntity.TicketID, DateTime.Now)); } //add create user ticketUserEntity.Type = TicketUsersType.Create; ticketUserEntity.TicketID = result; ticketUserEntity.UserID = ticketsEntity.CreatedBy; new TicketsApplication().AddTicketUser(ticketUserEntity); if (UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.ADMIN) { //添加当前Project中的Leader到此ticket下. List <ProjectUsersEntity> ProjectUsers = new ProjectApplication().GetProjectSunnetUserList(projectsEntity.ID); if (ProjectUsers != null) { List <ProjectUsersEntity> leaders = ProjectUsers.FindAll(r => r.Role == RolesEnum.Leader); foreach (ProjectUsersEntity leader in leaders) { ticketUserEntity = new TicketUsersEntity(); ticketUserEntity.Type = TicketUsersType.Dev; ticketUserEntity.TicketID = result; ticketUserEntity.UserID = leader.UserID; new TicketsApplication().AddTicketUser(ticketUserEntity); } } } } #endregion #region send email TicketStatusManagerApplication ex = new TicketStatusManagerApplication(); if (!ticketsEntity.IsInternal) { ex.SendEmailToPMWhenTicketAdd(result, ticketsEntity.TicketType); } #endregion #region add file if (fileupload.PostedFile.ContentLength > 0) { string FolderName = string.Empty; if (null != projectsEntity) { FolderName = projectsEntity.ProjectID.ToString(); } string filderPath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"]; //~/path string savepath = Server.MapPath(filderPath) + FolderName; string filename = fileupload.PostedFile.FileName; string fileExtension = Path.GetExtension(filename); if (!Directory.Exists(savepath)) { Directory.CreateDirectory(savepath); } string sNewFileName = string.Format("{0}_{1}{2}", result, DateTime.Now.ToString("yyMMddssmm"), fileExtension); fileupload.PostedFile.SaveAs(savepath + @"\" + sNewFileName); FilesEntity fileEntity = new FilesEntity(); fileEntity.ContentType = fileExtension.ToLower(); fileEntity.CreatedBy = ticketsEntity.CreatedBy; fileEntity.FilePath = filderPath.Substring(2) + FolderName + @"/" + sNewFileName; fileEntity.FileSize = fileupload.PostedFile.ContentLength; fileEntity.FileTitle = filename.Substring(0, filename.LastIndexOf('.')); fileEntity.IsPublic = !ticketsEntity.IsInternal; fileEntity.ProjectId = ticketsEntity.ProjectID; fileEntity.TicketId = result; fileEntity.CreatedOn = DateTime.Now.Date; fileEntity.FeedbackId = 0; fileEntity.SourceType = (int)FileSourceType.Ticket; fileEntity.ThumbPath = ""; fileEntity.CompanyID = ticketsEntity.CompanyID; int response = new FileApplication().AddFile(fileEntity); } #endregion switch (save) { case 1: ShowMessageAndRedirect("The ticket has been added.", "/sunnet/Clients/ListTicket.aspx"); break; case 2: ShowMessageAndRedirect("The ticket has been added.", "/sunnet/Clients/ListTicketDrafted.aspx"); break; case 3: ShowMessageAndRedirect("The ticket has been added.", "/sunnet/Clients/AddBug.aspx"); break; } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ProjectApplication projectApplication = new ProjectApplication(); List <ProjectDetailDTO> list = projectApplication.GetUserProjectsForCreateObject(UserInfo); List <TicketsEntity> listTicket = ticketAPP.GetTicketsByCreateId(UserInfo.UserID); var projectDetailDto = list.FirstOrDefault(c => { var firstOrDefault = listTicket.FirstOrDefault(); return(firstOrDefault != null && c.Title == firstOrDefault.ProjectTitle); }); if (projectDetailDto != null) { List <UsersEntity> users = new List <UsersEntity>(); var sunnetUser = projectApplication.GetProjectSunnetUserList(projectDetailDto.ProjectID); users.AddRange(sunnetUser.Select(t => userApp.GetUser(t.UserID)).Where(user => user != null && user.Status.Trim() != "INACTIVE")); UsersEntity myselef = users.FirstOrDefault(c => c.UserID == UserInfo.UserID); if (myselef != null) { users.Remove(myselef); users.Add(new UsersEntity() { FirstName = "System", UserID = -1 }); users.BindDropdown <UsersEntity>(ddlRes, "FirstAndLastName", "UserID", myselef.FirstAndLastName, myselef.UserID.ToString(), "", true); } else { users.Add(new UsersEntity() { FirstName = "System", UserID = -1 }); users.BindDropdown <UsersEntity>(ddlRes, "FirstAndLastName", "UserID"); } list.Remove(projectDetailDto); list.Insert(0, projectDetailDto); list.BindDropdown <ProjectDetailDTO>(ddlProject, "Title", "ProjectID"); ddlProject.Items.FindByValue(projectDetailDto.ProjectID.ToString()).Selected = true; } else { list.BindDropdown <ProjectDetailDTO>(ddlProject, "Title", "ProjectID", DefaulSelectText, "", QS("project")); } jsonProjectInfo = projectApplication.GetProjectInfoJson(list); if (UserInfo.Role == RolesEnum.PM) { dvRes.Style.Remove("display"); lblRes.Style.Remove("display"); } if (UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.ADMIN || UserInfo.Role == RolesEnum.Sales) { ViewState["curRole"] = UserInfo.Role.ToString(); dvSource.Style.Remove("display"); lblSource.Style.Remove("display"); lblAccounting.Style.Remove("display"); dvAccounting.Style.Remove("display"); rdoAccounting.SelectedIndex = 0; ddlSource.DataSource = ConvertEnumtToListItem(typeof(RolesEnum)); ddlSource.DataBind(); if (UserInfo.Role == RolesEnum.PM || UserInfo.Role == RolesEnum.ADMIN) { ddlSource.SelectedValue = RolesEnum.PM.ToString(); } else { ddlSource.SelectedValue = RolesEnum.Sales.ToString(); } dvIsInteral.Style.Remove("display"); lblIsInternal.Style.Remove("display"); } else { rdoAccounting.SelectedIndex = 2; } if (list.Count == 1 && !projectApplication.CheckIfEstimated(list[0])) //只有一个Project,且已过期 { this.btnSubmit.Enabled = false; this.btnSave.Enabled = false; this.btnSubmitAndNew.Enabled = false; } } }
/// <summary> /// save : 1:save ; 2:draft ;3 save and new /// </summary> /// <param name="save"></param> private void SaveTicket(int save) { ProjectsEntity projectsEntity = new ProjectApplication().Get(int.Parse(ddlProject.SelectedValue)); TicketsEntity ticketsEntity = GetEntity(save, projectsEntity.ProjectID, projectsEntity.CompanyID); int result = new TicketsApplication().AddTickets(ticketsEntity); if (result > 0) { ticketsEntity.TicketID = result; List <int> userIds; AddDefaultTicketUsers(projectsEntity, ticketsEntity, result, out userIds); AssignTicketUsers(ticketsEntity, userIds); AddIniHistroy(ticketsEntity); if (rdoShareKnowlege.Checked) { ShareEntity shareEntity = new ShareEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); int type = 0; shareEntity.Title = ticketsEntity.Title; shareEntity.Note = ticketsEntity.FullDescription; shareEntity.Type = type; shareEntity.TicketID = result; shareEntity.TypeEntity.Title = ticketsEntity.Title; _shareApp.Save(shareEntity); } if (!ticketsEntity.IsInternal) { new SendHandler(() => ex.SendEmailToPMWhenTicketAdd(ticketsEntity, UserInfo)) .BeginInvoke(null, null); } string fileName = hidUploadFile.Value; if (fileName.Trim() != string.Empty) { string[] files = fileName.Split('|'); foreach (string str in files) { InsertFile(str, ticketsEntity.ProjectID, result, ticketsEntity.CompanyID); } } ProposalTrackerRelationEntity model = new ProposalTrackerRelationEntity(); if (hid_Proposal.Value != "") { model.CreatedBy = IdentityContext.UserID; model.TID = ticketsEntity.TicketID; model.WID = int.Parse(this.hid_Proposal.Value); wrApp.AddProposalTrackerRelation(model); } switch (save) { case 1: Redirect("/SunnetTicket/Index.aspx", true); break; case 3: Redirect("/SunnetTicket/New.aspx?project=" + ddlProject.SelectedValue, true); break; } } else { ShowFailMessageToClient(); } }
protected void Page_Load(object sender, EventArgs e) { projApp = new ProjectApplication(); if (!Page.IsPostBack) { List <ProjectDetailDTO> list = projApp.GetUserProjects(UserInfo); switch (UserInfo.Role) { case RolesEnum.Leader: case RolesEnum.DEV: case RolesEnum.QA: list = list.FindAll(r => r.CompanyID == Config.SunnetCompany); break; } list.BindDropdown <ProjectDetailDTO>(ddlProjects, "Title", "ProjectID", "ALL", "-1"); ddlYears.SelectedValue = DateTime.Now.Year.ToString(); ddlMonths.SelectedValue = DateTime.Now.Month.ToString(); List <UsersEntity> userList = new List <UsersEntity>(); List <int> userIdList = new App.ProjectApplication().GetProjectUserIds(UserInfo.UserID); if (UserInfo.Role == RolesEnum.CLIENT) { foreach (int tmpId in userIdList) { UsersEntity tmpUserEntity = new App.UserApplication().GetUser(tmpId); if (tmpUserEntity != null && tmpUserEntity.Status.ToUpper() == "ACTIVE") { if (tmpUserEntity.Role == RolesEnum.CLIENT) { userList.Add(tmpUserEntity); } else if (tmpUserEntity.Office.ToUpper() == "US" && tmpUserEntity.UserType.ToUpper() == "SUNNET") { userList.Add(tmpUserEntity); } } } } else { if (UserInfo.UserType.ToUpper() == "SUNNET") { if (UserInfo.Office.ToUpper() == "US") { foreach (int tmpId in userIdList) { UsersEntity tmpUserEntity = new App.UserApplication().GetUser(tmpId); if (tmpUserEntity != null && tmpUserEntity.Status.ToUpper() == "ACTIVE") { userList.Add(tmpUserEntity); } } } else { foreach (int tmpId in userIdList) { UsersEntity tmpUserEntity = new App.UserApplication().GetUser(tmpId); if (tmpUserEntity != null && tmpUserEntity.Status.ToUpper() == "ACTIVE") { if (tmpUserEntity.Office.ToUpper() == "CN") { userList.Add(tmpUserEntity); } } } } } else { userList.Add(UserInfo); } } if (userIdList.Count == 0) { userList.Add(UserInfo); } userList = userList.Distinct(new CompareUser()).ToList(); hiUserIds.Value = string.Join(",", userList.Select(r => r.UserID).ToArray()); ddlUser.DataSource = userList.OrderBy(r => r.FirstName); ddlUser.DataBind(); ddlUser.Items.Insert(0, new ListItem() { Text = "ALL", Value = "0" }); } SearchEvents(); if (ddlProjects.Items.Count <= 0) { ddlProjects.Items.Add(new ListItem() { Selected = true, Text = "None", Value = "0" }); } }
public static void UpdateProjectFreeHour() { ProjectApplication projApp = new ProjectApplication(); projApp.UpdateProjectFreeHour(); }
protected void btnSave_Click(object sender, EventArgs e) { int id = QS("id", 0); if (id == 0) { ShowFailMessageToClient("unauthorized access."); return; } else { ProjectsEntity projectEntity = new ProjectApplication().Get(id); if (projectEntity == null) { ShowFailMessageToClient("unauthorized access."); return; } if (fileUpload.PostedFile.ContentLength == 0) { ShowFailMessageToClient("Please specify a file to upload."); return; } FilesEntity model = FileFactory.CreateFileEntity(UserInfo.ID, ObjectFactory.GetInstance <ISystemDateTime>()); model.FilePath = UtilFactory.Helpers.FileHelper.SaveUploadFiles("Project", id, fileUpload.PostedFile);; model.CompanyID = projectEntity.CompanyID; model.ContentType = fileUpload.PostedFile.ContentType; model.FileID = 0; model.FileSize = fileUpload.PostedFile.ContentLength; if (string.IsNullOrEmpty(txtFileTitle.Text)) { model.FileTitle = Path.GetFileName(fileUpload.FileName); model.FileTitle = model.FileTitle.Substring(0, model.FileTitle.LastIndexOf(".")); } else { model.FileTitle = txtFileTitle.Text; } model.IsDelete = false; model.IsPublic = UserInfo.Role == RolesEnum.CLIENT; model.SourceType = (int)FileSourceType.Project; model.ProjectId = id; model.ThumbPath = Path.GetFileName(fileUpload.PostedFile.FileName); model.IsDelete = false; FileApplication fileApp = new FileApplication(); int result = fileApp.AddFile(model); OperateDocManagements.OperateDocManagementSoapClient client = new OperateDocManagements.OperateDocManagementSoapClient(); List <FilesEntity> clientFiles = new List <FilesEntity>(); clientFiles.Add(model); client.AddDocManagement(Newtonsoft.Json.JsonConvert.SerializeObject(clientFiles)); if (result <= 0) { Redirect("File upload error.", "AddProjectFile.aspx?ID" + QS("ID")); } else { Redirect(EmptyPopPageUrl, false, true); } } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { if (IdentityContext.UserID <= 0) { return; } string isClient = context.Request["isClient"]; string projectIdList = context.Request["checkboxList"]; int uid = int.Parse(context.Request["uid"]); string[] projectIds = projectIdList.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); #region 获取已经分配了的project SearchProjectsRequest request = new SearchProjectsRequest(SearchProjectsType.ListByUserID , false, "projectId", "ASC"); request.UserID = uid; SearchProjectsResponse projectList = new ProjectApplication().SearchProjects(request); for (int i = 0; i < projectIds.Length; i++) { int projectId = 0; int.TryParse(projectIds[i], out projectId); ProjectDetailDTO project = projectList.ResultList.Find(t => t.ProjectID == projectId); if (project != null && project.ProjectID != 0) { context.Response.Write("some of the selected projects have been assigned to this user!"); return; } } #endregion List <BrokenRuleMessage> listmsgs = new List <BrokenRuleMessage>(); foreach (string projectId in projectIds) { ProjectUsersEntity model = ProjectsFactory.CreateProjectUser(IdentityContext.UserID , ObjectFactory.GetInstance <ISystemDateTime>()); model.ProjectID = int.Parse(projectId); model.UserID = uid; model.ISClient = Boolean.Parse(isClient); if (projApp.AssignUserToProject(model) < 0) { RecordMsg(listmsgs, projApp.BrokenRuleMessages); } } if (listmsgs.Count > 0) { context.Response.Write("Assign Fail!"); } else { context.Response.Write("The project has been assigned."); } } catch (Exception ex) { context.Response.Write("Input special symbol is not allowed,please check title and description!"); WebLogAgent.Write(string.Format("Error Ashx:DoAddTicketHandler.ashx Messages:\r\n{0}", ex)); return; } }
protected void Page_Load(object sender, EventArgs e) { app = new ProjectApplication(); ((Pop)this.Master).Width = 540; }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; try { if (IdentityContext.UserID <= 0) { return; } String statusValue = context.Request["statusValue"]; int tid = Convert.ToInt32(context.Request["tid"]); TicketsEntity ticketEntity = new TicketsEntity(); ticketEntity = ticketAPP.GetTickets(tid); TicketsState originalStatus = ticketEntity.Status; bool Update = true; bool isCompleteMsgInfo = false; if (statusValue == "pReview") { // if (HasDevOrQaUnderTicket(ticketEntity)) { ticketEntity.Status = TicketsState.PM_Reviewed; } else { context.Response.Write("696"); //context.Response.Write("Please assign user before you change status."); return; } } else if (statusValue == "pmReviewMaintenanceValidate") { ProjectApplication projectApplication = new ProjectApplication(); ProjectsEntity projectsEntity = projectApplication.Get(ticketEntity.ProjectID); if ((projectsEntity.MainPlanOption == UserMaintenancePlanOption.NO || projectsEntity.MainPlanOption == UserMaintenancePlanOption.NEEDAPPROVAL || projectsEntity.MainPlanOption == UserMaintenancePlanOption.ALLOWME) && ticketEntity.IsEstimates == false) { context.Response.Write("-1"); } else { context.Response.Write("1"); } return; } else if (statusValue == "approve") { isCompleteMsgInfo = true; ticketEntity.Status = TicketsState.Completed; } else if (statusValue == "deny") { ticketEntity.Status = TicketsState.Not_Approved; } else if (statusValue == "estApp") { ticketEntity.Status = TicketsState.Estimation_Approved; } else if (statusValue == "estDeny") { ticketEntity.Status = TicketsState.Estimation_Fail; } else if (statusValue == "notBug") { ticketEntity.ConvertDelete = CovertDeleteState.NotABug; } else if (statusValue == "isBug") { ticketEntity.ConvertDelete = CovertDeleteState.Normal; notSendEmail = true; } else if (statusValue == "toEs") { ticketEntity.IsEstimates = true; ChangeToEs = false; } else if (statusValue == "toNotEs") { ticketEntity.IsEstimates = false; } bool IsPass = true; #region //validate if (statusArray.Contains(statusValue)) { if (!BaseValidate(originalStatus, ticketEntity.Status)) { IsPass = false; } } else { if (!NostatusArray.Contains(statusValue)) { if (BaseValidate(originalStatus, (TicketsState)Enum.Parse(typeof(TicketsState), statusValue))) { ticketEntity.Status = (TicketsState)Enum.Parse(typeof(TicketsState), statusValue); } else { IsPass = false; } } } if (!IsPass) { context.Response.Write("same"); return; } #endregion ticketEntity.ModifiedOn = DateTime.Now; ticketEntity.ModifiedBy = IdentityContext.UserID; ticketEntity.PublishDate = DateTime.Now.Date; Update = ticketAPP.UpdateTickets(ticketEntity); #region send email if (!notSendEmail) { if (ChangeToEs) { ticketStatusMgr.SendEmailToSalerWithStatusToEs(ticketEntity); } else { if (statusValue == "notBug") { ticketStatusMgr.SendEmailToAllUserUnderProjectWithNotABug(ticketEntity); } else if (ticketEntity.Status == TicketsState.Ready_For_Review) { ticketStatusMgr.SendEmailtoClientForVerify(ticketEntity); } else if (ticketEntity.Status == TicketsState.Not_Approved) { ticketStatusMgr.SendEmailWithClientNotApp(ticketEntity); } else if (ticketEntity.Status == TicketsState.Waiting_For_Estimation) { ticketStatusMgr.SendEmailToAssignedUserTs(ticketEntity); } else if (ticketEntity.Status == TicketsState.Waiting_Sales_Confirm) { ticketStatusMgr.SendEmailToSalerWithStatusToEs(ticketEntity); } else if (ticketEntity.Status == TicketsState.Tested_Fail_On_Local || ticketEntity.Status == TicketsState.Testing_On_Local || ticketEntity.Status == TicketsState.Tested_Success_On_Local || ticketEntity.Status == TicketsState.Tested_Fail_On_Client || ticketEntity.Status == TicketsState.Testing_On_Client || ticketEntity.Status == TicketsState.Tested_Success_On_Client || ticketEntity.Status == TicketsState.Cancelled) { ticketStatusMgr.SendEmailToUserWithSpecStatus(ticketEntity); if (ticketEntity.Status == TicketsState.Tested_Success_On_Client) { ticketStatusMgr.SendEmailToUserWithTestRSuccToPm(ticketEntity); } } else { if (ticketEntity.Status != TicketsState.Developing) { ticketStatusMgr.SendEmailToQaAndDevWhenStatusChanged(ticketEntity); } } } } #endregion if (Update) { if (statusValue == "notBug") { context.Response.Write("Question sent, please wait for PM to verify."); } else { if (isCompleteMsgInfo) { context.Response.Write("The ticket has been approved."); } else { context.Response.Write("The ticket’s status has been updated."); } } } else { context.Response.Write("Update ticket’s status fail."); } } catch (Exception ex) { context.Response.Write("para error!" + ex.Message); WebLogAgent.Write(string.Format("Error Ashx:DoUpdateTicketStatus.ashx Messages:\r\n{0}", ex)); return; } }
private void InitProjects() { ProjectApplication projApp = new ProjectApplication(); projApp.GetUserProjects(UserInfo).BindDropdown(ddlProjects, "Title", "ID", "Please select", "0"); }
public ProjectController(ProjectApplication projectApp) => this.ProjectApp = projectApp;
protected void Page_Load(object sender, EventArgs e) { int userID = QS("user", 0); int projectID = QS("project", 0); if (userID == 0 || projectID == 0) { this.Alert("Current Page get an error,please check your argument!", "/Pto/Pto.aspx?viewmodel=detailmodel"); } UserApplication userApp = new UserApplication(); this.SelectedUser = userApp.GetUser(userID); ProjectApplication projApp = new ProjectApplication(); this.SelectedProject = projApp.Get(projectID); //DateTime startDate = DateTime.MinValue; //DateTime endDate = DateTime.MinValue; //DateTime.TryParse(Request.QueryString["startdate"], out startDate); //DateTime.TryParse(Request.QueryString["enddate"], out endDate); DateTime StartDate; DateTime EndDate; if (!DateTime.TryParse(Request.QueryString["year"], out StartDate)) { StartDate = new DateTime(1753, 1, 1); EndDate = new DateTime(2200, 1, 1);; } else { EndDate = StartDate.AddYears(1).AddDays(-1); } _eventsApplication = new EventsApplication(); DataTable evdt = _eventsApplication.GetPtoByProjectUser(projectID, userID, StartDate, EndDate); IList <PtoUserView> eventPtolist = ModelConvertHelper <PtoUserView> .ConvertToModel(evdt); List <PtoUserDetailView> ptoUserDetailViews = new List <PtoUserDetailView>(); if (eventPtolist != null && eventPtolist.Count > 0) { foreach (var t in eventPtolist) { PtoUserDetailView ptoUserDetailView = new PtoUserDetailView { Title = t.Title, Name = t.Name, Details = t.Details }; double hours = 0; if (t.Office == "CN") { #region if (t.AllDay) { if (t.ToDay.Date == t.FromDay.Date) { hours += 8; } else { var days = t.ToDay.Day - t.FromDay.Day + 1; hours = hours + days * 8; } ptoUserDetailView.FromDay = t.FromDay.Date.AddHours(8).AddMinutes(30); ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(17).AddMinutes(30); } if (!t.AllDay) { var fromTime = t.FromTime.Split(':'); var toTime = t.ToTime.Split(':'); DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "HH:mm"; var fromTimeHour = Int32.Parse(fromTime[0]); var fromtimeMinutes = Int32.Parse(fromTime[1]); var toTimeHour = Int32.Parse(toTime[0]); var toTimeMinutes = Int32.Parse(toTime[1]); var fromTimeDate = Convert.ToDateTime(t.FromTime, dtFormat); var toTimeDate = Convert.ToDateTime(t.ToTime, dtFormat); var workTime = Convert.ToDateTime("8:30", dtFormat); var restTimeBegin = Convert.ToDateTime("12:30", dtFormat); var restTimeEnd = Convert.ToDateTime("13:30", dtFormat); var closeTime = Convert.ToDateTime("17:30", dtFormat); if (t.FromTimeType == 2) { if (fromTimeHour <= 5) { fromTimeDate = Convert.ToDateTime(t.FromTime, dtFormat).AddHours(12); } } if (t.FromTimeType == 1) { if (fromTimeHour == 12) { fromTimeDate = workTime; } } if (t.ToTimeType == 2) { if (toTimeHour <= 5) { toTimeDate = Convert.ToDateTime(t.ToTime, dtFormat).AddHours(12); } if (5 < toTimeHour && toTimeHour < 12) { toTimeDate = closeTime; } } if (toTimeDate < restTimeBegin) { hours = hours + (toTimeDate - fromTimeDate).TotalHours; } if (toTimeDate > restTimeEnd) { hours = hours + (restTimeBegin - fromTimeDate).TotalHours; hours = hours + (toTimeDate - restTimeEnd).TotalHours; } if (t.FromTimeType == 1) { ptoUserDetailView.FromDay = t.FromDay.Date.AddHours(fromTimeHour).AddMinutes(fromtimeMinutes); } else { if (fromTimeHour <= 5) { ptoUserDetailView.FromDay = t.FromDay.Date.AddHours(fromTimeHour).AddHours(12).AddMinutes(fromtimeMinutes); } } if (t.ToTimeType == 1) { ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(toTimeHour).AddMinutes(toTimeMinutes); } else { if (toTimeHour <= 5) { ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(toTimeHour).AddHours(12).AddMinutes(toTimeMinutes); } if (toTimeHour > 5 && toTimeHour < 12) { ptoUserDetailView.ToDay = closeTime; } if (toTimeHour == 12) { ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(12).AddMinutes(toTimeMinutes); } } } #endregion } else { var workTimes = _eventsApplication.GetWorkTime(t.UserID); var worksViews = workTimes.Select(k => new WorkTimeView { FromTime = k.FromTime, ToTime = k.ToTime, FromTimeType = k.FromTimeType, ToTimeType = k.ToTimeType }).OrderBy(c => c.FromDate).ToList(); if (!worksViews.Any()) { #region if (t.AllDay) { if (t.ToDay.Date == t.FromDay.Date) { hours += 8; } else { var days = t.ToDay.Day - t.FromDay.Day + 1; hours = hours + days * 8; } ptoUserDetailView.FromDay = t.FromDay.Date.AddHours(8).AddMinutes(30); ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(17).AddMinutes(30); } if (!t.AllDay) { var fromTime = t.FromTime.Split(':'); var toTime = t.ToTime.Split(':'); DateTimeFormatInfo dtFormat = new DateTimeFormatInfo(); dtFormat.ShortDatePattern = "HH:mm"; var fromTimeHour = Int32.Parse(fromTime[0]); var fromtimeMinutes = Int32.Parse(fromTime[1]); var toTimeHour = Int32.Parse(toTime[0]); var toTimeMinutes = Int32.Parse(toTime[1]); var fromTimeDate = Convert.ToDateTime(t.FromTime, dtFormat); var toTimeDate = Convert.ToDateTime(t.ToTime, dtFormat); var workTime = Convert.ToDateTime("8:30", dtFormat); var restTimeBegin = Convert.ToDateTime("12:30", dtFormat); var restTimeEnd = Convert.ToDateTime("13:30", dtFormat); var closeTime = Convert.ToDateTime("17:30", dtFormat); if (t.FromTimeType == 2) { if (fromTimeHour <= 5) { fromTimeDate = Convert.ToDateTime(t.FromTime, dtFormat).AddHours(12); } } if (t.FromTimeType == 1) { if (fromTimeHour == 12) { fromTimeDate = workTime; } } if (t.ToTimeType == 2) { if (toTimeHour <= 5) { toTimeDate = Convert.ToDateTime(t.ToTime, dtFormat).AddHours(12); } if (5 < toTimeHour && toTimeHour < 12) { toTimeDate = closeTime; } } if (toTimeDate < restTimeBegin) { hours = hours + (toTimeDate - fromTimeDate).TotalHours; } if (toTimeDate > restTimeEnd) { hours = hours + (restTimeBegin - fromTimeDate).TotalHours; hours = hours + (toTimeDate - restTimeEnd).TotalHours; } if (t.FromTimeType == 1) { ptoUserDetailView.FromDay = t.FromDay.Date.AddHours(fromTimeHour).AddMinutes(fromtimeMinutes); } else { if (fromTimeHour <= 5) { ptoUserDetailView.FromDay = t.FromDay.Date.AddHours(fromTimeHour).AddHours(12).AddMinutes(fromtimeMinutes); } } if (t.ToTimeType == 1) { ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(toTimeHour).AddMinutes(toTimeMinutes); } else { if (toTimeHour <= 5) { ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(toTimeHour).AddHours(12).AddMinutes(toTimeMinutes); } if (toTimeHour > 5 && toTimeHour < 12) { ptoUserDetailView.ToDay = closeTime; } if (toTimeHour == 12) { ptoUserDetailView.ToDay = t.ToDay.Date.AddHours(12).AddMinutes(toTimeMinutes); } } } #endregion } else { var mindate = worksViews.Min(x => x.FromDate); var maxdate = worksViews.Max(x => x.ToDate); #region if (t.AllDay) { if (t.ToDay.Date == t.FromDay.Date) { hours += 8; } else { var days = t.ToDay.Day - t.FromDay.Day + 1; hours = hours + days * 8; } ptoUserDetailView.FromDay = mindate; ptoUserDetailView.ToDay = maxdate; } else { #region DateTimeFormatInfo dtFormat = new DateTimeFormatInfo { ShortDatePattern = "HH:mm" }; var fromTime = t.FromTime.Split(':'); var toTime = t.ToTime.Split(':'); var fromTimeHour = Int32.Parse(fromTime[0]); var fromtimeMinutes = Int32.Parse(fromTime[1]); var toTimeHour = Int32.Parse(toTime[0]); var toTimeMinutes = Int32.Parse(toTime[1]); var fromTimeDate = Convert.ToDateTime(t.FromTime, dtFormat); var toTimeDate = Convert.ToDateTime(t.ToTime, dtFormat); foreach (var g in worksViews) { var workTime = g.FromDate; var closeTime = g.ToDate; switch (t.FromTimeType) { case 1: fromTimeDate = fromTimeHour == 12 ? Convert.ToDateTime("00:" + fromtimeMinutes, dtFormat) : Convert.ToDateTime(t.FromTime, dtFormat); break; case 2: fromTimeDate = fromTimeHour == 12 ? Convert.ToDateTime(t.FromTime, dtFormat) : Convert.ToDateTime(t.FromTime, dtFormat).AddHours(12); break; } switch (t.ToTimeType) { case 1: toTimeDate = toTimeHour == 12 ? Convert.ToDateTime("00:" + toTimeMinutes, dtFormat) : Convert.ToDateTime(t.ToTime, dtFormat); break; case 2: toTimeDate = toTimeHour == 12 ? Convert.ToDateTime(t.ToTime, dtFormat) : Convert.ToDateTime(t.ToTime, dtFormat).AddHours(12); break; } if (fromTimeDate <= workTime && closeTime <= toTimeDate) { if ((closeTime - workTime).TotalHours < 0) { continue; } hours = hours + (closeTime - workTime).TotalHours; } if (fromTimeDate <= workTime && closeTime > toTimeDate) { if ((toTimeDate - workTime).TotalHours < 0) { continue; } hours = hours + (toTimeDate - workTime).TotalHours; } if (fromTimeDate > workTime && closeTime <= toTimeDate) { if ((closeTime - fromTimeDate).TotalHours < 0) { continue; } hours = hours + (closeTime - fromTimeDate).TotalHours; } if (fromTimeDate > workTime && closeTime > toTimeDate) { if ((toTimeDate - fromTimeDate).TotalHours < 0) { continue; } hours = hours + (toTimeDate - fromTimeDate).TotalHours; } } ptoUserDetailView.FromDay = t.FromTimeType == 1 ? t.FromDay.Date.AddHours(fromTimeHour == 12 ? 0 : fromTimeHour).AddMinutes(fromtimeMinutes) : t.FromDay.Date.AddHours(fromTimeHour == 12 ? 0 : fromTimeHour).AddHours(12).AddMinutes(fromtimeMinutes); ptoUserDetailView.ToDay = t.ToTimeType == 1 ? t.ToDay.Date.AddHours(toTimeHour == 12 ? 0 : toTimeHour).AddMinutes(toTimeMinutes) : t.ToDay.Date.AddHours(toTimeHour == 12 ? 0 : toTimeHour).AddHours(12).AddMinutes(toTimeMinutes); #endregion } #endregion } } ptoUserDetailView.Hours = hours; ptoUserDetailViews.Add(ptoUserDetailView); } this.ptoDetail.DataSource = ptoUserDetailViews; this.ptoDetail.DataBind(); } else { ShowFailMessageToClient("There is no records "); } litUserName.Text = SelectedUser.FirstName + " " + SelectedUser.LastName; if (ptoUserDetailViews.Any()) { foreach (var t in ptoUserDetailViews) { _totalHours += t.Hours; } } litTotalhours.Text = _totalHours.ToString("#0.00") + " h"; }