K2 Blackpearl start from Asp.net
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;
public partial class InitiatorRework : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Connection
k2Conn = new Connection();
try
{
k2Conn.Open("DLX");
WorklistItem wli =
k2Conn.OpenWorklistItem(Request.QueryString["sn"]);
#region Bind Form Data from Data Fields
QuoteNumber.Text = wli.ProcessInstance.Folio;
Region.Text = wli.ProcessInstance.DataFields
["Region"].Value.ToString();
ReqFullName.Text = wli.ProcessInstance.DataFields
["OriginatorFullName"].Value.ToString();
ReqTitle.Text = wli.ProcessInstance.DataFields
["OriginatorTitle"].Value.ToString();
Email.Text = wli.ProcessInstance.DataFields
["OriginatorEmail"].Value.ToString();
Username.Text = wli.ProcessInstance.DataFields
["OriginatorUsername"].Value.ToString();
TransactionType.SelectedValue = wli.ProcessInstance.DataFields
["TransactionType"].Value.ToString();
NumPayees.Text = wli.ProcessInstance.DataFields
["NumPayees"].Value.ToString();
CustomerName.SelectedValue = wli.ProcessInstance.DataFields
["CustomerName"].Value.ToString();
PrimaryBusiness.Text = wli.ProcessInstance.DataFields
["PrimaryBusiness"].Value.ToString();
AnnualRevenue.Text = wli.ProcessInstance.DataFields
["AnnualRevenue"].Value.ToString();
PricingList.Text = wli.ProcessInstance.DataFields
["PricingList"].Value.ToString();
PricingNet.Text = wli.ProcessInstance.DataFields
["PricingNet"].Value.ToString();
PricingDiscount.Text = wli.ProcessInstance.DataFields
["PricingDiscount"].Value.ToString();
Maintenance.SelectedValue = wli.ProcessInstance.DataFields
["Maintenance"].Value.ToString();
FirstYearRate.Text = wli.ProcessInstance.DataFields
["FirstYearRate"].Value.ToString();
RenewalRate.Text = wli.ProcessInstance.DataFields
["RenewalRate"].Value.ToString();
Competition.Text = wli.ProcessInstance.DataFields
["Competition"].Value.ToString();
ClientBudget.Text = wli.ProcessInstance.DataFields
["ClientBudget"].Value.ToString();
ApproximateCloseDate.Text = wli.ProcessInstance.DataFields
["ApproximateCloseDate"].Value.ToString();
OutsideFinancingOffered.Text = wli.ProcessInstance.DataFields
["OutsideFinancingOffered"].Value.ToString();
ServicesTraining.Text = wli.ProcessInstance.DataFields
["ServicesTraining"].Value.ToString();
ServicesConsulting.Text = wli.ProcessInstance.DataFields
["ServicesConsulting"].Value.ToString();
ReqComments.Text = wli.ProcessInstance.DataFields
["OriginatorComments"].Value.ToString();
ApprovalHistory.Text = wli.ProcessInstance.DataFields
["ApprovalHistory"].Value.ToString().Replace(System.Environment.NewLine, "
");
string[] ModulesList =
wli.ProcessInstance.DataFields["ModulesRequested"].Value.ToString().Replace(", ", ",").Split(',');
for (int
i = 0; i < ModulesList.Length; i++)
{
foreach (ListItem item in ModulesRequested.Items)
{
if (item.Value == ModulesList[i])
{
item.Selected = true;
}
}
}
#endregion
}
catch (Exception exception)
{
Response.Write("
Error: " +
exception.Message);
}
finally
{
k2Conn.Close();
}
}
}
protected void btnResubmit_Click(object sender, EventArgs e)
{
ProcessAction("Resubmitted");
}
protected
void btnCancel_Click(object sender, EventArgs e)
{
ProcessAction("Cancelled");
}
private void ProcessAction(string actionName)
{
Connection k2Conn = new Connection();
try
{
k2Conn.Open("DLX");
WorklistItem wli = k2Conn.OpenWorklistItem(Request.QueryString["sn"]);
#region Update Approval History
wli.ProcessInstance.DataFields["ApprovalHistory"].Value += DateTime.Today.ToShortDateString() + ": " + actionName + " by " +
k2Conn.User.Name.Replace("DENALLIX\\", "") + " - " + ReworkComments.Text + System.Environment.NewLine + System.Environment.NewLine;
#endregion
wli.Actions[actionName].Execute();
Response.Redirect("ThankYou.aspx");
}
catch (Exception exception)
{
Response.Write("
Error: " + exception.Message);
}
finally
{
k2Conn.Close();
}
}
}
============================
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();
}
}
}
========================
using System;
using System.Data;
using System.Configuration;
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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Request.ServerVariables["LOGON_USER"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
Connection k2Conn = new Connection();
try
{
k2Conn.Open("DLX");
ProcessInstance pi = k2Conn.CreateProcessInstance("SAPIDRequestSystem\\SAPID");
#region Bind Data Fields from Form Data
pi.DataFields["SAPStatus"].Value = Label1.Text;
pi.Folio = "SQLStar" + System.DateTime.Now;
#endregion
k2Conn.StartProcessInstance(pi);
Label1.Text = "Success";
}
catch (Exception exception)
{
Response.Write("
Error: " + exception.Message);
}
finally
{
k2Conn.Close();
}
}
}
==========================
using System;
using System.Data;
using System.Configuration;
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;
using SourceCode.SmartObjects.Client;
// C:\WINDOWS\assembly\GAC_32\SourceCode.Workflow.Client\4.0.0.0__16a2c5aaaa1b130d\SourceCode.Workflow.Client.dll
using SourceCode.Workflow.Client;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
#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("NewEmployee");
soEmployee.MethodToExecute = "Load";
soEmployee.Properties["Username"].Value = System.Environment.UserName;
soClient.ExecuteScalar(soEmployee);
#endregion
#region Bind Employee Information with Form Data
Username.Text = soEmployee.Properties["Username"].Value.ToString();
ReqFullName.Text = soEmployee.Properties["name"].Value.ToString();
ReqTitle.Text = soEmployee.Properties["description"].Value.ToString();
Email.Text = soEmployee.Properties["mail"].Value.ToString();
Region.Text = soEmployee.Properties["Region"].Value.ToString();
#endregion
ApproximateCloseDate.Text = DateTime.Today.AddDays(14).ToShortDateString();
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Connection k2Conn = new Connection();
try
{
k2Conn.Open("DLX");
ProcessInstance pi = k2Conn.CreateProcessInstance("Processes\\Pricing Approval");
#region Bind Data Fields from Form Data
pi.DataFields["Region"].Value = Region.Text;
pi.DataFields["TransactionType"].Value = TransactionType.SelectedValue;
pi.DataFields["NumPayees"].Value = Convert.ToInt32(NumPayees.Text);
pi.DataFields["CustomerName"].Value = CustomerName.SelectedValue;
pi.DataFields["PrimaryBusiness"].Value = PrimaryBusiness.Text;
pi.DataFields["AnnualRevenue"].Value = Convert.ToInt32(AnnualRevenue.Text);
pi.DataFields["PricingList"].Value = Convert.ToInt32(PricingList.Text);
pi.DataFields["PricingNet"].Value = Convert.ToInt32(PricingNet.Text);
pi.DataFields["PricingDiscount"].Value = Convert.ToInt32(PricingDiscount.Text);
pi.DataFields["Maintenance"].Value = Maintenance.SelectedValue;
pi.DataFields["FirstYearRate"].Value = Convert.ToInt32(FirstYearRate.Text);
pi.DataFields["RenewalRate"].Value = Convert.ToInt32(RenewalRate.Text);
pi.DataFields["Competition"].Value = Competition.Text;
pi.DataFields["ClientBudget"].Value = ClientBudget.Text;
pi.DataFields["ApproximateCloseDate"].Value = Convert.ToDateTime(ApproximateCloseDate.Text).ToShortDateString();
pi.DataFields["OutsideFinancingOffered"].Value = OutsideFinancingOffered.Text;
pi.DataFields["ServicesTraining"].Value = ServicesTraining.Text;
pi.DataFields["ServicesConsulting"].Value = ServicesConsulting.Text;
pi.DataFields["OriginatorComments"].Value = ReqComments.Text;
pi.DataFields["OriginatorUsername"].Value = Username.Text;
pi.DataFields["OriginatorEmail"].Value = Email.Text;
pi.DataFields["OriginatorTitle"].Value = ReqTitle.Text;
pi.DataFields["OriginatorFullName"].Value = ReqFullName.Text;
foreach (ListItem item in ModulesRequested.Items)
{
if (item.Selected == true)
{
pi.DataFields["ModulesRequested"].Value += item.Value + ", ";
}
}
pi.DataFields["ModulesRequested"].Value = pi.DataFields["ModulesRequested"].Value.ToString().Trim().TrimEnd(',');
#endregion
k2Conn.StartProcessInstance(pi);
}
catch (Exception exception)
{
Response.Write("
Error: " + exception.Message);
}
finally
{
k2Conn.Close();
}
}
}