Int64 IMDDepartmentDataAccess.Add(MDDepartmentEntity mDDepartmentEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Add(mDDepartmentEntity, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = AddTran(mDDepartmentEntity, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        Int64 IMDDepartmentDataAccess.Delete(MDDepartmentEntity mDDepartmentEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Delete(mDDepartmentEntity, filterExpression, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = DeleteTran(mDDepartmentEntity, filterExpression, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private MDDepartmentEntity BuildMDDepartmentEntity()
        {
            MDDepartmentEntity mDDepartmentEntity = CurrentMDDepartmentEntity;

            if (ddlParentDepartmentID.Items.Count > 0)
            {
                if (ddlParentDepartmentID.SelectedValue == "0")
                {
                    mDDepartmentEntity.ParentDepartmentID = null;
                }
                else
                {
                    mDDepartmentEntity.ParentDepartmentID = Int64.Parse(ddlParentDepartmentID.SelectedValue);
                }
            }

            mDDepartmentEntity.DepartmentCode = txtDepartmentCode.Text.Trim();
            mDDepartmentEntity.Name           = txtName.Text.Trim();
            mDDepartmentEntity.Location       = txtLocation.Text.Trim();
            if (!txtHODEmployeeID.Text.Trim().IsNullOrEmpty())
            {
                mDDepartmentEntity.HODEmployeeID = Int64.Parse(txtHODEmployeeID.Text.Trim());
            }
            else
            {
                mDDepartmentEntity.HODEmployeeID = null;
            }

            mDDepartmentEntity.IsRemoved = chkIsRemoved.Checked;


            return(mDDepartmentEntity);
        }
        private Int64 UpdateTran(MDDepartmentEntity mDDepartmentEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDDepartment_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, "@DepartmentID", DbType.Int64, mDDepartmentEntity.DepartmentID);
                db.AddInParameter(cmd, "@ParentDepartmentID", DbType.Int64, mDDepartmentEntity.ParentDepartmentID);
                db.AddInParameter(cmd, "@DepartmentCode", DbType.String, mDDepartmentEntity.DepartmentCode);
                db.AddInParameter(cmd, "@Name", DbType.String, mDDepartmentEntity.Name);
                db.AddInParameter(cmd, "@Location", DbType.String, mDDepartmentEntity.Location);
                db.AddInParameter(cmd, "@HODEmployeeID", DbType.Int64, mDDepartmentEntity.HODEmployeeID);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDDepartmentEntity.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 void SaveMDDepartmentEntity()
        {
            if (IsValid)
            {
                try
                {
                    MDDepartmentEntity mDDepartmentEntity = BuildMDDepartmentEntity();

                    Int64 result = -1;

                    if (mDDepartmentEntity.IsNew)
                    {
                        result = FCCMDDepartment.GetFacadeCreate().Add(mDDepartmentEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(MDDepartmentEntity.FLD_NAME_DepartmentID, mDDepartmentEntity.DepartmentID.ToString(), SQLMatchType.Equal);
                        result = FCCMDDepartment.GetFacadeCreate().Update(mDDepartmentEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _DepartmentID       = 0;
                        _MDDepartmentEntity = new MDDepartmentEntity();
                        PrepareInitialView();
                        BindMDDepartmentList();

                        if (mDDepartmentEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Department Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Department Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (mDDepartmentEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Department Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Department Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
        protected void lvMDDepartment_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 DepartmentID;

            Int64.TryParse(e.CommandArgument.ToString(), out DepartmentID);

            if (DepartmentID > 0)
            {
                if (string.Equals(e.CommandName, "EditItem"))
                {
                    _DepartmentID = DepartmentID;

                    PrepareEditView();

                    cpeEditor.Collapsed   = false;
                    cpeEditor.ClientState = "false";
                }
                else if (string.Equals(e.CommandName, "DeleteItem"))
                {
                    try
                    {
                        Int64 result = -1;

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(MDDepartmentEntity.FLD_NAME_DepartmentID, DepartmentID.ToString(), SQLMatchType.Equal);

                        MDDepartmentEntity mDDepartmentEntity = new MDDepartmentEntity();


                        result = FCCMDDepartment.GetFacadeCreate().Delete(mDDepartmentEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _DepartmentID       = 0;
                            _MDDepartmentEntity = new MDDepartmentEntity();
                            PrepareInitialView();
                            BindMDDepartmentList();

                            MiscUtil.ShowMessage(lblMessage, "Department has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete Department.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private Int64 DeleteTran(MDDepartmentEntity mDDepartmentEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDDepartment_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(MDDepartmentEntity mDDepartmentEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDDepartment_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);

                Database.AddInParameter(cmd, "@DepartmentID", DbType.Int64, mDDepartmentEntity.DepartmentID);
                Database.AddInParameter(cmd, "@ParentDepartmentID", DbType.Int64, mDDepartmentEntity.ParentDepartmentID);
                Database.AddInParameter(cmd, "@DepartmentCode", DbType.String, mDDepartmentEntity.DepartmentCode);
                Database.AddInParameter(cmd, "@Name", DbType.String, mDDepartmentEntity.Name);
                Database.AddInParameter(cmd, "@Location", DbType.String, mDDepartmentEntity.Location);
                Database.AddInParameter(cmd, "@HODEmployeeID", DbType.Int64, mDDepartmentEntity.HODEmployeeID);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDDepartmentEntity.IsRemoved);

                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("MDDepartmentEntity already exists. Please specify another MDDepartmentEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("MDDepartmentEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("MDDepartmentEntity already exists. Please specify another MDDepartmentEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
        private void PrepareEditView()
        {
            MDDepartmentEntity mDDepartmentEntity = CurrentMDDepartmentEntity;


            if (!mDDepartmentEntity.IsNew)
            {
                if (ddlParentDepartmentID.Items.Count > 0 && mDDepartmentEntity.ParentDepartmentID != null)
                {
                    ddlParentDepartmentID.SelectedValue = mDDepartmentEntity.ParentDepartmentID.ToString();
                }

                txtDepartmentCode.Text = mDDepartmentEntity.DepartmentCode.ToString();
                txtName.Text           = mDDepartmentEntity.Name.ToString();
                txtLocation.Text       = mDDepartmentEntity.Location.ToString();
                txtHODEmployeeID.Text  = mDDepartmentEntity.HODEmployeeID.ToString();
                chkIsRemoved.Checked   = mDDepartmentEntity.IsRemoved;

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _DepartmentID       = 0;
     _MDDepartmentEntity = new MDDepartmentEntity();
     PrepareInitialView();
 }
Beispiel #11
0
 Int64 IMDDepartmentFacade.Delete(MDDepartmentEntity mDDepartmentEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDDepartmentDataAccess().Delete(mDDepartmentEntity, filterExpression, option, reqTran));
 }
Beispiel #12
0
 Int64 IMDDepartmentFacade.Add(MDDepartmentEntity mDDepartmentEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDDepartmentDataAccess().Add(mDDepartmentEntity, option, reqTran));
 }