public List<Maticsoft.Model.Shop.Tags.TagCategories> DataTableToList(DataTable dt) { List<Maticsoft.Model.Shop.Tags.TagCategories> list = new List<Maticsoft.Model.Shop.Tags.TagCategories>(); int count = dt.Rows.Count; if (count > 0) { for (int i = 0; i < count; i++) { Maticsoft.Model.Shop.Tags.TagCategories item = new Maticsoft.Model.Shop.Tags.TagCategories(); if ((dt.Rows[i]["ID"] != null) && (dt.Rows[i]["ID"].ToString() != "")) { item.ID = int.Parse(dt.Rows[i]["ID"].ToString()); } if ((dt.Rows[i]["CategoryName"] != null) && (dt.Rows[i]["CategoryName"].ToString() != "")) { item.CategoryName = dt.Rows[i]["CategoryName"].ToString(); } if ((dt.Rows[i]["ParentCategoryId"] != null) && (dt.Rows[i]["ParentCategoryId"].ToString() != "")) { item.ParentCategoryId = new int?(int.Parse(dt.Rows[i]["ParentCategoryId"].ToString())); } if ((dt.Rows[i]["DisplaySequence"] != null) && (dt.Rows[i]["DisplaySequence"].ToString() != "")) { item.DisplaySequence = int.Parse(dt.Rows[i]["DisplaySequence"].ToString()); } if ((dt.Rows[i]["Depth"] != null) && (dt.Rows[i]["Depth"].ToString() != "")) { item.Depth = int.Parse(dt.Rows[i]["Depth"].ToString()); } if ((dt.Rows[i]["Path"] != null) && (dt.Rows[i]["Path"].ToString() != "")) { item.Path = dt.Rows[i]["Path"].ToString(); } if ((dt.Rows[i]["Meta_Title"] != null) && (dt.Rows[i]["Meta_Title"].ToString() != "")) { item.Meta_Title = dt.Rows[i]["Meta_Title"].ToString(); } if ((dt.Rows[i]["Meta_Description"] != null) && (dt.Rows[i]["Meta_Description"].ToString() != "")) { item.Meta_Description = dt.Rows[i]["Meta_Description"].ToString(); } if ((dt.Rows[i]["Meta_Keywords"] != null) && (dt.Rows[i]["Meta_Keywords"].ToString() != "")) { item.Meta_Keywords = dt.Rows[i]["Meta_Keywords"].ToString(); } if ((dt.Rows[i]["HasChildren"] != null) && (dt.Rows[i]["HasChildren"].ToString() != "")) { if ((dt.Rows[i]["HasChildren"].ToString() == "1") || (dt.Rows[i]["HasChildren"].ToString().ToLower() == "true")) { item.HasChildren = true; } else { item.HasChildren = false; } } if ((dt.Rows[i]["Status"] != null) && (dt.Rows[i]["Status"].ToString() != "")) { item.Status = new int?(int.Parse(dt.Rows[i]["Status"].ToString())); } if ((dt.Rows[i]["Remark"] != null) && (dt.Rows[i]["Remark"].ToString() != "")) { item.Remark = dt.Rows[i]["Remark"].ToString(); } list.Add(item); } } return list; }
public Maticsoft.Model.Shop.Tags.TagCategories GetModel(int ID) { StringBuilder builder = new StringBuilder(); builder.Append("SELECT TOP 1 ID,CategoryName,ParentCategoryId,DisplaySequence,Depth,Path,Meta_Title,Meta_Description,Meta_Keywords,HasChildren,Status,Remark FROM Shop_TagCategories "); builder.Append(" WHERE ID=@ID"); SqlParameter[] cmdParms = new SqlParameter[] { new SqlParameter("@ID", SqlDbType.Int, 4) }; cmdParms[0].Value = ID; Maticsoft.Model.Shop.Tags.TagCategories categories = new Maticsoft.Model.Shop.Tags.TagCategories(); DataSet set = DbHelperSQL.Query(builder.ToString(), cmdParms); if (set.Tables[0].Rows.Count <= 0) { return null; } if ((set.Tables[0].Rows[0]["ID"] != null) && (set.Tables[0].Rows[0]["ID"].ToString() != "")) { categories.ID = int.Parse(set.Tables[0].Rows[0]["ID"].ToString()); } if ((set.Tables[0].Rows[0]["CategoryName"] != null) && (set.Tables[0].Rows[0]["CategoryName"].ToString() != "")) { categories.CategoryName = set.Tables[0].Rows[0]["CategoryName"].ToString(); } if ((set.Tables[0].Rows[0]["ParentCategoryId"] != null) && (set.Tables[0].Rows[0]["ParentCategoryId"].ToString() != "")) { categories.ParentCategoryId = new int?(int.Parse(set.Tables[0].Rows[0]["ParentCategoryId"].ToString())); } if ((set.Tables[0].Rows[0]["DisplaySequence"] != null) && (set.Tables[0].Rows[0]["DisplaySequence"].ToString() != "")) { categories.DisplaySequence = int.Parse(set.Tables[0].Rows[0]["DisplaySequence"].ToString()); } if ((set.Tables[0].Rows[0]["Depth"] != null) && (set.Tables[0].Rows[0]["Depth"].ToString() != "")) { categories.Depth = int.Parse(set.Tables[0].Rows[0]["Depth"].ToString()); } if ((set.Tables[0].Rows[0]["Path"] != null) && (set.Tables[0].Rows[0]["Path"].ToString() != "")) { categories.Path = set.Tables[0].Rows[0]["Path"].ToString(); } if ((set.Tables[0].Rows[0]["Meta_Title"] != null) && (set.Tables[0].Rows[0]["Meta_Title"].ToString() != "")) { categories.Meta_Title = set.Tables[0].Rows[0]["Meta_Title"].ToString(); } if ((set.Tables[0].Rows[0]["Meta_Description"] != null) && (set.Tables[0].Rows[0]["Meta_Description"].ToString() != "")) { categories.Meta_Description = set.Tables[0].Rows[0]["Meta_Description"].ToString(); } if ((set.Tables[0].Rows[0]["Meta_Keywords"] != null) && (set.Tables[0].Rows[0]["Meta_Keywords"].ToString() != "")) { categories.Meta_Keywords = set.Tables[0].Rows[0]["Meta_Keywords"].ToString(); } if ((set.Tables[0].Rows[0]["HasChildren"] != null) && (set.Tables[0].Rows[0]["HasChildren"].ToString() != "")) { if ((set.Tables[0].Rows[0]["HasChildren"].ToString() == "1") || (set.Tables[0].Rows[0]["HasChildren"].ToString().ToLower() == "true")) { categories.HasChildren = true; } else { categories.HasChildren = false; } } if ((set.Tables[0].Rows[0]["Status"] != null) && (set.Tables[0].Rows[0]["Status"].ToString() != "")) { categories.Status = new int?(int.Parse(set.Tables[0].Rows[0]["Status"].ToString())); } if ((set.Tables[0].Rows[0]["Remark"] != null) && (set.Tables[0].Rows[0]["Remark"].ToString() != "")) { categories.Remark = set.Tables[0].Rows[0]["Remark"].ToString(); } return categories; }