예제 #1
0
        private bool IsValidData()
        {
            string        userName      = tbUserName.Text;
            string        password      = MD5EncryptionFunction.Encrypt(tbPassword.Text);
            string        selectSql     = @"SELECT * FROM `user` WHERE `status`=1 AND username = @username AND password = @password";
            SqlParameters sqlParameters = new SqlParameters();

            sqlParameters.Add(new SqlParameter("username", userName));
            sqlParameters.Add(new SqlParameter("password", password));
            DataTable resultDt = MySqlFunction.GetDataTable(new SqlDetail(selectSql, sqlParameters));

            if (resultDt.Rows.Count <= 0)
            {
                fncFilter.alert(MessagesVariable.InvalidUserNameOrPasswod);
                ClearData();
                tbUserName.Select();
                return(false);
            }

            string code     = resultDt.Rows[0]["usercode"].ToString();
            string fullName = resultDt.Rows[0]["fullname"].ToString();
            string syncId   = resultDt.Rows[0]["SyncId"].ToString();

            selectSql = @"SELECT * FROM `userauth` WHERE `userid` = @userwid";
            sqlParameters.Clear();
            sqlParameters.Add(new SqlParameter("userwid", syncId));
            resultDt = MySqlFunction.GetDataTable(new SqlDetail(selectSql, sqlParameters));
            List <string> Authorizations = new List <string>();

            foreach (DataRow dr in resultDt.Rows)
            {
                Authorizations.Add(dr["authorization"].ToString());
            }
            User = new cls_user();
            User.setcls_user(code, fullName, Authorizations, Convert.ToInt32(syncId));
            return(true);
        }
예제 #2
0
        public void login()
        {
            try_connection();
            txtUsername.Text = txtUsername.Text.Trim();

            if (!isconnected)
            {
                fncFilter.alert("This device is not connected to the server.");
                this.Close();
                return;
            }

            if (btnLogIn.Enabled == false)
            {
                return;
            }

            btnLogIn.Enabled = false;

            string pass = MD5EncryptionFunction.Encrypt(txtPassword.Text);

            string        SQL        = @"SELECT * FROM `user` WHERE `status`=1 AND username = @username AND password = @password";
            List <string> parameters = new List <string>();
            List <string> values     = new List <string>();

            parameters.Add("@username");
            parameters.Add("@password");
            values.Add(txtUsername.Text);
            values.Add(pass);

            DataTable dt = mySQLFunc.getdb(SQL, parameters, values);

            if (dt.Rows.Count <= 0)
            {
                fncFilter.alert(cls_globalvariables.warning_userpass_invalid);
                txtUsername.Focus();
                txtUsername.SelectAll();
                btnLogIn.Enabled = true;
                return;
            }

            string code     = dt.Rows[0]["usercode"].ToString();
            string fullname = dt.Rows[0]["fullname"].ToString();
            string SyncId   = dt.Rows[0]["SyncId"].ToString();
            string SQLauth  = @"SELECT * FROM `userauth` WHERE `userid` = @userwid";

            parameters = new List <string>();
            values     = new List <string>();
            parameters.Add("@userwid");
            values.Add(SyncId);
            DataTable     dtauth         = mySQLFunc.getdb(SQLauth, parameters, values);
            List <string> Authorizations = new List <string>();

            foreach (DataRow dr in dtauth.Rows)
            {
                Authorizations.Add(dr["authorization"].ToString());
            }

            this.cashier.setcls_user(code, fullname, Authorizations, Convert.ToInt32(SyncId));

            //Does not continue if Mac address is incorrect
            //if (!cls_globalfunc.CheckMacAddress() && cashier.getwid() != 0 && cashier.getwid() != 1)
            //{
            //    fncFilter.alert("INCORRECT MAC Address SETUP!");
            //    cashier = new cls_user();
            //    txtUsername.Focus();
            //    txtUsername.SelectAll();
            //    btnLogIn.Enabled = true;
            //    return;
            //}

            this.Close();
        }