public ActionResult OrgAttribute(int? optitemCount,Guid id) { MemberOrganization memberOrganization; if (Session["sessionId"] != null) { string sid = Session["sessionId"].ToString(); id = new Guid(sid); memberOrganization = (from m in dbEntity.MemberOrganizations where (m.Gid == id) select m).Single(); } else memberOrganization = new MemberOrganization(); if (!ModelState.IsValid) { ICollection<MemberOrgAttribute> memberOrgAttributes = new List<MemberOrgAttribute>(); for (int i = 0; i < optitemCount; i++) { MemberOrgAttribute memberOrgAttribute = new MemberOrgAttribute(); memberOrgAttribute.OrgID = memberOrganization.Gid; // memberOrgAttribute.OptID = memberOrganization.Attributes.ElementAt(i).OptID; // memberOrgAttribute.OptResult = memberOrganization.Attributes.ElementAt(i).OptResult; // memberOrgAttribute.Matter = memberOrganization.Attributes.ElementAt(i).Matter ; memberOrgAttribute.OptID = new Guid(Request.Form["OptID" + i]); memberOrgAttribute.OptResult = new Guid(Request.Form["OptResult" + i]); memberOrgAttribute.Matter = Request.Form["Matter" + i]; memberOrgAttributes.Add(memberOrgAttribute); } memberOrganization.Attributes = memberOrgAttributes; if (Session["sessionId"] == null) { dbEntity.MemberOrganizations.Add(memberOrganization); } dbEntity.SaveChanges(); return RedirectToAction("Index"); } return View(); }
/// <summary> /// 导入组织属性 /// </summary> /// <param name="sExcelFile">Excel文件名</param> /// <param name="sSheetName">Sheet名</param> public void ImportOrgAttrib(string sExcelFile, string sSheetName) { try { ExcelData oExcel = new ExcelData(sExcelFile, sSheetName); DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"]; DataColumn colMainCode = oExcel.ExcelTable.Columns["属性代码"]; DataColumn colOptCode = oExcel.ExcelTable.Columns["结果代码"]; DataColumn colOptValue = oExcel.ExcelTable.Columns["结果值"]; DataColumn colRemark = oExcel.ExcelTable.Columns["备注"]; string sLastOrgCode = ""; MemberOrganization oOrgan = null; foreach (DataRow row in oExcel.ExcelTable.Rows) { string sOrgCode = row[colOrgan].ToString(); string sMainCode = row[colMainCode].ToString(); string sOptCode = row[colOptCode].ToString(); string sOptValue = row[colOptValue].ToString(); string sRemark = row[colRemark].ToString(); if (!String.IsNullOrEmpty(sOrgCode) && (sOrgCode != sLastOrgCode)) { oOrgan = (from o in dbEntity.MemberOrganizations where o.Code == sOrgCode && o.Otype == (byte)ModelEnum.OrganizationType.CORPORATION select o).FirstOrDefault(); sLastOrgCode = sOrgCode; } var oOptional = (from o in dbEntity.GeneralOptionals where o.Deleted == false && o.OrgID == oOrgan.Gid && o.Code == sMainCode select o).FirstOrDefault(); if (oOptional != null) { GeneralOptItem oOptItem = null; if (oOptional.InputMode == (byte)ModelEnum.OptionalInputMode.COMBOBOX) { oOptItem = (from i in dbEntity.GeneralOptItems where i.Deleted == false && i.Code == sOptCode && i.OptID == oOptional.Gid select i).FirstOrDefault(); } var oOrgAttrib = (from a in dbEntity.MemberOrgAttributes where a.OrgID == oOrgan.Gid && a.OptID == oOptional.Gid select a).FirstOrDefault(); if (oOrgAttrib == null) { oOrgAttrib = new MemberOrgAttribute { Organization = oOrgan, Optional = oOptional }; dbEntity.MemberOrgAttributes.Add(oOrgAttrib); } oOrgAttrib.OptionalResult = oOptItem; oOrgAttrib.Matter = sOptValue; oOrgAttrib.Remark = sRemark; dbEntity.SaveChanges(); if (Utility.ConfigHelper.GlobalConst.IsDebug) Debug.WriteLine("{0} {1} {2}", this.ToString(), sMainCode, sRemark); } } oEventBLL.WriteEvent(String.Format("导入MemberOrgAttribute成功: {0} {1}", sExcelFile, sSheetName), ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString()); } catch (Exception ex) { oEventBLL.WriteEvent(String.Format("导入MemberOrgAttribute错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message), ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString()); } }