此方法用于两个不同类型Entity Framework 对象相同名称属性之间的拷贝
public class EntityHelper
{
/// <summary>
///用","号分隔忽略属性
/// </summary>
/// <param name="source">源对象</param>
/// <param name="target">目标对象</param>
/// <param name="ignorePoperties"></param>
/// <returns></returns>
public static TTarget EntityCopy<TSource, TTarget>(TSource source, TTarget target, string ignorePoperties)
{
List<string> ignoreP = new List<string>();
if (!string.IsNullOrEmpty(ignorePoperties))
{
ignoreP = ignorePoperties.ToLower().Split(',').ToList();
}
ignoreP.Add("entitykey");
ignoreP.Add("entitystate");
var tFields = target.GetType().GetProperties();
var sFields = source.GetType().GetProperties();
foreach (var item in tFields)
{
if (!ignoreP.Contains(item.Name.ToLower()))
{
foreach (var si in sFields)
{
if (si.Name == item.Name)
{
object svalue = si.GetValue(source, null);
object tvalue = item.GetValue(target, null);
if (svalue != null && !svalue.Equals(tvalue))
{
item.SetValue(target, svalue, null);
}
}
}
}
}
return target;
}
/// <summary>
///用","号分隔忽略属性
/// </summary>
/// <param name="source">源对象</param>
/// <param name="target">目标对象</param>
/// <returns></returns>
public static TTarget EntityCopy<TSource, TTarget>(TSource source, TTarget target)
{
return EntityCopy(source, target, "");
}
调用:
/// <summary>
///更新上下级关系
/// </summary>
public int GetChagedPositionRelations()
{
var query = from pr in EISEEntities.View_Interface_PositionReport
join p in EISEEntities.View_Interface_Position on pr.PositionId equals p.PositionId
join dic in EISEEntities.View_Interface_Dictionary on p.DivisionID equals dic.DictionaryId
where DivtionFilt.IndexOf(dic.Code) != -1
&& pr.LastModifiedOn > StartTime
&& pr.LastModifiedOn < EndTime
select new { pr, p.PositionCode };
var list = query.ToList();
foreach (var item in list)
{
ocm_map_PositionRelation_Approval model = new ocm_map_PositionRelation_Approval();
//插入
EntityHelper.EntityCopy(item.pr, model);
model.HRPositionCode = item.PositionCode;
if (item.pr.ParentPositionId != null)
{
model.ParentPositionCode = (from pp in EISEEntities.View_Interface_Position
where pp.PositionId == item.pr.ParentPositionId
select pp.PositionCode).FirstOrDefault();
}
model.PositionRelationApprovalId = Guid.NewGuid();
model.ApprovalStatus = (int)EISSyncApprovalStatus.Stored;
SDMEntities.ocm_map_PositionRelation_Approval.AddObject(model);
}
SDMEntities.SaveChanges(SaveOptions.AcceptAllChangesAfterSave);
return list.Count;
}
表结构:


1 internal class Node 2 { 3 protected Node m_next; 4 public Node(Node next) 5 { 6 m_next = next; 7 } 8 9 } 10 internal class TypedNode<T> : Node 11 { 12 public T m_data; 13 public TypedNode(T data) 14 : this(data, null) 15 { 16 17 } 18 public TypedNode(T data, Node next) 19 : base(next) 20 { 21 m_data = data; 22 } 23 public override string ToString() 24 { 25 return m_data.ToString() + ((m_next == null ? null : m_next.ToString())); 26 } 27 }
测试代码:
Node head = new TypedNode<Char>('.'); head = new TypedNode<DateTime>(DateTime.Now, head); head = new TypedNode<string>(" Today is ", head); Console.WriteLine(head.ToString());
Codes from <CLR via C# 3>
一个经典的创建职位申请/审批流程
虽然只是对现有系统的扩充,但是总觉得这样写的代码不够美....但又不知道更好该怎么设计
protected void SetFormView(Enumerator.ApprovalResult approvalResult)
{
switch (approvalResult)
{
case Enumerator.ApprovalResult.Pending:
SelectDictionaryItemsCity.Enabled = false;
SelectDictionaryItemsProvince.Enabled = false;
if (IsHR)
{
//待审核状态
trHRInfo.Visible = true;
PnAppraval.Visible = true;
trApprovalRemark.Visible = true;
txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = false;
}
else
{
//非HR
trHRInfo.Visible = false;
trApprovalRemark.Visible = false;
PnAppraval.Visible = txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = false;
}
break;
case Enumerator.ApprovalResult.Reject:
SelectDictionaryItemsCity.Enabled = false;
SelectDictionaryItemsProvince.Enabled = false;
//已拒绝状态
trHRInfo.Visible = false;
trApprovalRemark.Visible = true;
txtApprovalRemark.Enabled = false;
PnAppraval.Visible = txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = false;
break;
case Enumerator.ApprovalResult.Return:
//待重新提交状态
if (IsHR)
{
trHRInfo.Visible = false;
trApprovalRemark.Visible = true;
txtApprovalRemark.Enabled = false;
PnAppraval.Visible = false;
txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = false;
}
else
{
trHRInfo.Visible = false;
trApprovalRemark.Visible = true;
txtApprovalRemark.Enabled = false;
PnAppraval.Visible = false;
txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = true;
}
break;
case Enumerator.ApprovalResult.Waiting:
//待提交状态
trHRInfo.Visible = false;
trApprovalRemark.Visible = false;
PnAppraval.Visible = false;
txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = true;
break;
case Enumerator.ApprovalResult.Approved:
SelectDictionaryItemsCity.Enabled = false;
SelectDictionaryItemsProvince.Enabled = false;
//已拒绝状态
trHRInfo.Visible = false;
trApprovalRemark.Visible = true;
txtApprovalRemark.Enabled = false;
PnAppraval.Visible = txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = false;
break;
default:
//默认状态
trHRInfo.Visible = false;
trApprovalRemark.Visible = false;
PnAppraval.Visible = false;
txtRemark.Enabled = btnSave.Visible = PnSubmit.Visible = true;
break;
}
}
创建职位申请
经理申请流程:
-
列表
只能看到自己提交的单子
-
新建/保存
保存后效果在这里看是一样的,只是打开方式和职位信息后面有个(已保存)

-
查看已提交

-
查看已通过

-
查看已退回

-
查看已拒绝

HR审批流程:
-
列表
HR 不能删除任何单据
列表显示所有已提交状态的单据和 当前登录人已审核过的单据

-
创建
创建功能待定
-
审批单据

-
查看已通过/查看已退回/查看已拒绝
可查看 不可编辑
- 打开"开始"菜单,选择"Control Panel"。
- 在打开的面板中选择"Administrative Tools"。
- 在打开的应用列表中选择"Component Services"。
- 依次选择"Computers","My Computer","DCOM Config","Microsoft Excel Application"
- 右键单击"Microsoft Excel Application",在弹出的菜单中选择"Properties"。
- 在弹出的功能面板中,选择"Security"选项卡,修改"Launch and Activation Permissions"和"Access Permissions"为"Customize",并添加用户"NETWORK SERVICE",赋予如下图示的权限:
- 在弹出的功能面板中,选择"Identity"选项卡,选中选项"This user",指定用户为"administrator"并输入账号密码。
- 权限设置完成。
就像这样:
<a onclick="window.open(this.href,'page title','location=0,status=0,menubar=0,scrollbars=0,toolbar=0,width=550,height=740');return false" href="javascript:void(0)" target="_blank">POP UP</a>
去掉Page title 中的空格 问题解决
错误解决:未能找到类型集或命名空间名称 "xxxx" (是否缺少using 指令或引用?)

1.检查是否添加引用..
2.检查生成依赖

3.检查目标框架.
我的错误出在这里

cmd 进入ASP.NET 4.0安装目录 运行 aspnet_regiis -i 向IIS注册
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>aspnet_regiis -i
开始安装 ASP.NET (4.0.30319)。
.......................
ASP.NET (4.0.30319)安装完毕。
之后出现
由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面。
1.选择 IIS 根节点 (就是服务器名称那里)
2.主窗体中间 "ISAPI和cgi限制"
3.允许 描述为: ASP.NET v4.0.30319 (32-bit) 的两项

