Пример #1
0
        private void Save(bool isNew)
        {
            SchedulesEntity entity = new App.SchedulesApplication().GetInfo(int.Parse(hdID.Value));

            entity.Title       = txtTitle.Text;
            entity.Description = txtDescription.Text;
            entity.StartTime   = string.Format("{0}:{1}", ddlStartHours.SelectedValue, ddlStartMinute.SelectedValue);
            entity.EndTime     = string.Format("{0}:{1}", ddlEndHours.SelectedValue, ddlEndMinute.SelectedValue);
            entity.UpdateBy    = UserInfo.UserID;
            entity.UpdateOn    = DateTime.Now;

            int start = ScheduleTimeHelpers.TimeHandle(entity.StartTime);
            int end   = ScheduleTimeHelpers.TimeHandle(entity.EndTime);

            if (start > end)
            {
                ShowMessageToClient("Please entry again , Starting time should not exceed finishing time.", 0, false, false);
                return;
            }
            if (DateTime.Parse(string.Format("{0} {1}", entity.PlanDate.ToString("MM/dd/yyyy"), entity.StartTime)) < DateTime.Now)
            {
                ShowMessageToClient("Plan time not less than the current time.", 0, false, false);
                return;
            }

            for (int i = start; i < end; i++)
            {
                ScheduleTimeEntity t = ScheduleTimeList.Find(r => r.Cell == i && r.IsPlan && r.ScheduleID != entity.ID);
                if (t != null)
                {
                    ShowMessageToClient("The hours of the two schedules conflict.", 0, false, false);
                    return;
                }
            }

            if (chkMeeting.Checked)
            {
                List <UsersEntity> usersList = new List <UsersEntity>();
                foreach (ListItem li in lstMeetingUsers.Items)
                {
                    usersList.Add(new App.UserApplication().GetUser(int.Parse(li.Value)));
                }
                if (usersList.Find(r => r.UserID == UserInfo.UserID) == null) //如果不包括创建者,就添加他
                {
                    usersList.Add(UserInfo);
                }

                List <UsersEntity> moveSales = new App.SchedulesApplication().GetMeetingUsers(entity.MeetingID);
                List <UsersEntity> newList   = new List <UsersEntity>();
                UsersEntity        tmpUser;

                foreach (UsersEntity tmp in usersList)
                {
                    tmpUser = moveSales.Find(r => r.UserID == tmp.UserID);
                    if (tmpUser != null)
                    {
                        moveSales.Remove(tmpUser);
                    }
                    else
                    {
                        newList.Add(tmp);
                    }
                }

                if (new App.SchedulesApplication().Update(entity, moveSales, newList))
                {
                    if (isNew)
                    {
                        Server.Transfer("AddSchedules.aspx?Date=" + entity.PlanDate.ToString("MM/dd/yyyy"));
                    }
                    else
                    {
                        ShowSuccessMessageToClient(true, true);
                    }
                }
                else
                {
                    ShowFailMessageToClient();
                }
            }
            else
            {
                if (new App.SchedulesApplication().Update(entity))
                {
                    if (isNew)
                    {
                        Server.Transfer("AddSchedules.aspx?Date=" + entity.PlanDate.ToString("MM/dd/yyyy"));
                    }
                    else
                    {
                        ShowSuccessMessageToClient(true, true);
                    }
                }
                else
                {
                    ShowFailMessageToClient();
                }
            }
        }
