public static Year GetYear(int iYearId, bool bCategoryItem = true) { try { DataTableCollection dtc = SqlDataAccess.ExecuteDatasetSP("TYear_ById_SLCT", new List <SqlParameter>() { new SqlParameter("iYearId", iYearId), new SqlParameter("bCategoryItem", bCategoryItem) }).Tables; if (dtc[0].Rows.Count == 0) { return(null); } Year year = ObjectGenerator <Year> .GeneratFromDataRow(dtc[0].Rows[0]); List <CategoryItem> lCategoryItem = new List <CategoryItem>(); if (bCategoryItem) { foreach (DataRow dr in dtc[2].Rows) { lCategoryItem.Add(ObjectGenerator <CategoryItem> .GeneratFromDataRow(dr)); } } List <CategoryType> lCategoryType = new List <CategoryType>(); foreach (DataRow dr in dtc[1].Rows) { lCategoryType.Add(ObjectGenerator <CategoryType> .GeneratFromDataRow(dr)); lCategoryType.Last().lCategoryItem = lCategoryItem.Where(ci => ci.iCatTypeId == lCategoryType.Last().iCatTypeId).ToList(); } foreach (CategoryType ct in lCategoryType) { CategoryType cat = lCategoryType.Where(c => c.iCatTypeId == ct.iCatTypeParentId).FirstOrDefault(); if (cat != null) { cat.lCategoryType.Add(ct); } } year.lCategoryType = lCategoryType.Where(c => c.iCatTypeParentId == 0).ToList(); return(year); } catch (Exception ex) { Log.LogError("GetYear / TYear_SLCT", "iYearId = " + iYearId + ", exception = " + ex); return(null); } }
public static CategoryType InsertUpdateCategoryType(int iUserId, CategoryType categoryType) { try { List <SqlParameter> parameters = ObjectGenerator <CategoryType> .GetSqlParametersFromObject(categoryType); parameters.Add(new SqlParameter("iUserId", iUserId)); categoryType.iCatTypeId = int.Parse(SqlDataAccess.ExecuteDatasetSP("TCategoryType_INS_UPD", parameters).Tables[0].Rows[0][0].ToString()); return(categoryType); } catch (Exception ex) { Log.LogError("InsertUpdateCategoryType / TCategoryType_INS_UPD", "iUserId = " + iUserId + ", categoryType = " + JsonConvert.SerializeObject(categoryType) + ", exception = " + ex); return(null); } }
public static List <Year> GetYears() { try { DataTableCollection dtc = SqlDataAccess.ExecuteDatasetSP("TYear_SLCT").Tables; List <CategoryType> lCategoryType = new List <CategoryType>(); foreach (DataRow dr in dtc[1].Rows) { lCategoryType.Add(ObjectGenerator <CategoryType> .GeneratFromDataRow(dr)); } foreach (CategoryType ct in lCategoryType) { CategoryType cat = lCategoryType.Where(c => c.iCatTypeId == ct.iCatTypeParentId).FirstOrDefault(); if (cat != null) { cat.lCategoryType.Add(ct); } } List <Year> years = new List <Year>(); foreach (DataRow dr in dtc[0].Rows) { years.Add(ObjectGenerator <Year> .GeneratFromDataRow(dr)); years.Last().lCategoryType = lCategoryType.Where(c => c.iCatTypeParentId == 0 && c.iYearId == years.Last().iYearId).ToList(); } return(years); } catch (Exception ex) { Log.LogError("GetYears / TYear_SLCT", "exception = " + ex); return(null); } }