private void GrdLfsM2TablesAdd() { if (ValidateFooter()) { Page.Validate("dataFooter"); if (Page.IsValid) { Guid id = new Guid(Request.QueryString["id"].ToString()); int companyId = Convert.ToInt32(Session["companyID"]); float? videoDistance = null; if(((TextBox)grdLfsM2.FooterRow.FindControl("tbxVideoDistanceFooter")).Text != "") videoDistance = Single.Parse(((TextBox)grdLfsM2.FooterRow.FindControl("tbxVideoDistanceFooter")).Text.Trim()); string clockPosition = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxClockPositionFooter")).Text.Trim() != "") clockPosition = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxClockPositionFooter")).Text.Trim(); string liveOrAbandoned = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxLiveOrAbandonedFooter")).Text.Trim() != "") liveOrAbandoned = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxLiveOrAbandonedFooter")).Text.Trim(); string distanceToCentreOfLateral = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxDistanceToCentreFooter")).Text.Trim() != "") distanceToCentreOfLateral = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxDistanceToCentreFooter")).Text.Trim(); string lateralDiameter = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxLateralDiameterFooter")).Text.Trim() != "") lateralDiameter = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxLateralDiameterFooter")).Text.Trim(); string lateralType = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxLateralTypeFooter")).Text.Trim() != "") lateralType = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxLateralTypeFooter")).Text.Trim(); string dateTimeOpened = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxTimeOpenedFooter")).Text.Trim() != "") dateTimeOpened = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxTimeOpenedFooter")).Text.Trim(); string comments = ""; if (((TextBox)grdLfsM2.FooterRow.FindControl("tbxCommentFooter")).Text.Trim() != "") comments = ((TextBox)grdLfsM2.FooterRow.FindControl("tbxCommentFooter")).Text.Trim(); string reverseSetup = ""; if (distanceToCentreOfLateral != "") { TDSLFSRecord.LFS_MASTER_AREARow lfsMasterAreaRow = tdsLfsRecord.LFS_MASTER_AREA.FindByIDCOMPANY_ID(new Guid(tbxID.Text), Convert.ToInt32(Session["companyID"])); reverseSetup = Distance.Subtract(lfsMasterAreaRow.IsActualLengthNull() ? "" : lfsMasterAreaRow.ActualLength, distanceToCentreOfLateral); } bool archived = false; bool deleted = false; bool inDatabase = false; ViewFullLengthLiningLfsM2Tables model = new ViewFullLengthLiningLfsM2Tables(viewFullLengthLiningTDS); model.Insert(id, companyId, videoDistance, clockPosition, liveOrAbandoned, distanceToCentreOfLateral, lateralDiameter, lateralType, dateTimeOpened, comments, reverseSetup, deleted, archived, inDatabase); Session.Remove("lfsM2TablesDummy"); Session["viewFullLengthLiningTDS"] = viewFullLengthLiningTDS; lfsM2Tables = viewFullLengthLiningTDS.LfsM2Tables; Session["lfsM2Tables"] = lfsM2Tables; grdLfsM2.DataBind(); grdLfsM2.PageIndex = grdLfsM2.PageCount - 1; } } }
protected void grdLfsM2_RowDeleting(object sender, GridViewDeleteEventArgs e) { Guid id = new Guid(((Label)grdLfsM2.Rows[e.RowIndex].Cells[0].FindControl("lblId")).Text); int refId = Int32.Parse(((Label)grdLfsM2.Rows[e.RowIndex].Cells[1].FindControl("lblRefId")).Text); int companyId = Int32.Parse(((Label)grdLfsM2.Rows[e.RowIndex].Cells[2].FindControl("lblCOMPANY_ID")).Text); ViewFullLengthLiningLfsM2Tables model = new ViewFullLengthLiningLfsM2Tables(viewFullLengthLiningTDS); model.Delete(id, refId, companyId); Session["viewFullLengthLiningTDS"] = viewFullLengthLiningTDS; }
protected void grdLfsM2_RowUpdating(object sender, GridViewUpdateEventArgs e) { Page.Validate("dataEdit"); if (Page.IsValid) { Guid id = new Guid(((Label)grdLfsM2.Rows[e.RowIndex].Cells[0].FindControl("lblId")).Text); int refId = Int32.Parse(((Label)grdLfsM2.Rows[e.RowIndex].Cells[1].FindControl("lblRefId")).Text); int companyId = Int32.Parse(((Label)grdLfsM2.Rows[e.RowIndex].Cells[2].FindControl("lblCOMPANY_ID")).Text); float? videoDistance = null; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxVideoDistanceEdit")).Text.Trim() != "") videoDistance = float.Parse(((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxVideoDistanceEdit")).Text.Trim()); string clockPosition = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxClockPositionEdit")).Text.Trim() != "") clockPosition = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxClockPositionEdit")).Text.Trim(); string liveOrAbandoned = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxLiveOrAbandonedEdit")).Text.Trim() != "") liveOrAbandoned = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxLiveOrAbandonedEdit")).Text.Trim(); string distanceToCentreOfLateral = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxDistanceToCentreEdit")).Text.Trim() != "") distanceToCentreOfLateral = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxDistanceToCentreEdit")).Text.Trim(); string lateralDiameter = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxLateralDiameterEdit")).Text.Trim() != "") lateralDiameter = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxLateralDiameterEdit")).Text.Trim(); string lateralType = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxLateralTypeEdit")).Text.Trim() != "") lateralType = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxLateralTypeEdit")).Text.Trim(); string dateTimeOpened = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxTimeOpenedEdit")).Text.Trim() != "") dateTimeOpened = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxTimeOpenedEdit")).Text.Trim(); string comments = ""; if (((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxCommentEdit")).Text.Trim() != "") comments = ((TextBox)grdLfsM2.Rows[e.RowIndex].Cells[3].FindControl("tbxCommentEdit")).Text.Trim(); string reverseSetup = ""; if (distanceToCentreOfLateral != "") { TDSLFSRecord.LFS_MASTER_AREARow lfsMasterAreaRow = tdsLfsRecord.LFS_MASTER_AREA.FindByIDCOMPANY_ID(new Guid(tbxID.Text), Convert.ToInt32(Session["companyID"])); reverseSetup = Distance.Subtract(lfsMasterAreaRow.IsActualLengthNull() ? "" : lfsMasterAreaRow.ActualLength, distanceToCentreOfLateral); } ViewFullLengthLiningLfsM2Tables model = new ViewFullLengthLiningLfsM2Tables(viewFullLengthLiningTDS); model.Update(id, refId, companyId, videoDistance, clockPosition, liveOrAbandoned, distanceToCentreOfLateral, lateralDiameter, lateralType, dateTimeOpened, comments, reverseSetup); Session["viewFullLengthLiningTDS"] = viewFullLengthLiningTDS; } else { e.Cancel = true; } }
// // UpdateRecord2 // // Updates the database from a typed dataset containing a row for LFS_MASTER_AREA, // and zero or more rows for LFS_M2_TABLES. // public void UpdateRecord2(TDSLFSRecord dataSet, int companyId, AddRecordTDS addRecordTDS, ViewFullLengthLiningTDS viewFullLengthLiningTDS, ViewJLinersheetTDS viewJLinersheetTDS, string tdsToWork) { //--- Prepare transaction //--- ... Open connection and start transaction dcConnection.Open(); SqlTransaction transaction2 = dcConnection.BeginTransaction(); //... Assign transaction to data adapters this.daLFSMasterArea.InsertCommand.Transaction = transaction2; this.daLFSMasterArea.UpdateCommand.Transaction = transaction2; this.daLFSMasterArea.DeleteCommand.Transaction = transaction2; this.daLFSJunctionLiner2.InsertCommand.Transaction = transaction2; this.daLFSJunctionLiner2.UpdateCommand.Transaction = transaction2; this.daLFSJunctionLiner2.DeleteCommand.Transaction = transaction2; this.daLfsMasterAreaRct.InsertCommand.Transaction = transaction2; this.daLfsMasterAreaRct.UpdateCommand.Transaction = transaction2; this.daLfsMasterAreaRct.DeleteCommand.Transaction = transaction2; this.daLfsJunctionLinerRct.InsertCommand.Transaction = transaction2; this.daLfsJunctionLinerRct.UpdateCommand.Transaction = transaction2; this.daLfsJunctionLinerRct.DeleteCommand.Transaction = transaction2; try { //Update database //... deletes daLFSJunctionLiner2.Update(dataSet.LFS_JUNCTION_LINER2.Select("", "", DataViewRowState.Deleted)); daLFSMasterArea.Update(dataSet.LFS_MASTER_AREA.Select("", "", DataViewRowState.Deleted)); //... updates daLFSJunctionLiner2.Update(dataSet.LFS_JUNCTION_LINER2.Select("", "", DataViewRowState.ModifiedCurrent)); daLFSMasterArea.Update(dataSet.LFS_MASTER_AREA.Select("", "", DataViewRowState.ModifiedCurrent)); //... inserts // Point Repairs daLFSMasterArea.Update(dataSet.LFS_MASTER_AREA.Select("", "", DataViewRowState.Added)); daLFSJunctionLiner2.Update(dataSet.LFS_JUNCTION_LINER2.Select("", "", DataViewRowState.Added)); //... record change tracking records daLfsMasterAreaRct.Update(dataSet); //--- Commit transaction transaction2.Commit(); } catch (DBConcurrencyException dBConcurrencyException) { //--- Rollback transaction transaction2.Rollback(); //--- Throw exception throw new Exception("Concurrency error: Another user already updated the data you are working on. Your operation has been cancelled.", dBConcurrencyException); } catch (SqlException sqlException) { //--- Rollback transaction transaction2.Rollback(); //--- Throw exception byte severityLevel = sqlException.Class; if (severityLevel <= 16) { throw new Exception("Low severity error. Your operation has been cancelled. SQL Error " + severityLevel + "."); } if ((severityLevel >= 17) && (severityLevel <= 19)) { throw new Exception("Mid severity error. Your operation has been cancelled. SQL Error " + severityLevel + "."); } if (severityLevel >= 20) { throw new Exception("High severity error. Your operation has been cancelled. SQL Error " + severityLevel + "."); } } catch (Exception e) { //--- Rollback transaction transaction2.Rollback(); //--- Throw exception throw new Exception("Unknow error. Your operation has been cancelled.", e); } finally { //--- Close connection if (dcConnection.State == System.Data.ConnectionState.Open) { dcConnection.Close(); } object[] array = dataSet.LFS_MASTER_AREA.Rows[0].ItemArray; Guid newId = (Guid)array.GetValue(0); if (tdsToWork == "addRecord") { AddRecordPointRepairs addRecordPointRepairs = new AddRecordPointRepairs(addRecordTDS); addRecordPointRepairs.Save(companyId, newId); } if (tdsToWork == "viewFullLengthLining") { ViewFullLengthLiningLfsM2Tables viewFullLengthLiningLfsM2Tables = new ViewFullLengthLiningLfsM2Tables(viewFullLengthLiningTDS); viewFullLengthLiningLfsM2Tables.Save(companyId, newId); } if (tdsToWork == "viewJLinersheet") { ViewJLinersheetJunctionLiner viewJLinersheetJunctionLiner = new ViewJLinersheetJunctionLiner(viewJLinersheetTDS); viewJLinersheetJunctionLiner.Save(companyId, newId); } } }