笔记:
详情已经在前面的章节有列述了,这里只点出几个比较重要的:
string name = DataGridView对象.SelectedRows[0].Cells[0].Value.ToString();获取在DataGridView控件中选中的一行的第cells[0]列数据。

窗体样式:



代码如下:

主窗体,“手机销售管理系统”代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace product6._10
{public partial class FrmSalesManage : Form{public FrmSalesManage(){InitializeComponent();}private void 客户添加ToolStripMenuItem_Click(object sender, EventArgs e){//客户添加FrmAddClient frmAdd = new FrmAddClient();frmAdd.MdiParent = this;frmAdd.Show();}private void 客户查询ToolStripMenuItem_Click(object sender, EventArgs e){//查询客户FrmSelectClient frmSelect = new FrmSelectClient();frmSelect.MdiParent = this;frmSelect.Show();}private void 客户查询ToolStripMenuItem1_Click(object sender, EventArgs e){//查询客户FrmSelectClient frmSelect = new FrmSelectClient();frmSelect.MdiParent = this;frmSelect.Show();}private void 客户添加ToolStripMenuItem1_Click(object sender, EventArgs e){//客户添加FrmAddClient frmAdd = new FrmAddClient();frmAdd.MdiParent = this;frmAdd.Show();}//退出所有程序private void FrmSalesManage_FormClosing(object sender, FormClosingEventArgs e){Application.Exit();}private void 安全退出ToolStripMenuItem_Click(object sender, EventArgs e){Application.Exit();}private void 安全退出ToolStripMenuItem1_Click(object sender, EventArgs e){Application.Exit();}
}
}


查询窗体:“客户查询”代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace product6._10
{public partial class FrmSelectClient : Form{public FrmSelectClient(){InitializeComponent();}//刷新列表public void RefreshList(){string sql = "select * from Customer";DataTable table = DBHelper.GetDataTable(sql);ClientInformation.DataSource = table;}//初始换程序选项private void FrmSelectClient_Load(object sender, EventArgs e){RefreshList();cbType.Items.Clear();cbType.Items.Add("--请选择--");cbType.Items.Add("按姓名");cbType.Items.Add("按电话");cbType.Items.Add("按地址");cbType.Items.Add("按编号");cbType.SelectedIndex = 0;}//完善搜索信息private void btSelect_Click(object sender, EventArgs e){string key = cbCondition.Text;if(cbType.SelectedIndex == 0){//没有确切客户信息,则全能查找string sql = string.Format("select * from Customer where Custname like '%{0}%' or CustID like '%{0}%'or Custtel like '%{0}%'or CustAddress like '%{0}%'or CustSex like '%{0}%'",key);DataTable table = DBHelper.GetDataTable(sql);ClientInformation.DataSource = table;if (table.Rows.Count == 0){MessageBox.Show(string.Format("没有找到与{0}相关的联系人", key));}}//查无此人报错if (cbType.SelectedIndex == 1){//根据姓名查询客户string sql = string.Format("select * from Customer where Custname like '%{0}%'",key);DataTable table = DBHelper.GetDataTable(sql);ClientInformation.DataSource = table;if(table.Rows.Count == 0){MessageBox.Show(string.Format("没有找到与{0}相关的联系人",key));}}else if(cbType.SelectedIndex == 2){//根据电话查询客户string sql = string.Format("select * from Customer where CustTel like '%{0}%'", key);DataTable table = DBHelper.GetDataTable(sql);ClientInformation.DataSource = table;if (table.Rows.Count == 0){MessageBox.Show(string.Format("没有找到与{0}相关的联系人", key));}}else if(cbType.SelectedIndex == 3){//根据地质查询客户string sql = string.Format("select * from Customer where CustAddress like '%{0}%'",key);DataTable table = DBHelper.GetDataTable(sql);ClientInformation.DataSource = table;if (table.Rows.Count == 0){MessageBox.Show(string.Format("没有找到与{0}相关的联系人", key));}}else if(cbType.SelectedIndex == 4){//根据客户编号查询客户string sql = string.Format("select * from Customer where CustID like '%{0}%'", key);DataTable table = DBHelper.GetDataTable(sql);ClientInformation.DataSource = table;if (table.Rows.Count == 0){MessageBox.Show(string.Format("没有找到与{0}相关的联系人", key));}}}//异窗口传参数public static string id = "0";public static string name;public static string tel;public static string sex;public static string address;private void ClientInformation_CellContentClick(object sender, DataGridViewCellEventArgs e){id = ClientInformation.SelectedRows[0].Cells[0].Value.ToString();name = ClientInformation.SelectedRows[0].Cells[1].Value.ToString();tel = ClientInformation.SelectedRows[0].Cells[2].Value.ToString();sex = ClientInformation.SelectedRows[0].Cells[3].Value.ToString();address = ClientInformation.SelectedRows[0].Cells[4].Value.ToString();  }//弹出修改客户信息窗口private void btAddClient_Click(object sender, EventArgs e){//选中客户失败   if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(name) || string.IsNullOrEmpty(tel) || string.IsNullOrEmpty(sex)){MessageBox.Show(string.Format("未选中唯一联系人,\n请重新单击选择客户"));return;}FrmAmendClient frmAmend = new FrmAmendClient();frmAmend.ShowDialog();RefreshList();}//删除客户private void buDeleteClient_Click(object sender, EventArgs e){id = ClientInformation.SelectedRows[0].Cells[0].Value.ToString();name = ClientInformation.SelectedRows[0].Cells[1].Value.ToString();//给一个删除客户提示string question = string.Format("你确定要将客户{0}拉入黑名单吗", name);DialogResult result =  MessageBox.Show(question,"删除提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question);if(result == DialogResult.No){return;}string sql = string.Format("delete from Customer where CustID = {0}",int.Parse(id));if (DBHelper.ExecuteNonQuery(sql)){MessageBox.Show(string.Format("客户{0}已被您从名单中拉黑",name));}else{MessageBox.Show(string.Format("客户{0}删除失败,请向管理员核实",name));}}//点击刷新列表private void button1_Click(object sender, EventArgs e){RefreshList();}
}
}


添加窗体,“添加用户”代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace product6._10
{public partial class FrmAddClient : Form{public FrmAddClient(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){//添加一个新客户,完善客户信息string name = textName.Text;string tel = textTel.Text;string sex = "";if(radMan.Checked == true){sex = radMan.Text;}else if(radWoman.Checked == true){sex = radWoman.Text;}string address = textAddress.Text;if(string.IsNullOrEmpty(name)|| string.IsNullOrEmpty(tel) || string.IsNullOrEmpty(sex)){MessageBox.Show("请完善客户信息");return;}string sql = string.Format("insert into Customer values('{0}','{1}','{2}','{3}')",name,tel,sex,address);if (DBHelper.ExecuteNonQuery(sql)){MessageBox.Show(string.Format("新客户{0}添加成功",name));textName.Text = "";textTel.Text = "";radMan.Checked = false;radWoman.Checked = false;textAddress.Text = "";}else{MessageBox.Show(string.Format("新客户{0}添加失败,请向管理员反映情况",name));}}//取消添加客户private void button2_Click(object sender, EventArgs e){//如果信息为空,直接关闭窗口if(string.IsNullOrEmpty(textName.Text) && string.IsNullOrEmpty(textTel.Text)&&radMan.Checked == false && radWoman.Checked == false && string.IsNullOrEmpty(textAddress.Text)){Close();}//信息不为空,清空信息textName.Text = "";textTel.Text = "";radMan.Checked = false;radWoman.Checked = false;textAddress.Text = "";}//姓名非空*号提示private void textName_TextChanged(object sender, EventArgs e){string name = textName.Text;if (string.IsNullOrEmpty(name)){labName.Text = "*";labName.ForeColor = Color.Red;}else{labName.Text = "";}}//电话非空*号提示private void textTel_TextChanged(object sender, EventArgs e){string tel = textTel.Text;if (string.IsNullOrEmpty(tel)){labTel.Text = "*";labName.ForeColor = Color.Red;}else{labTel.Text = "";}}//性别非空*号提示——男private void radMan_CheckedChanged(object sender, EventArgs e){if(radMan.Checked == false && radWoman.Checked == false){labSex.Text = "*";labSex.ForeColor = Color.Red;}else{labSex.Text =  ""; }}//性别非空*号提示——女private void radWoman_CheckedChanged(object sender, EventArgs e){if (radMan.Checked == false && radWoman.Checked == false){labSex.Text = "*";labSex.ForeColor = Color.Red;}else{labSex.Text = "";}}
}
}


修改信息,“修改客户信息”代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace product6._10
{public partial class FrmAmendClient : Form{public FrmAmendClient(){InitializeComponent();}//非空验证提示private void textName_TextChanged(object sender, EventArgs e){string name = textName.Text;if(string.IsNullOrEmpty(name)){labName.ForeColor = Color.Red;labName.Text = "*";}else{labName.Text = "";}}private void textTel_TextChanged(object sender, EventArgs e){string tel = textTel.Text;if (string.IsNullOrEmpty(tel)){labTel.ForeColor = Color.Red;labTel.Text = "*";}else{labTel.Text = "";}}private void radMan_CheckedChanged(object sender, EventArgs e){if(radMan.Checked == false && radWoman.Checked == false){labSex.Text = "*";labSex.ForeColor = Color.Red;}else{labSex.Text = "";}}private void radWoman_CheckedChanged(object sender, EventArgs e){if (radMan.Checked == false && radWoman.Checked == false){labSex.Text = "*";labSex.ForeColor = Color.Red;}else{labSex.Text = "";}}//确认修改客户信息系private void button1_Click(object sender, EventArgs e){int id = Convert.ToInt32(labID.Text);string name = textName.Text;string tel = textTel.Text;string sex = "男";if (radMan.Checked){sex = radMan.Text;}else if (radWoman.Checked){sex = radWoman.Text;}if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(tel) || string.IsNullOrEmpty(sex)){MessageBox.Show("请完善用户信息");return;}string address = textAddress.Text;string sql = string.Format("update Customer set Custname = '{0}',Custtel = '{1}',Custsex = '{2}',Custaddress = '{3}' where Custid = {4}",name,tel,sex,address,id);if (DBHelper.ExecuteNonQuery(sql)){MessageBox.Show(string.Format("编号为{0}的客户信息修改成功",id));this.Close();}else{MessageBox.Show(string.Format("编号为{0}的客户信息修改失败,请向管理员反映情况",id));}}//自动根据选中异窗体传输的信息填写文本信息private void FrmAmendClient_Load(object sender, EventArgs e){labID.Text = FrmSelectClient.id;textName.Text = FrmSelectClient.name;textTel.Text = FrmSelectClient.tel;if (FrmSelectClient.sex.Equals("男")){radMan.Checked = true;}else if (FrmSelectClient.sex.Equals("女")){radWoman.Checked = true;}textAddress.Text = FrmSelectClient.address;}//保存后关闭窗口private void button2_Click(object sender, EventArgs e){Close();}
}
}

C#可视化编程技术总结:制作可视化窗体软件相关推荐

  1. Visual C++——《可视化编程技术》实验报告——MFC编程

    一.实验目的和要求 使用MFC类库编制应用程序:按钮控件.静态控件及编辑框的应用. 二.实验内容 主窗口标题为实验三: MFC编程  学号  姓名; 完成例9_5; 完成例9_3; 用菜单实现9_5中 ...

  2. Visual C++——《可视化编程技术》实验报告——资源的应用—反弹的球

    一.实验目的和要求 熟悉资源在windows编程中的运用 二.实验内容 在窗口中显示一个球,该球以与水平成45度夹角作直线运动,当遇到边界时,反弹回来,仍与水平成45度角继续运动.(课本p173  7 ...

  3. Visual C++——《可视化编程技术》实验报告——资源的应用

    一.实验目的和要求 1. 使用API函数编制包含各种资源的Windows应用程序: 2. 实现Windows应用程序对键盘与鼠标的响应. 二.实验内容 1.问题描述: 创建一个菜单,其中有三个菜单项, ...

  4. Visual C++——《可视化编程技术》实验报告——绘图与文本操作

    一.实验目的和要求 1.掌握Windows应用程序的基本结构: 2.使用API函数建立窗口.消息循环,编制窗口函数: 3.使用API函数在用户区绘图.输出文本,理解Windows的图形设备接口. 二. ...

  5. blender 可视化编程_使用Blender可视化天体物理学数据

    blender 可视化编程 Blender会议不仅是吸引人的艺术和动画展示,而且是Blender和开源软件的非常规用法,已经成为一个奇妙的展示. 今年真正引起我注意的演讲之一是吉尔·奈曼博士(Jill ...

  6. 可视化IDE | 快速高效制作可视化大屏~

    微兔Visual Tools 2021 Beta版发布,旨在让更多人轻松打造炫酷实用的可视化大屏,一款全新高自由度图表配置.多数据源实时渲染.源码一键下载的数据可视化设计工具~免费下载可视化IDE搭建 ...

  7. 三维重建 阈值分割 3D可视化 医学图像分割 CT图像分割及重建系统 可视化编程技术及应用

    一. 概述 此系统实现了常见的VTK四视图,实现了很好的CT图像分割,可以用于骨骼,头部,肺部,脂肪等分割,,并且通过三维重建实现可视化.使用了第三方库 VTK,ITK 实现分割和生不重建. 窗口分为 ...

  8. DICOM 医学图像阅读器 CT MRI 超声 医疗软件 三维重建 可视化编程技术及应用

    一. 概述 此系统实现了常见 VTK 四视图,实现了很好的 DICOM 图像显示,可用于 DICOM 超声 X线 CT MR 三维重建 拾取像素值 窗宽 窗位 像素,距离测量,角度测量,提供源码: 并 ...

  9. Visual C++——《可视化编程技术》课程考核

    问题描述 工程文件的名字取" 学号_姓名_课内考查",工程文件中所有文件名均为"学号_姓名_课内考查"(包括.cpp,.rc,.h等文件),否则按照" ...

  10. C#可视化编程技术第三章:DBHelper类(内含思路、代码、注释)

    DBHelper类: DBHelper类,就是用类将ADO.NET用方法封装起来.减少程序员的工作量. 代码思路: 将已经学会的ADO.qNET用代码分开封装,比如说: 一个SqlConnection ...

最新文章

  1. 技术人员如何参与产品设计讨论:激活那一潭死水
  2. android activity生命周期的一张经典图片
  3. [INS-08109] Unexpected error occurred while validating inputs at state 'getOCMDetails'.
  4. oracle之基本的sql_select语句之课后练习
  5. 浅析基于 Serverless 的前后端一体化框架
  6. UILabel 宽高自适应
  7. linux六个标准目录,Linux基本目录规范——XDG
  8. 迎春舞会之三人组舞 vijos1061 动态规划
  9. Day 5 20190120 老男孩python学习第5天 内容整理
  10. JavaSE基础Day01
  11. 使用Java快速实现进度条
  12. 神经网络在科研中的应用,基于神经网络的论文
  13. 120日均线金叉250日均线是大牛市来临的重要信号
  14. 【网络安全】网络安全期末大题 复习题
  15. java jnlp被阻止_JNLP 被java安全阻止
  16. 做透视表时,提示“数据源引用无效”
  17. 一个小白对接电子面单的哪些坑?
  18. unsigned char,char ,uchar ,UCHAR的区别
  19. NSFC 申请不中的反思 (内部讨论)
  20. c++实现STL标准库

热门文章

  1. 常用的 7 款 MySQL 客户端工具,你值得拥有
  2. 详细安装sqlmap详细教程
  3. map转json字符串字段排序
  4. 小甲鱼鱼c论坛python作业_[全套55讲]鱼C论坛小甲鱼Python课后题试题.doc
  5. 【python】conda配置python项目环境(Conda常用命令)
  6. 区块链发展迎来新机遇
  7. 求生之路2服务器无线跳,求生之路连跳宏 | 手游网游页游攻略大全
  8. C语言练习——打印九九乘法表
  9. java64位安装包下载_java64位安装包
  10. Fortran入门教程(八)——子例程及函数