コード例 #1
0
ファイル: frmLogin.cs プロジェクト: glcc4it/inventory
        private void btn_login_Click(object sender, EventArgs e)
        {
            if (Username.Text.Trim(' ').Length == 0)
            {
                MessageBox.Show("Please enter user id", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Username.Focus();
                return;
            }
            if (Username.Text.Trim(' ').Length == 0)
            {
                MessageBox.Show("Please enter password", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                Password.Focus();
                return;
            }
            try
            {
                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                ModCommonClasses.cmd             = ModCommonClasses.con.CreateCommand();
                ModCommonClasses.cmd.CommandText = "SELECT RTRIM(UserID),RTRIM(Password) FROM tbl_login where UserType = @d1 and Name = @d2 and Password=@d3 and Active='Yes'";
                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", combo_type.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d2", Username.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d3", ModFunc.Encrypt(Password.Text));
                ModCommonClasses.rdr = ModCommonClasses.cmd.ExecuteReader();
                if (ModCommonClasses.rdr.Read())
                {
                    ModCommonClasses.con = new SqlConnection(ModCS.cs);
                    ModCommonClasses.con.Open();
                    ModCommonClasses.cmd             = ModCommonClasses.con.CreateCommand();
                    ModCommonClasses.cmd.CommandText = "SELECT usertype FROM tbl_login where UserType=@d4 and Name=@d5 and Password=@d6";
                    ModCommonClasses.cmd.Parameters.AddWithValue("@d4", combo_type.Text);
                    ModCommonClasses.cmd.Parameters.AddWithValue("@d5", Username.Text);
                    ModCommonClasses.cmd.Parameters.AddWithValue("@d6", ModFunc.Encrypt(Password.Text));
                    ModCommonClasses.rdr = ModCommonClasses.cmd.ExecuteReader();
                    if (ModCommonClasses.rdr.Read())
                    {
                    }
                    if (ModCommonClasses.rdr != null)
                    {
                        ModCommonClasses.rdr.Close();
                    }
                    if (ModCommonClasses.con.State == ConnectionState.Open)
                    {
                        ModCommonClasses.con.Close();
                    }


                    string st = "Successfully logged in";
                    ModFunc.LogFunc(Username.Text, st);
                    this.Hide();
                    Dashboard ss = new Dashboard();
                    ss.Show();

                    ss.lblUser.Text     = Username.Text;
                    ss.lblUserType.Text = combo_type.Text;
                }
                else
                {
                    Interaction.MsgBox("Login is Failed...Try again !", MsgBoxStyle.Critical, "Login Denied");
                    Username.Text = "";
                    Password.Text = "";
                    Username.Focus();
                }
                ModCommonClasses.cmd.Dispose();
                ModCommonClasses.con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
ファイル: UserrRegisterd.cs プロジェクト: glcc4it/inventory
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "")
            {
                MessageBox.Show("Please Enter Username", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtName.Focus();
                return;
            }


            try
            {
                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string ct = "select userid from tbl_login where UserID=@d1";
                ModCommonClasses.cmd = new SqlCommand(ct);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", txtUserID.Text);
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                ModCommonClasses.rdr            = ModCommonClasses.cmd.ExecuteReader();
                if (ModCommonClasses.rdr.Read())
                {
                    MessageBox.Show("User ID Already Exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtUserID.Text = "";
                    txtUserID.Focus();
                    if (ModCommonClasses.rdr != null)
                    {
                        ModCommonClasses.rdr.Close();
                    }
                    return;
                }

                if (chkActive.Checked == true)
                {
                    st1 = "Yes";
                }
                else
                {
                    st1 = "No";
                }
                ModCommonClasses.con = new SqlConnection(ModCS.cs);
                ModCommonClasses.con.Open();
                string cb = "insert into tbl_login(UserID, UserType, Name, Password, Address, Email, Mobile, JoiningDate, Active) VALUES (@d1,@d2,@d3,@d4,@d5,@d6,@d7,@d8,@d9)";
                ModCommonClasses.cmd = new SqlCommand(cb);
                ModFunc ep = new ModFunc();
                ModCommonClasses.cmd.Connection = ModCommonClasses.con;
                ModCommonClasses.cmd.Parameters.AddWithValue("@d1", txtUserID.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d2", cmbUserType.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d3", txtName.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d4", ModFunc.Encrypt(txtPassword.Text.Trim()));

                ModCommonClasses.cmd.Parameters.AddWithValue("@d5", txtAddress.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d6", txtemail.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d7", txtmobile.Text);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d8", DateTime.Now);
                ModCommonClasses.cmd.Parameters.AddWithValue("@d9", st1);
                ModCommonClasses.cmd.ExecuteReader();
                ModCommonClasses.con.Close();
                string st = "added the new user '" + txtUserID.Text + "'";

                MessageBox.Show("Successfully Registered", "User", MessageBoxButtons.OK, MessageBoxIcon.Information);
                ModFunc.LogFunc(lblUser.Text, "Add New User '" + txtName.Text + "' Having UserID '" + txtUserID.Text + "'");
                autonumber();
                this.ActiveControl = cmbUserType;
                cmbUserType.Focus();
                DisplayData();
                ClearData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }