/// <summary> /// 保存添加的私有分类 /// </summary> /// <param name="parentId">父类ID</param> /// <param name="StandardCategoryNodeCollection"></param> /// <returns></returns> public ActionResult AddPrivateCategoryNode(GeneralPrivateCategory newGeneralCategory) { GeneralPrivateCategory oGeneralPrivateCategory = new GeneralPrivateCategory { Ctype = newGeneralCategory.Ctype, Code = newGeneralCategory.Code, aParent = newGeneralCategory.aParent, Name = new GeneralResource(ModelEnum.ResourceType.STRING, newGeneralCategory.Name), Sorting = newGeneralCategory.Sorting, OrgID = GetOrganization() }; Guid? parentId = newGeneralCategory.aParent; dbEntity.GeneralPrivateCategorys.Add(oGeneralPrivateCategory); dbEntity.SaveChanges(); return RedirectToAction("PrivateCategoryListTable", new { categoryId = parentId }); }
/// <summary> /// 添加程序 /// </summary> /// <param name="parentId"></param> /// <param name="programNodeCollection"></param> /// <returns></returns> public ActionResult AddProgramNode(Guid parentId, FormCollection programNodeCollection) { GeneralPrivateCategory oGeneralPrivateCategory = new GeneralPrivateCategory(); oGeneralPrivateCategory.OrgID = GetOrganization(); oGeneralPrivateCategory.aParent = parentId; oGeneralPrivateCategory.Code = programNodeCollection["Code"]; oGeneralPrivateCategory.Sorting = Convert.ToInt32(programNodeCollection["Sorting"]); GeneralResource oResouce = new GeneralResource(); oResouce.Code = "4534645"; oResouce.Culture = 2052; oResouce.Matter = programNodeCollection["Name.Matter"]; dbEntity.GeneralResources.Add(oResouce); oGeneralPrivateCategory.Name = oResouce; dbEntity.GeneralPrivateCategorys.Add(oGeneralPrivateCategory); dbEntity.SaveChanges(); return RedirectToAction("Index"); }
/// <summary> /// 导入私有分类 /// </summary> /// <param name="sExcelFile"></param> /// <param name="sSheetName"></param> public void ImportPrivateCategories(string sExcelFile, string sSheetName) { try { ExcelData oExcel = new ExcelData(sExcelFile, sSheetName); DataColumn colOrgan = oExcel.ExcelTable.Columns["组织"]; DataColumn colCode = oExcel.ExcelTable.Columns["代码"]; DataColumn colParent = oExcel.ExcelTable.Columns["上级"]; DataColumn colType = oExcel.ExcelTable.Columns["类型"]; DataColumn colNameCN = oExcel.ExcelTable.Columns["中文名称"]; DataColumn colNameUS = oExcel.ExcelTable.Columns["英文名称"]; DataColumn colSort = oExcel.ExcelTable.Columns["排序"]; DataColumn colUnitType = oExcel.ExcelTable.Columns["单位类型"]; DataColumn colUnitCode = oExcel.ExcelTable.Columns["计量单位"]; DataColumn colShow = oExcel.ExcelTable.Columns["是否显示"]; DataColumn colGuarantee = oExcel.ExcelTable.Columns["显示保质期"]; DataColumn colRemark = oExcel.ExcelTable.Columns["备注"]; string sLastParent = ""; GeneralPrivateCategory oParent = null; foreach (DataRow row in oExcel.ExcelTable.Rows) { string sOrgan = row[colOrgan].ToString(); var oOrgan = (from o in dbEntity.MemberOrganizations where o.Code == sOrgan && o.Otype == (byte)ModelEnum.OrganizationType.CORPORATION select o).FirstOrDefault(); string sCode = row[colCode].ToString(); string sParent = row[colParent].ToString(); byte nType; Byte.TryParse(row[colType].ToString(), out nType); GeneralResource oName = new GeneralResource(ModelEnum.ResourceType.STRING, 2052, row[colNameCN].ToString(), 1033, row[colNameUS].ToString()); int nSort; Int32.TryParse(row[colSort].ToString(), out nSort); byte nUnitType; Byte.TryParse(row[colUnitType].ToString(), out nUnitType); string sUnitCode = row[colUnitCode].ToString(); bool bShow = row[colShow].ToString() == "1" ? true : false; bool bGuarantee = row[colGuarantee].ToString() == "1" ? true : false; string sRemark = row[colRemark].ToString(); if (String.IsNullOrEmpty(sParent)) { oParent = null; sLastParent = ""; } else if (sParent != sLastParent) { oParent = (from c in dbEntity.GeneralPrivateCategorys where c.OrgID == oOrgan.Gid && c.Ctype == nType && c.Code == sParent select c).FirstOrDefault(); sLastParent = sParent; } var oCategory = (from c in dbEntity.GeneralPrivateCategorys where c.OrgID == oOrgan.Gid && c.Ctype == nType && c.Code == sCode select c).FirstOrDefault(); if (oCategory == null) { oCategory = new GeneralPrivateCategory { Organization = oOrgan, Ctype = nType, Code = sCode }; dbEntity.GeneralPrivateCategorys.Add(oCategory); } oCategory.Parent = oParent; if (oCategory.Name == null) oCategory.Name = oName; else oCategory.Name.SetResource(ModelEnum.ResourceType.STRING, oName); oCategory.Sorting = nSort; oCategory.StandardUnit = dbEntity.GeneralMeasureUnits.Where(u => u.Utype == nUnitType && u.Code == sUnitCode).FirstOrDefault(); oCategory.Show = bShow; oCategory.ShowGuarantee = bGuarantee; oCategory.Remark = sRemark; dbEntity.SaveChanges(); if (Utility.ConfigHelper.GlobalConst.IsDebug) Debug.WriteLine("{0} {1} {2}", this.ToString(), sCode, sRemark); } oEventBLL.WriteEvent(String.Format("导入GeneralPrivateCategory成功: {0} {1}", sExcelFile, sSheetName), ModelEnum.ActionLevel.GENERIC, ModelEnum.ActionSource.SYSTEM, this.ToString()); } catch (Exception ex) { oEventBLL.WriteEvent(String.Format("导入GeneralPrivateCategory错误: {0} {1} {2}", sExcelFile, sSheetName, ex.Message), ModelEnum.ActionLevel.ERROR, ModelEnum.ActionSource.SYSTEM, this.ToString()); } }
/// <summary> /// 添加程序 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult ProgramNodeAdd(Guid id) { GeneralPrivateCategory oGeneralPrivateCategory = new GeneralPrivateCategory(); oGeneralPrivateCategory.aParent = id; oGeneralPrivateCategory.Parent = dbEntity.GeneralPrivateCategorys.Where(p => p.Gid == id).Single(); return View(oGeneralPrivateCategory); }
public List<SelectListItem> GetPrivateCategoryTypeSelectlist() { List<SelectListItem> oPrivateCategoryTypeList = new List<SelectListItem>(); List<ListItem> oPrivateCategorys = new GeneralPrivateCategory().CategoryTypeList; foreach (var item in oPrivateCategorys) { oPrivateCategoryTypeList.Add(new SelectListItem { Value = item.Value, Text = item.Text }); } return oPrivateCategoryTypeList; }
/// <summary> /// 保存编辑的私有分类 /// </summary> /// <param name="gid"></param> /// <param name="standardCategoryNodeCollection"></param> /// <returns></returns> public ActionResult SavePrivateCategoryNode(GeneralPrivateCategory editPrivateCategory) { var oldPrivateCategory = dbEntity.GeneralPrivateCategorys.Include("Name").Include("Parent").Where(s => s.Gid == editPrivateCategory.Gid).Single(); oldPrivateCategory.Code = editPrivateCategory.Code; oldPrivateCategory.Name.SetResource(ModelEnum.ResourceType.STRING, editPrivateCategory.Name); oldPrivateCategory.Sorting = editPrivateCategory.Sorting; if (ModelState.IsValid) { dbEntity.Entry(oldPrivateCategory).State = EntityState.Modified; dbEntity.SaveChanges(); } return RedirectToAction("PrivateCategoryListTable", new { categoryId = oldPrivateCategory.aParent }); }
/// <summary> /// 添加私有分类页面 /// </summary> /// <param name="id"></param> /// <returns></returns> public ActionResult PrivateCategoryNodeAdd(byte categoryType) { var oParent = dbEntity.GeneralPrivateCategorys.Where(g => g.Gid == oPrivateCagegoryGid).SingleOrDefault(); Guid orgId = GetOrganization(); Guid orgGid = (oPrivateCategoryOrg == null) ? orgId : (Guid)oPrivateCategoryOrg; if (oParent != null) { GeneralPrivateCategory oGeneralPrivateCategory = new GeneralPrivateCategory { Ctype = categoryType, aParent = oPrivateCagegoryGid, Name = NewResource(ModelEnum.ResourceType.STRING,orgGid), Parent = oParent }; ViewBag.IsShow = SelectEnumList(oGeneralPrivateCategory.Show); ViewBag.UnitList = GetUnitList(); return View(oGeneralPrivateCategory); } else { GeneralPrivateCategory oGeneralPrivateCategory = new GeneralPrivateCategory { Ctype = categoryType, Name = NewResource(ModelEnum.ResourceType.STRING, orgGid) }; ViewBag.IsShow = SelectEnumList(oGeneralPrivateCategory.Show); ViewBag.UnitList = GetUnitList(); return View(oGeneralPrivateCategory); } }