Example #1
0
        //Convert DataTable To List method
        public List <CategoriesClass> ConvertToList(DataTable dt)
        {
            List <CategoriesClass> Categorieslist = new List <CategoriesClass>();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                CategoriesClass obj_Categories = new CategoriesClass();

                if (Convert.ToString(dt.Rows[i]["Categoryid"]) != "")
                {
                    obj_Categories.Categoryid = Convert.ToInt32(dt.Rows[i]["Categoryid"]);
                }

                if (Convert.ToString(dt.Rows[i]["Categoryname"]) != "")
                {
                    obj_Categories.Categoryname = Convert.ToString(dt.Rows[i]["Categoryname"]);
                }

                if (Convert.ToString(dt.Rows[i]["Parentcategoryid"]) != "")
                {
                    obj_Categories.Parentcategoryid = Convert.ToInt32(dt.Rows[i]["Parentcategoryid"]);
                }

                if (Convert.ToString(dt.Rows[i]["Categoryurl"]) != "")
                {
                    obj_Categories.Categoryurl = Convert.ToString(dt.Rows[i]["Categoryurl"]);
                }

                if (Convert.ToString(dt.Rows[i]["Isfeaturedcategory"]) != "")
                {
                    obj_Categories.Isfeaturedcategory = Convert.ToBoolean(dt.Rows[i]["Isfeaturedcategory"]);
                }

                if (Convert.ToString(dt.Rows[i]["Isactive"]) != "")
                {
                    obj_Categories.Isactive = Convert.ToBoolean(dt.Rows[i]["Isactive"]);
                }

                if (Convert.ToString(dt.Rows[i]["Isdeleted"]) != "")
                {
                    obj_Categories.Isdeleted = Convert.ToBoolean(dt.Rows[i]["Isdeleted"]);
                }

                if (Convert.ToString(dt.Rows[i]["Createdon"]) != "")
                {
                    obj_Categories.Createdon = Convert.ToDateTime(dt.Rows[i]["Createdon"]);
                }

                if (Convert.ToString(dt.Rows[i]["Deletedon"]) != "")
                {
                    obj_Categories.Deletedon = Convert.ToDateTime(dt.Rows[i]["Deletedon"]);
                }


                Categorieslist.Add(obj_Categories);
            }
            return(Categorieslist);
        }
Example #2
0
        //update edited object
        public CategoriesClass updateObject(CategoriesClass obj)
        {
            try
            {
                CategoriesClass oldObj = selectById(obj.Categoryid);
                if (obj.Categoryname == null)
                {
                    obj.Categoryname = oldObj.Categoryname;
                }

                if (obj.Parentcategoryid == null)
                {
                    obj.Parentcategoryid = oldObj.Parentcategoryid;
                }

                if (obj.Categoryurl == null)
                {
                    obj.Categoryurl = oldObj.Categoryurl;
                }

                if (obj.Isfeaturedcategory == null)
                {
                    obj.Isfeaturedcategory = oldObj.Isfeaturedcategory;
                }

                if (obj.Isactive == null)
                {
                    obj.Isactive = oldObj.Isactive;
                }

                if (obj.Isdeleted == null)
                {
                    obj.Isdeleted = oldObj.Isdeleted;
                }

                if (obj.Createdon == null)
                {
                    obj.Createdon = oldObj.Createdon;
                }

                if (obj.Deletedon == null)
                {
                    obj.Deletedon = oldObj.Deletedon;
                }

                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #3
0
 //update data into database
 public Int32?update(CategoriesClass obj)
 {
     try
     {
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Update);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_Categories_update", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Categoryid = Convert.ToInt32(obj_con.getValue("@Categoryid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_Categories_update:" + ex.Message);
     }
 }
Example #4
0
        //Select Constructor
        public CategoriesCtl(Int32?id)
        {
            obj_con = new ConnectionCls();
            CategoriesClass obj_Cat = new CategoriesClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_Cat.Categoryid         = Convert.ToInt32(dt.Rows[0]["Categoryid"]);
                    obj_Cat.Categoryname       = Convert.ToString(dt.Rows[0]["Categoryname"]);
                    obj_Cat.Parentcategoryid   = Convert.ToInt32(dt.Rows[0]["Parentcategoryid"]);
                    obj_Cat.Categoryurl        = Convert.ToString(dt.Rows[0]["Categoryurl"]);
                    obj_Cat.Isfeaturedcategory = Convert.ToBoolean(dt.Rows[0]["Isfeaturedcategory"]);
                    obj_Cat.Isactive           = Convert.ToBoolean(dt.Rows[0]["Isactive"]);
                    obj_Cat.Isdeleted          = Convert.ToBoolean(dt.Rows[0]["Isdeleted"]);
                    obj_Cat.Createdon          = Convert.ToDateTime(dt.Rows[0]["Createdon"]);
                    obj_Cat.Deletedon          = Convert.ToDateTime(dt.Rows[0]["Deletedon"]);
                }
            }
        }
