protected void btnDeleteActor_Click(object sender, EventArgs e) { int iCharacterActorID; if (int.TryParse(hidDeleteActorID.Value, out iCharacterActorID)) { Classes.cActor cActor = new Classes.cActor(); cActor.CharacterActorID = iCharacterActorID; cActor.RecordStatus = Classes.RecordStatuses.Delete; cActor.Save(Master.UserID); _Reload = true; } }
protected void btnSaveActor_Click(object sender, EventArgs e) { oCharSelect.LoadInfo(); List <Classes.cActor> cActors = oCharSelect.CharacterInfo.Actors; int iCharacterActorID; if (int.TryParse(hidActorID.Value, out iCharacterActorID)) { Classes.cActor NewActor = new Classes.cActor(); NewActor.CharacterActorID = iCharacterActorID; NewActor.CharacterID = Convert.ToInt32(hidCharacterID.Value); NewActor.Comments = tbActorComments.Text; NewActor.StaffComments = tbActorStaffComments.Text; DateTime dtActorStartDate; if (DateTime.TryParse(tbActorStartDate.Text, out dtActorStartDate)) { NewActor.StartDate = dtActorStartDate; } DateTime dtActorEndDate; if (DateTime.TryParse(tbActorEndDate.Text, out dtActorEndDate)) { NewActor.EndDate = dtActorEndDate; } NewActor.RecordStatus = Classes.RecordStatuses.Active; if (ddlActorName.SelectedIndex >= 0) { int iActorID; if (int.TryParse(ddlActorName.SelectedValue, out iActorID)) { NewActor.loginUserName = ddlActorName.SelectedItem.Text; NewActor.UserID = iActorID; } } // If the record is already in the list, remove it so we don't have duplicates. cActors.RemoveAll(x => x.CharacterActorID == iCharacterActorID); cActors.Add(NewActor); // Now we go through and check all of the records for overlaps. var ActorList = cActors.OrderBy(x => x.StartDate).ToList(); hidActorDateProblems.Value = ""; if (ActorList.Count > 1) { // Now we get convoluted. Go through and check each record against the next record. // If the end date of the first record is null, make it 1 day less than the start // of the next record. // if Rec2.StartDate < Rec1.EndDate = raise problem. // Screen will already not allow the end date to be before the start date. for (int i = 0; i < (ActorList.Count - 1); i++) { // If the current record has no end date, fill it in with the date before the start of the next record. if (!ActorList[i].EndDate.HasValue) { ActorList[i].EndDate = ActorList[i + 1].StartDate.Value.AddDays(-1); } if (ActorList[i + 1].StartDate < ActorList[i].EndDate) { hidActorDateProblems.Value = "Y"; lblmodalError.Text = "With this change there are actors with overlapping dates.<br>Please reenter the corrected dates."; ScriptManager.RegisterStartupScript(this, this.GetType(), "Pop", "openError();", true); } } } if (String.IsNullOrEmpty(hidActorDateProblems.Value)) { NewActor.Save(Master.UserID); } _Reload = true; } }