Пример #2
0
        private void Save(bool isNew)
        {
            SchedulesEntity entity = new App.SchedulesApplication().GetInfo(int.Parse(hdID.Value));

            entity.Title       = txtTitle.Text;
            entity.Description = txtDescription.Text;
            entity.StartTime   = string.Format("{0}:{1}", ddlStartHours.SelectedValue, ddlStartMinute.SelectedValue);
            entity.EndTime     = string.Format("{0}:{1}", ddlEndHours.SelectedValue, ddlEndMinute.SelectedValue);
            entity.UpdateBy    = UserInfo.UserID;
            entity.UpdateOn    = DateTime.Now;

            int start = ScheduleTimeHelpers.TimeHandle(entity.StartTime);
            int end   = ScheduleTimeHelpers.TimeHandle(entity.EndTime);

            if (string.IsNullOrEmpty(entity.Title))
            {
                ShowFailMessageToClient("Please enter the title.");
                return;
            }
            if (start > end)
            {
                ShowFailMessageToClient("Please entry again , Starting time should not exceed finishing time.");
                return;
            }

            if (DateTime.Parse(string.Format("{0} {1}", entity.PlanDate.ToString("MM/dd/yyyy"), entity.StartTime)) < DateTime.Now)
            {
                ShowFailMessageToClient("Plan time not less than the current time.");
                return;
            }

            for (int i = start; i < end; i++)
            {
                ScheduleTimeEntity t = ScheduleTimeList.Find(r => r.Cell == i && r.IsPlan);
                if (t != null)
                {
                    ShowFailMessageToClient("The hours of the two schedules conflict.");
                    return;
                }
            }

            if (chkMeeting.Checked)
            {
                List <UsersEntity> usersList = new List <UsersEntity>();
                for (int i = 0; i < this.rtpUser.Items.Count; i++)
                {
                    CheckBox check = (CheckBox)this.rtpUser.Items[i].FindControl("cbUser");
                    if (check.Checked)
                    {
                        Literal lit = this.rtpUser.Items[i].FindControl("ltlid") as Literal;
                        usersList.Add(new App.UserApplication().GetUser(int.Parse(lit.Text)));
                    }
                }
                if (usersList.Find(r => r.UserID == UserInfo.UserID) == null) //如果不包括创建者,就添加他
                {
                    usersList.Add(UserInfo);
                }

                List <UsersEntity> moveSales = new App.SchedulesApplication().GetMeetingUsers(entity.MeetingID);
                List <UsersEntity> newList   = new List <UsersEntity>();
                UsersEntity        tmpUser;

                foreach (UsersEntity tmp in usersList)
                {
                    tmpUser = moveSales.Find(r => r.UserID == tmp.UserID);
                    if (tmpUser != null)
                    {
                        moveSales.Remove(tmpUser);
                    }
                    else
                    {
                        newList.Add(tmp);
                    }
                }

                if (new App.SchedulesApplication().Update(entity, moveSales, newList))
                {
                    if (isNew)
                    {
                        Redirect("Add.aspx?Date=" + entity.PlanDate.ToString("MM/dd/yyyy"), true);
                    }
                    else
                    {
                        Redirect(EmptyPopPageUrl, false, true);
                    }
                }
                else
                {
                    ShowFailMessageToClient();
                }
            }
            else
            {
                if (new App.SchedulesApplication().Update(entity))
                {
                    if (isNew)
                    {
                        Redirect("Add.aspx?Date=" + entity.PlanDate.ToString("MM/dd/yyyy"), true);
                    }
                    else
                    {
                        Redirect(EmptyPopPageUrl, false, true);
                    }
                }
                else
                {
                    ShowFailMessageToClient();
                }
            }
        }
Пример #3
0
        private string Edit(string title, string description, SchedulesEntity entity, string startTime
                            , string endTime, bool isMeeting, List <string> meetingUserIDs)
        {
            entity.Title       = title.NoHTML();
            entity.Description = description.NoHTML();
            entity.StartTime   = startTime;
            entity.EndTime     = endTime;
            entity.UpdateBy    = UserID;
            entity.UpdateOn    = DateTime.Now;

            string result = IsValidEditSchedule(entity, startTime, endTime);

            if (result != "1" && result != "-1")
            {
                return(result);
            }

            if (isMeeting)
            {
                List <UsersEntity> usersList = new List <UsersEntity>();
                foreach (string userID in meetingUserIDs)
                {
                    usersList.Add(new App.UserApplication().GetUser(int.Parse(userID)));
                }
                UsersEntity userInfo = new App.UserApplication().GetUser(UserID);
                if (usersList.Find(r => r.UserID == UserID) == null) //如果不包括创建者,就添加他
                {
                    usersList.Add(userInfo);
                }

                List <UsersEntity> moveSales = new App.SchedulesApplication().GetMeetingUsers(entity.MeetingID);
                List <UsersEntity> newList   = new List <UsersEntity>();
                UsersEntity        tmpUser;

                foreach (UsersEntity tmp in usersList)
                {
                    tmpUser = moveSales.Find(r => r.UserID == tmp.UserID);
                    if (tmpUser != null)
                    {
                        moveSales.Remove(tmpUser);
                    }
                    else
                    {
                        newList.Add(tmp);
                    }
                }

                if (new App.SchedulesApplication().Update(entity, moveSales, newList))
                {
                    return("1");
                }
                else
                {
                    return("Operation failed.");
                }
            }
            else
            {
                if (new App.SchedulesApplication().Update(entity))
                {
                    return("1");
                }
                else
                {
                    return("Operation failed.");
                }
            }
        }