




已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 面向对象的基本概念(P135)了解对象的意义目前较新的编程语言,如C#、J#、C+、Java和Visual Basic,都是面向对象编程(简称:OOP)的方式进行软件开发。OOP模型中,程序不在面向过程,不在遵循顺序的逻辑,编程人员无须控制和决定执行的顺序,而是采用事件驱动的方式,通过按键、单击窗口中的各个按钮等进行操作。2、面向对象的三大特征(P135)封装性,多态性,继承性3、类的访问权限(P141)(1)public:类的成员函数、类的对象和该类的派生类都可以访问。 (2)protected:类的成员函数和该类的派生类可以访问。 (3)private:只有本类的成员函数可以访问。(4)internal:内部成员通过在成员中使用internal修饰符来定义,该成员只能在当前程序中访问。(5)protected internal :保护内部成员是同时使用了protected和internal这两个修饰符来定义的,访问权限仅限于当前程序集或该类的派生类访问。3、构造函数和析构函数(P151)(1)构造函数:构造函数是类的重要成员,是用于初始化一个对象状态的特殊方法。语法格式:访问修饰符 类名(参数列表) 语句 说明:(1)构造函数的参数列表有0到多个参数(2)构造函数不能包含任何返回值(3)一个构造函数的可访问性决定了引用类型的新实例可以在哪里创建。Example:一个Person类的无参构造: Public Person() age=19; 有参构造: Public Person(String s) Name=s;创建对象:Person p1=new person(“王二小”); Person p2=new person(“李小二”); 构造函数可以重载(2)析构函数:析构函数用于销毁对象。当不需要某个类的某个对象时,通常希望他所占的存储空间能被收回。C#中提供了析构函数,专门用于释放对象占用的系统资源,它是类的特殊成员。语法格式:类名() 语句; 4、程序调试与异常处理P215;(1)程序错误:语法错误运行时错误逻辑错误5、数据库知识(P299)(1)概念:数据库是专门用于信息存储的软件系统,是一组特定的数据集合。(2)SQL知识(P300)(a)查询select:基本格式Select From *代表所有字段(b)插入语句insert:insert into (字段名1,字段名n的值)values(字段名1的值,字段名n的值)(c)修改语句update:update Set =,=, Where(d)删除语句delete:delete from where6、ADO.NET概念(P306)(1)五个核心对象:Connection(连接),用来建立与特定数据源的连接。Command(命令),用来对据源执行SQL命令语句或存储过程。DataReader(数据阅读器),用来对数据源中获取只读,向前的数据流。DataAdapter(数据适配器),用来在数据源和数据集之间交换数据。DataSet(数据集),用来处理从数据源读出的数据,表示数据在内存中的缓存。7、ADO.NET访问数据库模式(P310)(1):联机模式:步骤:用SqlConnection对象与数据库建立连接。用SqlCommand对象向数据库检索所需数据,或直接进行编辑(插入,删除,修改)。如果SqlCommand对象向数据库执行的是数据检索操作,则把取出来的数据放在SqlDataReader对象中读取;如果SqlCommand对象向数据库执行的是数据编辑操作,则直接进行步骤。在完成数据的检索操作后,关闭SqlDataReader对象。关闭SqlConnection对象。(2)脱机模式(利用ADO.NET访问数据库P310:步骤:)8、ADO.NET访问数据库的基本步骤 1使用对象connection连接数据源 2使用命令对象command执行sql语句或存储过程,操纵数据库 3使用数据读取器对象datareader读取数据 4使用数据集对象dataset和数据适配器对象dataadapter访问数据库9、使用DataAdapter访问数据库操作 建立数据库连接 建立SqlDataAdapter对象! 实例化SqlDataAdapter对象! 建立一个DataSet对象,执行SQL语句得到的表添加到其中 关闭数据库连接 10、数据绑定的类型(P331) 简单数据绑定:将一个控件绑定到单个数据元素的能力(如TextBox、Label控件) 常用的绑定方法:控件名.DataBindingsAdd(“属性名”,数据源,”字段名”) 复杂数据绑定(P332)画图常用方法(Graphics类C#结构化程序设计代码p26P32的简化)Graphics.FillRectangle( Brush brush,Rectangle rect)方法 填充 Rectangle 结构,指定的矩形的内部。Graphics.FillEllipse(Brush brush, float x,float y, float width,float height) 方法填充边框所定义的椭圆的内部,该边框由一对坐标、一个宽度和一个高度指定。Graphics.FillPie( Brush brush,int x, int y,int width, int height,int startAngle, int sweepAngle)方法填充由一对坐标、一个宽度、一个高度以及两条射线指定的椭圆所定义的扇形区的内部。Graphics.DrawArc( Pen pen,int x,int y,int width,int height,int startAngle, int sweepAngle)方法绘制一段弧线,它表示由一对坐标、宽度和高度指定的椭圆部分。Graphics.DrawEllipse 方法 (Pen, Rectangle(F)绘制边界 Rectangle 结构指定(即制定一个矩形)的椭圆。Graphics.DrawLine (Pen pen, Point pt1,Point pt2)方法 绘制一条连接两个 Point 结构的线。Graphics.DrawPie( Pen pen,Rectangle rect, float startAngle,float sweepAngle) 方法 绘制由一个 Rectangle 结构和两条射线所指定的椭圆定义的扇形。1.连接字符串的获取(配置文件App.config) 注:数据库若不为默认实例时,DataSource=.实例名2、数据库的相关操作 添加用户 private void butqd_Click(object sender, EventArgs e) if (txtmm1.Text.Trim() = txtmm2.Text.Trim()/若密码文本框的值与确认密码的文本框的值一样 string myconnstring = ConfigurationManager.AppSettingsconnectionstring.ToString();/获取连接字符串 SqlConnection myconn = new SqlConnection();/创建SqlConnection 对象 myconn.ConnectionString = myconnstring;/设置它的ConnectionString属性 try myconn.Open();/以上步骤表示连上数据库 string insertstr = insert into xtyh values( + txtyhm.Text.Trim() + , + txtmm1.Text.Trim() + , + yhqx + );/定义命令语句串,添加数据 SqlCommand insertcom = new SqlCommand(insertstr, myconn);/创建并使用SqlCommand对象 insertcom.ExecuteNonQuery();/执行insert命令 MessageBox.Show(成功添加新用户!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); catch MessageBox.Show(添加新用户未成功!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); finally myconn.Close(); else MessageBox.Show(密码与确认密码不一致!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; 修改用户 private void butqd_Click(object sender, EventArgs e) if (txtmm1.Text.Trim() = txtmm2.Text.Trim()string myconnstring = ConfigurationManager.AppSettingsconnectionstring.ToString(); SqlConnection myconn = new SqlConnection(); myconn.ConnectionString = myconnstringtry/联机方式 /myconn.Open(); /string insertstr = update xtyh set yhm= + txtyhm.Text.Trim() + ,mm= + txtmm1.Text.Trim() + ,qx= + yhqx + where id=+id+; /SqlCommand insertcom = new SqlCommand(insertstr, myconn); /SqlCommand selectcom = new SqlCommand(select * from xtyh, myconn); /insertcom.ExecuteNonQuery(); / string strsql1 = update xtyh set yhm=name,mm=mm,qx=qx where id= + id + ; SqlCommand commupdate = new SqlCommand(strsql1, conn); commupdate.Parameters.Add(new SqlParameter(name, System.Data.SqlDbType.NChar, 10, yhm);/定义命令的参数(名称,类型,长度,关联字段) commupdate.Parameters.Add(new SqlParameter(mm, System.Data.SqlDbType.NChar, 16, mm); commupdate.Parameters.Add(new SqlParameter(qx, System.Data.SqlDbType.NChar, 10, qx); SqlCommand selectcom = new SqlCommand(select * from xtyh , conn); SqlDataAdapter da = new SqlDataAdapter();/创建 SqlDataAdapter 对象 da.UpdateCommand = commupdate; da.SelectCommand = selectcom; conn.Open(); DataSet ds = new DataSet(); da.Fill(ds);/填充DataSet对象 conn.Close(); /脱机处理程序/ DataTable mytable = ds.Tables0;/ds.Tables0表示ds中的第一个表,ds可理解为临时的数据库 DataRow myrow = mytable.Rows0;/mytable.Rows0表示ds中的第一个表的第一行 myrowyhm = txtyhm.Text.Trim(); myrowmm = txtmm1.Text.Trim(); myrowqx = yhqx; / conn.Open(); da.Update(ds); conn.Close(); 删除用户 private void butqd_Click(object sender, EventArgs e) if (MessageBox.Show(确实要删除吗?删除后信息不能恢复!, 警告, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) = DialogResult.Yes) if (id != 0) string myconnstring = ConfigurationManager.AppSettingsconnectionstring.ToString(); SqlConnection myconn = new SqlConnection(); myconn.ConnectionString = myconnstring; trymyconn.Open(); string strqrxxcx = delete from xtyh where id= + id + ;/取单元格值 SqlCommand mycommqrxxcx = new SqlCommand(strqrxxcx, myconn); mycommqrxxcx.ExecuteNonQuery();MessageBox.Show(成功删除用户数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); catchMessageBox.Show(无法删除用户数据!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); finally myconn.Close(); elseMessageBox.Show(请选择要删除的用户!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Information); return; else return; Frmscyh_Load(sender, e); private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) if (e.RowIndex 0) return; DataGridViewRow row = dataGridView1.Rowse.RowIndex; id = Convert.ToInt16(row.Cellscid.Value); private void Frmscyh_Load(object sender, EventArgs e)/显示表数据 id = 0; string myconnstring = ConfigurationManager.AppSettingsconnectionstring.ToString(); SqlConnection myconn = new SqlConnection(); myconn.ConnectionString = myconnstring; trymyconn.Open(); string strconn = select * from xtyh; SqlCommand mycommzzmm = new SqlCommand(strconn, myconn); SqlDataAdapter myda = new SqlDataAdapter(); myda.SelectCommand = mycommzzmm; DataSet ds = new DataSet(); myda.Fill(ds); dataGridView1.DataSource = ds.Tables0.DefaultView; catchMessageBox.Show(无法显示数据表!, 提示, MessageBoxButtons.OK, MessageBoxIcon.Warning); finally myconn.Close();3、动态组建查询字符串String strcx = select sfzfwtd,sfzdhsj,sfzydbs,sfzqjmh,sfzyjss,fwqfwtd,fwqcytj,fwqzstj,fwqqjmh,fwqyjss,fwqqyhf,fwqydbs,pzss,sykk,fhss, lhss,ldbs,msbs,aqbs,sfzfwtdjy,sfzdhsjjy,sfzydbsjy,sfzqjmhjy,sfzyjssjy,fwqfwtdjy,fwqcytjjy,fwqzstjjy,fwqqjmhjy,fwqyjssjy,fwqqyhfjy,fwqydbsjy,pzssjy,sykkjy,fhssjy,lhssjy,ldbsjy,msbsjy,aqbsjy from scrydcb where cpsj= + riqi + ; if (nl != ) strcx = strcx + and nl= + nl + ; if (xb != ) strcx = strcx + and xb= + xb + ; if (jl != ) strcx = strcx + and jl= + jl + ; if (xcblx != ) strcx = strcx + and xcblx= + xcblx + ; if (jclx != ) strcx = strcx + and jclx= + jclx + ; if (whcd != ) strcx = strcx + and whcd= + whcd + ;4、画图(画点,线,饼图,趋势图,树状图) private void button1_Click(object sender, EventArgs e) /点与线 int x = 150; int y = 150; int y1 = 300; Graphics gl = pictureBox1.CreateGraphics(); Color c1 = Color.Black; Point d1 = new Point(x, y);/x,y分别为横纵坐标 Point d2 = new Point(x, y1); gl.DrawLine(new Pen(c1), d1, d2);/画线,d1、d2分别为始末点柱状图 gl.DrawLine(new Pen(c1,8), d1, d2);/其中8为线的宽度,即成为条状饼图 Graphics g2 = pictureBox1.CreateGraphics(); Color c11 = Color.Green; Color c22 = Color.Blue; Color c3 = Color.Fuchsia; Color c4 = Color.Brown; Color c5 = Color.Red; float hd1 =30;/hd1表弧度1 float hd2 = 120; float hd3 = 50; float hd4 = 100; float hd5 =60 ; g2.Clear(pictureBox1.BackColor);/将pictureBox1清空,相当于画图前的白纸g2.FillPie(new SolidBrush(c11), new Rectangle(120, 10, 280, 280), 0, hd1);/new Rectangle表示画一个矩形;SolidBrush为刷子;120,10表示矩形左端点的坐标;280,280分别表示宽度和高度,0表示开始位置(矩形的右端线与高度的中心线的交点),hd1表示最终位置g2.FillPie(new SolidBrush(c22), new Rectangle(120, 10, 280, 280), hd1, hd2);/FillPie为画饼图的方法,g2.FillPie(new SolidBrush(c3), new Rectangle(120, 10, 280, 280), hd1 + hd2, hd3);g2.FillPie(new SolidBrush(c4), new Rectangle(120, 10, 280, 280), hd1 + hd2 + hd3, hd4);g2.FillPie(new SolidBrush(c5), new Rectangle(120, 10, 280, 280), hd1 + hd2 + hd3 + hd4, hd5);3. 动态画线(象限分析)横坐标表示权重系数的平均值,纵坐标表示满意指数的平均值已知中心点的横坐标为常量,纵坐标为变量。PictureBox的尺寸为930,300 private void button1_Click(object sender, EventArgs e)/计算中心点坐标 double zxx, zxy = 0; zxx = 0.0833; for (int i = 0; i 12; i+) zxy += sjzsi; /表示各个三级指标的满意指数之和 Graphics gl = picxxt.CreateGraphics(); Color c1 = Color.Black; Color c2 = Color.Red; int zxy1 = (int)(zxy / 12.0);/满意指数的平均值 int zxx1 = (int)(zxx * 930); gl.Clear(picxxt.BackColor); Point qdx = new Point(30, 300 - zxy1 * 3); Point zdx = new Point(900, 300 - zxy1 * 3); Point qdy = new Point(300 + zxx1, 30);/横轴向右平移 Point zdy = new Point(300 + zxx1, 270);/横轴向右平移 gl.DrawLine(new Pen(c1), qdx, zdx); gl.DrawLi
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 金山职业技术学院《聚焦徽派建筑(摄影)》2024-2025学年第一学期期末试卷
- 哈尔滨科学技术职业学院《国际货运代理》2024-2025学年第一学期期末试卷
- 湖北交通职业技术学院《电子CAD》2024-2025学年第一学期期末试卷
- 小学食堂卫生管理规章制度范本
- 制药企业质量管理体系文件范本
- 小学四年级语文单元检测题库汇编
- 中学生课余活动兴趣调查报告
- 黑龙江中医药大学《建筑设计应用》2024-2025学年第一学期期末试卷
- 学生生源地报名及委托流程模板
- 甘肃中医药大学《生物信息学与组学》2024-2025学年第一学期期末试卷
- 《Gitlab使用流程》课件
- 与供应商的合作与谈判
- IT技术支持与服务响应机制建设指南
- 2024年房县人民医院高层次卫技人才招聘笔试历年参考题库频考点附带答案
- 有机合成实验室技安规程(3篇)
- GB/T 5534-2024动植物油脂皂化值的测定
- DBJ52T 096-2019 城市轨道交通土建工程施工质量验收标准
- 《合成孔径雷达原理》课件
- 人教版(2024新版)七年级上册英语Starter Unit1单元测试卷(含答案)
- HSK标准教程1-第一课lesson1
- 新课标人教版七年级数学上册教案全册
评论
0/150
提交评论