Win form碎知识点
判断1.ds不能为空 2.ds的表数量必须大于0 3.判断ds的第一个表中的行数必须有
if (ds.Tables.Count > 0 && ds != null && ds.Tables[0].Rows.Count > 0)
首先ds不能为空,然后ds大集合里的table要有(数量>0)ds.tables.count>0 ds.tables[0].Rows.Count>0
窗体位于屏幕中心 strtposition
form前提下 acceptbutton canclebutton
Tabindex table键 不需要的设为0
MaximizeBox--false 最大框禁用
panle radiobutton 年级GropDownList
groupBox 容器 panl 面板 radiobutton放在Panle中,实现单选互斥
菜单项 toolstrip menustrip
menustrip一用于左上角,如文件,编辑...之类的;
ContextMenuStrip是你单击出来修改,删除,这样之类的
!!!!!!!!!!!!!!!ToolStrip 介个控件很实用,很实用!!!!!!!!!!!!!!!!!!!
strvalue = comboBox1.SelectedValue.ToString();~~~~~~~~~~~~~~~~~~~~~~~~~~SelectedValue=DisplayMember+ValueMember
登录的时候要想密码和账号都匹配 就需要在select语句时:
select * from UserLogin where LoginName='" + username + "' and Loginpwd='" + userpwd + "'
传参数username userpwd
当重置按钮的时候,要给用户名获得焦点: txtUsername.Focus();
txtUsername.Text = ""; txtpwd.Text = "";
登录事件都是点击提交的时候进行事件的运行,所以主代码都要写到btn_Sumit中
为什么要进行异常处理:
代码错误 资源不可用 公共语言运行库遇到意外 ....多种原因
Exception是异常的基类
IOException SQLException Exception 开发人员
try{可能出现的异常} catch(Exception ex){异常处理} ----consoele.writeLine();
try
{s
File.Delete("C:/test/aa.txt");//第一段异常
//第二顿异常
SqlConnection conn = new SqlConnection("server=.;database=student;integrated security=true");
conn.Open();
conn.Close();
//异常代码
int i = 100;
int j = 0;
int k = i / j;
}
catch (IOException h)
{
Console.WriteLine("出现IO异常:" + h.ToString());
throw h;错误在其他信息中
}
catch (SqlException ex)
{
Console.WriteLine("出现IO异常:" + ex.ToString());
Console.WriteLine("错误信息是"+ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("出现其他异常:"+ ex.ToString());
}
Console.ReadKey();
要更改控件属性头名字:
DataTable dt = new System.Data.DataTable();
dt = SaleBLL.BuyInGoodsListBLL.BuyInGoodsList(); 先绑定数据源先绑定数据源先绑定数据源先绑定数据源先绑定数据源先绑定数据源
dataGridView1.DataSource = dt;
dataGridView1.Columns[0].HeaderText = "ID编号";
dataGridView1.Columns[1].HeaderText = "学生编号";
dataGridView1.Columns[2].HeaderText = "学生姓名";
dataGridView1.Columns[3].HeaderText = "性别";
DataTable dt = NewsBLL.GetNewsType();
DropDownList1.DataValueField = "NewID";
DropDownList1.DataTextField = "NewName";
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
public void GetGrade()
{
Grade Gd=new Grade();
GrideList.ValueMember="ID"; DataValueFiled="ID";
GrideList.DisplayMember="name"; DataTextField="name";
selectText=name
selectvalue=ID
}
this.txtUser.text.trim()=="";
this.txtUser.text.trim().Equals(string.Empty)性能更好,更优化,空间的开辟
MessageBox.Show("你好", "取消", MessageBoxButtons.OK, MessageBoxIcon.Error);
dataDataReader返回的是TRUE false 结束后必须关闭数据库
string.Empty 不占用空间 "" 占用空间
DialogResult 对话框
DataTable dt = TransBLL.ComBoxBLL.GetProList();
comboBox1.DataSource = dt;
DataRow dr = dt.NewRow();
dr["ProvinceName"] = "请选择";
dt.Rows.InsertAt(dr, 0);
comboBox1.ValueMember = "ProvinceName";
comboBox1.SelectedIndex = 0;
——————————————————————@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@————————————————————————————————
窗体之间的跳转就是将目标窗体在本窗体代码中实例化一下,然后showDilog一下
给DataGrview添加事件
selectionMode的值变成FullRowSelect
private void dataGridView1_Click(object sender, EventArgs e)
{
this.tBoxName.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
this.tBoxGoodsStyle.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
。。。。。。
}
将winform窗体中获取的修改的值传递给model中的值
Modeltb_Goods GG = new Modeltb_Goods();
GG.BarCode = bar;
GG.GoodsName = name;
GG.GoodsSize = size;
GG.GoodsTypeID = ConvertType(style);//要写一个装换的方法
GG.JinPrice = jin;
GG.PiFaPrice = PiFa;
GG.LingPrice = Ling;
GG.CurrentNum = currNum;
GG.GoodsNote = Note;
GG.GoodsProduct = Pro;
//获取点击行的ID
int ID =Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
GG.GoodsID = ID;
int result = SaleBLL.GoodsMangerBLL.Update(GG);/
————————————@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@—————————————————————
要想出现那个删除的按钮,就是在控件中添加contextMenuStrip控件
!!!!!!!!!!!!在datadriview中有一个contextMenuStrip属性,值指向contextMenuStrip1
private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
{}
由主窗体跳转到子窗体的时候,主窗体有一个ISMdiContainer属性设置为TRUE;!!!!!!!!!!!!!!!!!!
private void 添加货物ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!ShowChildrenForm("AddGoods"))
{
AddGoods AG = new AddGoods();//将要打开的窗体实例化
AG.MdiParent = this;//要子窗体的父窗体设置为当前窗体
AG.Show();
}
}
/// <summary>
/// 防止子窗体重复出现
/// </summary>
/// <param name="ChildFormName">把子窗体的name传递过来</param>
/// <returns></returns>
private bool ShowChildrenForm(string ChildFormName)
{
int i;
for (i = 0; i < this.MdiChildren.Length; i++)
{
//判断子窗体是否已经打开
if (this.MdiChildren[i].Name == ChildFormName)
{
//如果子窗体已经打开,设置子窗体位焦点
this.MdiChildren[i].Activate();
return true;
}
}
return false;
}
------------@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@———————————————————
弹出框的确定 取消
DialogResult dr=MessageBox.Show("确定要删除吗?","删除",MessageBoxButtons.YesNoCancel);
if (dr == DialogResult.Yes){}
else{return;}
int ID =Convert.ToInt32( dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
---------------------------------@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@______________________-----------
/// <summary>
///选择dataGriview里的一行,传到修改里去,前提dataGriview的selectMode属性变成一行
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dataGridView1_Click(object sender, EventArgs e)
{
this.tBoxBar.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
this.tBoxName.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
this.tBoxSize.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
this.CmbStyle.Text = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();
this.tBoxBuyIn.Text = dataGridView1.SelectedRows[0].Cells[5].Value.ToString();
this.tBoxPiFa.Text = dataGridView1.SelectedRows[0].Cells[6].Value.ToString();
this.tBoxLPrice.Text = dataGridView1.SelectedRows[0].Cells[7].Value.ToString();
this.tBoxCurNum.Text = dataGridView1.SelectedRows[0].Cells[8].Value.ToString();
this.tBoxNote.Text= dataGridView1.SelectedRows[0].Cells[9].Value.ToString();
this.tBoxProduct.Text = dataGridView1.SelectedRows[0].Cells[10].Value.ToString();
}
----------------------------------------------------字符串分割----------------------------------------------------------------------
private void button2_Click(object sender, EventArgs e)
{
//循环输出所有字符
string txtinput = textBox1.Text.Trim();
foreach (char item in txtinput)
{
//MessageBox.Show(item.ToString());
}
for (int i = 0; i < txtinput.Length; i++)
{
MessageBox.Show(txtinput[i].ToString());
}
}
private void button1_Click(object sender, EventArgs e)
{
string txtinput = textBox1.Text.Trim();
string[] str = txtinput.Split(',');//按照特定的符号进行分割
foreach (string item in str)
{
// MessageBox.Show(item.ToString());
}
for (int i = 0; i < str.Length; i++)
{
MessageBox.Show(str[i]);
}
}
------------------------------------------------------------------------------------------------------------------------------------------
从登录页面传登录类型,以便frm_main 页面的显示情况
string s_LoginName = "";
string s_Role = "";
public Frm_main(string strLoginName,string strRole)
{
InitializeComponent();
s_LoginName = strLoginName;
s_Role = strRole;
if(s_Role=="普通人")
{
管理员系统ToolStripMenuItem.Visible = false;
管理员列表ToolStripMenuItem.Visible = false;
购物管理ToolStripMenuItem.Visible = false;
添加货物ToolStripMenuItem.Visible = false;
}
}
------------------------------------------------------------------------------------------------------------------------------------------
/// <summary>
/// 检查数据库中是否存在用户
/// </summary>
/// <param name="MM"></param>
/// <returns></returns>
public static int CheckUsers(ModelManger MM)
{
SqlConnection conn = new SqlConnection("server=.;initial Catalog=GoodsManger;integrated security=true;");
conn.Open();
string strsql = "select Adminion from Manger where Adminion=@Admin";
SqlParameter sps = new SqlParameter("@Admin",MM.Adminion);
object obj = sqlhelper.GetExecuteScalar(strsql, sps);
if (obj != null && obj.ToString() != "")
{
return 1;
}
else
{
return 0;
}
}
---------------------------------------------------------------------------------------------------------------
/// <summary>
/// 查看登录人的权限是否正确
/// </summary>
/// <param name="MM"></param>
/// <returns></returns>
public static string Match(ModelManger MM)
{
SqlConnection conn = new SqlConnection("server=.;initial Catalog=GoodsManger;integrated security=true;");
conn.Open();
string strsql = "select LimiterName from Manger where Adminion=@Admin";
SqlParameter sps = new SqlParameter("@Admin", MM.Adminion);
return sqlhelper.GetExecuteScalar(strsql, sps).ToString();//ToString() 是将数据库中相对应的名字取出来
}
------------------------------------------------------------------------------------------------------------------------
Frm_main Fm = new Frm_main(name, sss);传递窗体用户名
Fm.Show();
string s_LoginName = "";
string s_Role = "";
public Frm_main(string strLoginName,string strRole)
{
InitializeComponent();
s_LoginName = strLoginName;
s_Role = strRole;
if(s_Role=="普通人")
{
管理员系统ToolStripMenuItem.Visible = false;
管理员列表ToolStripMenuItem.Visible = false;
购物管理ToolStripMenuItem.Visible = false;
添加货物ToolStripMenuItem.Visible = false;
}
toolStripStatusLabel2.Text = s_LoginName;
}
Win form碎知识点的更多相关文章
- Win Form程序线程点点
消息循环 Win32窗体程序基于消息驱动的,程序的模型就是一个用户触发事件消息->系统分发事件消息->程序处理事件的循环过程. .NET Win Form程序对消息循环进行了封装,可以看到 ...
- WPF / Win Form:多线程去修改或访问UI线程数据的方法( winform 跨线程访问UI控件 )
WPF:谈谈各种多线程去修改或访问UI线程数据的方法http://www.cnblogs.com/mgen/archive/2012/03/10/2389509.html 子线程非法访问UI线程的数据 ...
- WPF调用Win Form
WPF是win form的下一代版本,现在越来越多的公司使用WPF.如何兼容已有的使用win form开发的应用程序呢?下面有三种方式来在WPF中调用win form. 使用WPF中的WindowsF ...
- vue散碎知识点学习
1. vue散碎知识点学习 1.1. 特点 数据渲染/数据同步 组件化/模块化 其他功能路由,ajax,数据流 1.2. Vue.js学习资源 vuejs中文官网:http://cn.vuejs.or ...
- js的form基础知识点
在HTML 中,表单是由<form>元素来表示的,而在JavaScript 中,表单对应的则是HTMLForm-Element 类型.HTMLFormElement 继承了HTMLElem ...
- JS一些碎知识点
一些js基本知识点 Doctype 浏览器渲染模式 渲染模式发展历史 在多年以前(IE6诞生以前),各浏览器都处于各自比较封闭的发展中(基本没有兼容性可谈).随着WEB的发展,兼容性问题的解决越来越显 ...
- c# win form 显示支付宝二维码图片
System.Net.WebClient web = new System.Net.WebClient(); byte[] buffer = web.DownloadData(网络图片的地址); we ...
- Win Form不能响应键盘事件
在窗体属性中,将KeyPreview设置为true
- .NET(C#) win Form窗体的常用属性以及事件
使用.Net编写Windows程序,对于窗体控制常见项目 属性:1.让窗体在启动时在指定位置出现 form1.StartPosition Manual CenterScreen WindowsDefa ...
随机推荐
- ElementUi rules表单验证
ElementUi 表单验证 工作中常用到的JS验证 可以在pattern中书写正则,并且配合elementUI进行表单验证. pattern 属性规定用于验证输入字段的模式.模式指的是正则表达式. ...
- HTTP——学习笔记(8)
HTTP中的一些协议内容会限制某些网站的功能使用 比如,Facebook这类的社交网站,需要实时地观察到海量用户公开发布的内容,而HTTP中的以下标准就会成为瓶颈: 一条连接上只可发送一个请求 请求只 ...
- 【hackerrank week of code 26】Hard Homework
[题目链接]:https://www.hackerrank.com/contests/w26/challenges/hard-homework/problem [题意] 给你一个式子:sin(x)+s ...
- ASP.NET-本地化、全球化
在<system.web>中加入一个全球化的标识,网站就可以自适应全球化了 也可以将出错信息全球化 上面的这种方式测试过对google浏览器好像没用,但是对IE内核的是可行的,可能goog ...
- [Javascript] String Padding in Javascript using padStart and padEnd functions
ES2017 added two new string functions. They are padStart and padEndfunctions. In this lesson, we wil ...
- moble 设备多指手势识别 (tap , double_tap , pinch)
function(){ elem.addEventListener('touchstart', start , false) elem.addEventListener('touchend', end ...
- BsonDocument
http://api.mongodb.com/csharp/current/html/T_MongoDB_Bson_BsonDocument.htm 如何取出document中的数据 BsonDocu ...
- tp5使用oss存储图片
1.申请Access Key ID和Access Key Secret,以及创建好你的Bucket 2.通过composer安装oss插件 通过cmd,到项目的目录下,输入下面的指令. compose ...
- svn服务器的搭建过程 主要为服务端
yum -y install subversion 查看版本信息 svnserve --version 创建svn仓库目录 mkdir -p /var/svn/svnrepos 创建svn仓库 svn ...
- Spring SpEL in JSP and Assign SpEL value to Java variable in JSP
Spring SpEL in JSP and Assign SpEL value to Java variable in JSP method 1 use----ServletContextAttri ...