using System; using System.Collections.Generic; using System.Drawing; using System.Text; using System.Windows.Forms; using VEPROMS.CSLA.Library; using LBOutlookLibrary; namespace VEPROMS { public partial class frmBatchRefreshCheckedOut : Form { public SessionInfo MySessionInfo { get; set; } public List CheckedOutProcedures { get; set; } private readonly int RType = -1; // C2023-002: Flag type of checkout, docversion -1 or procedures 0 public frmBatchRefreshCheckedOut(int type) { RType = type; InitializeComponent(); } private void frmBatchRefreshCheckedOut_FormClosing(object sender, FormClosingEventArgs e) { Owner.Show(); DialogResult = DialogResult.Cancel; } private void frmBatchRefreshCheckedOut_Load(object sender, EventArgs e) { Owner.Hide(); // B2023-051 check for a null list container and an empty list if (CheckedOutProcedures != null && CheckedOutProcedures.Count > 0) { foreach (ProcedureInfo pi in CheckedOutProcedures) AddToDisplayList(pi); tmrCheck.Enabled = true; } } private void AddToDisplayList(ProcedureInfo pi) { Panel p = new Panel { BorderStyle = BorderStyle.FixedSingle, Dock = DockStyle.Top, Height = 28 }; if (RType != 1) // C2023-002: only put out ForceCheckin & sendemail buttons if on procedures (can't check in a docversion) { Button b = new Button { Dock = DockStyle.Right, Text = "Force Check In", Tag = pi }; b.Click += new EventHandler(ForceCheckIn_Click); p.Controls.Add(b); b = new Button { //b.FlatStyle = FlatStyle.Popup; Dock = DockStyle.Right, Text = "Send Email", Tag = pi }; b.Click += new EventHandler(SendEmail_Click); p.Controls.Add(b); } Label l = new Label { Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleLeft, Text = $"Procedure {pi.DisplayNumber} is checked out to {UserInfo.GetByUserID(OwnerInfo.GetByItemID(pi.ItemID, CheckOutType.Procedure).SessionUserID).UserID}" }; p.Controls.Add(l); pnlList.Controls.Add(p); p.BringToFront(); pnlList.Focus(); } void SendEmail_Click(object sender, EventArgs e) { ProcedureInfo pi = (sender as Button).Tag as ProcedureInfo; OwnerInfo oi = OwnerInfo.GetByItemID(pi.ItemID, CheckOutType.Procedure); UserInfo ui = UserInfo.GetByUserID(oi.SessionUserID); UserConfig uc = new UserConfig(ui.Config); string subject = "Please Check In A Procedure"; if (uc.User_UserEmail != string.Empty) { if (!SendOutlookEmail(uc.User_UserEmail, subject, BuildEmailMessageBody(pi))) (sender as Button).Enabled = false; } else MessageBox.Show("No email has been defined for this user. You will need to Force Check In this procedure", "No Email"); } private string BuildEmailMessageBody(ProcedureInfo pi) { StringBuilder body = new StringBuilder(); body.AppendLine($"The administrator needs you to check in procedure {pi.DisplayNumber} so the administrator can continue an administrative tool process"); return body.ToString(); } void ForceCheckIn_Click(object sender, EventArgs e) { ProcedureInfo pi = (sender as Button).Tag as ProcedureInfo; OwnerInfo oi = OwnerInfo.GetByItemID(pi.ItemID, CheckOutType.Procedure); UserInfo ui = UserInfo.GetByUserID(oi.SessionUserID); UserConfig uc = new UserConfig(ui.Config); MySessionInfo.CheckInItem(oi.OwnerID); pnlList.Controls.Remove((sender as Button).Parent as Panel); if (uc.User_UserEmail != string.Empty) { string subject = "A Procedure Was Forced Checked In"; SendOutlookEmail(uc.User_UserEmail, subject, BuildForcedMessageBody(pi)); } else MessageBox.Show("No email has been defined for this user. The procedure will be Force Checked In, but the user will not be notified.", "No Email"); } private string BuildForcedMessageBody(ProcedureInfo pi) { StringBuilder body = new StringBuilder(); body.AppendLine($"The administrator needed to force check in procedure {pi.DisplayNumber} so the administrator could continue an administrative tool process"); return body.ToString(); } private bool SendOutlookEmail(string email, string subject, string body) { try { LBApplicationClass app = new LBApplicationClass(); LBMailItemClass msg = app.CreateMailItem(); msg.To = email; msg.Subject = subject; msg.BodyFormat = LBOlBodyFormat.olFormatPlain; msg.Body = body; msg.Send(); return true; } catch (Exception ex) { if (ex.Message.ToLower().Contains("failed due to the following error: 80080005")) MessageBox.Show("You cannot send email via a running instance of Outlook from VE PROMS running from within Visual Studio."); else MessageBox.Show($"{ex.GetType().Name} - {ex.Message}"); return false; } } private void tmrCheck_Tick(object sender, EventArgs e) { tmrCheck.Enabled = false; string msg = string.Empty; pnlList.Controls.Clear(); List tmp = new List(); foreach(ProcedureInfo pi in CheckedOutProcedures) if (!MySessionInfo.CanCheckOutItem(pi.ItemID, CheckOutType.Procedure, ref msg)) tmp.Add(pi); CheckedOutProcedures = tmp; if (CheckedOutProcedures.Count == 0) { Close(); return; } foreach (ProcedureInfo pi in CheckedOutProcedures) AddToDisplayList(pi); tmrCheck.Enabled = true; } } }