示例#1
0
        Int64 IMDAssetCateogryDataAccess.Add(MDAssetCateogryEntity mDAssetCateogryEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private MDAssetCateogryEntity BuildMDAssetCateogryEntity()
        {
            MDAssetCateogryEntity mDAssetCateogryEntity = CurrentMDAssetCateogryEntity;

            mDAssetCateogryEntity.CategoryName = txtCategoryName.Text.Trim();
            mDAssetCateogryEntity.Description  = txtDescription.Text.Trim();
            mDAssetCateogryEntity.IsRemoved    = chkIsRemoved.Checked;

            return(mDAssetCateogryEntity);
        }
示例#3
0
        private Int64 UpdateTran(MDAssetCateogryEntity mDAssetCateogryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDAssetCateogry_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, "@AssetCateogryID", DbType.Int64, mDAssetCateogryEntity.AssetCateogryID);
                db.AddInParameter(cmd, "@ParentAssetCateogryID", DbType.Int64, mDAssetCateogryEntity.ParentAssetCateogryID);
                db.AddInParameter(cmd, "@CategoryName", DbType.String, mDAssetCateogryEntity.CategoryName);
                db.AddInParameter(cmd, "@Description", DbType.String, mDAssetCateogryEntity.Description);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDAssetCateogryEntity.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 PrepareEditView()
        {
            MDAssetCateogryEntity mDAssetCateogryEntity = CurrentMDAssetCateogryEntity;


            if (!mDAssetCateogryEntity.IsNew)
            {
                txtCategoryName.Text = mDAssetCateogryEntity.CategoryName.ToString();
                txtDescription.Text  = mDAssetCateogryEntity.Description.ToString();
                chkIsRemoved.Checked = mDAssetCateogryEntity.IsRemoved;

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        protected void lvMDAssetCateogry_ItemCommand(object sender, ListViewCommandEventArgs e)
        {
            Int64 AssetCateogryID;

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

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

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

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(MDAssetCateogryEntity.FLD_NAME_AssetCateogryID, AssetCateogryID.ToString(), SQLMatchType.Equal);

                        MDAssetCateogryEntity mDAssetCateogryEntity = new MDAssetCateogryEntity();


                        result = FCCMDAssetCateogry.GetFacadeCreate().Delete(mDAssetCateogryEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _AssetCateogryID       = 0;
                            _MDAssetCateogryEntity = new MDAssetCateogryEntity();
                            PrepareInitialView();
                            BindMDAssetCateogryList();

                            MiscUtil.ShowMessage(lblMessage, "Asset Cateogry has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete Asset Cateogry.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
示例#6
0
        private Int64 Update(MDAssetCateogryEntity mDAssetCateogryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDAssetCateogry_SET";

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

                Database.AddInParameter(cmd, "@AssetCateogryID", DbType.Int64, mDAssetCateogryEntity.AssetCateogryID);
                Database.AddInParameter(cmd, "@ParentAssetCateogryID", DbType.Int64, mDAssetCateogryEntity.ParentAssetCateogryID);
                Database.AddInParameter(cmd, "@CategoryName", DbType.String, mDAssetCateogryEntity.CategoryName);
                Database.AddInParameter(cmd, "@Description", DbType.String, mDAssetCateogryEntity.Description);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDAssetCateogryEntity.IsRemoved);

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

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

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

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

            return(returnCode);
        }
        private void DeleteItemCategory()
        {
            Int64 AssetCategoryID;

            Int64.TryParse(treeAssetCategory.SelectedValue, out AssetCategoryID);

            if (AssetCategoryID > 0)
            {
                try
                {
                    Int64 result = -1;

                    String fe = SqlExpressionBuilder.PrepareFilterExpression(MDAssetCateogryEntity.FLD_NAME_AssetCateogryID, AssetCategoryID.ToString(), SQLMatchType.Equal);

                    MDAssetCateogryEntity mDAssetCateogryEntity = new MDAssetCateogryEntity();


                    result = FCCMDAssetCateogry.GetFacadeCreate().Delete(mDAssetCateogryEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                    if (result == 0)
                    {
                        _AssetCateogryID       = 0;
                        _MDAssetCateogryEntity = new MDAssetCateogryEntity();

                        PrepareInitialView();

                        LoadTreeView();

                        MiscUtil.ShowMessage(lblMessage, "Asset Category has been successfully deleted.", true);
                    }
                    else
                    {
                        MiscUtil.ShowMessage(lblMessage, "Failed to delete Asset Category.", true);
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
示例#8
0
 Int64 IMDAssetCateogryFacade.Delete(MDAssetCateogryEntity mDAssetCateogryEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDAssetCateogryDataAccess().Delete(mDAssetCateogryEntity, filterExpression, option, reqTran));
 }
示例#9
0
 Int64 IMDAssetCateogryFacade.Add(MDAssetCateogryEntity mDAssetCateogryEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDAssetCateogryDataAccess().Add(mDAssetCateogryEntity, option, reqTran));
 }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _AssetCateogryID       = 0;
     _MDAssetCateogryEntity = new MDAssetCateogryEntity();
     PrepareInitialView();
 }
        private void SaveMDAssetCateogryEntity()
        {
            if (IsValid)
            {
                try
                {
                    MDAssetCateogryEntity mDAssetCateogryEntity = BuildMDAssetCateogryEntity();

                    Int64 result = -1;

                    if (mDAssetCateogryEntity.IsNew)
                    {
                        if (treeAssetCategory.SelectedNode != null)
                        {
                            if (treeAssetCategory.SelectedValue == "0")
                            {
                                mDAssetCateogryEntity.ParentAssetCateogryID = null;
                            }
                            else
                            {
                                mDAssetCateogryEntity.ParentAssetCateogryID = Int64.Parse(treeAssetCategory.SelectedValue);
                            }
                        }

                        result = FCCMDAssetCateogry.GetFacadeCreate().Add(mDAssetCateogryEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(MDAssetCateogryEntity.FLD_NAME_AssetCateogryID, mDAssetCateogryEntity.AssetCateogryID.ToString(), SQLMatchType.Equal);
                        result = FCCMDAssetCateogry.GetFacadeCreate().Update(mDAssetCateogryEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _AssetCateogryID       = 0;
                        _MDAssetCateogryEntity = new MDAssetCateogryEntity();
                        PrepareInitialView();
                        LoadTreeView();

                        if (mDAssetCateogryEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Asset Cateogry Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Asset Cateogry Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (mDAssetCateogryEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Asset Cateogry Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Asset Cateogry Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }