public JsonResult ModifyDataSave()
{
var cc_Technology = "TechnologyCarbonCopy";//技术主管部门CC
var cc_Finance = "FinanceCarbonCopy";//财务部CC
var cc_Purchase = "PurchaseCarbonCopy";//采购部CC
var cc_Factory = "FactoryCarbonCopy";
var cc_Review1 = string.Empty;
var cc_Review2 = string.Empty;
var cc_Review3 = string.Empty;
var cc_Review4 = string.Empty;
var stepId = 0;
var selectedRole = 0;
var financeApproval = new FixedAssetInspection1();
var tenderApproval = new FixedAssetInspection2();
var factoryApproval = new FixedAssetInspection3();
#region 原获取数据方式
//获取前台表单提交的数据
var formData = JsonConvert.DeserializeObject(Request["jsonStr"]);
//获取审批步骤类型ID (0:技术主管/财务审核前, 1:技术主管/财务, 2:采购审核前, 3:采购, 4:进口部前, 5:进口部门, 6:进口部门审批之后)
if (formData["Step"] != null)
{
stepId = JsonConvert.DeserializeObject(formData["Step"].ToString());
}
//获取第一次修改时用户选择的审批角色
if (formData["SelectedRole"] != null)
{
selectedRole = JsonConvert.DeserializeObject(formData["SelectedRole"].ToString());
}
//获取 技术主管/财务 填写内容
if (formData["FinanceApproval"] != null)
{
financeApproval = JsonConvert.DeserializeObject(formData["FinanceApproval"].ToString());
}
//获取 采购员 填写内容
if (formData["TenderApproval"] != null)
{
tenderApproval = JsonConvert.DeserializeObject(formData["TenderApproval"].ToString());
}
//获取 归口部门/厂务部门 填写内容
if (formData["FactoryApproval"] != null)
{
factoryApproval = JsonConvert.DeserializeObject(formData["FactoryApproval"].ToString());
}
#endregion
#region 新获取数据方式
//var jsonStr = Request["jsonStr"];
//if (!string.IsNullOrWhiteSpace(Request["Step"]))
//{
// int.TryParse(Request["Step"], out stepId);
//}
//if (!string.IsNullOrWhiteSpace(Request["SelectedRole"]))
//{
// int.TryParse(Request["SelectedRole"], out selectedRole);
//}
//if (!string.IsNullOrWhiteSpace(Request["FinanceApproval"]))
//{
// financeApproval=JsonConvert.DeserializeObject(Request["FinanceApproval"]);
//}
//if (!string.IsNullOrWhiteSpace(Request["TenderApproval"]))
//{
// tenderApproval = JsonConvert.DeserializeObject(Request["TenderApproval"]);
//}
//if (!string.IsNullOrWhiteSpace(Request["FactoryApproval"]))
//{
// factoryApproval = JsonConvert.DeserializeObject(Request["FactoryApproval"]);
//}
#endregion
///附件上传
var basePath = "/Uploads/FixedAssetReview/";
var path = Server.MapPath(basePath);
if (Request.Files.Count > 0)//有上传文件
{
//指定路径目录不存在时,创建目录
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
switch (stepId)
{
case 1:
{
var file1 = Request.Files["Annex_Technology"];//技术主管部门附件
var file2 = Request.Files["Annex_Finance"];//财务部附件
var file3 = Request.Files["Annex_Purchase"];//采购部门附件
if (db.FixedAssetInspection1.Where(p => p.DocumentId == financeApproval.DocumentId).Count() == 0)
{
db.FixedAssetInspection1.Add(financeApproval);
}
else
{
//在数据库中查询原有的记录
var temp = db.FixedAssetInspection1.Where(p => p.DocumentId == financeApproval.DocumentId).FirstOrDefault();
if (selectedRole == 1)
{
temp.AuditOpinion_Technology = financeApproval.AuditOpinion_Technology;
temp.CarbonCopy_Technology = financeApproval.CarbonCopy_Technology;
temp.Remark_Technology = financeApproval.Remark_Technology;
if (file1 != null && file1.ContentLength > 0)
{
var shortName = Guid.NewGuid().ToString() + Path.GetExtension(file1.FileName);
var filePath = Path.Combine(path, shortName);
file1.SaveAs(filePath);
temp.Annex_Technology = Path.Combine(basePath, shortName);
}
db.Entry(temp).State = EntityState.Modified;
db.OAApprovers.RemoveRange(db.OAApprovers.Where(p => p.DocumentId == financeApproval.DocumentId && p.ApproverKey == cc_Technology));
}
else if (selectedRole == 2)
{
temp.AuditOpinion_Finance = financeApproval.AuditOpinion_Finance;
temp.CarbonCopy_Finance = financeApproval.CarbonCopy_Finance;
temp.Remark_Finance = financeApproval.Remark_Finance;
temp.CostAmountTypeCode = financeApproval.CostAmountTypeCode;
temp.CostAmountTypeName = financeApproval.CostAmountTypeName;
if (file2 != null && file2.ContentLength > 0)
{
var shortName = Guid.NewGuid().ToString() + Path.GetExtension(file2.FileName);
var filePath = Path.Combine(path, shortName);
file2.SaveAs(filePath);
temp.Annex_Finance = Path.Combine(basePath, shortName);
}
db.Entry(temp).State = EntityState.Modified;
db.OAApprovers.RemoveRange(db.OAApprovers.Where(p => p.DocumentId == financeApproval.DocumentId && p.ApproverKey == cc_Finance));
}
}
if (db.FixedAssetInspection2.Where(p => p.DocumentId == tenderApproval.DocumentId).Count() == 0)
{
db.FixedAssetInspection2.Add(tenderApproval);
}
else
{
//在数据库中查询原有的记录
var temp = db.FixedAssetInspection2.Where(p => p.DocumentId == tenderApproval.DocumentId).FirstOrDefault();
if (selectedRole == 3)
{
temp.AssetRangeName = tenderApproval.AssetRangeName;
temp.AssetRangeCode = tenderApproval.AssetRangeCode;
temp.Remark_Purchase = tenderApproval.Remark_Purchase;
temp.AuditOpinion_Purchase = tenderApproval.AuditOpinion_Purchase;
temp.CarbonCopy_Purchase = tenderApproval.CarbonCopy_Purchase;
if (file3 != null && file3.ContentLength > 0)
{
var shortName = Guid.NewGuid().ToString() + Path.GetExtension(file3.FileName);
var filePath = Path.Combine(path, shortName);
file3.SaveAs(filePath);
temp.Annex_Purchase = Path.Combine(basePath, shortName);
}
db.Entry(temp).State = EntityState.Modified;
db.OAApprovers.RemoveRange(db.OAApprovers.Where(p => p.DocumentId == tenderApproval.DocumentId && p.ApproverKey == cc_Purchase));
}
}
//技术主管部门CC
if (!string.IsNullOrEmpty(financeApproval.CarbonCopy_Technology) && selectedRole == 1)
{
var oAApprover = new OAApprover();
oAApprover.DocumentId = financeApproval.DocumentId;
oAApprover.ApproverKey = cc_Technology;
oAApprover.ApproverValue = financeApproval.CarbonCopy_Technology;
db.OAApprovers.Add(oAApprover);
var cc_Array = financeApproval.CarbonCopy_Technology.Split(new char[] { ';' });
cc_Review1 = string.Empty;
foreach (string str in cc_Array)
{
if (!string.IsNullOrWhiteSpace(str))
{
cc_Review1 = cc_Review1 + "GWKF\\\\" + str + ";";
}
}
}
//财务部CC
if (!string.IsNullOrEmpty(financeApproval.CarbonCopy_Finance) && selectedRole == 2)
{
var oAApprover = new OAApprover();
oAApprover.DocumentId = financeApproval.DocumentId;
oAApprover.ApproverKey = cc_Finance;
oAApprover.ApproverValue = financeApproval.CarbonCopy_Finance;
db.OAApprovers.Add(oAApprover);
var cc_Array = financeApproval.CarbonCopy_Finance.Split(new char[] { ';' });
cc_Review2 = string.Empty;
foreach (string str in cc_Array)
{
if (!string.IsNullOrWhiteSpace(str))
{
cc_Review2 = cc_Review2 + "GWKF\\\\" + str + ";";
}
}
}
//采购部CC
if (!string.IsNullOrEmpty(tenderApproval.CarbonCopy_Purchase) && selectedRole == 3)
{
var oAApprover = new OAApprover();
oAApprover.DocumentId = financeApproval.DocumentId;
oAApprover.ApproverKey = cc_Purchase;
oAApprover.ApproverValue = tenderApproval.CarbonCopy_Purchase;
db.OAApprovers.Add(oAApprover);
var cc_Array = tenderApproval.CarbonCopy_Purchase.Split(new char[] { ';' });
cc_Review3 = string.Empty;
foreach (string str in cc_Array)
{
if (!string.IsNullOrWhiteSpace(str))
{
cc_Review3 = cc_Review3 + "GWKF\\\\" + str + ";";
}
}
}
////进出口部门
if (factoryApproval != null && selectedRole == 4)
{
factoryApproval.DocumentId = financeApproval.DocumentId;
db.FixedAssetInspection3.Add(factoryApproval);
}
}
break;
case 2:
{
var file4 = Request.Files["Annex_Factory"];
if (file4 != null && file4.ContentLength > 0)
{
var shortName = Guid.NewGuid().ToString() + Path.GetExtension(file4.FileName);
var filePath = Path.Combine(path, shortName);
file4.SaveAs(filePath);
factoryApproval.Annex_Factory = Path.Combine(basePath, shortName);
}
if (factoryApproval.FixedAssetInspection3Id == 0)
{
db.FixedAssetInspection3.Add(factoryApproval);
}
else
{
db.Entry(factoryApproval).State = EntityState.Modified;
db.OAApprovers.RemoveRange(db.OAApprovers.Where(p => p.DocumentId == factoryApproval.DocumentId && p.ApproverKey == cc_Factory));
}
if (!string.IsNullOrEmpty(factoryApproval.CarbonCopy_Factory))
{
var oAApprover = new OAApprover();
oAApprover.DocumentId = factoryApproval.DocumentId;
oAApprover.ApproverKey = cc_Factory;
oAApprover.ApproverValue = factoryApproval.CarbonCopy_Factory;
db.OAApprovers.Add(oAApprover);
var cc_Array = factoryApproval.CarbonCopy_Factory.Split(new char[] { ';' });
cc_Review4 = string.Empty;
foreach (string str in cc_Array)
{
if (!string.IsNullOrWhiteSpace(str))
{
cc_Review4 = cc_Review4 + "GWKF\\\\" + str + ";";
}
}
}
}
break;
default:
{ }
break;
}
//内管分组码
var innerTubeBlockCode = string.Empty;
#region 原获取数据方式
//if (formData["InnerTubeBlockCode"] != null)
//{
// innerTubeBlockCode = formData["InnerTubeBlockCode"].ToString();
// var documentId = 0;
// documentId = financeApproval.DocumentId;
// if (documentId == 0)
// {
// documentId = tenderApproval.DocumentId;
// }
// if (documentId == 0)
// {
// documentId = factoryApproval.DocumentId;
// }
// var fixedAsset = db.FixedAssets.Where(p => p.DocumentId == documentId).FirstOrDefault();
// if (fixedAsset != null)
// {
// fixedAsset.InnerTubeBlockCode = innerTubeBlockCode;
// }
//}
#endregion
#region 新获取数据方式
if (Request["InnerTubeBlockCode"] != null)
{
innerTubeBlockCode = Request["InnerTubeBlockCode"];
var documentId = 0;
documentId = financeApproval.DocumentId;
if (documentId == 0)
{
documentId = tenderApproval.DocumentId;
}
if (documentId == 0)
{
documentId = factoryApproval.DocumentId;
}
var fixedAsset = db.FixedAssets.Where(p => p.DocumentId == documentId).FirstOrDefault();
if (fixedAsset != null)
{
fixedAsset.InnerTubeBlockCode = innerTubeBlockCode;
}
}
#endregion
var count = db.SaveChanges();
//触发OA审批流程
var userID = string.Empty;
var userName = string.Empty;
var wFListItemID = 0;
var wFWorkListAuditingID = 0;
var actionName = string.Empty;
var OAMessage = "OK/同意! ";///审批意见
var OAFlowID = 0;///FlowID
#region 原获取数据方式
//if (formData["UserID"] != null)
//{
// userID = formData["UserID"].ToString();
//}
//if (formData["UserName"] != null)
//{
// userName = formData["UserName"].ToString();
//}
//if (formData["WFListItemID"] != null)
//{
// int.TryParse(formData["WFListItemID"].ToString(), out wFListItemID);
//}
//if (formData["WFWorkListAuditingID"] != null)
//{
// int.TryParse(formData["WFWorkListAuditingID"].ToString(), out wFWorkListAuditingID);
//}
//if (formData["ActionName"] != null)
//{
// actionName = formData["ActionName"].ToString();
//}
//if (formData["OAMessage"] != null)
//{
// OAMessage = formData["OAMessage"].ToString();
//}
//if (formData["OAFlowID"] != null)
//{
// int.TryParse(formData["OAFlowID"].ToString(), out OAFlowID);
// // OAFlowID = Convert.ToInt32(formData["OAFlowID"]);
//}
#endregion
#region 新获取数据方式
if (Request["UserID"] != null)
{
userID = Request["UserID"].ToString();
}
if (Request["UserName"] != null)
{
userName = Request["UserName"].ToString();
}
if (Request["WFListItemID"] != null)
{
int.TryParse(Request["WFListItemID"].ToString(), out wFListItemID);
}
if (Request["WFWorkListAuditingID"] != null)
{
int.TryParse(Request["WFWorkListAuditingID"].ToString(), out wFWorkListAuditingID);
}
if (Request["ActionName"] != null)
{
actionName = Request["ActionName"].ToString();
}
if (Request["OAMessage"] != null)
{
OAMessage = Request["OAMessage"].ToString();
}
if (Request["OAFlowID"] != null)
{
int.TryParse(Request["OAFlowID"].ToString(), out OAFlowID);
// OAFlowID = Convert.ToInt32(formData["OAFlowID"]);
}
#endregion
var oAGuid = db.Documents.Find(financeApproval.DocumentId).OAGuid;
var msg = "";
//审批动作
//var working = new SingleViewModel()
//{
// OaGuid = oAGuid,//工作流
// ActionName = actionName//步骤
//};
////查找 此工作流的该步骤 是否已存在 正在处理的审批动作
//var work = WorkingList.Where(p => p.OaGuid == working.OaGuid && p.ActionName == working.ActionName).FirstOrDefault();
//if (work != null)//有正在处理的审批动作
//{
// msg = "此任务正在被其他人审批中,请稍后再试!";
// //WorkingList.Remove(work);
// return new EmptyResult();
//}
//else//没有正在处理的审批动作
//{
// WorkingList.Add(working);//将审批动作添加到list
//}
var sb = new StringBuilder();
sb.Append("");
if (count > 0)
{
switch (stepId)
{
case 1:
{
sb.Clear();
sb.Append("{\"ActivityEditColumn\":[");
//sb.Append("{ ");
var hasKeyValue = false;
//财务部预算审核
if (!string.IsNullOrEmpty(financeApproval.CostAmountTypeCode.ToString()))
{
if (hasKeyValue == true)
{
sb.Append(",");
}
sb.Append("{ ");
sb.Append("\"ColumnName\":\"APAFinBudget\",");
sb.Append("\"ColumnValue\":\"" + financeApproval.CostAmountTypeCode + "\"");
sb.Append("}");
hasKeyValue = true;
}
//国内采购,国外采购
if (!string.IsNullOrEmpty(tenderApproval.AssetRangeCode.ToString()))
{
if (hasKeyValue == true)
{
sb.Append(",");
}
sb.Append("{ ");
sb.Append("\"ColumnName\":\"APAAssetClassification\",");
sb.Append("\"ColumnValue\":\"" + tenderApproval.AssetRangeCode + "\"");
sb.Append("}");
hasKeyValue = true;
}
//sb.Append("}");
//if (!string.IsNullOrEmpty(tenderApproval.BaseCurrencyTotalAmount.ToString()))///根据后面预算财务总金额
//{
// sb.Append(",");
// sb.Append("{ ");
// sb.Append("\"ColumnName\":\"TotalAmountRMB\",");
// sb.Append("\"ColumnValue\":\"" + tenderApproval.BaseCurrencyTotalAmount + "\"");
// sb.Append("}");
//}
if (!string.IsNullOrEmpty(cc_Review1))
{
if (hasKeyValue == true)
{
sb.Append(",");
}
sb.Append("{ ");
sb.Append("\"ColumnName\":\"CC\",");
sb.Append("\"ColumnValue\":\"" + cc_Review1 + "\"");
sb.Append("}");
hasKeyValue = true;
}
if (!string.IsNullOrEmpty(cc_Review2))
{
if (hasKeyValue == true)
{
sb.Append(",");
}
sb.Append("{ ");
sb.Append("\"ColumnName\":\"CC2\",");
sb.Append("\"ColumnValue\":\"" + cc_Review2 + "\"");
sb.Append("}");
hasKeyValue = true;
}
if (!string.IsNullOrEmpty(cc_Review3))
{
if (hasKeyValue == true)
{
sb.Append(",");
}
sb.Append("{ ");
sb.Append("\"ColumnName\":\"CC3\",");
sb.Append("\"ColumnValue\":\"" + cc_Review3 + "\"");
sb.Append("}");
hasKeyValue = true;
}
sb.Append("]}");
}
break;
case 2:
{
if (!string.IsNullOrEmpty(cc_Review4))
{
sb.Clear();
sb.Append("{\"ActivityEditColumn\":[");
sb.Append("{ ");
sb.Append("\"ColumnName\":\"CC4\",");
sb.Append("\"ColumnValue\":\"" + cc_Review4 + "\"");
sb.Append("}");
sb.Append("]}");
}
}
break;
default:
{ }
break;
}
}
APILog aPILog = new APILog
{
InterfaceSource = "Purchase",
Url = "/FixedAsset/ModifyDataSave",
MethodName = "FixedAssetModifyDataSave",
Caller = userName,
CallTime = DateTime.Now,
Remark = "固定资产OA同意或拒绝触发OA流程"
};
try
{
var aPILogDetail1 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sOAGuid",
Value = oAGuid
};
db.APILogDetails.Add(aPILogDetail1);
var aPILogDetail2 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sFlowTypeId",
Value = ((int)FlowTypeEnum.FixedAsset).ToString()
};
db.APILogDetails.Add(aPILogDetail2);
var aPILogDetail3 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sUserId",
Value = userID
};
db.APILogDetails.Add(aPILogDetail3);
var aPILogDetail4 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sUserName",
Value = userName
};
db.APILogDetails.Add(aPILogDetail4);
var aPILogDetail5 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sWFListItemID",
Value = wFListItemID.ToString()
};
db.APILogDetails.Add(aPILogDetail5);
var aPILogDetail6 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sWFWorkListAuditingID",
Value = wFWorkListAuditingID.ToString()
};
db.APILogDetails.Add(aPILogDetail6);
var aPILogDetail7 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sOAMessage",
Value = OAMessage
};
db.APILogDetails.Add(aPILogDetail7);
var aPILogDetail8 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sActionName",
Value = actionName
};
db.APILogDetails.Add(aPILogDetail8);
var aPILogDetail9 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = false,//入参
Key = "sUpdateJson",
Value = sb.ToString()
};
db.APILogDetails.Add(aPILogDetail9);
msg = new Common().UpdateOAWorkListAuditing(oAGuid, userID, userName, wFListItemID, wFWorkListAuditingID, OAMessage, actionName, sb.ToString(), (int)FlowTypeEnum.FixedAsset);
}
catch (Exception ex)
{
msg = "OA Exception:" + ex.Message;
var aPILogDetail11 = new APILogDetail
{
APILogId = aPILog.APILogId,
ParameterDirection = true,//出参
Key = "Exception",
Value = ex.Message
};
db.APILogDetails.Add(aPILogDetail11);
}
finally
{
aPILog.EndCallTime = DateTime.Now;
db.APILogs.Add(aPILog);
db.SaveChanges();
}
if (string.IsNullOrEmpty(msg))
{
//OA折腾,改回原来调接口API
//Thread t2 = new Thread(GetFlows);
//t2.Start(OAFlowID + "#" + working.OaGuid + "#" + working.ActionName);
////bool result = false;
////if (OAFlowID > 0 && !string.IsNullOrWhiteSpace(oAGuid))
//// result = new Common().GetFlowsInfo(oAGuid, OAFlowID);
////ExecuteThread = false;
}
//else
//{
// WorkingList.Remove(working);
//}
//return new EmptyResult();
return Json(new { Msg = msg }, JsonRequestBehavior.AllowGet);
}
HTML 代码:
@{
ViewBag.Title = "固定资产";
Layout = null;
}
需求内容 @*
需求内容 *@
资产一级分类
资产二级分类
资产三级分类
资产四级分类
资产型号
其他型号描述
工厂
需求数量
资产单价
预估金额
本位币金额
请购原因
预算信息
是否全新
需求日期
安置地点
是否低值资产
低值物料号
单据信息@*
单据信息 *@
请求单号
开 单 人
开单日期
需 求 人
需求公司
需求部门
成本中心
采购组
附件
点击查看附件
详细要求 @*
详细要求 *@
职能部门审批意见@*
职能部门审批意见 *@
数据决策 @*
数据决策 *@
审批职级 @*
审批职级 *@