using System;
using System.Configuration;
using System.Data;
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.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string strconn = "server=.;database=SIDB;uid=sa;pwd=01120817lhh";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
gridBind();
}
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
public DataSet BackDs()
{
SqlConnection con;
string strconn = "server=.;database=SIDB;uid=sa;pwd=01120817lhh";
string strSql = "SELECT ID,NameCN FROM Manu where id<2 ";
con = new SqlConnection(strconn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSql, con);
da.Fill(ds);
return ds;
}
public DataSet BackDlDs()
{
SqlConnection con;
string strconn = "server=.;database=SIDB;uid=sa;pwd=----";
string strSql = "SELECT ID,NameCN FROM Manu ";
con = new SqlConnection(strconn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSql, con);
da.Fill(ds);
return ds;
}
public void gridBind()
{
DataSet FirDs = BackDs();
GridView1.DataSource = FirDs.Tables[0];
GridView1.DataBind();
}
protected void PageDropDownList_DataBound(object sender, EventArgs e)
{
}
protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
DataSet Myds = BackDlDs();
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList goodsType = (DropDownList)e.Row.FindControl("DropDownList1");
if (goodsType != null)
{
goodsType.DataSource = Myds.Tables[0].DefaultView;
goodsType.DataTextField = "NameCN";
goodsType.DataValueField = "ID";
goodsType.DataBind();
}
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
int droplisttext = int.Parse(((DropDownList)row.FindControl("DropDownList1")).SelectedItem.Value);
string textValues1=((TextBox)row.FindControl("TextBox1")).Text;
string textValues2 = ((TextBox)row.FindControl("TextBox2")).Text;
string textValues3 = ((TextBox)row.FindControl("TextBox3")).Text;
string textValues4 = ((TextBox)row.FindControl("TextBox4")).Text;
string textValues5 = ((TextBox)row.FindControl("TextBox5")).Text;
string textValues6 = ((TextBox)row.FindControl("TextBox6")).Text;
string strsql = "insert into Project (ManuID,Project,Client,StartTime,FinishTime,Quantity,Cost) values (@ManId,@Proj,@Client,@StaTime,@FiniTime,@qunT,@Cos)";
SqlConnection sqconn = new SqlConnection(strconn);
sqconn.Open();
SqlCommand sqlcomm = new SqlCommand(strsql,sqconn);
sqlcomm.Parameters.Add("@ManId",SqlDbType.Int);
sqlcomm.Parameters["@ManId"].Value = droplisttext;
sqlcomm.Parameters.Add("@Proj", SqlDbType.NVarChar, 50);
sqlcomm.Parameters["@Proj"].Value = textValues1;
sqlcomm.Parameters.Add("@Client", SqlDbType.NVarChar,200);
sqlcomm.Parameters["@Client"].Value = textValues2;
sqlcomm.Parameters.Add("@StaTime", SqlDbType.DateTime);
sqlcomm.Parameters["@StaTime"].Value = textValues3;
sqlcomm.Parameters.Add("@FiniTime", SqlDbType.DateTime);
sqlcomm.Parameters["@FiniTime"].Value = textValues4;
sqlcomm.Parameters.Add("@qunT", SqlDbType.NVarChar, 50);
sqlcomm.Parameters["@qunT"].Value = textValues5;
sqlcomm.Parameters.Add("@Cos", SqlDbType.NVarChar, 50);
sqlcomm.Parameters["@Cos"].Value = textValues6;
sqlcomm.ExecuteNonQuery();
sqconn.Close();
}
}
}