Windows中的.net应用程序 [英] .net application in windows

查看:63
本文介绍了Windows中的.net应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个登录窗口表单,用户可以使用id和密码登录。身份验证后,用户可以移动到Select_Company表单。从那里用户选择公司和分支并移动到交易窗口表格。



初次登录时,用户正确登录并移至Select_company窗口表单。当他点击Select_company窗口表单上的注销按钮时,他会再次移动到登录表单。



从登录表单进一步登录后,他应该转移到select_company再次形成,但select_company表单不显示。



我正确调试了程序。它运行良好但我无法找到它在进一步登录后没有显示Select_company窗口表单的原因。


请告诉我该怎么做。在此先感谢。



以下是代码:



登录表格:



I have created a window form for login, where user can login with an id and password. After authentication the user can move to the Select_Company form. From there the user select the company and branch and moves to transaction window form.

On initial login the user properly logged in and moved to Select_company window form. When he clicks the log out button on Select_company window form he is moved to the login form again.

On further login from login form he is supposed to move to the select_company form again but the select_company form does not display.

I properly debugged the program. It runs well but I am unable to find the reasons for it not displaying the Select_company window form after further login.

Please advise me on what to do. Thanks in advance.

Below is the code:

Login form:

private void btnLogin_Click(object sender, EventArgs e)
{
    if (validation() == true)
    {
        try
        {
            conn = Aryan.connString();
            Aryan.sqlcon = new System.Data.SqlClient.SqlConnection(conn);
            if (Aryan.sqlcon.State == ConnectionState.Closed)
            {
                Aryan.sqlcon.Open();
            }
            Aryan.sqlcom = new System.Data.SqlClient.SqlCommand("Str_UserLogin", Aryan.sqlcon);
            Aryan.sqlcom.CommandType = CommandType.StoredProcedure;
            Aryan.sqlcom.Parameters.AddWithValue("@LoginId", txtUserName.Text);
            Aryan.sqlcom.Parameters.AddWithValue("@Password", txtPassword.Text);
            System.Data.SqlClient.SqlParameter pm = new System.Data.SqlClient.SqlParameter("@return", SqlDbType.Int);
            pm.Direction = ParameterDirection.Output;
            pm.Size = 50;
            Aryan.sqlcom.Parameters.Add(pm);
            System.Data.SqlClient.SqlParameter pm1 = new System.Data.SqlClient.SqlParameter("@UserId", SqlDbType.Int);
            pm1.Direction = ParameterDirection.Output;
            pm1.Size = 50;
            Aryan.sqlcom.Parameters.Add(pm1);
            System.Data.SqlClient.SqlParameter pm2 = new System.Data.SqlClient.SqlParameter("@UserType", SqlDbType.VarChar);
            pm2.Direction = ParameterDirection.Output;
            pm2.Size = 50;
            Aryan.sqlcom.Parameters.Add(pm2);
            Aryan.sqlcom.ExecuteNonQuery();
            int output = (int)Aryan.sqlcom.Parameters["@return"].Value;
            if (output == 1)
            {
                int usercode = (int)Aryan.sqlcom.Parameters["@UserId"].Value;
                string userType = (string)Aryan.sqlcom.Parameters["@UserType"].Value;
                updateUser(usercode);
                Aryan.GetID = usercode;
                Aryan.CurrentUserType = userType;
                Aryan.CurrentUser = txtUserName.Text;
                Aryan.CurrentSession = session;
                pAccept = true;
                this.Close();
                //this.Visible = false;
            }
            else if (output == 10)
            {
                MessageBox.Show("Invalid Login Id or Password", "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUserName.Text = "";
                txtPassword.Text = "";
                txtUserName.Focus();
                return;
            }
            else if (output == 20)
            {
                MessageBox.Show("This User Already Logged in. Contact to Administrator !");
                txtUserName.Text = "";
                txtPassword.Text = "";
                txtUserName.Focus();
                return;
            }
            else if (output == 30)
            {
                MessageBox.Show("This User Not Permitted For Any Transaction.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtUserName.Text = "";
                txtPassword.Text = "";
                txtUserName.Focus();
                //Environment.Exit(0);
            }
            else if (output == 40)
            {
                MessageBox.Show("This User is No Longer Active. Contact to Administrator.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtUserName.Text = "";
                txtPassword.Text = "";
                txtUserName.Focus();
                return;
                //Environment.Exit(0);
            }
            else
            {
                MessageBox.Show("Problem occur while Login");
                return;
            }
        }

        catch (Exception err)
        {
            MessageBox.Show(err.Message);
        }
        finally
        {
            Aryan.sqlcon.Close();
        }
    }
}





退出:





Log out:

private void LogOut()
        {
            conn = Aryan.connString();
            Aryan.sqlcon = new System.Data.SqlClient.SqlConnection(conn);
            try
            {
                if (Aryan.sqlcon.State == ConnectionState.Closed)
                {
                    Aryan.sqlcon.Open();
                }
                Aryan.sqlcom = new System.Data.SqlClient.SqlCommand("str_LogOut", Aryan.sqlcon);
                Aryan.sqlcom.CommandType = CommandType.StoredProcedure;
                Aryan.sqlcom.Parameters.AddWithValue("@userId", Aryan.GetID);
                Aryan.sqlcom.Parameters.AddWithValue("@LogOut", Aryan.getSqlDateStr(System.DateTime.Now));
                Aryan.sqlcom.Parameters.AddWithValue("@TimeOut", Aryan.getSqlTimeStr(System.DateTime.Now));
                Aryan.sqlcom.Parameters.AddWithValue("@Session", Aryan.CurrentSession);
                Aryan.sqlcom.ExecuteNonQuery();
                Aryan.GetID = 0;
                Aryan.CurrentUser = "";
                Aryan.CurrentSession = 0;
                Aryan.CurrentUserType = "";
                Aryan.CurrentCompany = "";
                Aryan.CurrentBranch = "";
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
            finally
            {
                Aryan.sqlcon.Close();
            }
        }

        
        private void btnLogOut_Click(object sender, EventArgs e)
        {
            LogOut();
            lstCompany.Items.Clear();
            lstBranch.Items.Clear();
            this.Visible = false;
            this.Close();
            frmLogin Login = new frmLogin();
            Login.ShowDialog();
        }



MainPage(父表):




MainPage(Parent Form):

private void CheckUser()
        {
            conn = Aryan.connString();
            Aryan.sqlcon = new System.Data.SqlClient.SqlConnection(conn);
            try
            {
                if (Aryan.sqlcon.State == ConnectionState.Closed)
                {
                    Aryan.sqlcon.Open();
                }
                Aryan.sqlcom = new System.Data.SqlClient.SqlCommand("str_CheckUserFirstTime", Aryan.sqlcon);
                Aryan.sqlcom.CommandType = CommandType.StoredProcedure;
                System.Data.SqlClient.SqlParameter pm = new System.Data.SqlClient.SqlParameter("return", SqlDbType.Int);
                pm.Direction = ParameterDirection.Output;
                pm.Size = 50;
                Aryan.sqlcom.Parameters.Add(pm);
                Aryan.sqlcom.ExecuteNonQuery();
                int output = (int)Aryan.sqlcom.Parameters["return"].Value;
                if (output == 0)
                {
                    frmSuperuser Super = new frmSuperuser();            // SuperUser call & create for first time
                    Super.ShowDialog();
                }
                else if (Aryan.CheckInstalledCompany())
                {
                    frmInstallCompany company = new frmInstallCompany();
                    company.ShowDialog();
                }
                else
                {
                    frmLogin Login = new frmLogin();
                    Login.ShowDialog();                    
                    if (Login.pAccept)
                    {                      
                        frmSelectCompany SelectCompany = new frmSelectCompany();                        
                        SelectCompany.ShowDialog();
                        if (SelectCompany.DialogResult == DialogResult.Cancel)
                        {
                            statusBar.Panels[0].Text = "User Name:" + Aryan.CurrentUser;
                            statusBar.Panels[1].Text = "User Type:" + Aryan.CurrentUserType;
                            statusBar.Panels[2].Text = "Session:" + Aryan.CurrentSession;
                            statusBar.Panels[3].Text = "Branch:" + Aryan.CurrentBranch;
                            statusBar.Panels[4].Text = "Clock:";
                            //frmMain main = new frmMain();
                            //main.Text = Aryan.CurrentCompany;
                            //statusBar.Show();
                            //statusBar.Visible = true;
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
                return;
            }
            finally
            {
                Aryan.sqlcon.Close();
            }
        }

推荐答案

老实说,我认为你需要重新设计你的应用程序,你不是使用不同的图层并在整个地方创建数据库连接。我建议你在解决任何进一步的问题之前重新设计一个DAL-BL-GUI分层方法。在业务层(BL)中,您可以保持用户的状态(登录或注销)并根据该值创建GUI逻辑。



你'将有一个更简单的调试方法,我的猜测是你的问题将在你完成时修复。
Honestly, I think you need to redesign your application, you''re not using different layers and are creating database connection all over the place. I propose you redesign to a DAL - BL - GUI layered approach before addressing any further problems. in The Business Layer (BL) you can then keep a status of the user (logged in or out) and create your GUI logic based on that value.

You''ll have an easier way to debug and my guess is your problem will be fixed by the time you''ve finished.


代码



The code

frmLogin Login = new frmLogin();
                    Login.ShowDialog();                    
                    if (Login.pAccept)
                    {                      
                        frmSelectCompany SelectCompany = new frmSelectCompany();                        
                        SelectCompany.ShowDialog();





显示,假设显示登录表单,并以某种方式关闭,选择公司如果Login.pAccept为true,将显示表单。



因此,登录表单未关闭或pAccept在关闭时为false。



我同意V - 这是一个混乱的代码,很难遵循;至少你需要将东西移到自己的方法中,以便更容易理解!



shows that , assuming the Login form is shown, and closed somehow, the select company form will be shown if Login.pAccept is true.

So, either the login form is not closing or pAccept is false when it does close.

I agree with V - this is messy code and very hard to follow; at the very least you need to move stuff into its own methods to make it easier to follow!


这篇关于Windows中的.net应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