protected void btnOk_Click(object sender, EventArgs e) { if (inputCheck()) { //string projectTagId = ddlProjectTag.SelectedValue; //string custmor = txtCustmor.Text.ToString().Trim(); //string mainContractTag = txtMainContractTag.Text.ToString().Trim(); //string cash = txtMoney.Text.ToString().Trim(); //string dateLine = btnDate.Text.ToString(); //string payment = txtPayment.Text.ToString().Trim(); //DataTable dt = Session["mainProductSelDs"] as DataTable; //foreach (GridViewRow gvr in mainProductGV.Rows) //{ // int index = gvr.DataItemIndex; // TextBox txb = gvr.FindControl("txtProductNum") as TextBox; // if (txb != null) // { // dt.DefaultView[index]["productNum"] = txb.Text; // } //} //DataTable contractProductTable = dt.DefaultView.ToTable("tbl_mainContrctProduct"); //DataColumn colMainContractId = new DataColumn("mainContractId", System.Type.GetType("System.Int32")); //contractProductTable.Columns.Add(colMainContractId); //#region dataset //DataSet dataSet = new DataSet(); //DataRow mainContractRow = null; //DataColumn colProjectTagId = new DataColumn("projectTagId", System.Type.GetType("System.String")); //DataColumn colContractCompName = new DataColumn("contractCompName", System.Type.GetType("System.String")); //DataColumn colMainContractTag = new DataColumn("mainContractTag", System.Type.GetType("System.String")); //DataColumn colCash = new DataColumn("cash", System.Type.GetType("System.String")); //DataColumn colDateLine = new DataColumn("dateLine", System.Type.GetType("System.String")); //DataColumn colPaymentMode = new DataColumn("paymentMode", System.Type.GetType("System.String")); //DataTable mainContractTable = new DataTable("tbl_mainContract"); //mainContractTable.Columns.Add(colProjectTagId); //mainContractTable.Columns.Add(colContractCompName); //mainContractTable.Columns.Add(colMainContractTag); //mainContractTable.Columns.Add(colCash); //mainContractTable.Columns.Add(colDateLine); //mainContractTable.Columns.Add(colPaymentMode); //mainContractRow = mainContractTable.NewRow(); //mainContractRow["projectTagId"] = projectTagId; //mainContractRow["contractCompName"] = custmor; //mainContractRow["mainContractTag"] = mainContractTag; //mainContractRow["cash"] = cash; //mainContractRow["dateLine"] = dateLine; //mainContractRow["paymentMode"] = payment; //mainContractTable.Rows.Add(mainContractRow); //dataSet.Tables.Add(mainContractTable); //dataSet.Tables.Add(contractProductTable); //#endregion DataTable mainContractTable = getInput(); string projectOutAddress = txtProjAddr.Text.ToString(); DataTable dt = Session["mainProductSelDs"] as DataTable; foreach (GridViewRow gvr in mainProductGV.Rows) { int index = gvr.DataItemIndex; TextBox txb = gvr.FindControl("txtProductNum") as TextBox; if (txb != null) { dt.DefaultView[index]["productNum"] = txb.Text; } } DataTable contractProductTable = dt.DefaultView.ToTable("tbl_mainContrctProduct"); DataColumn colMainContractId = new DataColumn("mainContractId", System.Type.GetType("System.Int32")); contractProductTable.Columns.Add(colMainContractId); #region dataset DataSet dataSet = new DataSet(); dataSet.Tables.Add(mainContractTable); dataSet.Tables.Add(contractProductTable); #endregion MainContractProcess mcp = new MainContractProcess(dataSet); mcp.Add(); string strMainContractId = mcp.StrRtn; foreach (DataRow dr in contractProductTable.Rows) { dr["mainContractId"] = strMainContractId; } MainContractProductProcess mcpp = new MainContractProductProcess(dataSet); mcpp.Add(); Xm_db xmDataCont = Xm_db.GetInstance(); int mainContractId = int.Parse(strMainContractId); var mainContractEdit = (from mainContract in xmDataCont.Tbl_mainContract where mainContract.MainContractId == mainContractId select mainContract).First(); int projectTagId = mainContractEdit.ProjectTagId; //int projectTagId = int.Parse(mainContractTable.Rows[0]["projectTagId"].ToString()); var projectEdit = (from project in xmDataCont.Tbl_projectTagInfo where project.ProjectTagId == projectTagId select project).First(); projectEdit.ProjectOutAddress = projectOutAddress; try { //xmDataCont.Refresh(System.Data.Linq.RefreshMode.KeepChanges, xmDataCont.tbl_mainContract); //xmDataCont.Refresh(System.Data.Linq.RefreshMode.KeepChanges, xmDataCont.tbl_projectTagInfo); xmDataCont.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict); } catch (System.Data.Linq.ChangeConflictException cce) { string strEx = cce.Message; foreach (System.Data.Linq.ObjectChangeConflict occ in xmDataCont.ChangeConflicts) { //No database values are merged into current. occ.Resolve(System.Data.Linq.RefreshMode.KeepChanges); } xmDataCont.SubmitChanges(); } Session.Remove("ddlProjectDtS"); Session.Remove("mainContractTable"); Session.Remove("mainProductSelDs"); Response.Redirect("~/Main/contractManager/subContractEdit.aspx"); } }