/// <summary> /// GetNewDetailId /// </summary> /// <remarks> Gets a new DetailID to insert a new lfs juntion liner record</remarks> public string GetNewDetailId(ViewJLinersheetTDS viewJLinersheetTDS) { string detailIDs = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; string newDetailID; int lastDetailIDIndex = -1; foreach (ViewJLinersheetTDS.JunctionLinerRow row in viewJLinersheetTDS.JunctionLiner) { if (row.Deleted == false) { int rowIndex = detailIDs.IndexOf(row.DetailID); if (lastDetailIDIndex < rowIndex) { lastDetailIDIndex = rowIndex; } } } if (lastDetailIDIndex < 25) { lastDetailIDIndex++; newDetailID = detailIDs[lastDetailIDIndex].ToString(); } else { newDetailID = "-1"; } return newDetailID; }
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); } } }
/// <summary> /// InitData /// </summary> protected override void InitData() { _data = new ViewJLinersheetTDS(); }
/// //////////////////////////////////////////////////////////////////////// /// EVENTS /// protected void Page_Load(object sender, System.EventArgs e) { // Register client scripts this.RegisterClientScripts(); 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."); } // Validate query string if (((string)Request.QueryString["source_page"] == null) && ((string)Request.QueryString["record_deleted"] == null)) { Response.Redirect("./../error_page.aspx?error=" + "Invalid query string in view_jlinersheet.aspx"); } // Prepare initial data Session.Remove("jlinerDummy"); lblMaxNumber.Visible = false; // If coming from navigator2.aspx or view_jlinersheet.aspx if (((string)Request.QueryString["source_page"] == "navigator2.aspx") || ((string)Request.QueryString["source_page"] == "view_jlinersheet.aspx")) { //... Get lfs master area record LFSRecordGateway lfsRecordGateway = new LFSRecordGateway(); viewJLinersheetTDS = new ViewJLinersheetTDS(); ViewJLinersheetJunctionLinerGateway viewJLinersheetJunctionLinerGateway = new ViewJLinersheetJunctionLinerGateway(viewJLinersheetTDS); viewJLinersheetJunctionLinerGateway.LoadById((Guid)Session["lfsMasterAreaId"], Convert.ToInt32(Session["companyID"])); tdsLfsRecord = lfsRecordGateway.GetRecordByIdCompanyId((Guid)Session["lfsMasterAreaId"], Convert.ToInt32(Session["companyID"])); //... Store datasets Session["tdsLfsRecord"] = tdsLfsRecord; Session["viewJLinersheetTDS"] = viewJLinersheetTDS; jliner = viewJLinersheetTDS.JunctionLiner; Session["jliner"] = jliner; } // If coming from delete_record.aspx if ((string)Request.QueryString["record_deleted"] == "false") { //... Restore dataset lfs record tdsLfsRecord = (TDSLFSRecord)Session["tdsLfsRecord"]; viewJLinersheetTDS = (ViewJLinersheetTDS)Session["viewJLinersheetTDS"]; } // ... for client CompaniesGateway companiesGateway = new CompaniesGateway(); tbxCOMPANIES_ID.Text = companiesGateway.GetName((int)tdsLfsRecord.LFS_MASTER_AREA.Rows[0]["COMPANIES_ID"], Convert.ToInt32(Session["companyID"])); // Databind Page.DataBind(); ddlMainLined.SelectedIndex = (tdsLfsRecord.LFS_MASTER_AREA[0].IsMainLinedNull()) ? 2 : ((tdsLfsRecord.LFS_MASTER_AREA[0].MainLined == "Yes") ? 0 : 1); ddlBenchingIssue.SelectedIndex = (tdsLfsRecord.LFS_MASTER_AREA[0].IsBenchingIssueNull()) ? 2 : ((tdsLfsRecord.LFS_MASTER_AREA[0].BenchingIssue == "Yes") ? 0 : 1); } else { //--- Restore dataset lfs record tdsLfsRecord = (TDSLFSRecord)Session["tdsLfsRecord"]; viewJLinersheetTDS = (ViewJLinersheetTDS)Session["viewJLinersheetTDS"]; } }