private void UpdateDatabase() { // Initialize extra data ViewFullLengthLiningTDS viewFullLengthLiningTDS = new ViewFullLengthLiningTDS(); ViewJLinersheetTDS viewJLinersheetTDS = new ViewJLinersheetTDS(); string tdsToWork = "addRecord"; // Save data int companyId = Convert.ToInt32(Session["companyID"]); LFSRecordGateway lfsRecordGateway = new LFSRecordGateway(); lfsRecordGateway.UpdateRecord2(tdsLfsRecord, companyId, addRecordTDS, viewFullLengthLiningTDS, viewJLinersheetTDS, tdsToWork); // Store datasets Session["tdsLfsRecord"] = tdsLfsRecord; Session["addRecordTDS"] = addRecordTDS; }
// // 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); } } }
/// //////////////////////////////////////////////////////////////////////// /// EVENTS /// protected void Page_Load(object sender, System.EventArgs e) { if (!IsPostBack) { //--- Security check if (!Convert.ToBoolean(Session["sgLFS_APP_VIEW"])) { Response.Redirect("./../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } // Prepare initial Session.Remove("lfsM2TablesDummy"); //... Restore data set lfs record tdsLfsRecord = (TDSLFSRecord)Session["tdsLfsRecord"]; // ... for client CompaniesGateway companiesGateway = new CompaniesGateway(); tbxCOMPANIES_ID.Text = companiesGateway.GetName((int)tdsLfsRecord.LFS_MASTER_AREA.Rows[0]["COMPANIES_ID"], Convert.ToInt32(Session["companyID"])); // ... for measurement type LFSMeasurementTypeGateway lfsMeasurementTypeGateway = new LFSMeasurementTypeGateway(); DataSet dsLfsMeasurementType = lfsMeasurementTypeGateway.GetLFSMeasurementTypeForDropDownList(""); ddlMeasurementType.DataSource = dsLfsMeasurementType; ddlMeasurementType.DataTextField = "MeasurementType"; // Load LfsM2Tables data int companyId = Convert.ToInt32(Session["companyID"]); Guid id = new Guid(Request.QueryString["id"].ToString()); hdfId.Value = Request.QueryString["id"].ToString(); viewFullLengthLiningTDS = new ViewFullLengthLiningTDS(); ViewFullLengthLiningLfsM2TablesGateway viewFullLengthLiningLfsM2TablesGateway = new ViewFullLengthLiningLfsM2TablesGateway(viewFullLengthLiningTDS); viewFullLengthLiningLfsM2TablesGateway.LoadById(id, companyId); Session["viewFullLengthLiningTDS"] = viewFullLengthLiningTDS; lfsM2Tables = viewFullLengthLiningTDS.LfsM2Tables; Session["lfsM2Tables"] = lfsM2Tables; // Databind Page.DataBind(); TDSLFSRecord.LFS_MASTER_AREARow lfsMasterAreaRow = tdsLfsRecord.LFS_MASTER_AREA.FindByIDCOMPANY_ID(new Guid(tbxID.Text), Convert.ToInt32(Session["companyID"])); ddlMeasurementType.SelectedValue = (lfsMasterAreaRow.IsMeasurementTypeNull()) ? "" : lfsMasterAreaRow.MeasurementType; } else { // Restore data set lfs record tdsLfsRecord = (TDSLFSRecord)Session["tdsLfsRecord"]; viewFullLengthLiningTDS = (ViewFullLengthLiningTDS)Session["viewFullLengthLiningTDS"]; } }
/// <summary> /// InitData /// </summary> protected override void InitData() { _data = new ViewFullLengthLiningTDS(); }