This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Data; | |
using System.Configuration; | |
using System.Collections; | |
using System.Web; | |
using System.Web.Security; | |
using System.Web.UI; | |
using System.Web.UI.WebControls; | |
using System.Web.UI.WebControls.WebParts; | |
using System.Web.UI.HtmlControls; | |
// C:\WINDOWS\assembly\GAC_32\SourceCode.Workflow.Client\4.0.0.0__16a2c5aaaa1b130d\SourceCode.Workflow.Client.dll | |
using SourceCode.Workflow.Client; | |
using SourceCode.SmartObjects.Client; | |
using System.Web.Mobile; | |
using System.Xml; | |
public partial class Approval : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
MobileCapabilities browserObj = (MobileCapabilities)Request.Browser; | |
if (browserObj.IsMobileDevice) | |
{ | |
Response.Redirect("MobileApproval.aspx?sn=" + Request.QueryString["sn"]); | |
} | |
else if (!Page.IsPostBack) | |
{ | |
Connection k2Conn = new Connection(); | |
try | |
{ | |
k2Conn.Open("DLX"); | |
WorklistItem wli = k2Conn.OpenWorklistItem(Request.QueryString["sn"]); | |
#region Bind Form Data from Xml Data Fields | |
QuoteNumber.Text = wli.ProcessInstance.Folio; | |
XmlDocument xmlDoc = new XmlDocument(); | |
// load the .NET XML doc With the contents Of this K2 XML field | |
xmlDoc.LoadXml(wli.ProcessInstance.XmlFields["QuoteApprovalForm"].Value.ToString()); | |
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDoc.NameTable); | |
nsMgr.AddNamespace("my", xmlDoc.DocumentElement.GetNamespaceOfPrefix("my")); | |
Region.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteInformation/my:Region", nsMgr).InnerText; | |
ReqFullName.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteInformation/my:FullName", nsMgr).InnerText; | |
ReqTitle.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteInformation/my:Title", nsMgr).InnerText; | |
Email.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteInformation/my:Email", nsMgr).InnerText; | |
Username.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteInformation/my:Username", nsMgr).InnerText; | |
TransactionType.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:TransactionType", nsMgr).InnerText; | |
NumPayees.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:NumPayees", nsMgr).InnerText; | |
CustomerName.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:CustomerName", nsMgr).InnerText; | |
PrimaryBusiness.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:PrimaryBusiness", nsMgr).InnerText; | |
AnnualRevenue.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:AnnualRevenue", nsMgr).InnerText; | |
CustomerContact.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:CustomerContact", nsMgr).InnerText; | |
ContactEmail.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:ContactEmail", nsMgr).InnerText; | |
PricingList.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:PricingList", nsMgr).InnerText; | |
PricingNet.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:PricingNet", nsMgr).InnerText; | |
PricingDiscount.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:PricingDiscount", nsMgr).InnerText; | |
Maintenance.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:Maintenance", nsMgr).InnerText; | |
FirstYearRate.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:FirstYearRate", nsMgr).InnerText; | |
RenewalRate.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:RenewalRate", nsMgr).InnerText; | |
Competition.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:IsCompetition", nsMgr).InnerText; | |
ClientBudget.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:ClientBudget", nsMgr).InnerText; | |
ApproximateCloseDate.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:ApproximateCloseDate", nsMgr).InnerText; | |
OutsideFinancingOffered.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:IsOutsideFinanceOffered", nsMgr).InnerText; | |
ServicesTraining.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:ServicesTraining", nsMgr).InnerText; | |
ServicesConsulting.Text = xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:ServicesConsulting", nsMgr).InnerText; | |
OriginatorComments.Text = xmlDoc.SelectSingleNode("//my:myFields/my:AdditionalComments", nsMgr).InnerText; | |
if (xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:IsModuleServer", nsMgr).InnerText == "yes") | |
ModulesRequested.Text += "Server "; | |
if (xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:IsModuleClient", nsMgr).InnerText == "yes") | |
ModulesRequested.Text += "Client "; | |
if (xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:IsModuleArchive", nsMgr).InnerText == "yes") | |
ModulesRequested.Text += "Archiving "; | |
if (xmlDoc.SelectSingleNode("//my:myFields/my:QuoteDetails/my:IsModuleManagement", nsMgr).InnerText == "yes") | |
ModulesRequested.Text += "Management "; | |
#endregion | |
#region Load Process Bar according to ActivityInstanceDestination.Name | |
if (Convert.ToInt32(PricingDiscount.Text) < 200000) | |
{ | |
if (wli.ActivityInstanceDestination.Name.Equals("Regional VP Approval")) | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_noCFO/pb_reg_dir_approval_noCFO.jpg"; | |
imgApprovalHistory.Visible = false; | |
} | |
else if (wli.ActivityInstanceDestination.Name.Equals("VP Approval")) | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_noCFO/pb_vp_approval_noCFO.jpg"; | |
} | |
else if (wli.ActivityInstanceDestination.Name.Equals("Legal Approval")) | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_noCFO/pb_legal_approval_noCFO.jpg"; | |
} | |
} | |
else | |
{ | |
if (wli.ActivityInstanceDestination.Name.Equals("Regional VP Approval")) | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_CFO/pb_reg_dir_approval.jpg"; | |
imgApprovalHistory.Visible = false; | |
} | |
else if (wli.ActivityInstanceDestination.Name.Equals("VP Approval")) | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_CFO/pb_vp_approval.jpg"; | |
} | |
else if (wli.ActivityInstanceDestination.Name.Equals("Legal Approval")) | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_CFO/pb_legal_approval.jpg"; | |
} | |
else | |
{ | |
imgProcessBar.ImageUrl = "Images/process_bar_CFO/pb_cfo_approval.jpg"; | |
} | |
} | |
#endregion | |
} | |
catch (Exception exception) | |
{ | |
Response.Write("Error: " + exception.Message); | |
} | |
finally | |
{ | |
k2Conn.Close(); | |
} | |
} | |
} | |
protected void imgbtnApprove_Click(object sender, ImageClickEventArgs e) | |
{ | |
ProcessAction("Approved"); | |
} | |
protected void imgbtnReject_Click(object sender, ImageClickEventArgs e) | |
{ | |
ProcessAction("Rejected"); | |
} | |
private void ProcessAction(string actionName) | |
{ | |
Connection k2Conn = new Connection(); | |
try | |
{ | |
k2Conn.Open("DLX"); | |
WorklistItem wli = k2Conn.OpenWorklistItem(Request.QueryString["sn"]); | |
#region Connect to SO Server for Employee Information | |
SmartObjectClientServer soClient = new SmartObjectClientServer(); | |
soClient.Connection = soClient.CreateConnection(); | |
if (soClient.Connection.IsConnected == false) | |
{ | |
//Very Important, use connection string builder to create connection string. | |
SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder connectionStr = new SourceCode.Hosting.Client.BaseAPI.SCConnectionStringBuilder(); | |
connectionStr.Host = "dlx"; | |
connectionStr.Integrated = true; | |
connectionStr.IsPrimaryLogin = true; | |
connectionStr.Port = 5555; | |
//Open connection | |
//Need method to handle closing of the connection when required - not implemented | |
try | |
{ | |
soClient.Connection.Open(connectionStr.ConnectionString); | |
} | |
catch (Exception ex) | |
{ | |
Response.Write("Error: " + ex.Message); | |
} | |
} | |
#endregion | |
#region Load Employee Information | |
SmartObject soEmployee = soClient.GetSmartObject("Employee"); | |
soEmployee.MethodToExecute = "Load"; | |
string sUser = HttpContext.Current.User.Identity.Name; | |
sUser = sUser.Replace("DENALLIX\\", string.Empty); | |
soEmployee.Properties["EmployeeID"].Value = sUser; //k2Conn.User.Name.Replace("DENALLIX\\", ""); | |
soClient.ExecuteScalar(soEmployee); | |
#endregion | |
#region Save Approval History | |
string approver = soEmployee.Properties["FullName"].Value.ToString(); | |
DateTime approvalDate = DateTime.Now; | |
SmartObject soComment = soClient.GetSmartObject("QuoteComment"); | |
soComment.MethodToExecute = "Create"; | |
soComment.Properties["QuoteID"].Value = QuoteNumber.Text; | |
soComment.Properties["EmployeeID"].Value = k2Conn.User.Name.Replace("DENALLIX\\", ""); | |
soComment.Properties["FullName"].Value = approver; | |
soComment.Properties["CommentDate"].Value = approvalDate.ToString(); | |
soComment.Properties["Comment"].Value = ApprovalComments.Text; | |
soComment.Properties["Action"].Value = actionName; | |
soClient.ExecuteScalar(soComment); | |
#endregion | |
wli.Actions[actionName].Execute(); | |
Response.Redirect("ThankYou.aspx?ProcessStage=" + imgProcessBar.ImageUrl); | |
} | |
catch (Exception exception) | |
{ | |
Response.Write("Error: " + exception.Message); | |
} | |
finally | |
{ | |
k2Conn.Close(); | |
} | |
} | |
} |