Click here to Skip to main content
15,891,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a program for user login.

Service has been running successfully.

But after the run (button clicked) displays the error message.

What is the solution?
C#
Service ----> StatusUserData.cs
using System;
using System.Data;

namespace WMS.Handler
{
    public class StatusUserData
    {
        public StatusUserData()
        {
            UserID = null;
            Status = string.Empty;
            Name = string.Empty;
            Email = string.Empty;
            Password = string.Empty;
            Username = string.Empty;
            }

        public Nullable<int> UserID
        {
            get;
            set;
        }
        public string Status
        {
            get;
            set;
        }
        public string Name
        {
            get;
            set;
        }
        public string Email
        {
            get;
            set;
        }
        public string Password
        {
            get;
            set;
        }
        public Nullable<int> RoleID
        {
            get;
            set;
        }
        public string Username
        {
            get;
            set;
        }
    }
}

Service ----> FilterStatusUser.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WMS.Handler
{
   public class FilterStatusUser
    {public FilterStatusUser()
        {
            FilterUserID = null;
            FilterStatus = string.Empty;
            FilterName = string.Empty;
            FilterEmail = string.Empty;
            FilterPassword = string.Empty;
            FilterUsername = string.Empty;
            }

    public Nullable<int> FilterUserID
        {
            get;
            set;
        }
    public string FilterStatus
        {
            get;
            set;
        }
    public string FilterName
        {
            get;
            set;
        }
    public string FilterEmail
        {
            get;
            set;
        }
    public string FilterPassword
        {
            get;
            set;
        }
    public Nullable<int> FilterRoleID
        {
            get;
            set;
        }
    public string FilterUsername
        {
            get;
            set;
        }
    }
    }

Service ----> StatusUserHandler.cs
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Data.Linq;

namespace WMS.Handler
{
    public class StatusUserHandler
    {public static StatusUserData GetStatusUser(FilterStatusUser filter)
        {
            using (WMS.DAL.WarehouseLinqDataContext dc = new WMS.DAL.WarehouseLinqDataContext())
            {
                var data = from d in dc.StatusUsers
                           select d;
                if (filter.FilterUserID != null)
                {
                    data = from d in data
                           where d.userID == filter.FilterUserID
                           select d;
                }
                if (filter.FilterName != string.Empty && filter.FilterName != null)
                {
                    data = from d in data
                           where d.name.ToLower().Contains(filter.FilterName.ToLower())
                           select d;
                }
                if (filter.FilterEmail != string.Empty && filter.FilterEmail != null)
                {
                    data = from d in data
                           where d.email.ToLower().Contains(filter.FilterEmail.ToLower())
                           select d;
                }
                if (filter.FilterUsername != string.Empty && filter.FilterUsername != null)
                {
                    data = from d in data
                           where d.username.ToLower().Contains(filter.FilterUsername.ToLower())
                           select d;
                }
                if (filter.FilterPassword != string.Empty && filter.FilterPassword != null)
                {
                    data = from d in data
                           where d.password.ToLower().Contains(filter.FilterPassword.ToLower())
                           select d;
                }
                if (filter.FilterStatus != string.Empty && filter.FilterStatus != null)
                {
                    data = from d in data
                           where d.status.ToLower().Contains(filter.FilterStatus.ToLower())
                           select d;
                }
                StatusUserData StatusUserData = new StatusUserData();
                foreach (var d in data)
                {
                    StatusUserData.UserID = d.userID;
                    StatusUserData.Name = d.name;
                    StatusUserData.Email = d.email;
                    StatusUserData.Username = d.username;
                    StatusUserData.Password = d.password;
                    StatusUserData.Status = d.status;
                 }
                return StatusUserData;
            }
        }}}

