/// <summary> /// Gets the available colour options /// </summary> /// <param name="showOneColour">Include the "one colour" option?</param> /// <returns>List of colour options</returns> public static List<PrintColourInfo> GetColourInfo(bool showOneColour) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); List<PrintColourInfo> results = db.PrintColourInfos.ToList(); if (showOneColour) results.RemoveAt(results.Count); // removes the last item (the one colour option) return results; }
/// <summary> /// Gets the user ID based on username /// </summary> /// <param name="username">Username of the user</param> /// <returns>ID of user, or null</returns> public static int? GetUserID(String username) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); var q = (from w in db.Users where w.Username == username select w.ID).FirstOrDefault(); return q; }
/// <summary> /// Submit the form! /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { btnSubmit.Enabled = false; // prevent double submission // from the information provided, create us a due date to store DateTime? duedate; if (ddAdType.SelectedValue.Equals("1")) { String strDate = DateTime.Now.Year + "/" + ddAiringMonth.SelectedValue + "/01"; duedate = strDate.ConvertToDate(); if (duedate.HasValue && duedate < DateTime.Now) duedate = duedate.Value.AddYears(1); } else duedate = (DateTime)txtStartAiringDate.Text.ConvertToDate(); // submit! using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { // skip the approval process for designers and coordinators bool IsUserDesigner = Users.IsUserDesigner(); bool NeedsApproval = !IsUserDesigner && !Users.IsUserCoordinator(); Workorder w = new Workorder(); w.submitted_date = DateTime.Now; w.submitted_by = Function.GetUserName(); w.wotype = 3; w.duedate = duedate; w.ProgramManager = int.Parse(ddCoordinators.SelectedValue); w.title = "Radio Ad"; w.status = NeedsApproval ? 1 : 2; db.Workorders.InsertOnSubmit(w); WorkOrdersRadio r = new WorkOrdersRadio(); r.Workorder = w; r.AdType = int.Parse(ddAdType.SelectedValue); r.AiringMonth = ddAiringMonth.SelectedIndex > 0 ? int.Parse(ddAiringMonth.SelectedValue) : (int?)null; r.RadioStation = ddRadioStation.SelectedIndex > 0 ? int.Parse(ddRadioStation.SelectedValue) : (int?)null; r.RadioStationOther = txtRadioStationOther.Text; r.LengthOfAd = ddLengthOfAd.SelectedIndex > 0 ? int.Parse(ddLengthOfAd.SelectedValue) : (int?)null; r.StartAiringDate = txtStartAiringDate.Text.ConvertToDate(); r.EndAiringDate = txtEndAiringDate.Text.ConvertToDate(); r.Budget = txtBudget.Text; r.RecordingOptions = ddRecordingOptions.SelectedIndex > 0 ? int.Parse(ddRecordingOptions.SelectedValue) : (int?)null; r.Notes = txtNotes.Text; db.WorkOrdersRadios.InsertOnSubmit(r); db.SubmitChanges(); int ID = w.ID; // upload attached files WO.UploadFiles(w.ID, AttachedFiles.UploadedFiles); // log the activity WO.LogAction(ID, "Work order created"); // send notificaiton if needed WO.SendNewWONotification(ID, NeedsApproval, IsUserDesigner); // complete! Response.Redirect("~/MyWorkOrders.aspx?success=true&ID=" + ID + "&type=" + w.wotype); } }
/// <summary> /// Toggles the status of a user (active to inactive and vice versa) /// </summary> /// <param name="ID">ID of a specific user</param> /// <returns>Updated Status (boolean)</returns> public static bool? SetUserStatus(int ID) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); User u = db.Users.Single(i => i.ID == ID); if (u == null) return null; u.Active = !u.Active; db.SubmitChanges(); return u.Active; }
/// <summary> /// Submit the form! /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { btnSubmit.Enabled = false; // prevent double submission using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { // if the user doesn't need approval, skip the approval process bool IsUserDesigner = Users.IsUserDesigner(); bool NeedsApproval = !IsUserDesigner && !Users.IsUserCoordinator(); Workorder w = new Workorder(); w.submitted_date = DateTime.Now; w.submitted_by = Function.GetUserName(); if (Request.QueryString["quote"] != null && Request.QueryString["quote"].Equals("1")) w.wotype = 5; else w.wotype = 1; w.duedate = txtDueDate.Text.ConvertToDate(); w.ProgramManager = int.Parse(ddCoordinators.SelectedValue); w.title = txtPubTitle.Text; w.status = NeedsApproval ? 1 : 2; db.Workorders.InsertOnSubmit(w); WorkOrdersPrint p = new WorkOrdersPrint(); p.Workorder = w; p.ProjectType = int.Parse(ddTypeProject.SelectedValue); p.ProjectTypeOther = txtProjectOther.Text; p.TypeOfDisplay = ddTypeOfDisplay.SelectedIndex > 0 ? int.Parse(ddTypeOfDisplay.SelectedValue) : (int?)null; p.TypeOfDisplayOther = txtDisplayOther.Text; p.PromoItem = txtPromoItem.Text; p.PrintingMethod = int.Parse(ddPrintingMethod.SelectedValue); p.Budget = txtBudget.Text; p.PaperSize = int.Parse(ddPaperSize.SelectedValue); p.CustomPaperSize = txtCustomPaperSize.Text; p.PaperType = int.Parse(ddPaperType.SelectedValue); p.ColourInfo = int.Parse(ddColourInfo.SelectedValue); p.NumberCopies = txtNumberCopies.Text; p.FullBleed = ddFullBleed.Value; p.Credit = int.Parse(ddCredits.SelectedValue); p.CreditName = txtCreditName.Text; p.Notes = txtNotes.Text; db.WorkOrdersPrints.InsertOnSubmit(p); db.SubmitChanges(); int ID = p.wID; // upload attached files WO.UploadFiles(w.ID, AttachedFiles.UploadedFiles); // log the activity WO.LogAction(ID, "Work order created"); // send notification (if necessary) WO.SendNewWONotification(ID, NeedsApproval, IsUserDesigner); // if the user added the option to add to the website, transfer user to web work order page if (ddAddToWebsite.Value == true) Response.Redirect("~/Create/Web.aspx?AddTo=" + ID); else // if not, success!! Response.Redirect("~/MyWorkOrders.aspx?success=true&ID=" + ID + "&type=" + w.wotype.ToString()); } }
/// <summary> /// Saves changes to the user account /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSubmit_Click(object sender, EventArgs e) { using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { int ID = int.Parse(Request.QueryString["ID"]); User u = db.Users.Single(z => z.ID == ID); u.Username = txtUsername.Text; u.FullName = txtFullName.Text; u.Email = txtEmail.Text; u.Role = int.Parse(ddRole.SelectedValue); db.SubmitChanges(); notSuccess.Visible = true; } }
/// <summary> /// Gets a report based on work orders by coordinator /// </summary> /// <param name="startDate">Start date</param> /// <param name="endDate">End date</param> /// <returns>List of work orders assigned to coordinators</returns> public static List<CoordinatorReport> ByCoordinator(DateTime startDate, DateTime endDate) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); // make sure we don't include the deleted work orders! var q = from w in db.Workorders where w.submitted_date.Date >= startDate.Date && w.submitted_date <= endDate.Date && w.status < 7 group w by w.User.FullName into g select new CoordinatorReport { CoordinatorName = g.Key, Count = g.Count() }; return q.ToList(); }
/// <summary> /// Formats a list of locations (stored as IDs) and creates a nice display string /// </summary> /// <param name="loc">Location string (as IDs)</param> /// <returns></returns> public static string DisplayLocations(string loc) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); string [] locations = loc.Split(new Char [] {','}); string output = String.Empty; for (int i = 0; i < locations.Length-1; i++) { var q = (from w in db.WebLocations where w.ID == int.Parse(locations[i]) select w.Value).FirstOrDefault(); output += q.ToString() + "; "; } return output; }
/// <summary> /// Gets a report based on work orders by print type /// </summary> /// <param name="startDate">Start date</param> /// <param name="endDate">End date</param> /// <returns>List of work orders grouped by print type</returns> public static List<PrintReport> ByPrintType(DateTime startDate, DateTime endDate) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); // make sure not to include deleted work orders var q = from w in db.WorkOrdersPrints where w.Workorder.submitted_date.Date >= startDate.Date && w.Workorder.submitted_date <= endDate.Date && w.Workorder.status < 7 && w.Workorder.WOType1.type.Equals("Print") group w by w.lookupPrintTypeOfProject.Value into g select new PrintReport { PrintType = g.Key, Count = g.Count() }; return q.ToList(); }
/// <summary> /// Get all of the users in the system. Users are only in the system if they have elevated priveleges (program managers, designers or admins) /// </summary> /// <returns>List of users with viewable details</returns> public static List<UserDetails> GetUsers() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); var q = from u in db.Users select new UserDetails { ID = u.ID, Username = u.Username, Role = u.UserRole.Role, Fullname = u.FullName, Email = u.Email, Active = u.Active }; return q.ToList(); }
/// <summary> /// Takes the video destinations from db (stored as IDs) and displays them in a nice format /// </summary> /// <param name="loc">Location string</param> /// <returns>Locations (nice format)</returns> public static string DisplayFormats(string loc) { using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { string[] formats = loc.Split(new Char[] { ',' }); string output = String.Empty; for (int i = 0; i < formats.Length - 1; i++) { var q = (from w in db.VideoDestinations where w.ID == int.Parse(formats[i]) select w.Value).FirstOrDefault(); output += q.ToString() + "; "; } return output; } }
public static void ChangeUserName(string oldusername, string newusername, int workorders, int activities) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); if (workorders > 0) { var wo = db.Workorders.Where(u => u.submitted_by == oldusername).ToList(); wo.ForEach(w => w.submitted_by = newusername); db.SubmitChanges(); } if (activities > 0) { var act = db.LogActivities.Where(u => u.username == oldusername).ToList(); act.ForEach(a => a.username = newusername); db.SubmitChanges(); } }
/// <summary> /// Submit the form /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { btnSubmit.Enabled = false; // prevent double entry using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { // skip approval process for designers and program managers (coordinators) bool IsUserDesigner = Users.IsUserDesigner(); bool NeedsApproval = !IsUserDesigner && !Users.IsUserCoordinator(); Workorder w = new Workorder(); w.submitted_date = DateTime.Now; w.submitted_by = Function.GetUserName(); w.wotype = 6; w.duedate = txtDueDate.Text.ConvertToDate(); w.ProgramManager = int.Parse(ddCoordinators.SelectedValue); w.title = txtTitleVideo.Text; w.status = NeedsApproval ? 1 : 2; db.Workorders.InsertOnSubmit(w); WorkOrdersVideo v = new WorkOrdersVideo(); v.Workorder = w; v.VideoSource = int.Parse(ddVideoSource.SelectedValue); v.VideoDestination = Function.GetChecklistItems(chkVideoDestination); v.DestinationURL = txtDestinationURL.Text; v.NumberDVDs = txtNumberDVDs.Text; v.VideoLength = txtVideoLength.Text; v.BackgroundMusic = ddBackgroundMusic.Value; v.SongChoices = txtSongChoices.Text; v.NarrationReqd = ddNarrationRequired.Value; v.Narrator = ddNarrator.SelectedIndex > 0 ? ddNarrator.SelectedIndex : (int?)null; v.VideoDescription = txtVideoDescription.Text; v.CreditsRequired = ddCreditsRequired.Value; v.Notes = txtNotes.Text; db.WorkOrdersVideos.InsertOnSubmit(v); db.SubmitChanges(); int ID = w.ID; // upload the attached files WO.UploadFiles(w.ID, AttachedFiles.UploadedFiles); // log it WO.LogAction(ID, "Work order created"); // send out the notifications if necessary WO.SendNewWONotification(ID, NeedsApproval, IsUserDesigner); // success! Response.Redirect("~/MyWorkOrders.aspx?success=true&ID=" + ID + "&type=" + w.wotype); } }
/// <summary> /// Submit the form! /// </summary> protected void btnSubmit_Click(object sender, EventArgs e) { btnSubmit.Enabled = false; // prevent double submission using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { // if the user is a designer or coordinator, they don't need to go through the approval process bool IsUserDesigner = Users.IsUserDesigner(); bool NeedsApproval = !IsUserDesigner && !Users.IsUserCoordinator(); Workorder w = new Workorder(); w.submitted_date = DateTime.Now; w.submitted_by = Function.GetUserName(); w.wotype = 4; w.duedate = txtDateToIssue.Text.ConvertToDate(); w.ProgramManager = int.Parse(ddCoordinators.SelectedValue); w.title = txtTitleTopic.Text; w.status = NeedsApproval ? 1 : 2; db.Workorders.InsertOnSubmit(w); WorkOrdersNews n = new WorkOrdersNews(); n.Workorder = w; n.DistributionOutlets = int.Parse(ddDistributionOutlets.SelectedValue); n.DistributionDetails = txtDistributionOutletsOther.Text; n.Contact = txtContact.Text; n.AdditionalNotes = txtNotes.Text; db.WorkOrdersNews.InsertOnSubmit(n); db.SubmitChanges(); int ID = w.ID; // look after the files WO.UploadFiles(w.ID, AttachedFiles.UploadedFiles); // log the work order WO.LogAction(ID, "Work order created"); // send notification as needed WO.SendNewWONotification(ID, NeedsApproval, IsUserDesigner); // move on! Response.Redirect("~/MyWorkOrders.aspx?success=true&ID=" + ID + "&type=" + w.wotype); } }
protected void btnSubmit_Click(object sender, EventArgs e) { // let's make sure the username exists in AD... if (Classes.Users.DoesUserExist(txtUsername.Text)) { using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { // next, let's make sure the user isn't already in the system... if (db.Users.Any(u => u.Username == txtUsername.Text)) { notSuccess.Type = Notification.Types.Error; notSuccess.Message = "It looks like this user already exists in the system..."; notSuccess.Visible = true; } // let's create the user! else { User u = new User(); u.Username = txtUsername.Text; u.FullName = txtFullName.Text; u.Email = txtEmail.Text; u.Role = int.Parse(ddRole.SelectedValue); db.Users.InsertOnSubmit(u); db.SubmitChanges(); SendWelcomeEmail(u.Email); notSuccess.Visible = true; // clear the fields for next use txtFullName.Text = txtEmail.Text = txtUsername.Text = String.Empty; } } } // username doesn't exist else { notSuccess.Type = Notification.Types.Error; notSuccess.Message = "Sorry - it doesn't seem that this username exists..."; notSuccess.Visible = true; } }
/// <summary> /// Sets the status of a work order accordingly /// </summary> /// <param name="ID">Work order ID</param> /// <param name="newStatus">New status ID</param> /// <param name="notes">Program coordinator notes</param> private static void UpdateStatus(int ID, int newStatus, string notes) { using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { Workorder wo = db.Workorders.Single(w => w.ID == ID); wo.status = newStatus; // only modify the status if it's "approved with changes" if (newStatus == 3) wo.coordinatorNotes = notes; // we want to add this to the activity log as well LogActivity log = new LogActivity(); log.action = "Marked '" + wo.Status1.status + "'"; log.DateTime = DateTime.Now; log.username = Function.GetUserName(); log.wID = wo.ID; db.LogActivities.InsertOnSubmit(log); db.SubmitChanges(); } }
/// <summary> /// Send email notifications when a work order is approved /// </summary> /// <param name="ID">Work order ID</param> private static void SendApprovedNotification(int ID, bool NeededApproval) { // get the work order in question WOLinqClassesDataContext db = new WOLinqClassesDataContext(); Workorder wo = db.Workorders.Single(w => w.ID == ID); // get user's email address string email = Users.GetUserEmail(wo.submitted_by); // create the emails // one to the creator, one to the designers string subject = "Work Order Approved"; string opening = "Greetings!<br /><br />A workorder that you have submitted has been approved by " + Users.GetUsername() +".<br /><br />"; string linkurl = HttpContext.Current.Request.Url.Host + "/View/Default.aspx?type=" + wo.wotype + "&ID=" + ID; string message = "<a href='" + linkurl + "'>" + linkurl + "</a><br /><br />"; message += "Thank you,<br /><br />Your friendly neighbourhood Work Order System"; MailMessage mail = new MailMessage("*****@*****.**", email, subject, opening + message); mail.IsBodyHtml = true; // if the work order needed to be approved, let the work order creator know! if (NeededApproval) SendMail(mail); opening = "Greetings!<br /><br />A workorder has been approved and is ready for you to do your magic!<br /><br />"; opening += "Some quick details:<br />"; opening += "Due date: " + wo.duedate.DisplayDate() + "<br />"; opening += "Type of Project: " + wo.WOType1.type; // if it's a print work order, send them some additional details if (wo.WOType1.type.Equals("Print")) { WorkOrdersPrint p = PrintWO.GetPrintWorkOrder(ID); opening += " - " + p.PrintTypeOfProject.Value + " - " + wo.title; } opening += "<br /><br />"; opening+= "Follow this link to check out more details.<br /><br />"; mail = new MailMessage("*****@*****.**", "*****@*****.**", subject, opening + message); mail.IsBodyHtml = true; SendMail(mail); }
/// <summary> /// Removes a file entry from the db /// </summary> /// <param name="ID">File ID</param> /// <returns>Filepath (used by DeleteFile())</returns> private static string RemoveFile(int ID) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); File f = db.Files.Single(fi => fi.ID == ID); if (f == null) return String.Empty; else { String filepath = HttpContext.Current.Server.MapPath("~/uploads/" + f.wID + "/" + f.Filename); db.Files.DeleteOnSubmit(f); db.SubmitChanges(); return filepath; } }
/// <summary> /// Adds file information to the database /// </summary> /// <param name="wID">Work order ID</param> /// <param name="filename">Name of the file</param> /// <param name="IsRevision">Whether this was uploaded by a program manager</param> private static void AddFile(int wID, string filename, bool IsRevision) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); File f = new File(); f.wID = wID; f.Filename = filename; f.Revision = IsRevision; db.Files.InsertOnSubmit(f); db.SubmitChanges(); }
/// <summary> /// Finds the number of work orders associated with a user /// </summary> /// <param name="username"></param> /// <returns></returns> public static int WorkOrderCount(string username) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.Workorders.Where(u => u.submitted_by == username).Count(); }
/// <summary> /// Sends email notificaitons when a new work order is created /// </summary> /// <param name="ID">Work order ID</param> public static void SendNewWONotification(int ID, bool NeedsApproval, bool IsDesigner) { // if the work order needs to be approved, let the program manager know. if it doesn't, let the designers know that it's ready for them to work on! if (NeedsApproval) { // get work order WOLinqClassesDataContext db = new WOLinqClassesDataContext(); Workorder wo = db.Workorders.Single(w => w.ID == ID); // get program manager's email address string email = wo.User.Email; // create the email string subject = "Work Order Submitted - Requires Approval"; string message = "Greetings!<br /><br />A workorder has been submitted to the HNHU Communications team that requires your approval. Please proceed to the following link to approve the work order.<br /><br />"; string linkurl = HttpContext.Current.Request.Url.Host + "/View/Default.aspx?type=" + wo.wotype + "&ID=" + ID; message += "<a href='" + linkurl + "'>" + linkurl + "</a><br /><br />"; message += "Thank you,<br /><br />Your friendly neighbourhood Work Order System"; MailMessage mail = new MailMessage("*****@*****.**", email, subject, message); mail.IsBodyHtml = true; SendMail(mail); } else { // we don't want to send a notification to the designers - they already know about it! if (!IsDesigner) SendApprovedNotification(ID, NeedsApproval); } }
/// <summary> /// Adds an action to the activity log /// </summary> /// <param name="wID">Work order ID</param> /// <param name="action">Text that will be added to the activity log</param> public static void LogAction(int wID, string action) { using (WOLinqClassesDataContext db = new WOLinqClassesDataContext()) { LogActivity l = new LogActivity(); l.DateTime = DateTime.Now; l.wID = wID; l.username = Function.GetUserName(); l.action = action; db.LogActivities.InsertOnSubmit(l); db.SubmitChanges(); } }
/// <summary> /// Get a single radio work order /// </summary> /// <param name="ID">ID of work order</param> /// <returns>Single Radio Work Order object</returns> public static WorkOrdersRadio GetRadioWorkOrder(int ID) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.WorkOrdersRadios.Single(w => w.wID == ID); }
/// <summary> /// Get available radio ad types /// </summary> /// <returns>List of radio ad types</returns> public static List<RadioAdType> GetRadioAdTypes() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.RadioAdTypes.ToList(); }
/// <summary> /// Get available ad lengths /// </summary> /// <returns>List of ad lengths</returns> public static List<RadioLength> GetRadioAdLengths() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.RadioLengths.ToList(); }
/// <summary> /// Get a list of work orders /// </summary> /// <returns>List of work orders with details</returns> public static List<WorkOrderWithDetails> GetWorkOrders() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); var q = from w in db.Workorders select new WorkOrderWithDetails { ID = w.ID, submitted_by = w.submitted_by, submitted_date = w.submitted_date, ProgramManager = w.ProgramManager, coordinatorName = w.User.FullName, duedate = w.duedate, wotype = w.wotype, wotypeText = w.WOType1.type, title = w.title, status = w.status, statusText = w.Status1.status }; return q.ToList(); }
/// <summary> /// Get available radio stations /// </summary> /// <returns>List of radio stations</returns> public static List<RadioStations> GetRadioStations() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.RadioStations.ToList(); }
/// <summary> /// Get a list of work order types /// </summary> /// <returns>List of work order types</returns> public static List<WOType> GetWorkOrderTypes() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.WOTypes.ToList(); }
/// <summary> /// Get available recording options /// </summary> /// <returns>List of recording options</returns> public static List<RadioRecordingOption> GetRecordingOptions() { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); return db.RadioRecordingOptions.ToList(); }
/// <summary> /// Is the work order approved? /// </summary> /// <param name="ID">Work order ID</param> /// <returns>True/false</returns> public static bool IsApproved(int ID) { WOLinqClassesDataContext db = new WOLinqClassesDataContext(); Workorder wo = db.Workorders.Single(w => w.ID == ID); if (wo != null) { if (wo.status > 1 && wo.status < 7) return true; else return false; } else return false; }