Windows 7 Professional 64 Bit
 Internet Explorer 8
 IIS 7
 Oracle Database 11g Release 2 64 Bit
 Oracle 11g ODAC and Oracle Developer Tools for Visual Studio 11.2.0.1.2
 Visual Web Developer 2010 Express

■ログイン処理 Prev Top Next
関連ページ:なし


今回はログイン画面を作成します。


20.Step.20 ログイン処理のコーディング

---Step03.aspx---


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Step03.aspx.cs" Inherits="AccountSample.Step03.Step03" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ログイン</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        ユーザーID:<asp:TextBox ID="Txt_UID" MaxLength="6" runat="server"></asp:TextBox>
        <br />
        パスワード:<asp:TextBox ID="Txt_Password" MaxLength="8" runat="server"></asp:TextBox>
        <p></p>
        <asp:Button ID="Cmd_Login" runat="server" Text="ログイン" onclick="Cmd_Login_Click" /> <asp:Label ID="Lbl_Msg" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

---Step03.aspx.cs---


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.DataAccess.Client;
using System.Configuration;

namespace AccountSample.Step03
{
    public partial class Step03 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Cmd_Login_Click(object sender, EventArgs e)
        {
            Lbl_Msg.Text = "";

            string UserID = Txt_UID.Text.Trim();
            string Password = Txt_Password.Text.Trim();

            OracleConnection connection = null;
            OracleCommand command = null;
            OracleDataReader reader = null;

            try
            {
                // OracleConnectionを作成
                connection = new OracleConnection(ConfigurationManager.ConnectionStrings["Sample"].ToString());

                // データベース接続
                connection.Open();

                // OracleCommandを作成
                command = new OracleCommand();

                command.Connection = connection;

                // ユーザーマスタに登録すみかチェックする
                command.CommandText = "";
                command.CommandText += "SELECT";
                command.CommandText += " * ";
                command.CommandText += "   FROM  USER_MASTER";
                command.CommandText += "   WHERE USERID='" + UserID + "'";
                command.CommandText += "     AND PASSWORD IS NOT NULL ";
                command.CommandText += "     AND PASSWORD='" + Password.Replace("'", "''" ) + "'";
                command.CommandText += "     AND DELETEDATE IS NULL ";

                // SELECT文を実行
                reader = command.ExecuteReader();

                // データあり
                if (reader.Read() == true)
                {
                    Lbl_Msg.Text = "ログインしました。";
                    Lbl_Msg.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    Lbl_Msg.Text = "ログインできませんでした。";
                    Lbl_Msg.ForeColor = System.Drawing.Color.Red;
                }
            }
            catch (Exception ex)
            {
                Lbl_Msg.Text = "ログインできませんでした。";
                Lbl_Msg.ForeColor = System.Drawing.Color.Red;
                goto EXIT;
            }


        EXIT:
            if (reader != null)
            {
                reader.Close();
                reader.Dispose();
                reader = null;
            }

            if (connection != null)
            {
                connection.Close();
                connection.Dispose();
                connection = null;
            }
        }
    }
}

ログイン画面をWebで作成しました。がネットゲームの起動時に行うログイン処理のことがあるため、フォームアプリでログインすることも考える必要があります。

クライアント端末上で実行するフォームアプリからOracleに接続する場合、Oracleクライアントをインストールする必要があるはずです。 しかし、ユーザーにOracleをインストールしてもらうなど非現実な話です。
ネットゲームプログラムとOracleを中継するサービスプログラムをサーバ上にセットアップし、 ネットゲームプログラムとサービスプログラムとをソケット通信でデータのやり取りを行い、 サービスプログラム側でOracle接続を行うような仕組みを作る必要があるかと思います。 そこまでやらないですけどね。


Prev Top Next
inserted by FC2 system