中南大學數(shù)據(jù)庫實驗報告_第1頁
中南大學數(shù)據(jù)庫實驗報告_第2頁
中南大學數(shù)據(jù)庫實驗報告_第3頁
中南大學數(shù)據(jù)庫實驗報告_第4頁
中南大學數(shù)據(jù)庫實驗報告_第5頁
已閱讀5頁,還剩27頁未讀, 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

中南大學數(shù)據(jù)庫課程設計課程設計題目雨傘薦購系統(tǒng)設計指導老師趙穎,周洋專業(yè)班級電子信息1102姓名張文博學號0909112002實驗日期2014年7月目錄前言·················································3············································3········································3····································3·······································3···········································3········································3后臺程序設計··········································4······································4···········································6····································9前臺程序設計········································12··································12······································12···········································13······································13四.實驗心得············································44前言一.面向?qū)ο笾心洗髮W2010級信息科學與工程學院電子信息工程專業(yè)1101-1102班學生課程設計目的。三.課程設計總體要求1.完成設計、程序編制、調(diào)試與檢查驗收2.書寫完整的課程設計報告(至少20頁),需求分析(要做什么事情如功能需求、信息需求、做到什么程度如性能需求、有哪些難點或關鍵技術),系統(tǒng)設計(功能模型、信息模型、數(shù)據(jù)庫設計、典型處理流程或算法、典型的后臺處理如觸發(fā)器或過程所涉及到的邏輯等)、系統(tǒng)實現(xiàn)及關鍵技術、總結(jié)與展望等章節(jié)。XXX_班號(+)學號尾4位例如car_master_10104即表示車輛主要信息表,為1班,學號尾數(shù)是0104設計的表結(jié)構(gòu),cloth_Detail_42309即表示衣服信息明細表,為4班,學號尾數(shù)是2309設計的表結(jié)構(gòu),對象(包括大的程序?qū)ο蠹俺绦蛎龋┤绻荒荏w現(xiàn)班級及學號等信息,則視為程序不合要求,程序部分成績可能不合格。課程設計要求(1)提出技術方案,主要包括開發(fā)與運行模式選擇、開發(fā)工具、數(shù)據(jù)庫管理系統(tǒng)及其主要的特性保證。(課程設計報告中體現(xiàn))(2)對系統(tǒng)的功能和數(shù)據(jù)進行需求分析、總體設計和詳細設計,并提交設計報告。報告中數(shù)據(jù)庫設計部分要包含系統(tǒng)E-R圖、數(shù)據(jù)字典、表、視圖、索引、文件組織結(jié)構(gòu)等的定義和描述,還需要包括對象命名法。(3)程序?qū)崿F(xiàn)各項功能,在課程設計報告中要反映實現(xiàn)過程中采用的關鍵技術和主要程序流程以及主要的操作界面。(4)數(shù)據(jù)庫后臺最好有觸發(fā)器與多個過程,數(shù)據(jù)結(jié)構(gòu)中最好有主明細結(jié)構(gòu)(即主表與明細表聯(lián)動)。開發(fā)工具MicrosoftSQLServer2008R2,MicrosoftVisualStudio2010中文版六.開發(fā)任務概述本次設計主要是開發(fā)商品薦購系統(tǒng)。其業(yè)務需求如下:某大型網(wǎng)購公司已積累了穩(wěn)定的用戶群,為了與用戶加強聯(lián)系、廣泛收集商品信息、給用戶更好的價格,特推出商品薦購系統(tǒng),即由用戶推薦網(wǎng)上其它門店的商品明細(含價格),系統(tǒng)管理員通過系統(tǒng)獲取薦購的商品信息后會通過各種渠道進行核對(主要是人工方法,系統(tǒng)輔助商品比較分析),如果信息屬實,系統(tǒng)管理員會給用戶(會員)增長積分(標準為1-10分),并根據(jù)會員積分的情況進行升級(如原來0分為初級會員,薦購成功積累大于等于10分,升級為1級會員,如積累100分及以上,則為10級會員,其它級別依此類推),再根據(jù)會員級別允許會員以級別相應折扣購買推薦的或其它用戶推薦的商品,如初級為全價,1級為9折、5級為5折可購買自薦商品或其它用戶薦購商品;6級為4折、9級為1折可購買自薦商品;10級及以上直接免費獲得自薦商品。商品薦購系統(tǒng)的功能主要包括1.用戶或會員操作功能:(1)用戶注冊、用戶登錄、用戶信息維護等;(2)商品搜索、比較、排名、推薦等;2.管理員操作功能:(1)推薦商品采納、會員積分、會員升級;(2)商品類別維護、類似商品信息統(tǒng)一等;(3)商品搜索、比較、排名;(4)操作日志記錄、查詢與維護等??刹捎肅/S模式也可以采用B/S模式,還可以采用C/S模式與B/S模式相結(jié)合的匯合模式如管理員功能中商品類別維護、類似商品信息統(tǒng)一等;操作日志記錄、查詢與維護等用C/S模式,其它功能用B/S模式等,混合模式只要實現(xiàn)部分功能其程序部分的成績將是良好及以上。最好以某一實際的商品為參考,盡量不重復!商品類別重復的,將考慮成績降檔,先由同學將開發(fā)技術與商品類別對象于18周二上午報上來(可報2-3個),由指導老師協(xié)調(diào)后于18周三反饋給大家。每種類型的商品其描述屬性不完全一樣,請注意數(shù)據(jù)表結(jié)構(gòu)的設計。商品可為車輛、衣服、圖書、運動器材、食品、電子設備、鮮花、手機等等,還可以冠以不同的廠家或公司如:通用汽車、紅旗轎車、山河智能輕型飛機、唯品會衣服、李寧運動服裝、三星手機、聯(lián)想電腦等等。后臺程序設計我選擇設計的是球員護腕薦購系統(tǒng),使用SQLServer2008R2建立后臺程序數(shù)據(jù)表,用MicrosoftVisualStudio2010編寫前臺程序代碼,然后連接數(shù)據(jù)庫完成程序?qū)崿F(xiàn)。系統(tǒng)E-R表構(gòu)建用戶用戶查找商品購買商品查看已有薦購商品注冊查找商品購買商品查看已有薦購商品注冊購買信息表查找信息表薦購信息表注冊會員信息表購買信息表查找信息表薦購信息表注冊會員信息表管理員管理員添加積分用戶表薦購信息表商品表用戶表更新查詢積分查看薦購商品添加積分用戶表薦購信息表商品表用戶表更新查詢積分查看薦購商品會員信息表用戶登錄購買商品購買信息表商品信息表會員信息表用戶登錄購買商品購買信息表商品信息表購買信息表查看登錄用戶購買信息表查看登錄用戶商品信息表會員信息表商品信息表會員信息表薦購信息表積分表商品信息表添加積分查詢更新管理員薦購信息表積分表商品信息表添加積分查詢更新管理員SQL表格部分截圖前臺程序設計前臺程序由MicrosoftVisualstudio2010設計,設計過程中與數(shù)據(jù)庫建立連接,實現(xiàn)程序的運行。開始開始管理員修改和刪除商品修改密碼推薦商品查詢商品登錄,注冊前臺程序設計圖形界面編寫實驗代碼設計后臺數(shù)據(jù)庫管理員修改和刪除商品修改密碼推薦商品查詢商品登錄,注冊前臺程序設計圖形界面編寫實驗代碼設計后臺數(shù)據(jù)庫功能模塊分析注冊:用戶必須注冊為會員才課進行購買及推薦業(yè)務.推薦商品:推薦商品分為兩個模塊,一個是對已有的商品進行推薦,只需輸入對應商品的編號就可以進行推薦,只要是會員就可以在推薦頁面中看到推薦的商品.另一個模塊是對沒有的商品進行推薦,推薦后只有管理員可以看見。購買商品:購買商品模塊只需輸入商品的編號就可以購買商品,購買成功后就可以在購物記錄里看見自己購買的商品。每個會員只能查看自己購買的商品無法看到別人購買的商品。管理員模塊:管理員模塊主要是添加管理員的功能,管理員可以對商品進行添加和刪除,以及查看會員的信息,還可以對進行推薦的會員進行添加積分的操作。積分模塊:積分模塊主要是用于商品的折扣,當會員進行商品推薦后,管理員就可以對其進行加積分的操作,隨著積分的增長會員的等級也會增長,而高等級以后購買商品就會有對應的折扣。業(yè)務流程用戶通過注冊可以成為本店的會員,注冊成會員后方可查看,購買和推薦商品,并可獲得相應的積分獎勵。會員可以修改自己的用戶信息,購買或者推薦商品成功后,操作完成。實驗設計及截圖設計注冊登錄界面。注冊成功會員后才可登錄。usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;usingSystem.IO;namespace雨傘薦購系統(tǒng){publicpartialclasslogin:Form{publiclogin(){InitializeComponent();}privatevoidlogin_Load(objectsender,EventArgse){}privatevoidbutton1_Click(objectsender,EventArgse){stringshenfen=comboBox1.Text;//定義身份stringusername=textBox1.Text;//定義用戶名stringpassword=textBox2.Text;//定義密碼變量if(shenfen==""||username==""||password=="")MessageBox.Show("不允許為空!!請檢查");else{if(shenfen=="會員"){//stringstrConnection=@"DataSource=.\SQLEXPRESS;InitialCatalog=yssys;IntegratedSecurity=True";//SqlConnectionconn=newSqlConnection(strConnection);stringconn2=Properties.Settings.Default.yssysConnectionString;SqlConnectionconn=newSqlConnection(conn2);//利用Format格式化字符串,將指定的String中的格式項替換為指定的Object實例的值的文本等效項。stringsql=string.Format("selectcount(*)fromuser_21102where會員名='{0}'and密碼='{1}'andid='{2}'",textBox1.Text.Trim(),textBox2.Text.Trim(),textBox3.Text.Trim());SqlCommandcmd=newSqlCommand(sql,conn);//利用一個現(xiàn)有連接創(chuàng)建一個Command,用以執(zhí)行sql指令;conn.Open();/*利用ExecuteScalar執(zhí)行查詢,并返回查詢所返回的結(jié)果集中第一行的第一列。所有其他的列和行將被忽略。*如果找不到結(jié)果集中第一行的第一列;則返回null引用,如果數(shù)據(jù)庫中的該值為null,此查詢將返回DBNull.Value。*/intcount=(int)cmd.ExecuteScalar();conn.Close();if(count==1){File.WriteAllText("yonghu.txt","");//清空文件內(nèi)容FileStreamfs=newFileStream("yonghu.txt",FileMode.OpenOrCreate,FileAccess.Write);StreamWritersw=newStreamWriter(fs);//通過指定字符編碼方式可以實現(xiàn)對漢字的支持,否則在用記事本打開查看會出現(xiàn)亂碼sw.Flush();sw.BaseStream.Seek(0,SeekOrigin.Begin);sw.WriteLine(textBox1.Text);sw.Flush();sw.Close();File.WriteAllText("id.txt","");//清空文件內(nèi)容FileStreamfs1=newFileStream("id.txt",FileMode.OpenOrCreate,FileAccess.Write);StreamWritersw1=newStreamWriter(fs1);//通過指定字符編碼方式可以實現(xiàn)對漢字的支持,否則在用記事本打開查看會出現(xiàn)亂碼sw1.Flush();sw1.BaseStream.Seek(0,SeekOrigin.Begin);sw1.WriteLine(textBox3.Text);sw1.Flush();sw1.Close();newuser_jm().ShowDialog();}else{MessageBox.Show("賬號或密碼錯誤!請確認后重新輸入","溫馨提醒");}}if(shenfen=="管理員"){//stringstrConnection=@"DataSource=.\SQLEXPRESS;InitialCatalog=yssys;IntegratedSecurity=True";stringconn2=Properties.Settings.Default.yssysConnectionString;SqlConnectionconn=newSqlConnection(conn2);//SqlConnectionconn=newSqlConnection(strConnection);//利用Format格式化字符串,將指定的String中的格式項替換為指定的Object實例的值的文本等效項。stringsql=string.Format("selectcount(*)fromsys_manager_21102where管理員名稱='{0}'and密碼='{1}'andid='{2}'",textBox1.Text.Trim(),textBox2.Text.Trim(),textBox3.Text.Trim());SqlCommandcmd=newSqlCommand(sql,conn);//利用一個現(xiàn)有連接創(chuàng)建一個Command,用以執(zhí)行sql指令;conn.Open();/*利用ExecuteScalar執(zhí)行查詢,并返回查詢所返回的結(jié)果集中第一行的第一列。所有其他的列和行將被忽略。*如果找不到結(jié)果集中第一行的第一列;則返回null引用,如果數(shù)據(jù)庫中的該值為null,此查詢將返回DBNull.Value。*/intcount=(int)cmd.ExecuteScalar();conn.Close();if(count==1){newsys_manager_jm().ShowDialog();}else{MessageBox.Show("賬號或密碼錯誤!請確認后重新輸入","溫馨提醒");}}elseif(shenfen!="管理員"&&shenfen!="會員"){MessageBox.Show("請選擇正確身份:“會員”或者“管理員”");}}}privatevoidbutton4_Click(objectsender,EventArgse){ClearText(this);}privatevoidClearText(ControlctrlTop)//用來清除文本{if(ctrlTop.GetType()==typeof(TextBox))ctrlTop.Text="";else{foreach(ControlctrlinctrlTop.Controls){ClearText(ctrl);/*這是一個遞歸。在ClearText函數(shù)中再次調(diào)用了ClearText。 整個函數(shù)的意思是:你傳一個控件進去,如果是文本框就清除內(nèi)容,如果不是文本框就查找里面子控件, 直到所有控件查找完。*/}}}privatevoidbutton3_Click(objectsender,EventArgse){Application.Exit();}privatevoidbutton2_Click(objectsender,EventArgse){newzc().ShowDialog();}}}下面是注冊的截圖:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespace雨傘薦購系統(tǒng){publicpartialclasszc:Form{publiczc(){InitializeComponent();}stringpassword;privatevoidbutton1_Click(objectsender,EventArgse){if(textBox5.Text==""||textBox1.Text==""||textBox2.Text==""||textBox3.Text==""||comboBox1.Text=="")MessageBox.Show("不允許為空!請檢查");else{try{if(textBox2.Text==textBox3.Text){password=textBox3.Text;stringconn2=Properties.Settings.Default.yssysConnectionString;SqlConnectionconn=newSqlConnection(conn2);//SqlConnectionconn=newSqlConnection(@"DataSource=.\SQLEXPRESS;InitialCatalog=yssys;IntegratedSecurity=True");//InitialCatalog后面跟你數(shù)據(jù)庫的名字,如果你的SqlServer服務器名稱后面不帶SQLEXPRESS,那么DataSource=.conn.Open();stringsql="insertintouser_21102(id,會員名,密碼,性別,積分,會員等級)values(@id,@會員名,@密碼,@性別,@積分,@會員等級)";SqlCommandcmd=newSqlCommand(sql,conn);SqlParameterparn=newSqlParameter("@id",textBox5.Text);cmd.Parameters.Add(parn);SqlParameterparp=newSqlParameter("@會員名",textBox1.Text);cmd.Parameters.Add(parp);SqlParameterparp2=newSqlParameter("@密碼",password);cmd.Parameters.Add(parp2);SqlParameterparp3=newSqlParameter("@性別",comboBox1.Text);cmd.Parameters.Add(parp3);SqlParameterparp4=newSqlParameter("@積分","0");cmd.Parameters.Add(parp4);SqlParameterparp5=newSqlParameter("@會員等級","0");cmd.Parameters.Add(parp5);intresult=cmd.ExecuteNonQuery();//result接收受影響行數(shù),也就是說result大于0的話表示添加成功conn.Close();cmd.Dispose();if(result>=0){MessageBox.Show("注冊成功");this.Close();}}else{MessageBox.Show("兩次輸入的密碼不一致");}}catch{MessageBox.Show("ID號不允許重復,請重新輸入任意不重復id號");}}}privatevoidzc_Load(objectsender,EventArgse){}}}購買界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace雨傘薦購系統(tǒng){publicpartialclassbuy:Form{publicbuy(){InitializeComponent();}privatevoidbuy_21102BindingNavigatorSaveItem_Click(objectsender,EventArgse){this.Validate();this.buy_21102BindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.yssysDataSet);}privatevoidbuy_Load(objectsender,EventArgse){//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.buy_21102TableAdapter.Fill(this.yssysDataSet.buy_21102);}privatevoidbuy_21102DataGridView_CellContentClick(objectsender,DataGridViewCellEventArgse){}privatevoidbuy_21102BindingNavigator_RefreshItems(objectsender,EventArgse){}}}價格界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace雨傘薦購系統(tǒng){publicpartialclassjg:Form{publicjg(){InitializeComponent();}privatevoidjg_21102BindingNavigatorSaveItem_Click(objectsender,EventArgse){this.Validate();this.jg_21102BindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.yssysDataSet);}privatevoidjg_Load(objectsender,EventArgse){//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.jg_21102TableAdapter.Fill(this.yssysDataSet.jg_21102);//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.jg_21102TableAdapter.Fill(this.yssysDataSet.jg_21102);}}}系統(tǒng)管理界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace雨傘薦購系統(tǒng){publicpartialclasssys_manager_jm:Form{publicsys_manager_jm(){InitializeComponent();}privatevoidbutton2_Click(objectsender,EventArgse){newys_manager().ShowDialog();}privatevoidbutton3_Click(objectsender,EventArgse){newjg().ShowDialog();}privatevoidbutton1_Click(objectsender,EventArgse){newuser_manager().ShowDialog();}}}商品添加usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Data.SqlClient;namespace雨傘薦購系統(tǒng){publicpartialclasstj:Form{publictj(){InitializeComponent();}stringname;privatevoidys_21102BindingNavigatorSaveItem_Click(objectsender,EventArgse){this.Validate();this.ys_21102BindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.yssysDataSet);}privatevoidtj_Load(objectsender,EventArgse){//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.ys_21102TableAdapter.Fill(this.yssysDataSet.ys_21102);//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.ys_21102TableAdapter.Fill(this.yssysDataSet.ys_21102);FileStreamfs=newFileStream("yonghu.txt",FileMode.Open,FileAccess.Read);//僅對文本進行讀寫操作StreamReadersr=newStreamReader(fs);//sr.ReadLine()這里是StreamReader的方法,而不是Console中的!//sr.BaseStream.Seek(0,SeekOrigin.Begin);name=sr.ReadLine();sr.Close();}privatevoidbutton1_Click(objectsender,EventArgse){try{stringconn2=Properties.Settings.Default.yssysConnectionString;SqlConnectionconn=newSqlConnection(conn2);//SqlConnectionconn=newSqlConnection(@"DataSource=.\SQLEXPRESS;InitialCatalog=yssys;IntegratedSecurity=True");//InitialCatalog后面跟你數(shù)據(jù)庫的名字,如果你的SqlServer服務器名稱后面不帶SQLEXPRESS,那么DataSource=.conn.Open();stringsql="insertintojg_21102(編號,推薦人,品牌,類型,顏色)values(@編號,@推薦人,@品牌,@類型,@顏色)";SqlCommandcmd=newSqlCommand(sql,conn);SqlParameterparn=newSqlParameter("@編號",textBox1.Text);cmd.Parameters.Add(parn);SqlParameterparp2=newSqlParameter("@推薦人",name);cmd.Parameters.Add(parp2);SqlParameterparp3=newSqlParameter("@品牌",comboBox1.Text);cmd.Parameters.Add(parp3);SqlParameterparp4=newSqlParameter("@類型",comboBox2.Text);cmd.Parameters.Add(parp4);SqlParameterparp5=newSqlParameter("@顏色",comboBox3.Text);cmd.Parameters.Add(parp5);intresult=cmd.ExecuteNonQuery();//result接收受影響行數(shù),也就是說result大于0的話表示添加成功conn.Close();cmd.Dispose();if(result>=0){MessageBox.Show("推薦成功");this.Close();}}catch{MessageBox.Show("該商品已經(jīng)被推薦過");}}privatevoidys_21102DataGridView_CellContentClick(objectsender,DataGridViewCellEventArgse){}}}用戶界面:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;namespace雨傘薦購系統(tǒng){publicpartialclassuser_jm:Form{publicuser_jm(){InitializeComponent();}privatevoiduser_jm_Load(objectsender,EventArgse){strings;FileStreamfs=newFileStream("yonghu.txt",FileMode.Open,FileAccess.Read);//僅對文本進行讀寫操作StreamReadersr=newStreamReader(fs);//sr.ReadLine()這里是StreamReader的方法,而不是Console中的!//sr.BaseStream.Seek(0,SeekOrigin.Begin);s=sr.ReadLine();textBox1.Text=s;sr.Close();}privatevoidbutton1_Click(objectsender,EventArgse){newjg().ShowDialog();}privatevoidbutton3_Click(objectsender,EventArgse){newys().ShowDialog();}privatevoidbutton2_Click(objectsender,EventArgse){newbuy().ShowDialog();}privatevoidbutton4_Click(objectsender,EventArgse){newtj().ShowDialog();}}}用戶管理界面usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace雨傘薦購系統(tǒng){publicpartialclassuser_manager:Form{publicuser_manager(){InitializeComponent();}privatevoiduser_21102BindingNavigatorSaveItem_Click(objectsender,EventArgse){this.Validate();this.user_21102BindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.yssysDataSet);}privatevoiduser_manager_Load(objectsender,EventArgse){//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.user_21102TableAdapter.Fill(this.yssysDataSet.user_21102);//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.user_21102TableAdapter.Fill(this.yssysDataSet.user_21102);}privatevoidbutton1_Click(objectsender,EventArgse){this.Validate();this.user_21102BindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.yssysDataSet);}privatevoiduser_21102DataGridView_CellContentClick(objectsender,DataGridViewCellEventArgse){}}}雨傘界面:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.IO;usingSystem.Data.SqlClient;namespace雨傘薦購系統(tǒng){publicpartialclassys:Form{publicys(){InitializeComponent();}privatevoidys_21102BindingNavigatorSaveItem_Click(objectsender,EventArgse){this.Validate();this.ys_21102BindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.yssysDataSet);}stringID;stringname;privatevoidys_Load(objectsender,EventArgse){//TODO:這行代碼將數(shù)據(jù)加載到表“”中。您可以根據(jù)需要移動或移除它。this.ys_21102TableAdapter.Fill(this.yssysDataSet.ys_21102);FileStreamfs=newFileStream("yonghu.txt",FileMode.Open,FileAccess.Read);//僅對文本進行讀寫操作StreamReadersr=newStreamReader(fs);//sr.ReadLine()這里是StreamReader的方法,而不是Console中的!//sr.BaseStream.Seek(0,SeekOrigin.Begin);name=sr.ReadLine();sr.Close();FileStreamfs1=newFileStream("id.txt",FileMode.Open,FileAccess.Read);//僅對文本進行讀寫操作StreamReadersr1=newStreamReader(fs1);//sr.ReadLine()這里是StreamReader的方法,而不是Console中的!//sr.BaseStream.Seek(0,SeekOrigin.Begin);ID=sr1.ReadLine();sr1.Close();}privatevoidbutton1_Click(objectsender,EventArgse){try{stringconn2=Properties.Settings.Default.yssysConnectionString;SqlConnectionconn=newSqlConnection(conn2);//SqlConnectionconn=newSqlConnection(@"DataSource=.\SQLEXPRESS;InitialCatalog=yssys;IntegratedSecurity=True");//InitialCatalog后面跟你數(shù)據(jù)庫的名字,如果你的SqlServer服務器名稱后面不帶SQLEXPRESS,那么DataSource=.conn.Open();stringsql="insertintobuy_21102(編號,購買用戶ID,用戶名,品牌,類型,顏色,價格,實際價格)values(@編號,@購買用戶ID,@用戶名,@品牌,@類型,@顏色,@價格,@實際價格)";SqlCommandcmd=newSqlCommand(sql,conn);SqlParameterparn=newSqlParameter("@編號",textBox1.Text);cmd.Parameters.Add(parn);SqlParameterparp=newSqlParameter("@購買用戶ID",ID);cmd.Parameters.Add(parp);SqlParameterparp2=newSqlParameter("@用戶名",name);cmd.Parameters.Add(parp2);SqlParameterparp3=newSqlParameter("@品牌",comboBox1.Text);cmd.Parameters.Add(parp3);SqlParameterparp4=newSqlParameter("@類型",comboBox2.Text);cmd.Parameters.Add(parp4);SqlParameterparp5=newSqlParameter("@顏色",comboBox3.Text);cmd.Parameters.Add(parp5);SqlParameterparp6=newSqlParameter("@價格",textBox3.Text);cmd.Parameters.Add(parp6);intmoney=Convert.ToInt32(textBox3.Text);///////////////////////////////////////////////////////////SqlParameterparp7=newSqlParameter("@實際價格",textBox3.Text);cmd.Parameters.Add(parp7);intresult=cmd.ExecuteNonQuery();//result接收受影響行數(shù),也就是說result大于0的話表示添加成功conn.Close();cmd.Dispose();if(result>=0){MessageBox.Show("購買成功");this.Close();}}catch{MessageBox.Show("你好,你已經(jīng)購買過該商品");}}privatevoidbutton2_Click(objectsender,EventArgse){stringconn2=Properties.Settings.Default.yssysConnectionString;SqlConnectionconn=newSqlConnection(conn2);//SqlConnectionconn=newSqlConnection(@"Data

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論