判断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属性,值指向contextMenuStrip1private 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; }