//页面文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" ForeColor="#333333"
GridLines="None" Height="326px" Width="1052px"
onrowediting="GridView1_RowEditing" AllowPaging="True"
AutoGenerateColumns="False" onpageindexchanging="GridView1_PageIndexChanging"
onrowupdating="GridView1_RowUpdating"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdeleting="GridView1_RowDeleting"
style="margin-bottom: 0px; margin-right: 3px;"
onrowcreated="GridView1_RowCreated" PageSize="5" EnableViewState="False">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:BoundField DataField="id" HeaderText="编号" Visible="False" />
<asp:BoundField DataField="Project" HeaderText="项目名" />
<asp:BoundField DataField="Client" HeaderText="客户" />
<asp:BoundField DataField="StartTime" HeaderText="开始时间" />
<asp:BoundField DataField="FinishTime" HeaderText="结束时间" />
<asp:BoundField DataField="Quantity" HeaderText="数量" />
<asp:BoundField DataField="Cost" HeaderText="成本" />
<asp:BoundField DataField="ManuID" HeaderText="主表编号" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" ForeColor="#333333" Font-Bold="True" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<br />
<asp:Button ID="btntrans" runat="server" οnclick="btntrans_Click" Text="添加记录" />
</div>
</form>
</body>
</html>
//主页后台c#代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.EnterpriseServices;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
FroDefaultPage pagecs = new FroDefaultPage();
string conn;
string strsqlupdata;
SqlConnection MyConnection;
SqlCommand MyCommand;
//构造器
public _Default()
{
conn= "server=.;database=SIDB;uid=sa;pwd=01120817lhh";
strsqlupdata = "UPDATE PROJECT SET PROJECT=@PEONAM,Client=@CLIE,StartTime=@STRA,FinishTime=@END,Quantity=@QUAN,Cost=@COT WHERE ID=@ID"; ;
MyConnection = new SqlConnection(conn);
MyCommand = new SqlCommand(strsqlupdata,MyConnection);
}
//数据绑定
protected void Page_Load(object sender, EventArgs e)
{
showDb();
}
//页面跳转
protected void btntrans_Click(object sender, EventArgs e)
{
Server.Transfer("AddPage.aspx", true);
}
#region-------------------控件事件集合--------------
//行编辑事件
public void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
showDb();
}
//分页事件
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
showDb();
}
//页面绑定方法
public void showDb()
{
GridView1.DataKeyNames = new string[] { "id" };
GridView1.DataSource =pagecs.BackdsforGv();
GridView1.DataBind();
}
//-数据更新事件
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
MyConnection.Open();
MyCommand.Parameters.Add("@ID", SqlDbType.Int);
MyCommand.Parameters["@ID"].Value = GridView1.DataKeys[e.RowIndex].Value.ToString();
MyCommand.Parameters.Add("@PEONAM", SqlDbType.NVarChar, 50);
MyCommand.Parameters["@PEONAM"].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
MyCommand.Parameters.Add("@CLIE", SqlDbType.NVarChar, 200);
MyCommand.Parameters["@CLIE"].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
MyCommand.Parameters.Add("@STRA", SqlDbType.DateTime);
MyCommand.Parameters["@STRA"].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
MyCommand.Parameters.Add("@END", SqlDbType.DateTime);
MyCommand.Parameters["@END"].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
MyCommand.Parameters.Add("@QUAN", SqlDbType.NVarChar, 50);
MyCommand.Parameters["@QUAN"].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[5].Controls[0]).Text;
MyCommand.Parameters.Add("@COT", SqlDbType.NVarChar, 50);
MyCommand.Parameters["@COT"].Value = ((TextBox)GridView1.Rows[e.RowIndex].Cells[6].Controls[0]).Text;
try { MyCommand.ExecuteNonQuery(); showDb(); }
catch { MyConnection.Close(); }
finally { GridView1.EditIndex = -1; showDb(); }
}
//取消删除事件
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
showDb();
}
//------删除事件
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
MyConnection.Open();
MyCommand.CommandText = "DELETE from Project where id=@ID";
MyCommand.Parameters.Add("@ID", SqlDbType.Int);
MyCommand.Parameters["@ID"].Value = id;
try { MyCommand.ExecuteNonQuery(); }
catch (Exception ex) { Response.Write(ex.Message); }
finally { MyConnection.Close();showDb();}
}
//--判断删除事件
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//DataControlRowType.DataRow属性判断是GridView数据行,而不是页眉和页脚
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Cells[0].Controls.Count > 0 判断单元格0内是否有控件,如果没有则不进行任何转换,注意点击编辑按钮时,删除按钮不可见
if (e.Row.Cells[9].Controls.Count > 0)
{
LinkButton lbDelete = (LinkButton)e.Row.Cells[9].Controls[0];
if (lbDelete.Text == "删除")
{
lbDelete.Attributes.Add("onclick", "javascript:return confirm('删除确定')");
}
}
}
}
#endregion
}
//添加页面代码文件
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AddPage.aspx.cs" Inherits="AddPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" onrowdatabound="GridView1_RowDataBound"
>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListgc" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
厂商全称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
项目名称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
客户
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
开始时间
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Height="16px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
结束时间
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
数量
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
成本
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" BorderWidth="5px" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:Button ID="Button5" runat="server" οnclick="Button5_Click" Text="添加" />
<asp:Label ID="labMes" runat="server" ForeColor="#669999"></asp:Label>
<br />
<br />
</div>
<div>
<asp:GridView ID="GridViewproducts" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
onrowdatabound="GridViewproducts_RowDataBound"
>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListproducts1" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
厂商全称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListproducts2" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
项目名称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxproducts1" runat="server" Width="215px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
品牌
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxproducts2" runat="server" Width="218px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
型号
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxproducts3" runat="server" Height="16px" Width="202px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
样式
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxproducts4" runat="server"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
合格证
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" BorderWidth="5px" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:Button ID="btnpip" runat="server" Text="添加" οnclick="btnpip_Click" />
<asp:Label ID="Labelawad" runat="server" Font-Bold="True" Font-Names="Aharoni"
ForeColor="#669999"></asp:Label>
<br />
<br />
</div>
<div>
</div>
<div>
<br />
<br />
<asp:GridView ID="GridViewlink" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" onrowdatabound="GridViewlink_RowDataBound"
>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListlink1" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
厂商全称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListlink2" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
项目名称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxlink1" runat="server" Width="452px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
链接网址
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxlink2" runat="server" Width="360px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
标题
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" BorderWidth="5px" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:Button ID="btnlink" runat="server" οnclick="btnlink_Click" Text="添加" />
<asp:Label ID="lbllink" runat="server"></asp:Label>
<br />
<br />
</div>
<div>
<asp:GridView ID="GridViewAwad" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
onrowdatabound="GridViewAwad_RowDataBound" style="margin-right: 1px"
>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
厂商全称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
项目名称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Width="826px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
获奖
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" BorderWidth="5px" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:Button ID="btnforAwad" runat="server" οnclick="btnforAwad_Click"
Text="添加" />
<asp:Label ID="lblforAwad" runat="server"></asp:Label>
<br />
</div>
<p>
</p>
<div>
<asp:GridView ID="GridViewSubSystem" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None" onrowdatabound="GridViewSubSystem_RowDataBound"
>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListSubSystem1" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
厂商全称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID="DropDownListSubSystem2" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderTemplate>
项目名称
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBoxSubSystem1" runat="server" Height="22px" Width="825px"></asp:TextBox>
</ItemTemplate>
<HeaderTemplate>
系统
</HeaderTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#E2DED6" BorderStyle="None" Font-Bold="True"
ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" BorderWidth="5px" Font-Bold="True"
ForeColor="White" />
<EditRowStyle BackColor="#999999" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:Button ID="Button4" runat="server" Text="添加"
Height="23px" Width="45px" οnclick="Button4_Click" />
<asp:Label ID="Label4" runat="server" Font-Bold="True" Font-Names="Aharoni"
ForeColor="#669999"></asp:Label>
</div>
</form>
</body>
</html>
//后台处理文件
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class AddPage : System.Web.UI.Page
{
//引用类文件
FroAddPage AdPgcs = new FroAddPage();
//创建数据集
DataSet forgvds;
DataSet fordlds;
DataSet fordlprods;
//创建字符串
string strsql;
string strconn;
string strsqllink;
string strsqlproduct;
string strsqlawad;
string strsqlsystem;
//创建ado组建
SqlConnection sqconn;
SqlCommand sqlcomm;
SqlCommand sqlcommlink;
SqlCommand sqlcommproduct;
SqlCommand sqlcommawad;
SqlCommand sqlcommsystem;
//构造函数
public AddPage()
{
forgvds = AdPgcs.BackDsForGv();
fordlds = AdPgcs.BackForDrolistDs();
fordlprods = AdPgcs.BackDsFordroplistPro();
strsql = "insert into Project (ManuID,Project,Client,StartTime,FinishTime,Quantity,Cost) values (@ManId,@Proj,@Client,@StaTime,@FiniTime,@qunT,@Cos)";
strconn = "server=.;database=SIDB;uid=sa;pwd=01120817lhh";
strsqllink = "insert into Project_Link(ManuID,ProjectID,Links,Title) values (@MaId,@ProJ,@Lik,@Title)";
strsqlproduct = "insert into Project_Product (ManuID,ProjectID,Brand,Type,Model,Qualification) values(@manid,@projid,@brand,@pype,@model,@qualifi)";
strsqlawad = "insert into Project_Award (ManuID,ProjectID,Award)values(@amaid,@aproid,@awad)";
strsqlsystem = "insert into Project_SubSystem (ManuID,ProjectID,System) values (@smaid,@sproj,@system)";
sqconn = new SqlConnection(strconn);
sqlcommlink = new SqlCommand(strsqllink,sqconn);
sqlcomm = new SqlCommand(strsql,sqconn);
sqlcommproduct = new SqlCommand(strsqlproduct,sqconn);
sqlcommawad = new SqlCommand(strsqlawad,sqconn);
sqlcommsystem = new SqlCommand(strsqlsystem,sqconn);
}
//页面加载
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridBind();
gridAwadbind();
gridlinkbind();
gridprodbind();
gridsystembind();
}
}
#region-------------------表绑定-----------------------
// 绑定项目添加表方法
public void gridBind()
{
GridView1.DataSource = forgvds.Tables[0];
GridView1.DataBind();
}
// 绑定获奖添加表的方法
public void gridAwadbind()
{
GridViewAwad.DataSource = forgvds.Tables[0];
GridViewAwad.DataBind();
}
//绑定产品表的方法
public void gridprodbind()
{
GridViewproducts.DataSource=forgvds.Tables[0];
GridViewproducts.DataBind();
}
// 绑定网站添加表方法
public void gridlinkbind()
{
GridViewlink.DataSource = forgvds.Tables[0];
GridViewlink.DataBind();
}
//绑定系统添加表方法
public void gridsystembind()
{
GridViewSubSystem.DataSource=forgvds.Tables[0];
GridViewSubSystem.DataBind();
}
#endregion
#region-------------下拉列表数据绑定事件---------------
// 项目表公司下拉菜单数据绑定事件
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList goodsType = (DropDownList)e.Row.FindControl("DropDownListgc");
if (goodsType != null)
{
goodsType.DataSource = fordlds.Tables[0].DefaultView;
goodsType.DataTextField = "NameCN";
goodsType.DataValueField = "ID";
goodsType.DataBind();
}
}
}
//项目添加表的下拉列表数据绑定事件
protected void GridViewAwad_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropWaType = (DropDownList)e.Row.FindControl("DropDownList1");
if (dropWaType != null)
{
dropWaType.DataSource = fordlds.Tables[0].DefaultView;
dropWaType.DataTextField = "NameCN";
dropWaType.DataValueField = "ID";
dropWaType.DataBind();
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropProtype = (DropDownList)e.Row.FindControl("DropDownList2");
if (dropProtype != null)
{
dropProtype.DataSource = fordlprods.Tables[0].DefaultView;
dropProtype.DataTextField = "Project";
dropProtype.DataValueField = "ID";
dropProtype.DataBind();
}
}
}
//链接表下拉菜单数据绑定事件
protected void GridViewlink_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropproType=(DropDownList)e.Row.FindControl("DropDownListlink1");
if(dropproType!=null)
{
dropproType.DataSource = fordlds.Tables[0].DefaultView;
dropproType.DataTextField = "NameCN";
dropproType.DataValueField = "ID";
dropproType.DataBind();
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropProtype = (DropDownList)e.Row.FindControl("DropDownListlink2");
if (dropProtype != null)
{
dropProtype.DataSource = fordlprods.Tables[0].DefaultView;
dropProtype.DataTextField = "Project";
dropProtype.DataValueField = "ID";
dropProtype.DataBind();
}
}
}
//产品添加表下拉菜单绑定事件
protected void GridViewproducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropproType = (DropDownList)e.Row.FindControl("DropDownListproducts1");
if (dropproType != null)
{
dropproType.DataSource = fordlds.Tables[0].DefaultView;
dropproType.DataTextField = "NameCN";
dropproType.DataValueField = "ID";
dropproType.DataBind();
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropProtype = (DropDownList)e.Row.FindControl("DropDownListproducts2");
if (dropProtype != null)
{
dropProtype.DataSource = fordlprods.Tables[0].DefaultView;
dropProtype.DataTextField = "Project";
dropProtype.DataValueField = "ID";
dropProtype.DataBind();
}
}
}
//系统添加列表下拉菜单绑定事件
protected void GridViewSubSystem_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropproType = (DropDownList)e.Row.FindControl("DropDownListSubSystem1");
if (dropproType != null)
{
dropproType.DataSource = fordlds.Tables[0].DefaultView;
dropproType.DataTextField = "NameCN";
dropproType.DataValueField = "ID";
dropproType.DataBind();
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList dropProtype = (DropDownList)e.Row.FindControl("DropDownListSubSystem2");
if (dropProtype != null)
{
dropProtype.DataSource = fordlprods.Tables[0].DefaultView;
dropProtype.DataTextField = "Project";
dropProtype.DataValueField = "ID";
dropProtype.DataBind();
}
}
}
#endregion
#region------------------添加按钮事件-------------------
// gridview1添加数据事件
protected void Button5_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
sqconn.Open();
sqlcomm.Parameters.Add("@ManId", SqlDbType.Int);
sqlcomm.Parameters["@ManId"].Value = int.Parse(((DropDownList)row.FindControl("DropDownListgc")).SelectedIndex.ToString());
sqlcomm.Parameters.Add("@Proj", SqlDbType.NVarChar, 50);
sqlcomm.Parameters["@Proj"].Value = ((TextBox)row.FindControl("TextBox1")).Text;
sqlcomm.Parameters.Add("@Client", SqlDbType.NVarChar, 200);
sqlcomm.Parameters["@Client"].Value = ((TextBox)row.FindControl("TextBox2")).Text;
sqlcomm.Parameters.Add("@StaTime", SqlDbType.DateTime);
sqlcomm.Parameters["@StaTime"].Value = ((TextBox)row.FindControl("TextBox3")).Text;
sqlcomm.Parameters.Add("@FiniTime", SqlDbType.DateTime);
sqlcomm.Parameters["@FiniTime"].Value = ((TextBox)row.FindControl("TextBox4")).Text;
sqlcomm.Parameters.Add("@qunT", SqlDbType.NVarChar, 50);
sqlcomm.Parameters["@qunT"].Value = ((TextBox)row.FindControl("TextBox5")).Text;
sqlcomm.Parameters.Add("@Cos", SqlDbType.NVarChar, 50);
sqlcomm.Parameters["@Cos"].Value = ((TextBox)row.FindControl("TextBox6")).Text;
try
{
sqlcomm.ExecuteNonQuery();
gridAwadbind();
labMes.Text = "插入成功!";
}
catch (Exception ex)
{
Response.Write(ex.Message + "时间格式标准例如:2002-5-5");
}
finally
{
sqconn.Close();
}
}
}
//产品添加按钮事件
protected void btnpip_Click(object sender, EventArgs e)
{
foreach (GridViewRow prow in GridViewproducts.Rows)
{
sqconn.Open();
sqlcommproduct.Parameters.Add("@manid",SqlDbType.Int);
sqlcommproduct.Parameters["@manid"].Value = int.Parse(((DropDownList)prow.FindControl("DropDownListproducts1")).SelectedIndex.ToString());
sqlcommproduct.Parameters.Add("@projid", SqlDbType.Int);
sqlcommproduct.Parameters["@projid"].Value = int.Parse(((DropDownList)prow.FindControl("DropDownListproducts2")).SelectedIndex.ToString());
sqlcommproduct.Parameters.Add("@brand",SqlDbType.NVarChar,50);
sqlcommproduct.Parameters["@brand"].Value = ((TextBox)prow.FindControl("TextBoxproducts1")).Text;
sqlcommproduct.Parameters.Add("@pype", SqlDbType.NVarChar, 50);
sqlcommproduct.Parameters["@pype"].Value = ((TextBox)prow.FindControl("TextBoxproducts2")).Text;
sqlcommproduct.Parameters.Add("@model", SqlDbType.NVarChar, 50);
sqlcommproduct.Parameters["@model"].Value = ((TextBox)prow.FindControl("TextBoxproducts3")).Text;
sqlcommproduct.Parameters.Add("@qualifi", SqlDbType.NVarChar, 50);
sqlcommproduct.Parameters["@qualifi"].Value = ((TextBox)prow.FindControl("TextBoxproducts4")).Text;
try
{
sqlcommproduct.ExecuteNonQuery();
Labelawad.Text = "添加成功!";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sqconn.Close();
}
}
}
//连接表按钮添加事件
protected void btnlink_Click(object sender, EventArgs e)
{
foreach (GridViewRow lrow in GridViewlink.Rows)
{
sqconn.Open();
sqlcommlink.Parameters.Add("@MaId", SqlDbType.Int);
sqlcommlink.Parameters["@MaId"].Value = Convert.ToInt32(((DropDownList)lrow.FindControl("DropDownListlink1")).SelectedIndex.ToString());
sqlcommlink.Parameters.Add("@ProJ", SqlDbType.Int);
sqlcommlink.Parameters["@ProJ"].Value = int.Parse(((DropDownList)lrow.FindControl("DropDownListlink2")).SelectedIndex.ToString());
sqlcommlink.Parameters.Add("@Lik", SqlDbType.NVarChar, 500);
sqlcommlink.Parameters["@Lik"].Value = ((TextBox)lrow.FindControl("TextBoxlink1")).Text;
sqlcommlink.Parameters.Add("@Title", SqlDbType.NVarChar, 100);
sqlcommlink.Parameters["@Title"].Value = ((TextBox)lrow.FindControl("TextBoxlink2")).Text;
try
{
sqlcommlink.ExecuteNonQuery();
lbllink.Text = "插入成功!";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
sqconn.Close();
}
}
}
//获奖表按钮添加事件
protected void btnforAwad_Click(object sender, EventArgs e)
{
foreach (GridViewRow Arow in GridViewAwad.Rows)
{
sqconn.Open();
sqlcommawad.Parameters.Add("@amaid", SqlDbType.Int);
sqlcommawad.Parameters["@amaid"].Value = Convert.ToInt32(((DropDownList)Arow.FindControl("DropDownList1")).SelectedIndex.ToString());
sqlcommawad.Parameters.Add("@aproid",SqlDbType.Int);
sqlcommawad.Parameters["@aproid"].Value = Convert.ToInt32(((DropDownList)Arow.FindControl("DropDownList1")).SelectedIndex.ToString());
sqlcommawad.Parameters.Add("@awad",SqlDbType.NVarChar,200);
sqlcommawad.Parameters["@awad"].Value = ((TextBox)Arow.FindControl("TextBox7")).Text.ToString().Trim();
try
{
sqlcommawad.ExecuteNonQuery();
lblforAwad.Text = "添加成功!";
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally { sqconn.Close(); }
}
}
//系统表按钮添加事件
protected void Button4_Click(object sender, EventArgs e)
{
foreach (GridViewRow srow in GridViewSubSystem.Rows)
{
sqconn.Open();
sqlcommsystem.Parameters.Add("@smaid", SqlDbType.Int);
sqlcommsystem.Parameters["@smaid"].Value = Convert.ToInt32(((DropDownList)srow.FindControl("DropDownListSubSystem1")).SelectedIndex.ToString());
sqlcommsystem.Parameters.Add("@sproj", SqlDbType.Int);
sqlcommsystem.Parameters["@sproj"].Value = Convert.ToInt32(((DropDownList)srow.FindControl("DropDownListSubSystem2")).SelectedIndex.ToString());
sqlcommsystem.Parameters.Add("@system", SqlDbType.NVarChar, 50);
sqlcommsystem.Parameters["@system"].Value = ((TextBox)srow.FindControl("TextBoxSubSystem1")).Text.Trim().ToString();
try { sqlcommsystem.ExecuteNonQuery(); Label4.Text = "添加成功!"; }
catch (Exception ex) { Response.Write(ex.Message); }
finally { sqconn.Close(); }
}
}
#endregion
}
//添加页面类文件
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///FroAddPage 的摘要说明
/// </summary>
public class FroAddPage
{
string strconn;
string strSqlGv;
SqlConnection con;
string strSqlDrolisM;
string strsqlpro;
public FroAddPage()
{
strconn = "server=.;database=SIDB;uid=sa;pwd=--";
strSqlGv = "SELECT ID,NameCN FROM Manu where id<2 ";
con = new SqlConnection(strconn);
strSqlDrolisM = "SELECT ID,NameCN FROM Manu ";
strsqlpro = "SELECT ID,Project FROM Project";
}
/// <summary>
/// 返回一个Dataset供gridview绑定
/// </summary>
/// <returns>dataset</returns>
public DataSet BackDsForGv()
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSqlGv, con);
da.Fill(ds);
return ds;
}
/// <summary>
/// 返回一个dataset供厂商下拉列表绑定
/// </summary>
/// <returns>dataset</returns>
public DataSet BackForDrolistDs()
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSqlDrolisM, con);
da.Fill(ds);
return ds;
}
public DataSet BackDsFordroplistPro()
{
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strsqlpro,con);
da.Fill(ds);
return ds;
}
}
//主页类文件
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
/// <summary>
///FroDefaultPage 的摘要说明
/// </summary>
public class FroDefaultPage
{
DataSet gridv1ds;
string strsql;
string strconn;
SqlDataAdapter gridvda;
public FroDefaultPage()
{
gridv1ds = new DataSet();
strsql = "SELECT * FROM Project";
strconn = "server=.;database=SIDB;uid=sa;pwd=---";
gridvda = new SqlDataAdapter(strsql,strconn);
}
//返回一个dataset给页面调用
public DataSet BackdsforGv()
{
gridvda.Fill(gridv1ds);
return gridv1ds;
}
}