Beispiel #1
0
        protected void grvUser_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            string strId = e.CommandArgument.ToString();

            switch (e.CommandName)
            {
            case "Edit":
                insert = false;
                ViewInput(true);
                lblAction.Text = "Update User";
                Id             = strId;

                DataTable dt = UserController.GetByColumn("Id", strId);
                txtName.Text      = dt.Rows[0]["Name"].ToString();
                txtUserName.Text  = dt.Rows[0]["UserName"].ToString();
                txtAddress.Text   = dt.Rows[0]["Address"].ToString();
                txtEmail.Text     = dt.Rows[0]["Email"].ToString();
                txtPhone.Text     = dt.Rows[0]["Phone"].ToString();
                chkActive.Checked = bool.Parse(dt.Rows[0]["Active"].ToString());


                break;


            case "Delete":
                tbUserInfo obj = new tbUserInfo();
                obj.Id = int.Parse(strId);
                UserController.Delete(obj);
                ViewInput(false);

                break;
            }
            _LoadUser();
        }
Beispiel #2
0
        protected void Update_Click(object sender, EventArgs e)
        {
            tbUserInfo obj = new tbUserInfo();

            obj.Name     = txtName.Text;
            obj.Username = txtUserName.Text;
            obj.Address  = txtAddress.Text;
            obj.Email    = txtEmail.Text;
            obj.Phone    = txtPhone.Text;
            obj.Active   = chkActive.Checked;
            obj.RoleId   = int.Parse
                               (ddlRole.SelectedValue.ToString());
            obj.Password = txtPass.Text;
            obj.Id       = int.Parse(Id);
            if (insert)
            {
                UserController.Insert(obj);
            }
            else
            {
                obj.Id = int.Parse(Id);
                UserController.Update(obj);
            }
            pnView.Visible   = true;
            pnUpdate.Visible = false;
            _LoadUser();
        }
Beispiel #3
0
        public static DataTable search(tbUserInfo obj)
        {
            string str = "Select * from tbUser,tbRole where tbRole.Id=tbUser.RoleId and ";

            str = str + "FullName like '%'+ '" + obj.Name + "' + '%'";
            return(GetData(str));
            //  string strSearch = "select * from tblModel where ModelName like '%'+'" + txtSearch.Text + "'+'%'";
        }
Beispiel #4
0
        public static void Update(tbUserInfo tbUser)
        {
            string q = "update [tbUser] set [Name] = @Name, [Username] = @Username,[Password] = @Password,";

            q = q + "[Address] = @Address,[Email] = @Email,[Phone] = @Phone,[Active] = @Active,";
            q = q + "[RoleId] = @RoleId where [Id] = @Id";
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = q;
            cmd.Connection  = GetConnection();
            cmd.Parameters.Add(new SqlParameter("@Name", tbUser.Name));
            cmd.Parameters.Add(new SqlParameter("@Username", tbUser.Username));
            cmd.Parameters.Add(new SqlParameter("@Password", tbUser.Password));

            cmd.Parameters.Add(new SqlParameter("@Address", tbUser.Address));
            cmd.Parameters.Add(new SqlParameter("@Email", tbUser.Email));
            cmd.Parameters.Add(new SqlParameter("@Phone", tbUser.Phone));
            cmd.Parameters.Add(new SqlParameter("@Active", tbUser.Active));
            cmd.Parameters.Add(new SqlParameter("@RoleId", tbUser.RoleId));
            cmd.Parameters.Add(new SqlParameter("@Id", tbUser.Id));
            ExecuteNonQuery(cmd);
        }
Beispiel #5
0
        // dbCmd.Parameters.Add(new SqlParameter("@CusName", data.CusName));
        public static void Insert(tbUserInfo tbUser)
        {
            string str = "insert into [tbUser] ([Name],[Username],[Password],[Address],[Email],";

            str = str + "[Phone],[Active],[RoleId]) values (@Name,@Username,@Password,";
            str = str + "@Address,@Email,@Phone,@Active,@RoleId)";

            SqlCommand cmd = new SqlCommand();

            cmd.CommandType = CommandType.Text;
            cmd.CommandText = str;
            cmd.Connection  = GetConnection();
            cmd.Parameters.Add(new SqlParameter("@Name", tbUser.Name));
            cmd.Parameters.Add(new SqlParameter("@Username", tbUser.Username));
            cmd.Parameters.Add(new SqlParameter("@Password", tbUser.Password));

            cmd.Parameters.Add(new SqlParameter("@Address", tbUser.Address));
            cmd.Parameters.Add(new SqlParameter("@Email", tbUser.Email));
            cmd.Parameters.Add(new SqlParameter("@Phone", tbUser.Phone));
            cmd.Parameters.Add(new SqlParameter("@Active", tbUser.Active));
            cmd.Parameters.Add(new SqlParameter("@RoleId", tbUser.RoleId));

            ExecuteNonQuery(cmd);
        }
Beispiel #6
0
        public static void Delete(tbUserInfo obj)
        {
            string q = "Delete from tbUser where Id=" + obj.Id;

            ExecuteNonQuery(q);
        }