Int64 ICRMMDAgreementVariableDataAccess.Add(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

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

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

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

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private Int64 UpdateTran(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CRMMDAgreementVariable_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, "@AgreementVariableID", DbType.Int64, cRMMDAgreementVariableEntity.AgreementVariableID);
                db.AddInParameter(cmd, "@Name", DbType.String, cRMMDAgreementVariableEntity.Name);
                db.AddInParameter(cmd, "@Value", DbType.String, cRMMDAgreementVariableEntity.Value);
                db.AddInParameter(cmd, "@Remarks", DbType.String, cRMMDAgreementVariableEntity.Remarks);
                db.AddInParameter(cmd, "@CreatedByEmployeeID", DbType.Int64, cRMMDAgreementVariableEntity.CreatedByEmployeeID);
                db.AddInParameter(cmd, "@CreateDate", DbType.DateTime, cRMMDAgreementVariableEntity.CreateDate);
                db.AddInParameter(cmd, "@IP", DbType.String, cRMMDAgreementVariableEntity.IP);
                db.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, cRMMDAgreementVariableEntity.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 SaveCRMMDAgreementVariableEntity()
        {
            if (IsValid)
            {
                try
                {
                    CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity = BuildCRMMDAgreementVariableEntity();

                    Int64 result = -1;

                    if (cRMMDAgreementVariableEntity.IsNew)
                    {
                        result = FCCCRMMDAgreementVariable.GetFacadeCreate().Add(cRMMDAgreementVariableEntity, DatabaseOperationType.Add, TransactionRequired.No);
                    }
                    else
                    {
                        String filterExpression = SqlExpressionBuilder.PrepareFilterExpression(CRMMDAgreementVariableEntity.FLD_NAME_AgreementVariableID, cRMMDAgreementVariableEntity.AgreementVariableID.ToString(), SQLMatchType.Equal);
                        result = FCCCRMMDAgreementVariable.GetFacadeCreate().Update(cRMMDAgreementVariableEntity, filterExpression, DatabaseOperationType.Update, TransactionRequired.No);
                    }

                    if (result > 0)
                    {
                        _AgreementVariableID          = 0;
                        _CRMMDAgreementVariableEntity = new CRMMDAgreementVariableEntity();
                        PrepareInitialView();
                        BindCRMMDAgreementVariableList();

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

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

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

                    PrepareEditView();

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

                        String fe = SqlExpressionBuilder.PrepareFilterExpression(CRMMDAgreementVariableEntity.FLD_NAME_AgreementVariableID, AgreementVariableID.ToString(), SQLMatchType.Equal);

                        CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity = new CRMMDAgreementVariableEntity();


                        result = FCCCRMMDAgreementVariable.GetFacadeCreate().Delete(cRMMDAgreementVariableEntity, fe, DatabaseOperationType.Delete, TransactionRequired.No);

                        if (result == 0)
                        {
                            _AgreementVariableID          = 0;
                            _CRMMDAgreementVariableEntity = new CRMMDAgreementVariableEntity();
                            PrepareInitialView();
                            BindCRMMDAgreementVariableList();

                            MiscUtil.ShowMessage(lblMessage, "C RMAgreement Variable has been successfully deleted.", true);
                        }
                        else
                        {
                            MiscUtil.ShowMessage(lblMessage, "Failed to delete C RMAgreement Variable.", true);
                        }
                    }
                    catch (Exception ex)
                    {
                        MiscUtil.ShowMessage(lblMessage, ex.Message, true);
                    }
                }
            }
        }
        private Int64 DeleteTran(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CRMMDAgreementVariable_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 CRMMDAgreementVariableEntity BuildCRMMDAgreementVariableEntity()
        {
            CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity = CurrentCRMMDAgreementVariableEntity;

            txtName.Text = MiscUtil.DocumentVariableParsing(txtName.Text.ToString());

            cRMMDAgreementVariableEntity.Name                = txtName.Text.Trim();
            cRMMDAgreementVariableEntity.Value               = txtValue.Text.Trim();
            cRMMDAgreementVariableEntity.Remarks             = txtRemarks.Text.Trim();
            cRMMDAgreementVariableEntity.CreatedByEmployeeID = CurrentemployeeID;
            cRMMDAgreementVariableEntity.CreateDate          = System.DateTime.Now;
            cRMMDAgreementVariableEntity.IP        = MiscUtil.GetLocalIP();
            cRMMDAgreementVariableEntity.IsRemoved = chkIsRemoved.Checked;

            return(cRMMDAgreementVariableEntity);
        }
        private void PrepareEditView()
        {
            CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity = CurrentCRMMDAgreementVariableEntity;


            if (!cRMMDAgreementVariableEntity.IsNew)
            {
                txtName.Text         = cRMMDAgreementVariableEntity.Name.ToString();
                txtValue.Text        = cRMMDAgreementVariableEntity.Value.ToString();
                txtRemarks.Text      = cRMMDAgreementVariableEntity.Remarks.ToString();
                chkIsRemoved.Checked = cRMMDAgreementVariableEntity.IsRemoved;

                btnSubmit.Text    = "Update";
                btnAddNew.Visible = true;
            }
        }
        private Int64 Update(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CRMMDAgreementVariable_SET";

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

                Database.AddInParameter(cmd, "@AgreementVariableID", DbType.Int64, cRMMDAgreementVariableEntity.AgreementVariableID);
                Database.AddInParameter(cmd, "@Name", DbType.String, cRMMDAgreementVariableEntity.Name);
                Database.AddInParameter(cmd, "@Value", DbType.String, cRMMDAgreementVariableEntity.Value);
                Database.AddInParameter(cmd, "@Remarks", DbType.String, cRMMDAgreementVariableEntity.Remarks);
                Database.AddInParameter(cmd, "@CreatedByEmployeeID", DbType.Int64, cRMMDAgreementVariableEntity.CreatedByEmployeeID);
                Database.AddInParameter(cmd, "@CreateDate", DbType.DateTime, cRMMDAgreementVariableEntity.CreateDate);
                Database.AddInParameter(cmd, "@IP", DbType.String, cRMMDAgreementVariableEntity.IP);
                Database.AddInParameter(cmd, "@IsRemoved", DbType.Boolean, cRMMDAgreementVariableEntity.IsRemoved);

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

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

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

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

            return(returnCode);
        }
        private Int64 Delete(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CRMMDAgreementVariable_SET";

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


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

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

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

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

            return(returnCode);
        }
 protected void btnAddNew_Click(object sender, EventArgs e)
 {
     _AgreementVariableID          = 0;
     _CRMMDAgreementVariableEntity = new CRMMDAgreementVariableEntity();
     PrepareInitialView();
 }
 Int64 ICRMMDAgreementVariableFacade.Delete(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateCRMMDAgreementVariableDataAccess().Delete(cRMMDAgreementVariableEntity, filterExpression, option, reqTran));
 }
 Int64 ICRMMDAgreementVariableFacade.Add(CRMMDAgreementVariableEntity cRMMDAgreementVariableEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateCRMMDAgreementVariableDataAccess().Add(cRMMDAgreementVariableEntity, option, reqTran));
 }