Int64 IBDMDTaskCategoryDataAccess.Add(BDMDTaskCategoryEntity bDMDTaskCategoryEntity, DatabaseOperationType option, TransactionRequired reqTran) { try { long retValues = -99; switch (reqTran) { case TransactionRequired.No: { retValues = Add(bDMDTaskCategoryEntity, option); break; } case TransactionRequired.Yes: { retValues = AddTran(bDMDTaskCategoryEntity, option); break; } default: { retValues = -99; break; } } return(retValues); } catch (Exception ex) { throw ex; } }
private Int64 UpdateTran(BDMDTaskCategoryEntity bDMDTaskCategoryEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDMDTaskCategory_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, "@TaskCategoryID", DbType.Int64, bDMDTaskCategoryEntity.TaskCategoryID); db.AddInParameter(cmd, "@ParentTaskCategoryID", DbType.Int64, bDMDTaskCategoryEntity.ParentTaskCategoryID); db.AddInParameter(cmd, "@DepartmentID", DbType.Int64, bDMDTaskCategoryEntity.DepartmentID); db.AddInParameter(cmd, "@Name", DbType.String, bDMDTaskCategoryEntity.Name); db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, bDMDTaskCategoryEntity.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); }
private Int64 Update(BDMDTaskCategoryEntity bDMDTaskCategoryEntity, String filterExpression, DatabaseOperationType option) { long returnCode = -99; const string SP = "dbo.BDMDTaskCategory_SET"; using (DbCommand cmd = Database.GetStoredProcCommand(SP)) { AddOptionParameter(cmd, option); AddOutputParameter(cmd); AddFilterExpressionParameter(cmd, filterExpression); Database.AddInParameter(cmd, "@TaskCategoryID", DbType.Int64, bDMDTaskCategoryEntity.TaskCategoryID); Database.AddInParameter(cmd, "@ParentTaskCategoryID", DbType.Int64, bDMDTaskCategoryEntity.ParentTaskCategoryID); Database.AddInParameter(cmd, "@DepartmentID", DbType.Int64, bDMDTaskCategoryEntity.DepartmentID); Database.AddInParameter(cmd, "@Name", DbType.String, bDMDTaskCategoryEntity.Name); Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, bDMDTaskCategoryEntity.IsRemoved); using (IDataReader reader = Database.ExecuteReader(cmd)) { returnCode = GetReturnCodeFromParameter(cmd); switch (returnCode) { case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST: { throw new ArgumentException("BDMDTaskCategoryEntity already exists. Please specify another BDMDTaskCategoryEntity."); } case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION: { throw new ArgumentException("BDMDTaskCategoryEntity data already updated from different session."); } case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION: { throw new ArgumentException("BDMDTaskCategoryEntity already exists. Please specify another BDMDTaskCategoryEntity."); } } } } return(returnCode); }
private void PrepareEditView() { BDMDTaskCategoryEntity bDMDTaskCategoryEntity = CurrentBDMDTaskCategoryEntity; if (!bDMDTaskCategoryEntity.IsNew) { if (ddlDepartmentID.Items.Count > 0 && bDMDTaskCategoryEntity.DepartmentID != null) { ddlDepartmentID.SelectedValue = bDMDTaskCategoryEntity.DepartmentID.ToString(); } txtName.Text = bDMDTaskCategoryEntity.Name.ToString(); chkIsRemoved.Checked = bDMDTaskCategoryEntity.IsRemoved; btnSubmit.Text = "Update"; btnAddNew.Visible = true; } }
private void DeleteTaskCategory() { Int64 taskCategoryID; Int64.TryParse(treeTaskCategory.SelectedValue, out taskCategoryID); if (taskCategoryID > 0) { try { Int64 result = -1; String fe = SqlExpressionBuilder.PrepareFilterExpression(BDMDTaskCategoryEntity.FLD_NAME_TaskCategoryID, taskCategoryID.ToString(), SQLMatchType.Equal); BDMDTaskCategoryEntity bDMDTaskCategoryEntity = new BDMDTaskCategoryEntity(); result = FCCBDMDTaskCategory.GetFacadeCreate().Delete(bDMDTaskCategoryEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No); if (result == 0) { _TaskCategoryID = 0; _BDMDTaskCategoryEntity = new BDMDTaskCategoryEntity(); PrepareInitialView(); LoadTreeView(); MiscUtil.ShowMessage(lblMessage, "Task Category has been successfully deleted.", true); } else { MiscUtil.ShowMessage(lblMessage, "Failed to delete Task Category.", true); } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }
private BDMDTaskCategoryEntity BuildBDMDTaskCategoryEntity() { BDMDTaskCategoryEntity bDMDTaskCategoryEntity = CurrentBDMDTaskCategoryEntity; if (ddlDepartmentID.Items.Count > 0) { if (ddlDepartmentID.SelectedValue == "0") { bDMDTaskCategoryEntity.DepartmentID = null; } else { bDMDTaskCategoryEntity.DepartmentID = Int64.Parse(ddlDepartmentID.SelectedValue); } } bDMDTaskCategoryEntity.Name = txtName.Text.Trim(); bDMDTaskCategoryEntity.IsRemoved = chkIsRemoved.Checked; return(bDMDTaskCategoryEntity); }
Int64 IBDMDTaskCategoryFacade.Delete(BDMDTaskCategoryEntity bDMDTaskCategoryEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateBDMDTaskCategoryDataAccess().Delete(bDMDTaskCategoryEntity, filterExpression, option, reqTran)); }
Int64 IBDMDTaskCategoryFacade.Add(BDMDTaskCategoryEntity bDMDTaskCategoryEntity, DatabaseOperationType option, TransactionRequired reqTran) { return(DataAccessFactory.CreateBDMDTaskCategoryDataAccess().Add(bDMDTaskCategoryEntity, option, reqTran)); }
protected void btnAddNew_Click(object sender, EventArgs e) { _TaskCategoryID = 0; _BDMDTaskCategoryEntity = new BDMDTaskCategoryEntity(); PrepareInitialView(); }
private void SaveBDMDTaskCategoryEntity() { if (IsValid) { try { BDMDTaskCategoryEntity bDMDTaskCategoryEntity = BuildBDMDTaskCategoryEntity(); Int64 result = -1; if (bDMDTaskCategoryEntity.IsNew) { if (treeTaskCategory.SelectedNode != null) { if (treeTaskCategory.SelectedValue == "0") { bDMDTaskCategoryEntity.ParentTaskCategoryID = null; } else { bDMDTaskCategoryEntity.ParentTaskCategoryID = Int64.Parse(treeTaskCategory.SelectedValue); } } result = FCCBDMDTaskCategory.GetFacadeCreate().Add(bDMDTaskCategoryEntity, DatabaseOperationType.Add, TransactionRequired.No); } else { String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(BDMDTaskCategoryEntity.FLD_NAME_TaskCategoryID, bDMDTaskCategoryEntity.TaskCategoryID.ToString(), SQLMatchType.Equal); result = FCCBDMDTaskCategory.GetFacadeCreate().Update(bDMDTaskCategoryEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No); } if (result > 0) { _TaskCategoryID = 0; _BDMDTaskCategoryEntity = new BDMDTaskCategoryEntity(); PrepareInitialView(); LoadTreeView(); if (bDMDTaskCategoryEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Task Category Information has been added successfully.", false); } else { MiscUtil.ShowMessage(lblMessage, "Task Category Information has been updated successfully.", false); } } else { if (bDMDTaskCategoryEntity.IsNew) { MiscUtil.ShowMessage(lblMessage, "Failed to add Task Category Information.", false); } else { MiscUtil.ShowMessage(lblMessage, "Failed to update Task Category Information.", false); } } } catch (Exception ex) { MiscUtil.ShowMessage(lblMessage, ex.Message, true); } } }