예제 #1
0
 //insert data into database
 public Int32?insert(CountriesClass obj)
 {
     try
     {
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Insert);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_Countries_insert", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Countryid = Convert.ToInt32(obj_con.getValue("@Countryid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_Countries_insert:" + ex.Message);
     }
 }
예제 #2
0
//Select Constructor
        public CountriesCtl(Int32?id)
        {
            obj_con = new ConnectionCls();
            CountriesClass obj_Cou = new CountriesClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_Cou.Countryid   = Convert.ToInt32(dt.Rows[0]["Countryid"]);
                    obj_Cou.Countryname = Convert.ToString(dt.Rows[0]["Countryname"]);
                    obj_Cou.Isactive    = Convert.ToBoolean(dt.Rows[0]["Isactive"]);
                    obj_Cou.Isdeleted   = Convert.ToBoolean(dt.Rows[0]["Isdeleted"]);
                    obj_Cou.Createdon   = Convert.ToDateTime(dt.Rows[0]["Createdon"]);
                    obj_Cou.Deletedon   = Convert.ToDateTime(dt.Rows[0]["Deletedon"]);
                }
            }
        }
예제 #3
0
//Convert DataTable To List method
        public List <CountriesClass> ConvertToList(DataTable dt)
        {
            List <CountriesClass> Countrieslist = new List <CountriesClass>();

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

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

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

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

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

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

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


                Countrieslist.Add(obj_Countries);
            }
            return(Countrieslist);
        }
예제 #4
0
//Convert DataTable To object method
        public CountriesClass ConvertToOjbect(DataTable dt)
        {
            CountriesClass obj_Countries = new CountriesClass();

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

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

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

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

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

                if (Convert.ToString(dt.Rows[i]["Deletedon"]) != "")
                {
                    obj_Countries.Deletedon = Convert.ToDateTime(dt.Rows[i]["Deletedon"]);
                }
            }
            return(obj_Countries);
        }
예제 #5
0
//update edited object
        public CountriesClass updateObject(CountriesClass obj)
        {
            try
            {
                CountriesClass oldObj = selectById(obj.Countryid);
                if (obj.Countryname == null)
                {
                    obj.Countryname = oldObj.Countryname;
                }

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

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