csharp Epicor标准练习片段
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Epicor标准练习片段相关的知识,希望对你有一定的参考价值。
//Place these comments in the first Custom Code block of a BPM
/***********************************************
BPM: {Current BPM Path & Name}
Date: {Date Created}
Author: {Primary Developer}
Purpose: {Brief description of purpose}
Requirements: {Brief overview of requirements}
***********************************************/
//Use these comments for in-line comments or method comments
/***********************************************
Summary:
{High-level overview of code block}
Inputs:
Outputs:
Created by:
Created on:
Change Log:
Initials Date Description
***********************************************/
By default, all customizations should be marked with "All Companies" (so that if we happen to add new companies in the future, our customizations will be available to them).
When saving a new customization, add the following header block:
/***********************************************
Based on:
{Previous Customization Name}
Date:
{Date Created}
Author:
{Primary Developer}
Purpose:
{Brief description of purpose}
***********************************************/
Example App.PartEntry.PartForm customization "02_Phase_II_Enhancements":
/***********************************************
Based on: 26774_Part_Master_Customization
Date: 10/19/2017
Author: Doug Lockwood
Purpose: Modifications to Part Master required for Phase II Rollout
***********************************************/
Examples:02_Phase_II_Enhancements
Number="02"
Customization Name="Phase_II_Enhancements"
//Use these comments for the main script section
/***********************************************
Customization: {Current Customization Name}
Date: {Date Created}
Author: {Primary Developer}
Purpose: {Brief description of purpose}
***********************************************/
//Use these comments for in-line comments or method comments
/***********************************************
Summary:
{High-level overview of code block}
Inputs:
Outputs:
Created by:
Created on:
Change Log:
Initials Date Description
***********************************************/
/*
Add this function to the beginning of any BPM directives and utilize whenever logging is needed.
This function will look for UDCodeTypeID "SYS006_001" (SYS006-DebugLog) and try to parse the toggle out of [WriteLogs?].[CodeDesc] and the log path out of [LogPath].[CodeDesc].
Updating either of these user codes will change the logging behavior for all debug logs written in the current environment that utilize this code. This gives developers a one-stop shop for turning logging on/off and configuring the folder path for the log.
This code can be modified to work in a form customization as well as a BPM. Just update the log name appropriately (this.Name + "_Log") and make it into a private method instead of a delegate.
User Defined Codes:
WriteLogs? True
Set "Description" to TRUE to turn on all developer logging.
Set "Description" to FALSE to turn off all developer logging.
LogPath \\allo-scdev\C$\Temp\EpicorDebugLogging\EpicorDEV\
Set "Description" to the network path for writing logs to the server.
Must be a path all users can access.
*/
Func<string, string> WriteLog = delegate(string msg)
{
try
{
bool logOK = false;
var log = Db.UDCodes.FirstOrDefault(u=>u.CodeTypeID.ToUpper()=="SYS006_001" && u.CodeID.ToLower()=="writelogs?");
if (log != null && bool.TryParse(log.CodeDesc, out logOK))
{
var path = Db.UDCodes.FirstOrDefault(u=>u.CodeTypeID.ToUpper()=="SYS006_001" && u.CodeID.ToLower()=="logpath");
if (logOK==true && path!=null)
{
System.IO.File.AppendAllText(
path.CodeDesc.Trim('/')
+ "/" + this.Name + "_Log-"
+ DateTime.Now.ToString("yyyy-MM-dd")
+ ".txt",
DateTime.Now.ToString() + " => "
+ Session.UserID + " => "
+ this.Name + " => "
+ "DEBUG => "
+ "MSG[[\r\n " + msg.Replace("\r\n","\r\n ") + "\r\n]]"
+ Environment.NewLine
);
}
}
}
catch (Exception ex)
{
this.PublishInfoMessage("There was a problem logging the message \"" + msg + "\"\r\n" + ex.Message, Ice.Common.BusinessObjectMessageType.Warning, Ice.Bpm.InfoMessageDisplayMode.Individual, "Developer Logging", "Error");
}
return "";
};
/*
Title: Check to see if we need to show Developer Message
Type: Standard Code Snippet
Requirements: (Values should be set in a previous process)
string DeveloperMessage
bool ShowDeveloperMessage
Author: Doug Lockwood
Date: 12/13/2017
Usage: This snippet is intended for use by any Epicor developer. Add this as a custom executable code block at the end of any BPM to display any DeveloperMessage strings created as an information message at the end of the BPM process. This snippet can be customized by adding UserIds to the (callContextClient.CurrentUserId.ToLower()=="dlockwood") condition. For questions, contact Doug Lockwood.
Modifications:
Date: Summary:
12/14/17 Modified to check for blank DeveloperMessage before anything else (If there is no message, there is no need to decide whether or not to display it).
*/
if (!String.IsNullOrEmpty(DeveloperMessage))
{
// Provide information about the current BPM
DeveloperMessage = "--------------------\r\n"
+ "{Current BPM Information}"
+ "\r\n--------------------\r\n"
+ DeveloperMessage + "\r\n";
// Show developer messages to Doug Lockwood always
if (callContextClient.CurrentUserId.ToLower()=="dlockwood")
{
ShowDeveloperMessage=true;
DeveloperMessage += "\r\n----------\r\n* Showing Developer Messages because current user is " + callContextClient.CurrentUserId + ".\r\n";
}
// Show developer messages to anyone in the DEV environment only
var curCompany = Db.Company.FirstOrDefault(x=>x.Company1==callContextClient.CurrentCompany && x.Name.ToLower().Contains("dev"));
if (curCompany!=null)
{
ShowDeveloperMessage=true;
DeveloperMessage += "\r\n----------\r\n* Showing Developer Messages because company \"" + curCompany.Name + "\" is a development company.\r\n";
}
// Queue up a Developer Message to display at the end of the process
if (ShowDeveloperMessage)
{
DeveloperMessage = "DEVELOPER MESSAGE*:\r\n====================\r\n"
+ DeveloperMessage
+ "\r\n\r\n====================\r\n"
+ "Assembly: " + callContextClient.AssemblyName + "\r\n"
+ "CGC: " + callContextClient.CGCCode + "\r\n"
+ "Client Type: " + callContextClient.ClientType + "\r\n"
+ "Current Company: " + callContextClient.CurrentCompany + "\r\n"
+ "Current Plant: " + callContextClient.CurrentPlant + "\r\n"
+ "Current User ID: " + callContextClient.CurrentUserId + "\r\n"
+ "Customization: " + callContextClient.CustomizationId + "\r\n"
+ "Process: " + callContextClient.ProcessId + "\r\n"
+ "====================\r\n";
this.PublishInfoMessage(DeveloperMessage,
Ice.Common.BusinessObjectMessageType.Information,
Ice.Bpm.InfoMessageDisplayMode.Individual,
"Developer Message",
"Information From the Developer");
}
}
/*
Had a thought tht we could easily create "featue flags" in Epicor that old enable us to turn on/off whole sets of customizations (Primarily BPMs) by using a secial UD Code Type ID to control whether features were turned on or off.
In any BPM you crate, add a variable named FeatureXEnabled (Wheere "X" is the name of the feature you want to check).
Next, add a custom code block with the following code:
*/
var featurexflag = Db.UDCodes.FirstOrDefault(u=>u.CodeTypeID=="FeatureFlg" && u.CodeID.ToLower()=="featurex");
FeatureXEnabled = (featurexflag!=null ? featurexflag.IsActive : false);
/*
Finally, add a Condition block to check whether FeatureXEnabled is true or false. If true, continue executing your BPM code. If false, stop the process.
This way, BPMs can be moved into production enviroments, but will remain inactive until someone adds th correct FeatureFlg and sets the "Active" column to true.
*/
/*
Add this function to the beginning of any BPM under development and utilize whenever you need to monitor the data being transmitted back and forth.
This function will use reflection to find the name and value of every property associated with the object passed in. Use this to see what data is being passed with each row in a temporary table, etc.
This function is for use on single objects. Use with a foreach clause to iterate through multiple instances of an object (Such as rows in a temporary table, etc.).
*/
using System.ComponentModel;
Func<object, string> GetProperties = delegate(object obj)
{
var msg = "";
try
{
for (var i=0; i<TypeDescriptor.GetProperties(obj).Count; i++)
{
var descriptor = TypeDescriptor.GetProperties(obj)[i];
var curVal = "";
try
{
curVal = (descriptor.GetValue(obj) ?? "").ToString();
}
catch (Exception ex)
{
curVal=ex.Message.ToString();
}
msg += descriptor.Name + "=" + curVal + "\r\n";
}
}
catch (Exception ex)
{
msg += "\r\nAN ERROR HAS OCCURRED:\r\n" + ex.ToString();
}
msg += "\r\n";
return msg;
};
以上是关于csharp Epicor标准练习片段的主要内容,如果未能解决你的问题,请参考以下文章
csharp Epicor UD Entry KeyField