Example #5
0
        //create parameter
        public void createParameter(CategoriesClass obj, DB_con.DBTrans trans)
        {
            try
            {
                obj_con.clearParameter();

                if (Convert.ToString(obj.Categoryname) != "")
                {
                    obj_con.addParameter("@Categoryname", string.IsNullOrEmpty(Convert.ToString(obj.Categoryname)) ? "" : obj.Categoryname);
                }
                else
                {
                    obj_con.addParameter("@Categoryname", DBNull.Value);
                }

                if (Convert.ToString(obj.Parentcategoryid) != "")
                {
                    obj_con.addParameter("@Parentcategoryid", string.IsNullOrEmpty(Convert.ToString(obj.Parentcategoryid)) ? 0 : obj.Parentcategoryid);
                }
                else
                {
                    obj_con.addParameter("@Parentcategoryid", DBNull.Value);
                }

                if (Convert.ToString(obj.Categoryurl) != "")
                {
                    obj_con.addParameter("@Categoryurl", string.IsNullOrEmpty(Convert.ToString(obj.Categoryurl)) ? "" : obj.Categoryurl);
                }
                else
                {
                    obj_con.addParameter("@Categoryurl", DBNull.Value);
                }

                if (Convert.ToString(obj.Isfeaturedcategory) != "")
                {
                    obj_con.addParameter("@Isfeaturedcategory", string.IsNullOrEmpty(Convert.ToString(obj.Isfeaturedcategory)) ? false : obj.Isfeaturedcategory);
                }
                else
                {
                    obj_con.addParameter("@Isfeaturedcategory", DBNull.Value);
                }

                if (Convert.ToString(obj.Isactive) != "")
                {
                    obj_con.addParameter("@Isactive", string.IsNullOrEmpty(Convert.ToString(obj.Isactive)) ? false : obj.Isactive);
                }
                else
                {
                    obj_con.addParameter("@Isactive", DBNull.Value);
                }

                if (Convert.ToString(obj.Isdeleted) != "")
                {
                    obj_con.addParameter("@Isdeleted", string.IsNullOrEmpty(Convert.ToString(obj.Isdeleted)) ? false : obj.Isdeleted);
                }
                else
                {
                    obj_con.addParameter("@Isdeleted", DBNull.Value);
                }

                if (Convert.ToString(obj.Createdon) != "")
                {
                    obj_con.addParameter("@Createdon", string.IsNullOrEmpty(Convert.ToString(obj.Createdon)) ? Convert.ToDateTime("1900-01-01") : obj.Createdon);
                }
                else
                {
                    obj_con.addParameter("@Createdon", DBNull.Value);
                }

                if (Convert.ToString(obj.Deletedon) != "")
                {
                    obj_con.addParameter("@Deletedon", string.IsNullOrEmpty(Convert.ToString(obj.Deletedon)) ? Convert.ToDateTime("1900-01-01") : obj.Deletedon);
                }
                else
                {
                    obj_con.addParameter("@Deletedon", DBNull.Value);
                }

                if (Convert.ToString(obj.Categoryid) != "")
                {
                    obj_con.addParameter("@Categoryid", Convert.ToInt32(obj.Categoryid), trans);
                }
                else
                {
                    obj_con.addParameter("@Categoryid", DBNull.Value);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }