Ejemplo n.º 1
0
        //Convert DataTable To List method
        public List <LocationClass> ConvertToList(DataTable dt)
        {
            List <LocationClass> Locationlist = new List <LocationClass>();

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

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

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

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

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

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

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

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


                Locationlist.Add(obj_Location);
            }
            return(Locationlist);
        }
Ejemplo n.º 2
0
 //insert data into database
 public Int32?insert(LocationClass obj)
 {
     try
     {
         obj.Locationid = 0;
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Insert);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_Location_insert", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Locationid = Convert.ToInt32(obj_con.getValue("@Locationid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_Location_insert:" + ex.Message);
     }
 }
Ejemplo n.º 3
0
        //Select Constructor
        public LocationCtl(Int32?id)
        {
            obj_con = new ConnectionCls();
            LocationClass obj_Loc = new LocationClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_Loc.Locationid   = Convert.ToInt32(dt.Rows[0]["Locationid"]);
                    obj_Loc.Locationname = Convert.ToString(dt.Rows[0]["Locationname"]);
                    obj_Loc.Locationurl  = Convert.ToString(dt.Rows[0]["Locationurl"]);
                    obj_Loc.Isactive     = Convert.ToBoolean(dt.Rows[0]["Isactive"]);
                    obj_Loc.Isdeleted    = Convert.ToBoolean(dt.Rows[0]["Isdeleted"]);
                    obj_Loc.Createdon    = Convert.ToDateTime(dt.Rows[0]["Createdon"]);
                    obj_Loc.Deletedon    = Convert.ToDateTime(dt.Rows[0]["Deletedon"]);
                }
            }
        }
Ejemplo n.º 4
0
        //update edited object
        public LocationClass updateObject(LocationClass obj)
        {
            try
            {
                LocationClass oldObj = selectById(obj.Locationid);
                if (obj.Locationname == null)
                {
                    obj.Locationname = oldObj.Locationname;
                }

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

                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);
            }
        }
Ejemplo n.º 5
0
        //create parameter
        public void createParameter(LocationClass obj, DB_con.DBTrans trans)
        {
            try
            {
                obj_con.clearParameter();

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

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