Int64 IMDRegionDataAccess.Delete(MDRegionEntity mDRegionEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Delete(mDRegionEntity, filterExpression, option); break; } case TransactionRequired.Yes: { retValues = DeleteTran(mDRegionEntity, filterExpression, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
Int64 IMDRegionDataAccess.Add(MDRegionEntity mDRegionEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(mDRegionEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(mDRegionEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private MDRegionEntity BuildMDRegionEntity() { MDRegionEntity mDRegionEntity = CurrentMDRegionEntity; mDRegionEntity.Name = txtName.Text.Trim(); mDRegionEntity.IsRemoved = chkIsRemoved.Checked; return(mDRegionEntity); }
private void SaveMDRegionEntity() { if (IsValid) { try { MDRegionEntity mDRegionEntity = BuildMDRegionEntity(); Int64 result = -1; if (mDRegionEntity.IsNew) { result = FCCMDRegion.GetFacadeCreate().Add(mDRegionEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(MDRegionEntity.FLD_NAME_RegionID, mDRegionEntity.RegionID.ToString(), SQLMatchType.Equal); result = FCCMDRegion.GetFacadeCreate().Update(mDRegionEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _RegionID = 0; _MDRegionEntity = new MDRegionEntity(); PrepareInitialView(); BindMDRegionList(); if (mDRegionEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Region Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Region Information has been updated successfully.", false); } } else { if (mDRegionEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Region Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Region Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private Int64 UpdateTran(MDRegionEntity mDRegionEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.MDRegion_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, "@RegionID", DbType.Int64, mDRegionEntity.RegionID); db.AddInParameter(cmd, "@Name", DbType.String, mDRegionEntity.Name); db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDRegionEntity.IsRemoved); 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); }
protected void lvMDRegion_ItemCommand(object sender, ListViewCommandEventArgs e) { Int64 RegionID; Int64.TryParse(e.CommandArgument.ToString(), out RegionID); if (RegionID > 0) { if (string.Equals(e.CommandName, "EditItem")) { _RegionID = RegionID; PrepareEditView(); cpeEditor.Collapsed = false; cpeEditor.ClientState = "false"; } else if (string.Equals(e.CommandName, "DeleteItem")) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(MDRegionEntity.FLD_NAME_RegionID, RegionID.ToString(), SQLMatchType.Equal); MDRegionEntity mDRegionEntity = new MDRegionEntity(); result = FCCMDRegion.GetFacadeCreate().Delete(mDRegionEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _RegionID = 0; _MDRegionEntity = new MDRegionEntity(); PrepareInitialView(); BindMDRegionList(); MiscUtil.ShowMessage(lblMessage, "Region has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete Region.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } } }
private void PrepareEditView() { MDRegionEntity mDRegionEntity = CurrentMDRegionEntity; if (!mDRegionEntity.IsNew) { txtName.Text = mDRegionEntity.Name.ToString(); chkIsRemoved.Checked = mDRegionEntity.IsRemoved; btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
private Int64 Update(MDRegionEntity mDRegionEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.MDRegion_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@RegionID", DbType.Int64, mDRegionEntity.RegionID); Database.AddInParameter(cmd, "@Name", DbType.String, mDRegionEntity.Name); Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDRegionEntity.IsRemoved); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("MDRegionEntity already exists. Please specify another MDRegionEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("MDRegionEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("MDRegionEntity already exists. Please specify another MDRegionEntity."); } } } } return(returnCode); }
Int64 IMDRegionFacade.Delete(MDRegionEntity mDRegionEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateMDRegionDataAccess().Delete(mDRegionEntity, filterExpression, option, reqTran)); }
Int64 IMDRegionFacade.Add(MDRegionEntity mDRegionEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateMDRegionDataAccess().Add(mDRegionEntity, option, reqTran)); }
protected void btnAddNew_Click(object sender, EventArgs e) { _RegionID = 0; _MDRegionEntity = new MDRegionEntity(); PrepareInitialView(); }