Beispiel #1
0
    public string ThemUser(string user, string pass, string hoten, string Email, string ngaysinh, string hinhanh, byte[] f, int phanquyen)
    {
        FilesTransfer trans = new FilesTransfer();

        try
        {
            OpenConnect();
            SqlCommand com = new SqlCommand("select * from tblUser where username=N'" + user + "' ", con);
            com.CommandType = CommandType.Text;
            SqlDataAdapter da         = new SqlDataAdapter(com);
            DataTable      dtdistrict = new DataTable("tblUser");
            da.Fill(dtdistrict);
            if (dtdistrict.Rows.Count > 0)
            {
                return("Tên tài khoản " + user + " đã tồn tại.!");
            }
            int n = 0;
            if (hinhanh != "")
            {
                string upfile = trans.UploadFile(f, hinhanh, "User");

                if (upfile == "OK")
                {
                    SqlCommand comm = new SqlCommand("insert into tblUser values (N'" + user + "',N'" + pass + "',N'" + phanquyen.ToString() + "',0,N'" + hoten + "',N'" + ngaysinh + "',N'" + Email + "',N'" + "/Images/User/" + hinhanh + "')", con);
                    n = comm.ExecuteNonQuery();
                }

                else
                {
                    CloseConnect();
                    return("Lỗi up ảnh: \n" + upfile);
                }
                CloseConnect();
            }
            else
            {
                SqlCommand comm = new SqlCommand("insert into tblUser values (N'" + user + "',N'" + pass + "',N'" + phanquyen.ToString() + "',0,N'" + hoten + "',N'" + ngaysinh + "',N'" + Email + "',N'')", con);
                n = comm.ExecuteNonQuery();
                CloseConnect();
            }
            if (n > 0)
            {
                return("Đăng ký thành công!");
            }
            else
            {
                return("Đăng ký không thành công!");
            }
        }
        catch (Exception ex)
        {
            return("Đăng ký không thành công!");
        }
    }
    public string ThemTonGiao(string Ten, string gioithieu, string hinhanh, byte[] f)
    {
        FilesTransfer trans = new FilesTransfer();

        try
        {
            OpenConnect();
            int n = 0;
            if (hinhanh != "")
            {
                string upfile = trans.UploadFile(f, hinhanh, "TonGiao");

                if (upfile == "OK")
                {
                    SqlCommand comm = new SqlCommand("insert into tblTonGiao values (N'" + Ten + "',N'" + gioithieu + "',N'" + "/Images/TonGiao/" + hinhanh + "',0,0)", conn);
                    n = comm.ExecuteNonQuery();
                }

                else
                {
                    CloseConnect();
                    return("Lỗi up file: \n" + upfile);
                }
                CloseConnect();
            }
            else
            {
                SqlCommand comm = new SqlCommand("insert into tblTonGiao values (N'" + Ten + "',N'" + gioithieu + "',N'',0,0)", conn);
                n = comm.ExecuteNonQuery();
                CloseConnect();
            }
            if (n > 0)
            {
                return("Thêm Tôn giáo thành công!");
            }
            else
            {
                return("Thêm Tôn giáo không thành công!");
            }
        }
        catch (Exception ex)
        {
            return("Thêm Tôn giáo không thành công!");
        }
    }
Beispiel #3
0
    public string Sua(string id, string hoten, string Email, string ngaysinh, string hinhanh, byte[] f, string quyen)
    {
        FilesTransfer trans = new FilesTransfer();

        try
        {
            OpenConnect();
            int n = 0;
            if (hinhanh != "")
            {
                string upfile = trans.UploadFile(f, hinhanh, "User");

                if (upfile == "OK")
                {
                    SqlCommand comm = new SqlCommand("update tblUser set Hoten=N'" + hoten + "',email=N'" + Email + "',ngaysinh=N'" + ngaysinh + "',hinhanh=N'" + "/Images/User/" + hinhanh + "',phanquyen=" + quyen + " where IDUser='******'", con);
                    n = comm.ExecuteNonQuery();
                }

                else
                {
                    CloseConnect();
                    return("Lỗi up ảnh: \n" + upfile);
                }
                CloseConnect();
            }
            else
            {
                SqlCommand comm = new SqlCommand("update tblUser set Hoten=N'" + hoten + "',email=N'" + Email + "',ngaysinh=N'" + ngaysinh + "',phanquyen=" + quyen + " where iduser='******'", con);
                n = comm.ExecuteNonQuery();
                CloseConnect();
            }
            if (n > 0)
            {
                return("Sửa thành công!");
            }
            else
            {
                return("Sửa không thành công!");
            }
        }
        catch (Exception ex)
        {
            return("Sửa không thành công!\n" + ex.ToString());
        }
    }
    public string SuaTonGiao(string id, string Ten, string gioithieu, string hinhanh, byte[] f)
    {
        FilesTransfer trans = new FilesTransfer();

        try
        {
            OpenConnect();
            int n = 0;
            if (hinhanh != "")
            {
                string upfile = trans.UploadFile(f, hinhanh, "TonGiao");

                if (upfile == "OK")
                {
                    SqlCommand comm = new SqlCommand("update tblTonGiao set TenTonGiao= N'" + Ten + "',GioiThieu= N'" + gioithieu + "',HinhAnh=N'~/Images/TonGiao/" + hinhanh + "' where IDTonGiao=" + id, conn);
                    n = comm.ExecuteNonQuery();
                }

                else
                {
                    CloseConnect();
                    return("Lỗi up file: \n" + upfile);
                }
                CloseConnect();
            }
            else
            {
                SqlCommand comm = new SqlCommand("update tblTonGiao set TenTonGiao= N'" + Ten + "',GioiThieu= N'" + gioithieu + " where IDTonGiao=" + id, conn);
                n = comm.ExecuteNonQuery();
                CloseConnect();
            }
            if (n > 0)
            {
                return("Sửa Tôn giáo thành công!");
            }
            else
            {
                return("Sửa Tôn giáo không thành công!");
            }
        }
        catch (Exception ex)
        {
            return("Sửa Tôn giáo không thành công!");
        }
    }