New form to handle Batch Refresh of Referenced Objects and Transitions
This commit is contained in:
171
PROMS/VEPROMS User Interface/frmBatchRefreshCheckedOut.cs
Normal file
171
PROMS/VEPROMS User Interface/frmBatchRefreshCheckedOut.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using VEPROMS.CSLA.Library;
|
||||
using LBOutlookLibrary;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Net.Mail;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
|
||||
namespace VEPROMS
|
||||
{
|
||||
public partial class frmBatchRefreshCheckedOut : Form
|
||||
{
|
||||
private SessionInfo _MySessionInfo;
|
||||
public SessionInfo MySessionInfo
|
||||
{
|
||||
get { return _MySessionInfo; }
|
||||
set { _MySessionInfo = value; }
|
||||
}
|
||||
private List<ProcedureInfo> _CheckedOutProcedures;
|
||||
public List<ProcedureInfo> CheckedOutProcedures
|
||||
{
|
||||
get { return _CheckedOutProcedures; }
|
||||
set { _CheckedOutProcedures = value; }
|
||||
}
|
||||
public frmBatchRefreshCheckedOut()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
private void frmBatchRefreshCheckedOut_FormClosing(object sender, FormClosingEventArgs e)
|
||||
{
|
||||
Owner.Show();
|
||||
}
|
||||
private void frmBatchRefreshCheckedOut_Load(object sender, EventArgs e)
|
||||
{
|
||||
Owner.Hide();
|
||||
foreach (ProcedureInfo pi in CheckedOutProcedures)
|
||||
AddToDisplayList(pi);
|
||||
tmrCheck.Enabled = true;
|
||||
}
|
||||
private void AddToDisplayList(ProcedureInfo pi)
|
||||
{
|
||||
Panel p = new Panel();
|
||||
p.BorderStyle = BorderStyle.FixedSingle;
|
||||
p.Dock = DockStyle.Top;
|
||||
p.Height = 28;
|
||||
Button b = new Button();
|
||||
//b.FlatStyle = FlatStyle.Popup;
|
||||
b.Dock = DockStyle.Right;
|
||||
b.Text = "Force Check In";
|
||||
b.Tag = pi;
|
||||
b.Click += new EventHandler(ForceCheckIn_Click);
|
||||
p.Controls.Add(b);
|
||||
b = new Button();
|
||||
//b.FlatStyle = FlatStyle.Popup;
|
||||
b.Dock = DockStyle.Right;
|
||||
b.Text = "Send Email";
|
||||
b.Tag = pi;
|
||||
b.Click += new EventHandler(SendEmail_Click);
|
||||
p.Controls.Add(b);
|
||||
Label l = new Label();
|
||||
l.Dock = DockStyle.Fill;
|
||||
l.TextAlign = ContentAlignment.MiddleLeft;
|
||||
l.Text = string.Format("Procedure {0} is checked out to {1}", pi.DisplayNumber, 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 (!SendOutlookEmail(uc.User_UserEmail, subject, BuildEmailMessageBody(pi)))
|
||||
(sender as Button).Enabled = false;
|
||||
}
|
||||
|
||||
private string BuildEmailMessageBody(ProcedureInfo pi)
|
||||
{
|
||||
StringBuilder body = new StringBuilder();
|
||||
body.AppendLine("THIS IS A TEST MESSAGE FROM JIM BODINE");
|
||||
body.AppendLine();
|
||||
body.AppendLine(string.Format("I need you to check in procedure {0} so I can continue a batch refresh process", pi.DisplayNumber));
|
||||
body.AppendLine();
|
||||
body.AppendLine("Obviously, you do not really have this procedure checked out, so you really do not have to do anything.");
|
||||
body.AppendLine();
|
||||
body.AppendLine("However, I would appreciate it if you would reply to this email so I know the email worked");
|
||||
body.AppendLine();
|
||||
body.AppendLine("I will try NOT to overwhelm your email system :-)");
|
||||
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);
|
||||
string subject = "A Procedure Was Forced Checked In";
|
||||
SendOutlookEmail(uc.User_UserEmail, subject, BuildForcedMessageBody(pi));
|
||||
}
|
||||
|
||||
private string BuildForcedMessageBody(ProcedureInfo pi)
|
||||
{
|
||||
StringBuilder body = new StringBuilder();
|
||||
body.AppendLine("THIS IS A TEST MESSAGE FROM JIM BODINE");
|
||||
body.AppendLine();
|
||||
body.AppendLine(string.Format("I needed to force check in procedure {0} so I could continue a batch refresh process", pi.DisplayNumber));
|
||||
body.AppendLine();
|
||||
body.AppendLine("Obviously, you do not really have this procedure checked out, so nothing really got forced checked in.");
|
||||
body.AppendLine();
|
||||
body.AppendLine("However, I would appreciate it if you would reply to this email so I know the email worked");
|
||||
body.AppendLine();
|
||||
body.AppendLine("I will try NOT to overwhelm your email system :-)");
|
||||
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(string.Format("{0} - {1}", 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<ProcedureInfo> tmp = new List<ProcedureInfo>();
|
||||
foreach(ProcedureInfo pi in CheckedOutProcedures)
|
||||
if (!MySessionInfo.CanCheckOutItem(pi.ItemID, CheckOutType.Procedure, ref msg))
|
||||
tmp.Add(pi);
|
||||
CheckedOutProcedures = tmp;
|
||||
if (CheckedOutProcedures.Count == 0)
|
||||
{
|
||||
this.Close();
|
||||
return;
|
||||
}
|
||||
foreach (ProcedureInfo pi in CheckedOutProcedures)
|
||||
AddToDisplayList(pi);
|
||||
tmrCheck.Enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user