Service ----> WMSDService.cs
using System;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WMSDService : System.Web.Services.WebService
{
    private string isStatusUser;
    private int? total = 0;
    public WMSDService()
    {}
#region StatusUser

    [WebMethod]
    public string checkStatusUser(string uname, string pass,string status)
    {

        WMS.Handler.FilterStatusUser tu = new WMS.Handler.FilterStatusUser();
        tu.FilterUsername = uname;
        tu.FilterPassword = pass;
        tu.FilterStatus = status;
        WMS.Handler.StatusUserData us = WMS.Handler.StatusUserHandler.GetStatusUser(tu);
        if (us.Password == pass && us.Username == uname && us.Status==status)
        {
            isStatusUser = "yes";
            return isStatusUser;
        }
        else
        {
            isStatusUser = "no";
            return isStatusUser;
        }

    }}
    #endregion


C# ----> Form1.cs
[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Client.localhost;

namespace Client
{
    public partial class Form1 : Form
    {
        Client.localhost.StatusUser gf = new Client.localhost.StatusUser();

        public Form1()
        {
            InitializeComponent();
        }
private void button2_Click(object sender, EventArgs e)
        {
            String name = textBoxName.Text;
            String email = textBoxEmail.Text;
            String user = textBoxUname.Text;
            String pass = textBoxPass.Text;
            String status = comboBox2.SelectedItem.ToString();
            WMSDService cf = new WMSDService();
            cf.newStatusUser(name, email, user, pass, status);
            
        }}}
Posted
Updated 16-Mar-12 17:29pm
v2
Comments
Ganesan Senthilvel 16-Mar-12 23:32pm    
what is the error message?
[no name] 17-Mar-12 2:15am    
sorry my script there is less

private void button1_Click(object sender, EventArgs e)
{
String user = textBox1.Text;
String pass = textBox2.Text;
String status = comboBox1.Text;
WMSDService cf = new WMSDService();
String hasil = cf.checkStatusUser(user, pass, status);
if ((hasil == user) && (hasil == pass) && (hasil == status))
{
Form2 st = new Form2();
st.Show();
}
else {
MessageBox.Show("error");
}
}

while in the press the button, it should show form2. but it appears "messagebox: error". Can you help me?
ZurdoDev 20-Mar-12 15:52pm    
Your code is checking to make sure hasil is the same as user, pass, and status. Is that right?
[no name] 20-Mar-12 15:55pm    
yes

1 solution

I've been able to find a solution

UPDATE:
Answer posted by OP:
C#
private void button1_Click(object sender, EventArgs e)
        {
            String user = this.textBox1.Text;
            String pass = this.textBox2.Text;
            String status = this.comboBox1.SelectedItem.ToString();
            WMSDService cf = new WMSDService();
            String hasil = cf.checkStatusUser(user, pass, status);
            if (hasil== "C")
            {
                Consumer st = new Consumer();
                st.Show();
                this.Hide();
            }
            else if (hasil == "yes")
            {
                Forestry st = new Forestry();
                st.Show();
                this.Hide();
            }
            else if (hasil == "CO")
            {
                Corporation st = new Corporation();
                st.Show();
                this.Hide();
            }
            else if (hasil == "CU")
            {
                Customs st = new Customs();
                st.Show();
                this.Hide();
            }
            else {
                MessageBox.Show("Login Failed");
            }}
 
Share this answer
 
v2
Comments
Sandeep Mewara 15-May-12 10:13am    
You better add it as a solution as it might help others.
[no name] 15-May-12 22:03pm    
ok
private void button1_Click(object sender, EventArgs e)
{
String user = this.textBox1.Text;
String pass = this.textBox2.Text;
String status = this.comboBox1.SelectedItem.ToString();
WMSDService cf = new WMSDService();
String hasil = cf.checkStatusUser(user, pass, status);
if (hasil== "C")
{
Consumer st = new Consumer();
st.Show();
this.Hide();
}
else if (hasil == "yes")
{
Forestry st = new Forestry();
st.Show();
this.Hide();
}
else if (hasil == "CO")
{
Corporation st = new Corporation();
st.Show();
this.Hide();
}
else if (hasil == "CU")
{
Customs st = new Customs();
st.Show();
this.Hide();
}
else {
MessageBox.Show("Login Failed");
}}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900