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

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

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

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

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

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

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

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

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


                Citieslist.Add(obj_Cities);
            }
            return(Citieslist);
        }
Example #2
0
 //insert data into database
 public Int32?insert(CitiesClass obj)
 {
     try
     {
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Insert);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_Cities_insert", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Cityid = Convert.ToInt32(obj_con.getValue("@Cityid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_Cities_insert:" + ex.Message);
     }
 }
Example #3
0
//Select Constructor
        public CitiesCtl(Int32?id)
        {
            obj_con = new ConnectionCls();
            CitiesClass obj_Cit = new CitiesClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_Cit.Cityid    = Convert.ToInt32(dt.Rows[0]["Cityid"]);
                    obj_Cit.Cityname  = Convert.ToString(dt.Rows[0]["Cityname"]);
                    obj_Cit.Stateid   = Convert.ToInt32(dt.Rows[0]["Stateid"]);
                    obj_Cit.Isactive  = Convert.ToBoolean(dt.Rows[0]["Isactive"]);
                    obj_Cit.Isdeleted = Convert.ToBoolean(dt.Rows[0]["Isdeleted"]);
                    obj_Cit.Createdon = Convert.ToDateTime(dt.Rows[0]["Createdon"]);
                    obj_Cit.Deletedon = Convert.ToDateTime(dt.Rows[0]["Deletedon"]);
                }
            }
        }
Example #4
0
//Convert DataTable To object method
        public CitiesClass ConvertToOjbect(DataTable dt)
        {
            CitiesClass obj_Cities = new CitiesClass();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (Convert.ToString(dt.Rows[i]["Cityid"]) != "")
                {
                    obj_Cities.Cityid = Convert.ToInt32(dt.Rows[i]["Cityid"]);
                }

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

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

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

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

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

                if (Convert.ToString(dt.Rows[i]["Deletedon"]) != "")
                {
                    obj_Cities.Deletedon = Convert.ToDateTime(dt.Rows[i]["Deletedon"]);
                }
            }
            return(obj_Cities);
        }
Example #5
0
//update edited object
        public CitiesClass updateObject(CitiesClass obj)
        {
            try
            {
                CitiesClass oldObj = selectById(obj.Cityid);
                if (obj.Cityname == null)
                {
                    obj.Cityname = oldObj.Cityname;
                }

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

                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 #6
0
//create parameter
        public void createParameter(CitiesClass obj, DB_con.DBTrans trans)
        {
            try
            {
                obj_con.clearParameter();

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

                if (Convert.ToString(obj.Stateid) != "")
                {
                    obj_con.addParameter("@Stateid", string.IsNullOrEmpty(Convert.ToString(obj.Stateid)) ? 0 : obj.Stateid);
                }
                else
                {
                    obj_con.addParameter("@Stateid", 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.Cityid) != "")
                {
                    obj_con.addParameter("@Cityid", Convert.ToInt32(obj.Cityid), trans);
                }
                else
                {
                    obj_con.addParameter("@Cityid", DBNull.Value);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }