protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "editt") { int xy = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView1.Rows[xy]; search.Visible = false; add.Visible = true; Button3.Text = "确定修改"; TextBox2.Text = row.Cells[2].Text; TextBox6.Text = row.Cells[3].Text; TextBox3.Text = row.Cells[4].Text; TextBox4.Text = row.Cells[5].Text; TextBox5.Text = row.Cells[6].Text; num = row.Cells[1].Text; providerName = row.Cells[2].Text; } if (e.CommandName == "deletee") { int x = Convert.ToInt32(e.CommandArgument); string dataid = GridView1.Rows[x].Cells[2].Text; bool success = new DAL.ReceiverDAO().deleteReceiverByName(dataid); if (success) { new Warehouse.Tools.AddSysLog().addlog("1", "收货商管理", "删除"); ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('删除成功!');", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('删除失败!');", true); } refresh(); } }
public void refresh() //刷新函数,查找并显示全部的供应商的信息 { if (name == null || name == "") //判断name里面存的有没有值,有的话说明刚才查询过,现在gridview显示的查询名字后的,刷新的时候就不能查询全部 { GridView1.DataSource = pros; GridView1.DataBind(); countPageIndex = pros.Count / 11 + 1; Label8.Text = "总记录数:" + pros.Count; Label9.Text = "总页数:" + countPageIndex; Label10.Text = "当前页:" + PageIndex; } else { List <Receiver> recss = new List <Receiver>(); //若获取的单个对象,需要添加到集合中,因为gridview的数据源不支持单个对象 Receiver pro = new DAL.ReceiverDAO().getReceiverByName(name); if (pro == null) { } else { recss.Add(pro); } GridView1.DataSource = recss; GridView1.DataBind(); countPageIndex = 1; PageIndex = 1; Label8.Text = "总记录数:" + recss.Count; Label9.Text = "总页数:1"; Label10.Text = "当前页:" + PageIndex; } if (GridView1.Rows.Count == 0) { DataTable dt = new DataTable(); dt.Columns.Add("ReceiverNum"); dt.Columns.Add("ReceiverName"); dt.Columns.Add("Leader"); dt.Columns.Add("Contact"); dt.Columns.Add("ContactNumber"); dt.Columns.Add("ReceiverAddress"); dt.Columns.Add("CreateTime"); dt.Columns.Add("UpdateTime"); dt.Rows.Add(dt.NewRow()); this.GridView1.DataSource = dt; this.GridView1.DataBind(); GridView1.Rows[0].Cells.Clear(); GridView1.Rows[0].Cells.Add(new TableCell()); GridView1.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count + 3; GridView1.Rows[0].Cells[0].Text = "您查询的信息为空"; GridView1.Rows[0].Cells[0].Style.Add("text-align", "center"); Label8.Text = "总记录数:0"; Label9.Text = "总页数:0"; Label10.Text = ""; } }
protected void Button3_Click(object sender, EventArgs e) { if (TextBox2.Text.Trim() == "" || TextBox3.Text.Trim() == "" || TextBox4.Text.Trim() == "" || TextBox5.Text.Trim() == "" || TextBox6.Text.Trim() == "") { Response.Write("<script>alert('信息都不能为空!')</script>"); } else { if (num != null) //判断num是否为空,不为空则说明是要修改信息,而不是添加 { Receiver r = new Receiver(); r.ReceiverName = num; r.ReceiverName = TextBox2.Text.Trim(); if (providerName != TextBox2.Text.Trim()) //判断名字修改了没有(即和修改前记录的是否一样),如果名字改了需要判断是否重复 { bool exit = new DAL.ReceiverDAO().hasReceiverOfName(r.ReceiverName); if (exit) //如果重复就提示 { Response.Write("<script>alert('收货商名字重复,请重新输入!')</script>"); } else { r.StaffName = TextBox6.Text.Trim(); r.Contact = TextBox3.Text.Trim(); r.ContactNumber = TextBox4.Text.Trim(); r.ReceiverAddress = TextBox5.Text.Trim(); r.UpdateTime = DateTime.Now; bool success = new DAL.ReceiverDAO().updateReceiver(r); if (success) { new Warehouse.Tools.AddSysLog().addlog("1", "收货商管理", "修改"); ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('修改成功!');", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('修改失败!');", true); } num = null; } } else { r.StaffName = TextBox6.Text.Trim(); r.Contact = TextBox3.Text.Trim(); r.ContactNumber = TextBox4.Text.Trim(); r.ReceiverAddress = TextBox5.Text.Trim(); r.UpdateTime = DateTime.Now; bool success = new DAL.ReceiverDAO().updateReceiver(r); if (success) { new Warehouse.Tools.AddSysLog().addlog("1", "收货商管理", "修改"); ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('修改成功!');", true); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('修改失败!');", true); } num = null; } } else { Receiver r = new Receiver(); r.ReceiverName = TextBox2.Text.Trim(); bool exit = new DAL.ReceiverDAO().hasReceiverOfName(r.ReceiverName); if (exit) { Response.Write("<script>alert('收货商名字重复,请重新输入!')</script>"); } else { DateTime dt = DateTime.Now; r.ReceiverNum = new Warehouse.Tools.receiverNum().protect_receiverNum(dt); r.Contact = TextBox3.Text.Trim(); r.ContactNumber = TextBox4.Text.Trim(); r.ReceiverAddress = TextBox5.Text.Trim(); r.UpdateTime = dt; r.StaffName = TextBox6.Text.Trim(); r.CreateTime = dt; bool success = new DAL.ReceiverDAO().addReceiver(r); //调用DAL层的添加方法 if (success) { new Warehouse.Tools.AddSysLog().addlog("1", "收货商管理", "添加"); ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('添加成功!');", true); TextBox2.Text = ""; TextBox6.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; search.Visible = true; add.Visible = false; refresh(); } else { ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", "alert('添加失败!');", true); } } } } }