計算機專業畢業設計:[30]網站登錄2?

計算機專業的很多同學臨近畢業了,才著急怎麼做一個畢業設計來進行答辯。很短的時間是不可能完成的,天使預計用三個月的時間和計算機專業的同學分享一下怎麼完成畢業之前的一項重要任務“畢業設計”。請小夥伴們跟上天使的步伐,在天使的帶領下,一起完成你們的畢業設計吧。後期,天使還會講解如何寫畢業論文等,希望小夥伴們持續關注哦。

工具/原料

Visual Studio 2008

方法/步驟

會員輸入賬號密碼之後,登錄成功跳轉到如圖所示界面

計算機專業畢業設計:[30]網站登錄2

雙擊打開類文件【MyClass】寫一個查詢數據庫是否存在相同記錄文件的類

計算機專業畢業設計:[30]網站登錄2

#region 判斷是否已有相同的記錄 public bool IsSameRecord(string scmd) { try { SqlConnection cn = this.Getcon(); cn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.Text; cmd.CommandText = scmd; SqlDataAdapter dataAdapter = new SqlDataAdapter(); dataAdapter.SelectCommand = cmd; DataSet dset = new DataSet(); dataAdapter.Fill(dset, "Info"); cn.Close(); cn.Dispose(); if (dset.Tables["Info"].Rows.Count > 0) return true; else return false; } catch { return false; } } #endregion

我們的網站會經常對數據庫進行增刪改查,我們可以直接寫一個類,每次有類似操作的時候就調用這個類

計算機專業畢業設計:[30]網站登錄2

每次登錄成功之後,就保存用戶名在電腦上,就不需要再次登錄,所以我們寫一個Cookies

public void WriteCook() { Response.Cookies["username"].Value = txtname.Text; Response.Cookies["username"].Expires = DateTime.Now.AddDays(1); }

計算機專業畢業設計:[30]網站登錄2

雙擊登錄按鈕,在代碼界面輸入代碼,首先查找是否存在這個用戶,假如存在,那麼在電腦上記錄用戶名,網頁跳轉到index0頁面

計算機專業畢業設計:[30]網站登錄2

protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { try { string sqlcon = "select * from [user] where user_name='" + txtname.Text + "' and user_password='" + txtpwd.Text + "'"; if (myclass.IsSameRecord(sqlcon)) { WriteCook(); string sq = "update [user] set register_time='"+DateTime.Now.ToString()+"' where user_name='" + txtname.Text + "' "; myclass.ExCom(sq); Session["username"] = txtname.Text; Server.Transfer("~/index0.aspx"); } else { Response.Write(""); } } catch (Exception ex) { Response.Write(""); } }

注意事項

不落淚的天使1原創整理,請尊重小編的辛苦耕耘

計算機, 網站, 計算機專業, 畢業設計,
相關問題答案