Exemple #1
0
        Int64 IMDItemCategoryDataAccess.Add(MDItemCategoryEntity mDItemCategoryEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemple #2
0
        Int64 IMDItemCategoryDataAccess.Delete(MDItemCategoryEntity mDItemCategoryEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private MDItemCategoryEntity BuildMDItemCategoryEntity()
        {
            MDItemCategoryEntity mDItemCategoryEntity = CurrentMDItemCategoryEntity;

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


            return(mDItemCategoryEntity);
        }
Exemple #4
0
        private Int64 UpdateTran(MDItemCategoryEntity mDItemCategoryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDItemCategory_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, "@ItemCategoryID", DbType.Int64, mDItemCategoryEntity.ItemCategoryID);
                db.AddInParameter(cmd, "@ParentItemCategoryID", DbType.Int64, mDItemCategoryEntity.ParentItemCategoryID);
                db.AddInParameter(cmd, "@CategoryName", DbType.String, mDItemCategoryEntity.CategoryName);
                db.AddInParameter(cmd, "@Description", DbType.String, mDItemCategoryEntity.Description);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDItemCategoryEntity.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()
        {
            MDItemCategoryEntity mDItemCategoryEntity = CurrentMDItemCategoryEntity;


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

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        private void DeleteItemCategory()
        {
            Int64 ItemCategoryID;

            Int64.TryParse(treeItemCategory.SelectedValue, out ItemCategoryID);

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

                    String fe = SqlExpressionBuilder.PrepareFilterExpression(MDItemCategoryEntity.FLD_NAME_ItemCategoryID, ItemCategoryID.ToString(), SQLMatchType.Equal);

                    MDItemCategoryEntity mDItemCategoryEntity = new MDItemCategoryEntity();


                    result = FCCMDItemCategory.GetFacadeCreate().Delete(mDItemCategoryEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                    if (result == 0)
                    {
                        _ItemCategoryID       = 0;
                        _MDItemCategoryEntity = new MDItemCategoryEntity();

                        // clearing cache
                        FCCMDItemCategory.GetFacadeCreate().RemoveCache();

                        PrepareInitialView();

                        LoadTreeView();

                        MiscUtil.ShowMessage(lblMessage, "Item Category has been successfully deleted.", true);
                    }
                    else
                    {
                        MiscUtil.ShowMessage(lblMessage, "Failed to delete Item Category.", true);
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
Exemple #7
0
        private Int64 Update(MDItemCategoryEntity mDItemCategoryEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.MDItemCategory_SET";

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

                Database.AddInParameter(cmd, "@ItemCategoryID", DbType.Int64, mDItemCategoryEntity.ItemCategoryID);
                Database.AddInParameter(cmd, "@ParentItemCategoryID", DbType.Int64, mDItemCategoryEntity.ParentItemCategoryID);
                Database.AddInParameter(cmd, "@CategoryName", DbType.String, mDItemCategoryEntity.CategoryName);
                Database.AddInParameter(cmd, "@Description", DbType.String, mDItemCategoryEntity.Description);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, mDItemCategoryEntity.IsRemoved);

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

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

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

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

            return(returnCode);
        }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _ItemCategoryID       = 0;
     _MDItemCategoryEntity = new MDItemCategoryEntity();
     PrepareInitialView();
 }
        private void SaveMDItemCategoryEntity()
        {
            if (IsValid)
            {
                try
                {
                    MDItemCategoryEntity mDItemCategoryEntity = BuildMDItemCategoryEntity();

                    Int64 result = -1;

                    if (mDItemCategoryEntity.IsNew)
                    {
                        if (treeItemCategory.SelectedNode != null)
                        {
                            if (treeItemCategory.SelectedValue == "0")
                            {
                                mDItemCategoryEntity.ParentItemCategoryID = null;
                            }
                            else
                            {
                                mDItemCategoryEntity.ParentItemCategoryID = Int64.Parse(treeItemCategory.SelectedValue);
                            }
                        }

                        result = FCCMDItemCategory.GetFacadeCreate().Add(mDItemCategoryEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(MDItemCategoryEntity.FLD_NAME_ItemCategoryID, mDItemCategoryEntity.ItemCategoryID.ToString(), SQLMatchType.Equal);
                        result = FCCMDItemCategory.GetFacadeCreate().Update(mDItemCategoryEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _ItemCategoryID       = 0;
                        _MDItemCategoryEntity = new MDItemCategoryEntity();

                        // clearing cache
                        FCCMDItemCategory.GetFacadeCreate().RemoveCache();

                        PrepareInitialView();

                        LoadTreeView();

                        if (mDItemCategoryEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Item Category Information has been added successfully.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Item Category Information has been updated successfully.", false);
                        }
                    }
                    else
                    {
                        if (mDItemCategoryEntity.IsNew)
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to add Item Category Information.", false);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to update Item Category Information.", false);
                        }
                    }
                }
                catch (Exception ex)
                {
                    MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                }
            }
        }
 Int64 IMDItemCategoryFacade.Delete(MDItemCategoryEntity mDItemCategoryEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDItemCategoryDataAccess().Delete(mDItemCategoryEntity, filterExpression, option, reqTran));
 }
 Int64 IMDItemCategoryFacade.Add(MDItemCategoryEntity mDItemCategoryEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateMDItemCategoryDataAccess().Add(mDItemCategoryEntity, option, reqTran));
 }