//Convert DataTable To List method public List <BusinessCategoryClass> ConvertToList(DataTable dt) { List <BusinessCategoryClass> BusinessCategorylist = new List <BusinessCategoryClass>(); for (int i = 0; i < dt.Rows.Count; i++) { BusinessCategoryClass obj_BusinessCategory = new BusinessCategoryClass(); if (Convert.ToString(dt.Rows[i]["Businesscategoryid"]) != "") { obj_BusinessCategory.Businesscategoryid = Convert.ToInt32(dt.Rows[i]["Businesscategoryid"]); } if (Convert.ToString(dt.Rows[i]["Businessid"]) != "") { obj_BusinessCategory.Businessid = Convert.ToInt32(dt.Rows[i]["Businessid"]); } if (Convert.ToString(dt.Rows[i]["Categoryid"]) != "") { obj_BusinessCategory.Categoryid = Convert.ToInt32(dt.Rows[i]["Categoryid"]); } BusinessCategorylist.Add(obj_BusinessCategory); } return(BusinessCategorylist); }
//Select Constructor public BusinessCategoryCtl(Int32?id) { obj_con = new ConnectionCls(); BusinessCategoryClass obj_Bus = new BusinessCategoryClass(); using (DataTable dt = selectdatatable(id)) { if (dt.Rows.Count > 0) { obj_Bus.Businesscategoryid = Convert.ToInt32(dt.Rows[0]["Businesscategoryid"]); obj_Bus.Businessid = Convert.ToInt32(dt.Rows[0]["Businessid"]); obj_Bus.Categoryid = Convert.ToInt32(dt.Rows[0]["Categoryid"]); } } }
//insert data into database public Int32?insert(BusinessCategoryClass obj) { try { obj_con.clearParameter(); createParameter(obj, DBTrans.Insert); obj_con.BeginTransaction(); obj_con.ExecuteNoneQuery("sp_BusinessCategory_insert", CommandType.StoredProcedure); obj_con.CommitTransaction(); return(obj.Businesscategoryid = Convert.ToInt32(obj_con.getValue("@Businesscategoryid"))); } catch (Exception ex) { obj_con.RollbackTransaction(); throw new Exception("sp_BusinessCategory_insert:" + ex.Message); } }
//update edited object public BusinessCategoryClass updateObject(BusinessCategoryClass obj) { try { BusinessCategoryClass oldObj = selectById(obj.Businesscategoryid); if (obj.Businessid == null) { obj.Businessid = oldObj.Businessid; } if (obj.Categoryid == null) { obj.Categoryid = oldObj.Categoryid; } return(obj); } catch (Exception ex) { throw new Exception(ex.Message); } }
//create parameter public void createParameter(BusinessCategoryClass obj, DB_con.DBTrans trans) { try { obj_con.clearParameter(); if (Convert.ToString(obj.Businessid) != "") { obj_con.addParameter("@Businessid", string.IsNullOrEmpty(Convert.ToString(obj.Businessid)) ? 0 : obj.Businessid); } else { obj_con.addParameter("@Businessid", DBNull.Value); } if (Convert.ToString(obj.Categoryid) != "") { obj_con.addParameter("@Categoryid", string.IsNullOrEmpty(Convert.ToString(obj.Categoryid)) ? 0 : obj.Categoryid); } else { obj_con.addParameter("@Categoryid", DBNull.Value); } if (Convert.ToString(obj.Businesscategoryid) != "") { obj_con.addParameter("@Businesscategoryid", Convert.ToInt32(obj.Businesscategoryid), trans); } else { obj_con.addParameter("@Businesscategoryid", DBNull.Value); } } catch (Exception ex) { throw ex; } }
//Convert DataTable To object method public BusinessCategoryClass ConvertToOjbect(DataTable dt) { BusinessCategoryClass obj_BusinessCategory = new BusinessCategoryClass(); for (int i = 0; i < dt.Rows.Count; i++) { if (Convert.ToString(dt.Rows[i]["Businesscategoryid"]) != "") { obj_BusinessCategory.Businesscategoryid = Convert.ToInt32(dt.Rows[i]["Businesscategoryid"]); } if (Convert.ToString(dt.Rows[i]["Businessid"]) != "") { obj_BusinessCategory.Businessid = Convert.ToInt32(dt.Rows[i]["Businessid"]); } if (Convert.ToString(dt.Rows[i]["Categoryid"]) != "") { obj_BusinessCategory.Categoryid = Convert.ToInt32(dt.Rows[i]["Categoryid"]); } } return(obj_BusinessCategory); }