用户注册,报修
一、需求分析
(1)還沒有注冊的客戶,可以進入注冊界面進行注冊。
(2)新建一個報修表,名字為repair_info0,列有用戶名、報修類型、報修地點、報修內容,報修日期和時間、用戶報修次數。
(3)在報修界面中,當用戶點擊“報修”按鈕時,軟件會把用戶報修的信息寫入數據庫中,還可以更新報修次數,同時會清空相應的文本框。
二、具體設計思路
(1)首先建一個報修表,然后在窗體上擺些所需的控件。
(2)我們需要做的有查詢、插入、修改。當點擊查詢的時候,數據會從數據庫里讀取到相應的控件里,然后我們可以對報修次數進行更改;我們在相應的控件里填寫信息,點擊報修會把數據插入到數據庫里,同時清空了相應的文本框。
(3)我們感覺如果插入日期用填寫的方法沒有多大意義,還容易出錯,于是我們用NumericUpDown控件來獲取當日的日期。獲取的日期用Label顯示,然后插入數據庫里,為了不影響界面美觀,我們把NumericUpDown控件隱藏起來。
(4)查詢、插入、修改都要連接數據庫,這樣連接數據庫的代碼要重寫多次,所以我們把查詢、插入、修改的代碼寫在一個類里。
三、代碼實現
封裝代碼
?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Windows.Forms; using System.Data;namespace zhuce {class Class1{public string strCon = "data source=.;initial catalog=H:\\DATA\\REPAIR.MDF;integrated security=true";public SqlConnection sqlCon = new SqlConnection();public SqlDataReader sdr;public DataTable dt = new DataTable();public SqlDataAdapter sda = new SqlDataAdapter();public DataSet ds = new DataSet();public void dbcon(){try{sqlCon = new SqlConnection(strCon);}catch (Exception e){MessageBox.Show("數據庫連接不成功:" + e.ToString());}}public void dbFill(string selstr){dt.Clear();sda = new SqlDataAdapter(selstr, strCon);sda.Fill(ds, "repair_info0");dt = ds.Tables["repair_info0"];}public void dbSelect(string showInfo){sqlCon.Open();SqlCommand sqlcmd = new SqlCommand(showInfo, sqlCon);sdr = sqlcmd.ExecuteReader();}public void dbInsert(string insertInfo){sqlCon.Open();SqlCommand sqlcmd = new SqlCommand(insertInfo, sqlCon);try{sqlcmd.ExecuteNonQuery();MessageBox.Show("報修成功!");}catch (Exception e){MessageBox.Show("報修失敗" + e.ToString());}sqlCon.Close();}public void dbInsert1(string insertInfo){sqlCon.Open();SqlCommand sqlcmd = new SqlCommand(insertInfo, sqlCon);try{sqlcmd.ExecuteNonQuery();MessageBox.Show("注冊成功!");}catch (Exception e){MessageBox.Show("注冊失敗" + e.ToString());}sqlCon.Close();}public void dbUpdate(string updStr){sqlCon.Open();SqlCommand sqlcmd = new SqlCommand(updStr, sqlCon);try{sqlcmd.ExecuteNonQuery();MessageBox.Show("更新成功!");}catch (Exception e){MessageBox.Show("更新失敗" + e.ToString());}sqlCon.Close();}}}?
?
?
注冊代碼
?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;namespace zhuce {public partial class Zhuce : Form{public Zhuce(){InitializeComponent();}Class1 cl = new Class1();private void zc_Click(object sender, EventArgs e){cl.dbcon();string sql = "insert into user_info(userName,passWord) values('" + textBox1.Text +"','" + textBox2.Text + "')";cl.dbInsert1(sql); baoxiu b = new baoxiu();b.Show();}}}?
?
?
報修代碼
?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;namespace zhuce {public partial class baoxiu : Form{public baoxiu(){InitializeComponent();}string selStr = "select * from repair_info0";Class1 cl = new Class1();private void bx_Click(object sender, EventArgs e){year.Value = Convert.ToDecimal(DateTime.Now.Year);month.Value = Convert.ToDecimal(DateTime.Now.Month);day.Value = Convert.ToDecimal(DateTime.Now.Day);cl.dbcon();string insrtInfo = "insert into repair_info0(userName,bxplace,bxtype,bxcontent,bxdate,bxtime) values('" + comboBox2.Text + "','" + textBox1.Text +"','" + comboBox1.Text + "','" + richTextBox1.Text + "','" + label1.Text + "','" + textBox3.Text + "')";cl.dbInsert(insrtInfo);textBox1.Text = "";comboBox2.Text = "";textBox3.Text = "";comboBox1.Text = "";richTextBox1.Text = "";}private void year_ValueChanged(object sender, EventArgs e){label1.Text = year.Value + "-" + month.Value + "-" + day.Value;}private void month_ValueChanged(object sender, EventArgs e){label1.Text = year.Value + "-" + month.Value + "-" + day.Value;}private void day_ValueChanged(object sender, EventArgs e){label1.Text = year.Value + "-" + month.Value + "-" + day.Value;}private void chaxun_Click(object sender, EventArgs e){cl.dbcon();cl.dbFill(selStr);comboBox2.ValueMember = "userName";comboBox2.DataSource = cl.dt.DefaultView;}private void button1_Click(object sender, EventArgs e){cl.dbcon();string strUpd = "update repair_info0 set bxtime='" + textBox3.Text + "' where userName='" + comboBox2.Text + "' ";cl.dbUpdate(strUpd);textBox1.Text = "";comboBox2.Text = "";textBox3.Text = "";comboBox1.Text = "";richTextBox1.Text = "";}private void comboBox2_SelectedIndexChanged(object sender, EventArgs e){string selStr = "select * from repair_info0 where userName='" + comboBox2.Text + "'";cl.dbcon();cl.dbSelect(selStr);if (cl.sdr.Read()){comboBox2.Text = cl.sdr["userName"].ToString();textBox1.Text = cl.sdr["bxplace"].ToString();comboBox1.Text = cl.sdr["bxtype"].ToString();richTextBox1.Text = cl.sdr["bxcontent"].ToString();textBox3.Text = cl.sdr["bxtime"].ToString();label1.Text = cl.sdr["bxdate"].ToString();}}} }?
四、測試
五、PSP耗時分析
?
| PSP2.1 | Personal Software Process Stages | Time(h) |
| Planning | 計劃 | 10 |
| ? ? Estimate | 估計這個任務需要多長時間 | 10 |
| Development | 開發 | 7 |
| ? ? Analysis | 需求分析 | 1 |
| ? ? Design Spec | 生成設計文檔 | 1 |
| ? ? Coding Standard | 代碼規范 | 2 |
| ? ? Design | 具體設計 | 1 |
| ? ? Coding | 具體代碼 | 1 |
| ? ? Code Review | 代碼復審 | 0.5 |
| ? ? Text | 測試 | 0.5 |
| Reporting | 報告 | 3 |
| ? ? Test Report | 測試報告 | 1 |
| ? ? Size Measurement | 計算工作量 | 1 |
| ? ? Postmortem | 事后總結 | 1 |
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
?
六、團隊分工
?這次團隊作業是我們一個宿舍的七個人,有付媛媛、徐玉瑩、王遠離、衛文靜、梁秋萍、胡田鴿、龔園苑。
? ??具體分工如下:
? ? ? ??團隊負責人:付媛媛
? ? ? 創建數據庫:徐玉瑩
? ? ? 連接數據庫:王遠離
? ? ? 外觀設計人員:龔園苑
? ? ? 寫代碼人員:徐玉瑩、付媛媛
? ? ? 測試人員:梁秋萍
? ? ? 寫文檔人員:胡田鴿
? ? ???團隊人員得分情況如下:
? ? ? 付媛媛:3分
? ? ??徐玉瑩:2分
? ? ? 衛文靜:1分
? ? ? 王遠離:1分
? ? ? 梁秋萍:1分?
? ? ? 胡田鴿:1分
? ? ? 龔園苑:1分
七、總結
? ? ?這次增量作業比上次難一點,涉及的范圍比較廣,但我們是打不死的小強,再難也要堅持。當然這種題對我們班的學霸來說是小菜一碟,對我們來說就是學習的過程。其實我們這次完成的還有缺陷。比如更新報修次數,并沒有達到我們預想的結果。我們在相應的文本框里填寫用戶報修信息后,當點擊報修的時候,就自動在數據庫里bxtime(報修次數)列添加1次報修次數,當我們再讀取到這一用戶時,再點擊報修,就自動更改了數據庫里報修次數列為2;而不是我們手動來更改報修次數。不知道老師這次增量的要求是不是表達這個意思。
? ? ?我們想實現這種結果,但是代碼寫了又改,總是出錯,于是就添加了一個更新按鈕來手動更新報修次數。
?
? ? ?紙上得來終覺淺,絕知此事要躬行!當我們看到書上寫的一些程序時,總覺得實現的功能太過于簡單,而且那些都是別人的知識,紙上談兵終究不行,但當我自己親自寫一些程序時,才發現即使想實現一個很小的功能也是不易的,但只要每一次都能實現小小的功能就算是有了很大的收獲。
?
? ? ?想要實現一個完美的程序,需要很好的基礎功底和思考能力,我們就特別缺少基礎知識,希望老師每次布置的作業能讓我們鞏固基礎知識,提高思考能力。
? ? ?
?
轉載于:https://www.cnblogs.com/twinkle-0908/p/5043664.html
總結
- 上一篇: java文件读写操作类
- 下一篇: Unity3d 配置OpenCV(Emg