欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    可视化编程技术作业二.doc

    • 资源ID:70333070       资源大小:152.50KB        全文页数:17页
    • 资源格式: DOC        下载积分:15金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要15金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    可视化编程技术作业二.doc

    可视化编程技术作业(二)班级:11网络B班 姓名:张耀东 学号:37一、问题描述:对SQL Server中的Northwind数据库创建一数据库应用程序,该应用程序能够实现浏览每一雇员的相关信息。二、 分析与设计该应用程序涉及到对雇员数据进行显示、操作的用户界面,涉及到读取雇员数据库表中的记录。为了避免对数据库进行反复操作,我们声明方法getAll一次将数据库表中的所有数据读出,并用每条雇员记录创建一个雇员对象将雇员对象添加到ArrayList对象中,这样雇员表中的每条记录以雇员对象的形式暂存在ArrayList对象中,雇员表中的一条对应一个ArrayList列表中的一个雇员对象。然后,我们对ArrayList列表中的雇员对象进行操作,浏览每个雇员的数据。根据以上思路,我们必须声明一个雇员Employee类,以存储雇员记录的数据。雇员数据库表有多少字段,雇员类就应该有多少字段,并在雇员类为每个字段声明属性。同时声明一个Employee类,该类有一个ArrayList对象字段,有getAll方法和获取ArrayList列表中雇员对象的方法(包括包括获取第一条、上一条、下一条、最后一条、添加、修改、删除雇员的方法)。图形界面类与Employee类和EmployeeDA类进行交互,而不直接与数据库进行交互。三、解决方案1、 创建项目和编写Employee类及EmployeeDA类。(1) 创建项目名为Northwind的Windows应用程序。(2) 创建Employee类。向Northwind项目添加Employee类:using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Northwind public class Employee private int _EmployeeID; public int EmployeeID get return _EmployeeID; set _EmployeeID = value; private String _LastName; public String LastName get return _LastName; set _LastName = value; private String _FirstName; public String FirstName get return _FirstName; set _FirstName = value; private String _Title; public String Title get return _Title; set _Title = value; private String _TitleOfCourtesy; public String TitleOfCourtesy get return _TitleOfCourtesy; set _TitleOfCourtesy = value; private String _BirthDate; public String BirthDate get return _BirthDate; set _BirthDate = value; private String _HireDate; public String HireDate get return _HireDate; set _HireDate = value; private String _Address; public String Address get return _Address; set _Address = value; private String _City; public String City get return _City; set _City = value; private String _Region; public String Region get return _Region; set _Region = value; private String _PostalCode; public String PostalCode get return _PostalCode; set _PostalCode = value; private String _Country; public String Country get return _Country; set _Country = value; private String _HomePhone; public String HomePhone get return _HomePhone; set _HomePhone = value; private String _Extension; public String Extension get return _Extension; set _Extension = value; private String _Notes; public String Notes get return _Notes; set _Notes = value; private int _ReportsTo; public int ReportsTo get return _ReportsTo; set _ReportsTo = value; private String _photoPath; public String PhotoPath get return _photoPath; set _photoPath = value; public Employee() public Employee(int id, String mLastName, String mFirstName, String mTitle, String mTitleOfCourtesy, String mBirthDate, String mHireDate, String mAddress, String mCity, String mRegion, String mPostalCode, String mCountry, String mHomePhone, String mExtension, int mReportsTo) _EmployeeID = id; _LastName = mLastName; _FirstName = mFirstName; _Title = mTitle; _TitleOfCourtesy = mTitleOfCourtesy; _BirthDate = mBirthDate; _HireDate = mHireDate; _Address = mAddress; _City = mCity; _Region = mRegion; _PostalCode = mPostalCode; _Country = mCountry; _HomePhone = mHomePhone; _Extension = mExtension; _ReportsTo = mReportsTo; public override string ToString() return this.FirstName + " " + this.LastName; (3) 创建EmployeeDA类。向Northwind项目添加如下EmployeeDA类:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;using System.Collections;namespace Northwind public class EmployeeDA private static ArrayList employess = new ArrayList(); private static int i = 0; private static SqlConnection aConnection; /- private static void GetDBConnection() try string strConn = "Data Source=(local);User ID=sa;Password=1234;Initial Catalog=Northwind" aConnection = new SqlConnection(strConn); /aConnection.ConnectionString = strConn; catch(Exception oExcept) MessageBox.Show(oExcept.Message); /- public static ArrayList GetAll() employess.Clear(); SqlCommand oCmd; SqlDataReader oDR = null; String strSQL = "SELECT * from Employees" try GetDBConnection(); oCmd = new SqlCommand(); oCmd.Connection = aConnection; oCmd.Connection.Open(); oCmd.CommandText = strSQL; oDR = oCmd.ExecuteReader(); while (oDR.Read() Employee aEmployee = new Employee(); aEmployee.EmployeeID = Int32.Parse(oDR"EmployeeID".ToString(); aEmployee.LastName = oDR"LastName".ToString(); aEmployee.FirstName = oDR"FirstName".ToString(); aEmployee.BirthDate = oDR"BirthDate".ToString(); aEmployee.HireDate = oDR"HireDate".ToString(); aEmployee.Title = oDR"Title".ToString(); aEmployee.TitleOfCourtesy = oDR"TitleOfCourtesy".ToString(); aEmployee.Address = oDR"Address".ToString(); aEmployee.Country = oDR"Country".ToString(); aEmployee.Extension = oDR"Extension".ToString(); aEmployee.HomePhone = oDR"HomePhone".ToString(); aEmployee.Notes = oDR"Notes".ToString(); aEmployee.PostalCode = oDR"PostalCode".ToString(); aEmployee.Region = oDR"Region".ToString(); if (oDR.IsDBNull(16) aEmployee.ReportsTo = 0; else aEmployee.ReportsTo = Int32.Parse(oDR"ReportsTo".ToString(); if (oDR.IsDBNull(17) aEmployee.PhotoPath = " " else aEmployee.PhotoPath = oDR"PhotoPath".ToString(); employess.Add(aEmployee); catch (Exception oExcept) MessageBox.Show(oExcept.Message); finally CloseSqlDataReader(oDR); CloseConnection(); return employess; /- private static void CloseConnection() if(aConnection != null) aConnection.Close(); /- private static void CloseSqlDataReader(SqlDataReader oDR) if (oDR != null) oDR.Close(); /- public static Employee GetCurrentEmployee() if (employess.Count > 0) Employee aEmployee = (Employee)employessi; return aEmployee; else return null; /- public static Employee GetFirstEmployee() Employee aEmployee = new Employee(); if (employess.Count > 0) i = 0; aEmployee = (Employee)employessi; return aEmployee; /- public static Employee GetNextEmployee() Employee aEmployee = new Employee(); if (i < employess.Count - 1) i = i + 1; aEmployee = (Employee)employessi; return aEmployee; i = employess.Count - 1; return aEmployee = (Employee)employessemployess.Count - 1; /- public static Employee GetPrevEmployee() Employee aEmployee = new Employee(); if (i > 0) i = i - 1; aEmployee = (Employee)employessi; return aEmployee; return aEmployee = (Employee)employess0; /- public static Employee GetLastEmployee() Employee aEmployee = new Employee(); if (employess.Count > 0) i = employess.Count - 1; aEmployee = (Employee)employessi; return aEmployee; /- public static void AddNew(Employee aEmployee) SqlDataReader oDR = null; string strSQL = "INSERT INTO Employees" strSQL += "(Address,BirthDate,Country,Extension," + "FirstName,LastName,HireDate," strSQL += "HomePhone,Notes,PostalCode,Region," + "City,ReportsTo,Title,TitleOfCourtesy)" strSQL += "VALUES(" strSQL += "'" + aEmployee.Address + "'" + "," strSQL += "'" + aEmployee.BirthDate + "'" + "," strSQL += "'" + aEmployee.Country + "'" + "," strSQL += "'" + aEmployee.Extension + "'" + "," strSQL += "'" + aEmployee.FirstName + "'" + "," strSQL += "'" + aEmployee.LastName + "'" + "," strSQL += "'" + aEmployee.HireDate + "'" + "," strSQL += "'" + aEmployee.HomePhone + "'" + "," strSQL += "'" + aEmployee.Notes + "'" + "," strSQL += "'" + aEmployee.PostalCode + "'" + "," strSQL += "'" + aEmployee.Region + "'" + "," strSQL += "'" + aEmployee.City + "'" + "," strSQL += aEmployee.ReportsTo + "," strSQL += "'" + aEmployee.Title + "'" + "," /strSQL += "'" + aEmployee.getPhotoPath() + "'" + "," strSQL += "'" + aEmployee.TitleOfCourtesy + "'" + ")" try GetDBConnection(); SqlCommand oCmd = new SqlCommand(strSQL, aConnection); oCmd.Connection.Open(); oCmd.ExecuteNonQuery(); i = employess.Count; catch (Exception oExcept) MessageBox.Show(oExcept.Message); finally CloseSqlDataReader(oDR); CloseConnection(); /- public static void Update(Employee aEmployee) SqlDataReader oDR = null; Employee currentEmployee = GetCurrentEmployee(); int id = currentEmployee.EmployeeID; String strSQL = "UPDATE Employees SET" strSQL += " Address=" + "'" + aEmployee.Address + "'" + "," strSQL += " BirthDate=" + "'" + aEmployee.BirthDate + "'" + "," strSQL += " Country=" + "'" + aEmployee.Country + "'" + "," strSQL += " Extension=" + "'" + aEmployee.Extension + "'" + "," strSQL += " FirstName=" + "'" + aEmployee.FirstName + "'" + "," strSQL += " LastName=" + "'" + aEmployee.LastName + "'" + "," strSQL += " HireDate=" + "'" + aEmployee.HireDate + "'" + "," strSQL += " HomePhone=" + "'" + aEmployee.HomePhone + "'" + "," strSQL += " Notes=" + "'" + aEmployee.Notes + "'" + "," /strSQL += "'" + aEmployee.PhotoPath + "'" + "," strSQL += " PostalCode=" + "'" + aEmployee.PostalCode + "'" + "," strSQL += " Region=" + "'" + aEmployee.Region + "'" + "," strSQL += " City= " + "'" + aEmployee.City + "'" + "," strSQL += " ReportsTo=" + aEmployee.ReportsTo + "," strSQL += " Title=" + "'" + aEmployee.Title + "'" + "," strSQL += " TitleOfCourtesy=" + "'" + aEmployee.TitleOfCourtesy + "'" strSQL += " WHERE EmployeeID= " + id; try GetDBConnection(); SqlCommand oCmd = new SqlCommand(strSQL, aConnection); oCmd.Connection.Open(); oCmd.ExecuteNonQuery(); catch (Exception oExcept) MessageBox.Show(oExcept.Message); finally CloseSqlDataReader(oDR); CloseConnection(); /-

    注意事项

    本文(可视化编程技术作业二.doc)为本站会员(asd****56)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开