예제 #1
0
 //insert data into database
 public Int32 insert(usersClass obj)
 {
     try
     {
         obj_con.clearParameter();
         createParameter(obj, DBTrans.Insert);
         obj_con.BeginTransaction();
         obj_con.ExecuteNoneQuery("sp_users_insert", CommandType.StoredProcedure);
         obj_con.CommitTransaction();
         return(obj.Userid = Convert.ToInt32(obj_con.getValue("@Userid")));
     }
     catch (Exception ex)
     {
         obj_con.RollbackTransaction();
         throw new Exception("sp_users_insert");
     }
 }
예제 #2
0
//create parameter
        public void createParameter(usersClass obj, DB_con.DBTrans trans)
        {
            try
            {
                obj_con.clearParameter();
                obj_con.addParameter("@Email", string.IsNullOrEmpty(Convert.ToString(obj.Email)) ? "" : obj.Email);
                obj_con.addParameter("@Password", string.IsNullOrEmpty(Convert.ToString(obj.Password)) ? "" : obj.Password);
                obj_con.addParameter("@Devicetype", string.IsNullOrEmpty(Convert.ToString(obj.Devicetype)) ? "" : obj.Devicetype);
                obj_con.addParameter("@Deviceid", string.IsNullOrEmpty(Convert.ToString(obj.Deviceid)) ? "" : obj.Deviceid);
                obj_con.addParameter("@Isactive", string.IsNullOrEmpty(Convert.ToString(obj.Isactive)) ? false : obj.Isactive);
                obj_con.addParameter("@Userid", obj.Userid, trans);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
//Select Constructor
        public usersCtl(Int32 id)
        {
            obj_con = new ConnectionCls();
            usersClass obj_use = new usersClass();

            using (DataTable dt = selectdatatable(id))
            {
                if (dt.Rows.Count > 0)
                {
                    obj_use.Userid     = Convert.ToInt32(dt.Rows[0]["Userid"]);
                    obj_use.Email      = Convert.ToString(dt.Rows[0]["Email"]);
                    obj_use.Password   = Convert.ToString(dt.Rows[0]["Password"]);
                    obj_use.Devicetype = Convert.ToString(dt.Rows[0]["Devicetype"]);
                    obj_use.Deviceid   = Convert.ToString(dt.Rows[0]["Deviceid"]);
                    obj_use.Isactive   = Convert.ToBoolean(dt.Rows[0]["Isactive"]);
                }
            }
        }
예제 #4
0
//update edited object
        public usersClass updateObject(usersClass obj)
        {
            try
            {
                usersClass oldObj = selectById(obj.Userid);
                if (obj.Email == null || obj.Email.ToString().Trim() == "update")
                {
                    obj.Email = oldObj.Email;
                }

                if (obj.Password == null || obj.Password.ToString().Trim() == "update")
                {
                    obj.Password = oldObj.Password;
                }

                if (obj.Devicetype == null || obj.Devicetype.ToString().Trim() == "update")
                {
                    obj.Devicetype = oldObj.Devicetype;
                }

                if (obj.Deviceid == null || obj.Deviceid.ToString().Trim() == "update")
                {
                    obj.Deviceid = oldObj.Deviceid;
                }

                if (obj.Isactive == null || obj.Isactive.ToString().Trim() == "0")
                {
                    obj.Isactive = oldObj.Isactive;
                }

                return(obj);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #5
0
//Convert DataTable To object method
        public usersClass ConvertToOjbect(DataTable dt)
        {
            usersClass obj_users = new usersClass();

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

                if (Convert.ToString(dt.Rows[i]["Email"]) != "")
                {
                    obj_users.Email = Convert.ToString(dt.Rows[i]["Email"]);
                }
                else
                {
                    obj_users.Email = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Password"]) != "")
                {
                    obj_users.Password = Convert.ToString(dt.Rows[i]["Password"]);
                }
                else
                {
                    obj_users.Password = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Devicetype"]) != "")
                {
                    obj_users.Devicetype = Convert.ToString(dt.Rows[i]["Devicetype"]);
                }
                else
                {
                    obj_users.Devicetype = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Deviceid"]) != "")
                {
                    obj_users.Deviceid = Convert.ToString(dt.Rows[i]["Deviceid"]);
                }
                else
                {
                    obj_users.Deviceid = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Isactive"]) != "")
                {
                    obj_users.Isactive = Convert.ToBoolean(dt.Rows[i]["Isactive"]);
                }
                else
                {
                    obj_users.Isactive = Convert.ToBoolean(0);
                }
            }
            return(obj_users);
        }
예제 #6
0
//Convert DataTable To List method
        public List <usersClass> ConvertToList(DataTable dt)
        {
            List <usersClass> userslist = new List <usersClass>();

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

                if (Convert.ToString(dt.Rows[i]["Userid"]) != "")
                {
                    obj_users.Userid = Convert.ToInt32(dt.Rows[i]["Userid"]);
                }
                else
                {
                    obj_users.Userid = Convert.ToInt32("0");
                }

                if (Convert.ToString(dt.Rows[i]["Email"]) != "")
                {
                    obj_users.Email = Convert.ToString(dt.Rows[i]["Email"]);
                }
                else
                {
                    obj_users.Email = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Password"]) != "")
                {
                    obj_users.Password = Convert.ToString(dt.Rows[i]["Password"]);
                }
                else
                {
                    obj_users.Password = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Devicetype"]) != "")
                {
                    obj_users.Devicetype = Convert.ToString(dt.Rows[i]["Devicetype"]);
                }
                else
                {
                    obj_users.Devicetype = Convert.ToString("");
                }

                if (Convert.ToString(dt.Rows[i]["Deviceid"]) != "")
                {
                    obj_users.Deviceid = Convert.ToString(dt.Rows[i]["Deviceid"]);
                }
                else
                {
                    obj_users.Deviceid = Convert.ToString("");
                }

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


                userslist.Add(obj_users);
            }
            return(userslist);
        }