Int64 IBDProjectSubstationAndGeneratorDataAccess.Add(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(bDProjectSubstationAndGeneratorEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(bDProjectSubstationAndGeneratorEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private Int64 UpdateTran(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDProjectSubstationAndGenerator_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option, db); AddOutputParameter(cmd, db); AddFilterExpressionParameter(cmd, filterExpression, db); db.AddInParameter(cmd, "@ProjectSubstationAndGeneratorID", DbType.Int64, bDProjectSubstationAndGeneratorEntity.ProjectSubstationAndGeneratorID); db.AddInParameter(cmd, "@ProjectID", DbType.Int64, bDProjectSubstationAndGeneratorEntity.ProjectID); db.AddInParameter(cmd, "@CapacityOfSubstation", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfSubstation); db.AddInParameter(cmd, "@TotalNumberOfGenerator", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.TotalNumberOfGenerator); db.AddInParameter(cmd, "@CapacityOfGenerator1", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator1); db.AddInParameter(cmd, "@CapacityOfGenerator2", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator2); db.AddInParameter(cmd, "@CapacityOfGenerator3", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator3); db.AddInParameter(cmd, "@CapacityOfGenerator4", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator4); db.AddInParameter(cmd, "@CapacityOfGenerator5", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator5); db.AddInParameter(cmd, "@BrandID", DbType.Int64, bDProjectSubstationAndGeneratorEntity.BrandID); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (IDataReader reader = db.ExecuteReader(cmd, transaction)) { returnCode = GetReturnCodeFromParameter(cmd); } if (returnCode > 0) { transaction.Commit(); } else { throw new ArgumentException("Error Code." + returnCode.ToString()); } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); connection.Close(); connection = null; } } return(returnCode); }
private void SaveBDProjectSubstationAndGeneratorEntity() { if (IsValid) { try { BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity = BuildBDProjectSubstationAndGeneratorEntity(); Int64 result = -1; if (bDProjectSubstationAndGeneratorEntity.IsNew) { result = FCCBDProjectSubstationAndGenerator.GetFacadeCreate().Add(bDProjectSubstationAndGeneratorEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(BDProjectSubstationAndGeneratorEntity.FLD_NAME_ProjectSubstationAndGeneratorID, bDProjectSubstationAndGeneratorEntity.ProjectSubstationAndGeneratorID.ToString(), SQLMatchType.Equal); result = FCCBDProjectSubstationAndGenerator.GetFacadeCreate().Update(bDProjectSubstationAndGeneratorEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _ProjectSubstationAndGeneratorID = 0; _BDProjectSubstationAndGeneratorEntity = new BDProjectSubstationAndGeneratorEntity(); PrepareInitialView(); PrepareEditView(); BindBDProjectSubstationAndGeneratorList(); if (bDProjectSubstationAndGeneratorEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Project Substation And Generator Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Project Substation And Generator Information has been updated successfully.", false); } } else { if (bDProjectSubstationAndGeneratorEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Project Substation And Generator Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Project Substation And Generator Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private Int64 DeleteTran(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDProjectSubstationAndGenerator_SET"; Database db = DatabaseFactory.CreateDatabase(); using (DbCommand cmd = db.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd, db); AddFilterExpressionParameter(cmd, filterExpression, db); DbConnection connection = db.CreateConnection(); connection.Open(); DbTransaction transaction = connection.BeginTransaction(); try { using (IDataReader reader = db.ExecuteReader(cmd, transaction)) { returnCode = GetReturnCodeFromParameter(cmd); } if (returnCode >= 0) { transaction.Commit(); } else { throw new ArgumentException("Error Code." + returnCode.ToString()); } } catch (Exception ex) { transaction.Rollback(); throw ex; } finally { transaction.Dispose(); connection.Close(); connection = null; } } return(returnCode); }
private Int64 Update(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDProjectSubstationAndGenerator_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@ProjectSubstationAndGeneratorID", DbType.Int64, bDProjectSubstationAndGeneratorEntity.ProjectSubstationAndGeneratorID); Database.AddInParameter(cmd, "@ProjectID", DbType.Int64, bDProjectSubstationAndGeneratorEntity.ProjectID); Database.AddInParameter(cmd, "@CapacityOfSubstation", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfSubstation); Database.AddInParameter(cmd, "@TotalNumberOfGenerator", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.TotalNumberOfGenerator); Database.AddInParameter(cmd, "@CapacityOfGenerator1", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator1); Database.AddInParameter(cmd, "@CapacityOfGenerator2", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator2); Database.AddInParameter(cmd, "@CapacityOfGenerator3", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator3); Database.AddInParameter(cmd, "@CapacityOfGenerator4", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator4); Database.AddInParameter(cmd, "@CapacityOfGenerator5", DbType.Decimal, bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator5); Database.AddInParameter(cmd, "@BrandID", DbType.Int64, bDProjectSubstationAndGeneratorEntity.BrandID); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("BDProjectSubstationAndGeneratorEntity already exists. Please specify another BDProjectSubstationAndGeneratorEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("BDProjectSubstationAndGeneratorEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("BDProjectSubstationAndGeneratorEntity already exists. Please specify another BDProjectSubstationAndGeneratorEntity."); } } } } return(returnCode); }
private Int64 Delete(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDProjectSubstationAndGenerator_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("BDProjectSubstationAndGeneratorEntity already exists. Please specify another BDProjectSubstationAndGeneratorEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("BDProjectSubstationAndGeneratorEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("BDProjectSubstationAndGeneratorEntity already exists. Please specify another BDProjectSubstationAndGeneratorEntity."); } } } } return(returnCode); }
private void PrepareEditView() { BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity = CurrentBDProjectSubstationAndGeneratorEntity; if (!bDProjectSubstationAndGeneratorEntity.IsNew) { txtCapacityOfSubstation.Text = bDProjectSubstationAndGeneratorEntity.CapacityOfSubstation.ToString(); txtTotalNumberOfGenerator.Text = bDProjectSubstationAndGeneratorEntity.TotalNumberOfGenerator.ToString(); txtCapacityOfGenerator1.Text = bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator1.ToString(); txtCapacityOfGenerator2.Text = bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator2.ToString(); txtCapacityOfGenerator3.Text = bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator3.ToString(); txtCapacityOfGenerator4.Text = bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator4.ToString(); txtCapacityOfGenerator5.Text = bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator5.ToString(); if (ddlBrandID.Items.Count > 0 && bDProjectSubstationAndGeneratorEntity.BrandID != null) { ddlBrandID.SelectedValue = bDProjectSubstationAndGeneratorEntity.BrandID.ToString(); } btnSubmit.Text = "Update"; } }
private BDProjectSubstationAndGeneratorEntity BuildBDProjectSubstationAndGeneratorEntity() { BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity = CurrentBDProjectSubstationAndGeneratorEntity; bDProjectSubstationAndGeneratorEntity.ProjectID = OverviewProjectID; if (!txtCapacityOfSubstation.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.CapacityOfSubstation = Decimal.Parse(txtCapacityOfSubstation.Text.Trim()); } if (!txtTotalNumberOfGenerator.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.TotalNumberOfGenerator = Decimal.Parse(txtTotalNumberOfGenerator.Text.Trim()); } if (!txtCapacityOfGenerator1.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator1 = Decimal.Parse(txtCapacityOfGenerator1.Text.Trim()); } if (!txtCapacityOfGenerator2.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator2 = Decimal.Parse(txtCapacityOfGenerator2.Text.Trim()); } else { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator2 = null; } if (!txtCapacityOfGenerator3.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator3 = Decimal.Parse(txtCapacityOfGenerator3.Text.Trim()); } else { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator3 = null; } if (!txtCapacityOfGenerator4.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator4 = Decimal.Parse(txtCapacityOfGenerator4.Text.Trim()); } else { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator4 = null; } if (!txtCapacityOfGenerator5.Text.Trim().IsNullOrEmpty()) { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator5 = Decimal.Parse(txtCapacityOfGenerator5.Text.Trim()); } else { bDProjectSubstationAndGeneratorEntity.CapacityOfGenerator5 = null; } if (ddlBrandID.Items.Count > 0) { if (ddlBrandID.SelectedValue == "0") { } else { bDProjectSubstationAndGeneratorEntity.BrandID = Int64.Parse(ddlBrandID.SelectedValue); } } return(bDProjectSubstationAndGeneratorEntity); }
Int64 IBDProjectSubstationAndGeneratorFacade.Delete(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateBDProjectSubstationAndGeneratorDataAccess().Delete(bDProjectSubstationAndGeneratorEntity, filterExpression, option, reqTran)); }
Int64 IBDProjectSubstationAndGeneratorFacade.Add(BDProjectSubstationAndGeneratorEntity bDProjectSubstationAndGeneratorEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateBDProjectSubstationAndGeneratorDataAccess().Add(bDProjectSubstationAndGeneratorEntity, option, reqTran)); }